Skip to content

Commit

Permalink
Update: config module
Browse files Browse the repository at this point in the history
  • Loading branch information
i0gan committed May 5, 2024
1 parent e97b4f4 commit 511b05d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/lua/test/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ local ta = Squick:GetConfig(Excel.Scene.ThisName)
PrintTable(ta)

print("Get property by id")
local t = Squick:GetConfigByID("SceneID_3")
local t = Squick:GetConfigRow(Excel.Scene.ThisName, "SceneID_3")
PrintTable(t)
19 changes: 14 additions & 5 deletions src/squick/plugin/config/element_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,16 @@ bool ElementModule::CheckRef() {
return false;
}

const std::string ElementModule::GetConfigId(const std::string& class_name, const std::string& id) {
return class_name + "_" + id;
}

// 加载属性
bool ElementModule::Load(rapidxml::xml_node<> *attrNode, std::shared_ptr<IClass> pLogicClass) {
// attrNode is the node of a object
std::string configID = attrNode->first_attribute("Id")->value();
const std::string& class_name = pLogicClass->GetClassName();
std::string id = attrNode->first_attribute("Id")->value();
std::string configID = GetConfigId(class_name, id);
if (configID.empty()) {
SQUICK_ASSERT(0, configID, __FILE__, __FUNCTION__);
return false;
Expand All @@ -208,7 +214,7 @@ bool ElementModule::Load(rapidxml::xml_node<> *attrNode, std::shared_ptr<IClass>
AddElement(configID, pElementInfo);

// can find all configid by class name
pLogicClass->AddId(configID);
pLogicClass->AddId(id);

// ElementConfigInfo* pElementInfo = CreateElement( configID, pElementInfo );
std::shared_ptr<IPropertyManager> pElementPropertyManager = pElementInfo->GetPropertyManager();
Expand Down Expand Up @@ -316,11 +322,14 @@ bool ElementModule::Load(rapidxml::xml_node<> *attrNode, std::shared_ptr<IClass>
SquickData xDataClassName;
xDataClassName.SetString(pLogicClass->GetClassName());
pElementPropertyManager->SetProperty("ClassName", xDataClassName);

SquickData xDataID;
xDataID.SetString(configID);
xDataID.SetString(id);
pElementPropertyManager->SetProperty("ID", xDataID);
pElementPropertyManager->SetProperty("ConfigID", xDataID);

SquickData xDataConfigID;
xDataConfigID.SetString(configID);
pElementPropertyManager->SetProperty("ConfigID", xDataConfigID);

return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/squick/plugin/config/element_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class ElementModule : public IElementModule, MapEx<std::string, ElementConfigInf

IElementModule *GetThreadElementModule() override;

virtual const std::string GetConfigId(const std::string& class_name, const std::string& id) override;

virtual bool LoadSceneInfo(const std::string &fileName, const std::string &className) override;

virtual bool ExistElement(const std::string &configName) override;
Expand Down
2 changes: 2 additions & 0 deletions src/squick/plugin/config/i_element_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class IElementModule : public IModule {

virtual IElementModule *GetThreadElementModule() = 0;

virtual const std::string GetConfigId(const std::string &class_name, const std::string &id) = 0;

// special
virtual bool LoadSceneInfo(const std::string &fileName, const std::string &className) = 0;

Expand Down
13 changes: 9 additions & 4 deletions src/squick/plugin/lua/lua_script_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,15 @@ LuaIntf::LuaRef LuaScriptModule::GetConfig(const string &className) {
if (xLogicClass) {
auto list = xLogicClass->GetIDList();
for (auto &id : list) {
ret[id] = GetConfigByID(id);
ret[id] = GetConfigRow(className, id);
}
}
return ret;
}

LuaIntf::LuaRef LuaScriptModule::GetConfigByID(const string &id) {
LuaIntf::LuaRef LuaScriptModule::GetConfigRowByConfigID(const string &config_id) {
LuaIntf::LuaRef ret = LuaIntf::LuaRef::createTable(mLuaContext);
auto m = m_element_->GetPropertyManager(id);
auto m = m_element_->GetPropertyManager(config_id);
if (m == nullptr) {
return ret;
}
Expand Down Expand Up @@ -489,6 +489,10 @@ LuaIntf::LuaRef LuaScriptModule::GetConfigByID(const string &id) {
return ret;
}

LuaIntf::LuaRef LuaScriptModule::GetConfigRow(const std::string& class_name, const string& id) {
return GetConfigRowByConfigID(m_element_->GetConfigId(class_name, id));
}

INT64 LuaScriptModule::GetElePropertyInt(const std::string &configName, const std::string &propertyName) {
return m_element_->GetPropertyInt(configName, propertyName);
}
Expand Down Expand Up @@ -773,7 +777,8 @@ bool LuaScriptModule::Register() {
.addFunction("ExistElementObject", &LuaScriptModule::ExistElementObject)
.addFunction("GetConfigIDList", &LuaScriptModule::GetConfigIDList)
.addFunction("GetConfig", &LuaScriptModule::GetConfig)
.addFunction("GetConfigByID", &LuaScriptModule::GetConfigByID)
.addFunction("GetConfigRowByConfigID", &LuaScriptModule::GetConfigRowByConfigID)
.addFunction("GetConfigRow", &LuaScriptModule::GetConfigRow)
.addFunction("GetElePropertyInt", &LuaScriptModule::GetElePropertyInt)
.addFunction("GetElePropertyFloat", &LuaScriptModule::GetElePropertyFloat)
.addFunction("GetElePropertyString", &LuaScriptModule::GetElePropertyString)
Expand Down
3 changes: 2 additions & 1 deletion src/squick/plugin/lua/lua_script_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class LuaScriptModule : public ILuaScriptModule {
bool ExistElementObject(const std::string &configName);
LuaIntf::LuaRef GetConfigIDList(const string &className);
LuaIntf::LuaRef GetConfig(const string &className);
LuaIntf::LuaRef GetConfigByID(const string &id);
LuaIntf::LuaRef GetConfigRowByConfigID(const string &config_id);
LuaIntf::LuaRef GetConfigRow(const std::string& class_name, const string& id);
INT64 GetElePropertyInt(const std::string &configName, const std::string &propertyName);
double GetElePropertyFloat(const std::string &configName, const std::string &propertyName);
std::string GetElePropertyString(const std::string &configName, const std::string &propertyName);
Expand Down

0 comments on commit 511b05d

Please sign in to comment.