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.SdmMacroTypeEnum[source]#

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

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]
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 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 对象.

render() str[source]#

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

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_luaSuperDupeMacro.lua 文件路径.

  • macrosSDMMacro 对象的列表.

check_path_lua()[source]#

检查 SdmLua.path_lua 是否是 SuperDupeMacro.lua 文件.

check_macros()[source]#

检查 SdmLua.macros 中是否有重复的 macro id.

render() str[source]#

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