add text
This commit is contained in:
parent
260d18db55
commit
41062e5610
@ -64,6 +64,8 @@ execute_process(
|
|||||||
COMMAND touch -a cs_proto.pb.cc
|
COMMAND touch -a cs_proto.pb.cc
|
||||||
COMMAND touch -a cs_msgid.pb.h
|
COMMAND touch -a cs_msgid.pb.h
|
||||||
COMMAND touch -a cs_msgid.pb.cc
|
COMMAND touch -a cs_msgid.pb.cc
|
||||||
|
COMMAND touch -a metatable.pb.h
|
||||||
|
COMMAND touch -a metatable.pb.cc
|
||||||
)
|
)
|
||||||
aux_source_directory(.
|
aux_source_directory(.
|
||||||
SRC_LIST
|
SRC_LIST
|
||||||
@ -80,7 +82,7 @@ add_executable(
|
|||||||
add_custom_target(script_pb_protocol ALL)
|
add_custom_target(script_pb_protocol ALL)
|
||||||
add_custom_command(TARGET script_pb_protocol
|
add_custom_command(TARGET script_pb_protocol
|
||||||
PRE_BUILD
|
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)
|
add_dependencies(friend_rankserver script_pb_protocol)
|
||||||
|
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "metatable.pb.h"
|
@ -21,6 +21,9 @@ class MetaDataLoader
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::map<size_t, std::map<std::string, std::string> > dirty_words;
|
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()
|
void Load()
|
||||||
{
|
{
|
||||||
@ -45,7 +48,9 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
res_path = "../res/";
|
res_path = "../res/";
|
||||||
}
|
}
|
||||||
|
f8::ReadCsvMetaFile(res_path + "text@text.csv", text_meta_list);
|
||||||
LoadDirtyWordTable();
|
LoadDirtyWordTable();
|
||||||
|
BindToMetaData();
|
||||||
Check();
|
Check();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +83,9 @@ private:
|
|||||||
|
|
||||||
void BindToMetaData()
|
void BindToMetaData()
|
||||||
{
|
{
|
||||||
|
for (auto& meta : text_meta_list) {
|
||||||
|
text_hash[meta.textid()] = meta.text();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -121,3 +129,9 @@ bool MetaMgr::HasDirtyWord(const std::string& text)
|
|||||||
}
|
}
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
|
||||||
|
#define TEXT(textid, def_text) MetaMgr::Instance()->GetText(#textid, #def_text)
|
||||||
|
|
||||||
class MetaDataLoader;
|
class MetaDataLoader;
|
||||||
class MetaMgr : public a8::Singleton<MetaMgr>
|
class MetaMgr : public a8::Singleton<MetaMgr>
|
||||||
{
|
{
|
||||||
@ -17,6 +19,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
|
|||||||
void Reload();
|
void Reload();
|
||||||
|
|
||||||
bool HasDirtyWord(const std::string& text);
|
bool HasDirtyWord(const std::string& text);
|
||||||
|
std::string GetText(const std::string& textid, const std::string& def_text="");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MetaDataLoader* loader_ = nullptr;
|
MetaDataLoader* loader_ = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user