Skip to content

Commit

Permalink
feat: model alias
Browse files Browse the repository at this point in the history
角色卡模板支持别名
移除内置的BRP模板
  • Loading branch information
mystringEmpty committed Feb 29, 2024
1 parent f3001a5 commit cb5f9f7
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 19 deletions.
14 changes: 7 additions & 7 deletions Dice/CharacterCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ unordered_map<int, string> PlayerErrors{
{-23,"strPCLockedWrite"},
{-24,"strPCLockedRead"},
};
CardTemp ModelBRP{ "BRP", dict_ci<>{}, std::vector<std::vector<std::string>>{}, dict_ci<>{}, dict_ci<>{}, dict_ci<int>{
{"__DefaultDice",100}
}};
std::vector<std::pair<std::string, std::string>> BuildCOC7 = {
{"__Name", "{随机姓名}"},
{"力量", "3D6*5"},
Expand All @@ -114,7 +111,6 @@ CardTemp ModelCOC7{ "COC7", SkillNameReplace, BasicCOC7, mVariableCOC7, Expressi
{"bg", CardPreset{COC7_BG}},
} };
dict_ci<ptr<CardTemp>> CardModels{
{"BRP", std::make_shared<CardTemp>(ModelBRP),},
{"COC7", std::make_shared<CardTemp>(ModelCOC7),},
};

Expand All @@ -134,7 +130,12 @@ int loadCardTemp(const std::filesystem::path& fpPath, dict_ci<CardTemp>& 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();
Expand Down Expand Up @@ -228,7 +229,7 @@ void CardTemp::after_update(const ptr<AnysTable>& eve) {
ptr<CardTemp> 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() {
Expand Down Expand Up @@ -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))
{
Expand Down
5 changes: 4 additions & 1 deletion Dice/CharacterCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class CardTemp
{
public:
string type;
//alias of model
vector<string> alias;
//alias of attr
dict_ci<> replaceName = {};
//作成时生成
vector<vector<string>> vBasicList = {};
Expand Down Expand Up @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion Dice/DiceConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Console {
static const fifo_dict_ci<int> intDefault;
static const std::unordered_map<std::string, string> 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);
Expand Down
1 change: 1 addition & 0 deletions Dice/DiceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions Dice/DiceJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 15 additions & 3 deletions Dice/DiceMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ repo(std::make_shared<DiceRepo>(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);
}
}
}
Expand Down Expand Up @@ -863,10 +863,16 @@ void DiceMod::loadDir() {
}
}
if (auto dirModel{ pathDir / "model" }; fs::exists(dirModel)) {
if (vector<std::filesystem::path> fModels; listDir(dirModel, fModels, true))
if (vector<std::filesystem::path> 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");
Expand Down Expand Up @@ -1032,10 +1038,12 @@ void DiceModManager::build() {
final_reply = {};
auto rules_new = std::make_shared<DiceRuleSet>();
dict_ci<ptr<CardTemp>> models{
{"BRP", std::make_shared<CardTemp>(ModelBRP),},
{"COC7", std::make_shared<CardTemp>(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);
Expand All @@ -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()) + "";
Expand All @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion Dice/DiceMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class DiceMod {
private:
dict_ci<DiceRule> rules;
dict_ci<CardTemp> card_models;
dict_ci<>helpdoc;
dict_ci<> model_alias;
dict_ci<> helpdoc;
dict_ci<DiceSpeech>speech;
//native path of .lua
dict_ci<string>lua_scripts;
Expand Down
1 change: 1 addition & 0 deletions Dice/GlobalVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ const dict_ci<string> GlobalComment{
};
const dict_ci<> HelpDoc = {
{"更新",R"(
657:角色卡模板支持别名
656:重做文本转义
655:st优化且增加触发时点
654:重做角色卡模板
Expand Down
1 change: 1 addition & 0 deletions Dice/STLExtern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ template<typename T = std::string>
using dict_ci = std::unordered_map<string, T, hash_ci, equal_ci>;
template<typename T = std::string>
using multidict_ci = std::unordered_multimap<string, T, hash_ci, equal_ci>;
//using uset_ci = std::unordered_set<string, hash_ci, equal_ci>;

class fifo_cmpr_ci {
public:
Expand Down

0 comments on commit cb5f9f7

Please sign in to comment.