model#

为了能实现用 Python 来操作 SDM 插件的 SavedVariables/SuperDuperMacro.lua 文件, 我们要对 .lua 文件中的代码块进行数据建模, 定义一些 Python 类来代表这些代码块, 然后实现将 Python 对象转化为 .lua 代码块的逻辑.

class wow_wtf_manager.exp.e03_wotlk_backup.sdm.model.SDMCharacter(name: str, realm: str)[source]#

代表 Character Macro 专有宏命令中关于角色信息的部分. 对应着如下代码块:

["character"] = {
    ["name"] = "charname",
    ["realm"] = "realmname",
},
class wow_wtf_manager.exp.e03_wotlk_backup.sdm.model.SDMMacroTypeEnum[source]#

枚举 SDM 宏命令的三种类型.

class wow_wtf_manager.exp.e03_wotlk_backup.sdm.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]
set_id(id: int) SDMMacro[source]#

Update it’s attributes value.

set_char(name: str, realm: str) SDMMacro[source]#

Update it’s attributes value.

is_global() bool[source]#

Is this SDM macro a global macro or character macro

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 parse_yml(content: str) SDMMacro[source]#

从人类可读写的 yaml 文件中读取数据, 创建 SDMMacro 对象.

下面是一个示例的 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
classmethod from_yaml_file(path: Path) SDMMacro[source]#

从 yaml 文件中读取数据, 创建 SDMMacro 对象.

render() str[source]#

Render the corresponding SuperDupeMacro.lua code. See example at SDMMacro.

class wow_wtf_manager.exp.e03_wotlk_backup.sdm.model.SDMLua(path_lua: Path, macros: List[SDMMacro] = _Nothing.NOTHING)[source]#

代表了 SuperDupeMacro.lua 文件的抽象. 该类只能用于将数据写入到 SuperDupeMacro.lua, 而不能从 SuperDupeMacro.lua 中读取数据.

Parameters:
  • path_lua – SuperDupeMacro.lua 文件路径.

  • macrosSDMMacro 对象的列表.

validate_macros()[source]#

Todo: add doc string

render() str[source]#

将一堆 SDMMacro 对象渲染成 SuperDupeMacro.lua 文件的内容 (只是生成内容 而不将内容写入文件). 这里面会检查 macro_list 中的 macro id 是否有重复, 如果有重复, 则会抛出异常.