model#
为了能实现用 Python 来操作 SDM 插件的 SavedVariables/SuperDuperMacro.lua 文件,
我们要对 .lua 文件中的代码块进行数据建模, 定义一些 Python 类来代表这些代码块, 然后实现将
Python 对象转化为 .lua 代码块的逻辑.
- class wow_sdm.exp03_wotlk.model.SdmCharacter(name: str, realm: str)[source]#
代表 Character Macro 专有宏命令中关于角色信息的部分. 对应着如下代码块:
["character"] = { ["name"] = "charname", ["realm"] = "realmname", },
- class wow_sdm.exp03_wotlk.model.SdmMacro(name: str, character: Optional[SdmCharacter] = None, type: str = 'b', id: int = 0, icon: int = 1, text: str = '')[source]#
定义了一个魔兽世界中的 SDM 宏命令的抽象, 目前只支持 Button + Global 这一种模式.
代表着如下代码块:
{ ["type"] = "f", ["name"] = "macroname", ["character"] = { ["name"] = "charname", ["realm"] = "realmname", }, ["ID"] = 1, ["text"] = "/s hello", ["icon"] = 1, }, -- [1]
- encode_text() str[source]#
Encode macro text to single-ling Lua string. The final string of the macro body in lua has to have only one line.
- classmethod from_yaml(stream) SdmMacro[source]#
从人类可读写的 yaml 文件中读取数据, 创建
SDMMacro对象. 这是我们 这个模块的最核心的方法, 也是能让我们用 yaml 文件来维护宏命令的关键.下面是一个示例的 yaml 文件.
name: interrupt character: name: realm: type: b id: # you can find icon id on https://wotlk.evowow.com/?icons icon: description: | cancel casting spell, interrupt enemy casting immediately! text: | #showtooltip /stopcasting /cast Counterspell
- Parameters:
stream – 可以是 yaml 文件的字符串内容, 也可是 yaml 的 Path 对象, 也可以是 file object 对象.
- class wow_sdm.exp03_wotlk.model.SdmLua(path_lua: ~pathlib_mate.pathlib2.Path, macros: ~typing.List[~wow_sdm.exp03_wotlk.model.SdmMacro] = <factory>)[source]#
代表了
SuperDupeMacro.lua文件的抽象. 该类只能用于将数据写入到SuperDupeMacro.lua, 而不能从SuperDupeMacro.lua中读取数据.- Parameters:
path_lua –
SuperDupeMacro.lua文件路径.macros –
SDMMacro对象的列表.