// Metin2 文本脚本(.msa / .msm / 各种 .txt)—— token 树解析。 // 语法:空白分隔 token;`key value...` 行;`Group Name { ... }` 块;`"quoted"` 串;`#` 到行尾注释。 // 照 EterBase/CTextFileLoader + EterLib CTokenVector 的效果。M2 T1。 #pragma once #include #include namespace fmt { struct Node { std::string name; // Group 名(根节点为空) std::vector> lines; // 非 Group 行:token 列表([0]=key) std::vector groups; // 子 Group // 便捷取值(在本节点的 lines 里找 key,大小写不敏感) const std::vector* find(const char* key) const; std::string str(const char* key, const std::string& def = "") const; // 取第 1 个值(去引号) float num(const char* key, float def = 0) const; int inum(const char* key, int def = 0) const; const Node* group(const char* name) const; }; // 解析整段文本。失败返回 false 并写 err。 bool parse_textscript(const std::string& text, Node& root, std::string* err); bool parse_textscript_file(const std::string& path, Node& root, std::string* err); } // namespace fmt