From cb5f9f7f30fbf21d63748b873c290efa5d6abf40 Mon Sep 17 00:00:00 2001 From: "string.Empty" Date: Fri, 1 Mar 2024 01:55:45 +0800 Subject: [PATCH] feat: model alias MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 角色卡模板支持别名 移除内置的BRP模板 --- Dice/CharacterCard.cpp | 14 +++++++------- Dice/CharacterCard.h | 5 ++++- Dice/DiceConsole.h | 2 +- Dice/DiceEvent.h | 1 + Dice/DiceJS.cpp | 12 ++++++------ Dice/DiceMod.cpp | 18 +++++++++++++++--- Dice/DiceMod.h | 3 ++- Dice/GlobalVar.cpp | 1 + Dice/STLExtern.hpp | 1 + 9 files changed, 38 insertions(+), 19 deletions(-) diff --git a/Dice/CharacterCard.cpp b/Dice/CharacterCard.cpp index 9b73260d..adabef91 100644 --- a/Dice/CharacterCard.cpp +++ b/Dice/CharacterCard.cpp @@ -89,9 +89,6 @@ unordered_map PlayerErrors{ {-23,"strPCLockedWrite"}, {-24,"strPCLockedRead"}, }; -CardTemp ModelBRP{ "BRP", dict_ci<>{}, std::vector>{}, dict_ci<>{}, dict_ci<>{}, dict_ci{ - {"__DefaultDice",100} - }}; std::vector> BuildCOC7 = { {"__Name", "{}"}, {"", "3D6*5"}, @@ -114,7 +111,6 @@ CardTemp ModelCOC7{ "COC7", SkillNameReplace, BasicCOC7, mVariableCOC7, Expressi {"bg", CardPreset{COC7_BG}}, } }; dict_ci> CardModels{ - {"BRP", std::make_shared(ModelBRP),}, {"COC7", std::make_shared(ModelCOC7),}, }; @@ -134,7 +130,12 @@ int loadCardTemp(const std::filesystem::path& fpPath, dict_ci& m) { } if (auto root{ doc.FirstChildElement() }) { if (auto tp_name{ root->Attribute("name") }) { - auto& tp{ m[Text2GBK(tp_name)] }; + string model_name{ Text2GBK(tp_name) }; + auto& tp{ m[model_name] }; + tp.type = model_name; + if (auto raw_alias{ root->Attribute("alias") }) { + tp.alias = split(Text2GBK(raw_alias), "/"); + } for (auto elem = root->FirstChildElement(); elem; elem = elem->NextSiblingElement()) { if (string tag{ elem->Name()}; tag == "basic") { tp.vBasicList.clear(); @@ -228,7 +229,7 @@ void CardTemp::after_update(const ptr& eve) { ptr CharaCard::getTemplet()const{ if (string type{ get_str("__Type") }; !type.empty() && CardModels.count(type))return CardModels[type]; - return CardModels["BRP"]; + return CardModels["COC"]; } void CharaCard::update() { @@ -601,7 +602,6 @@ int Player::newCard(string& s, long long group, string type) { type = s.substr(0, Cnt); s.erase(s.begin(), s.begin() + Cnt + 1); - if (type == "COC")type = "COC7"; } else if (CardModels.count(s)) { diff --git a/Dice/CharacterCard.h b/Dice/CharacterCard.h index a44aa6c8..483a2da4 100644 --- a/Dice/CharacterCard.h +++ b/Dice/CharacterCard.h @@ -98,6 +98,9 @@ class CardTemp { public: string type; + //alias of model + vector alias; + //alias of attr dict_ci<> replaceName = {}; //ʱ vector> vBasicList = {}; @@ -186,7 +189,7 @@ class CharaCard: public AnysTable void setType(const string&); void update(); CharaCard(){ - dict["__Type"] = "COC7"; + setType("COC7"); dict["__Update"] = (long long)time(nullptr); } CharaCard(const CharaCard& pc){ diff --git a/Dice/DiceConsole.h b/Dice/DiceConsole.h index 8e819ce0..762e1e22 100644 --- a/Dice/DiceConsole.h +++ b/Dice/DiceConsole.h @@ -69,7 +69,7 @@ class Console { static const fifo_dict_ci intDefault; static const std::unordered_map confComment; //֪ͨб 1-ճ/2-¼/4-Ϣ/8-/16-û/32-㲥 - int log(const std::string& msg, int lv, const std::string& strTime = ""); + int log(const std::string& msg, int lv = 0, const std::string& strTime = ""); void log(const std::string& msg, const std::string& file); operator long long() const { return master; } void newMaster(long long); diff --git a/Dice/DiceEvent.h b/Dice/DiceEvent.h index 3c26e4c7..bba849e5 100644 --- a/Dice/DiceEvent.h +++ b/Dice/DiceEvent.h @@ -22,6 +22,7 @@ class DiceSession; //Ϣ class DiceEvent : public AnysTable { public: + MetaType getType()const override { return MetaType::Context; } chatInfo fromChat; string strLowerMessage; Chat* pGrp = nullptr; diff --git a/Dice/DiceJS.cpp b/Dice/DiceJS.cpp index 8f184ee8..4d91e856 100644 --- a/Dice/DiceJS.cpp +++ b/Dice/DiceJS.cpp @@ -741,16 +741,16 @@ int js_dice_context_get_own(JSContext* ctx, JSPropertyDescriptor* desc, JSValueC JS2OBJ(this_val); if (desc) { string key{ js_AtomtoGBK(ctx, prop) }; + console.log("context get:" + key); if (auto val{ getContextItem(obj, key) }) { desc->value = js_newAttr(ctx, val); + desc->flags = JS_PROP_C_W_E; + desc->getter = JS_UNDEFINED; + desc->setter = JS_UNDEFINED; + return TRUE; } - else return FALSE; } - else return FALSE; - desc->flags = JS_PROP_C_W_E; - desc->getter = JS_UNDEFINED; - desc->setter = JS_UNDEFINED; - return TRUE; + return FALSE; } int js_dice_context_get_keys(JSContext* ctx, JSPropertyEnum** ptab, uint32_t* plen, JSValueConst this_val) { JS2OBJ(this_val); diff --git a/Dice/DiceMod.cpp b/Dice/DiceMod.cpp index 4d83e209..08cfad0a 100644 --- a/Dice/DiceMod.cpp +++ b/Dice/DiceMod.cpp @@ -708,7 +708,7 @@ repo(std::make_shared(pathDir, url)) { fs::copy_file(pathDir / "descriptor.json", pathJson, fs::copy_options::overwrite_existing); string reason; if (!loadDesc(reason)) { - console.log(getMsg("strSelfNick") + "װװ" + mod + "ʧ:" + reason, 0); + console.log(getMsg("strSelfNick") + "װ" + mod + "ʧ:" + reason, 0); } } } @@ -863,10 +863,16 @@ void DiceMod::loadDir() { } } if (auto dirModel{ pathDir / "model" }; fs::exists(dirModel)) { - if (vector fModels; listDir(dirModel, fModels, true)) + if (vector fModels; listDir(dirModel, fModels, true)) { for (auto& p : fModels) { loadCardTemp(p, card_models); } + for (auto& [name, model] : card_models) { + for (auto& a : model.alias) { + model_alias[a] = name; + } + } + } } if (fs::exists(pathDir / "image")) { std::filesystem::create_directories(dirExe / "data" / "image"); @@ -1032,10 +1038,12 @@ void DiceModManager::build() { final_reply = {}; auto rules_new = std::make_shared(); dict_ci> models{ - {"BRP", std::make_shared(ModelBRP),}, {"COC7", std::make_shared(ModelCOC7),}, }; //merge mod + dict_ci<> model_alias{ + {"COC","COC7"}, + }; for (auto& mod : modOrder) { if (!mod->active || !mod->loaded)continue; map_merge(global_lua_scripts, mod->lua_scripts); @@ -1055,6 +1063,7 @@ void DiceModManager::build() { } ++cntModel; } + map_merge(model_alias, mod->model_alias); } //merge custom if (rules_new->build())resLog << "ע " + to_string(rules_new->rules.size()) + " "; @@ -1064,6 +1073,9 @@ void DiceModManager::build() { model->init(); } if (cntModel || CardModels.size() > 2)CardModels.swap(models); + for (auto& [alias, name] : model_alias) { + CardModels[alias] = CardModels[name]; + } if (cntSpeech += map_merge(global_speech, EditedMsg)) resLog << "עspeech " + to_string(cntSpeech) + " "; if (cntHelp += map_merge(global_helpdoc, CustomHelp)) diff --git a/Dice/DiceMod.h b/Dice/DiceMod.h index 077c992c..80669947 100644 --- a/Dice/DiceMod.h +++ b/Dice/DiceMod.h @@ -118,7 +118,8 @@ class DiceMod { private: dict_ci rules; dict_ci card_models; - dict_ci<>helpdoc; + dict_ci<> model_alias; + dict_ci<> helpdoc; dict_cispeech; //native path of .lua dict_cilua_scripts; diff --git a/Dice/GlobalVar.cpp b/Dice/GlobalVar.cpp index bc7780db..ef728bb9 100644 --- a/Dice/GlobalVar.cpp +++ b/Dice/GlobalVar.cpp @@ -515,6 +515,7 @@ const dict_ci GlobalComment{ }; const dict_ci<> HelpDoc = { {"",R"( +657:ɫģֱ֧ 656:ıת 655:stŻӴʱ 654:ɫģ diff --git a/Dice/STLExtern.hpp b/Dice/STLExtern.hpp index 7b093314..c1632cc8 100644 --- a/Dice/STLExtern.hpp +++ b/Dice/STLExtern.hpp @@ -97,6 +97,7 @@ template using dict_ci = std::unordered_map; template using multidict_ci = std::unordered_multimap; +//using uset_ci = std::unordered_set; class fifo_cmpr_ci { public: