This commit is contained in:
aozhiwei 2020-12-24 11:58:22 +08:00
parent 260d18db55
commit 41062e5610
4 changed files with 23 additions and 1 deletions

View File

@ -64,6 +64,8 @@ execute_process(
COMMAND touch -a cs_proto.pb.cc
COMMAND touch -a cs_msgid.pb.h
COMMAND touch -a cs_msgid.pb.cc
COMMAND touch -a metatable.pb.h
COMMAND touch -a metatable.pb.cc
)
aux_source_directory(.
SRC_LIST
@ -80,7 +82,7 @@ add_executable(
add_custom_target(script_pb_protocol ALL)
add_custom_command(TARGET script_pb_protocol
PRE_BUILD
COMMAND python ../../third_party/tools/scripts/construct/build_pb.py --cpp_out=. --pb_files=ss_proto,ss_msgid,cs_msgid,cs_proto --python_out=../tools/robot/virtualclient
COMMAND python ../../third_party/tools/scripts/construct/build_pb.py --cpp_out=. --pb_files=ss_proto,ss_msgid,cs_msgid,cs_proto,metatable --python_out=../tools/robot/virtualclient
)
add_dependencies(friend_rankserver script_pb_protocol)

View File

@ -0,0 +1,3 @@
#pragma once
#include "metatable.pb.h"

View File

@ -21,6 +21,9 @@ class MetaDataLoader
{
public:
std::map<size_t, std::map<std::string, std::string> > dirty_words;
std::list<metatable::Text> text_meta_list;
std::map<std::string, std::string> text_hash;
void Load()
{
@ -45,7 +48,9 @@ public:
} else {
res_path = "../res/";
}
f8::ReadCsvMetaFile(res_path + "text@text.csv", text_meta_list);
LoadDirtyWordTable();
BindToMetaData();
Check();
}
@ -78,6 +83,9 @@ private:
void BindToMetaData()
{
for (auto& meta : text_meta_list) {
text_hash[meta.textid()] = meta.text();
}
}
private:
@ -121,3 +129,9 @@ bool MetaMgr::HasDirtyWord(const std::string& text)
}
return false;
}
std::string MetaMgr::GetText(const std::string& textid, const std::string& def_text)
{
auto itr = loader_->text_hash.find(textid);
return itr != loader_->text_hash.end() ? itr->second : def_text;
}

View File

@ -2,6 +2,8 @@
#include "metadata.h"
#define TEXT(textid, def_text) MetaMgr::Instance()->GetText(#textid, #def_text)
class MetaDataLoader;
class MetaMgr : public a8::Singleton<MetaMgr>
{
@ -17,6 +19,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
void Reload();
bool HasDirtyWord(const std::string& text);
std::string GetText(const std::string& textid, const std::string& def_text="");
private:
MetaDataLoader* loader_ = nullptr;