1
This commit is contained in:
parent
c1fb30c835
commit
4e22aa0d89
@ -5,6 +5,8 @@
|
||||
#include "room.h"
|
||||
#include "player.h"
|
||||
#include "mt/Param.h"
|
||||
#include "mt/Text.h"
|
||||
#include "mt/Equip.h"
|
||||
|
||||
bool RollMsgHintInfo::Replace(int idx, std::string& text)
|
||||
{
|
||||
@ -52,23 +54,21 @@ void KillMgr::FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hin
|
||||
{
|
||||
hint_info.dead_name = dead_hum->GetName();
|
||||
|
||||
// 111
|
||||
#if 0
|
||||
switch (info->killer_id) {
|
||||
case VP_Gas:
|
||||
{
|
||||
hint_info.killer_name = "";
|
||||
hint_info.hint_template = MetaMgr::Instance()->GetTextElements
|
||||
hint_info.hint_template = mt::Text::GetTextElements
|
||||
("battle_server_dead_text_gas");
|
||||
}
|
||||
break;
|
||||
case VP_Buff:
|
||||
{
|
||||
hint_info.killer_name = "";
|
||||
hint_info.hint_template = MetaMgr::Instance()->GetTextElements
|
||||
hint_info.hint_template = mt::Text::GetTextElements
|
||||
(a8::Format("battle_server_dead_text_buff_%d", {info->weapon_id}));
|
||||
if (!hint_info.hint_template) {
|
||||
hint_info.hint_template = MetaMgr::Instance()->GetTextElements
|
||||
hint_info.hint_template = mt::Text::GetTextElements
|
||||
("battle_server_dead_text_buff_default");
|
||||
}
|
||||
}
|
||||
@ -76,10 +76,10 @@ void KillMgr::FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hin
|
||||
case VP_Explosion:
|
||||
{
|
||||
hint_info.killer_name = "";
|
||||
hint_info.hint_template = MetaMgr::Instance()->GetTextElements
|
||||
hint_info.hint_template = mt::Text::GetTextElements
|
||||
(a8::Format("battle_server_dead_text_explosion_%d", {info->weapon_id}));
|
||||
if (!hint_info.hint_template) {
|
||||
hint_info.hint_template = MetaMgr::Instance()->GetTextElements
|
||||
hint_info.hint_template = mt::Text::GetTextElements
|
||||
("battle_server_dead_text_explosion_default");
|
||||
}
|
||||
}
|
||||
@ -87,7 +87,7 @@ void KillMgr::FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hin
|
||||
case VP_Water:
|
||||
{
|
||||
hint_info.killer_name = "";
|
||||
hint_info.hint_template = MetaMgr::Instance()->GetTextElements
|
||||
hint_info.hint_template = mt::Text::GetTextElements
|
||||
("battle_server_dead_text_drown");
|
||||
}
|
||||
break;
|
||||
@ -95,18 +95,18 @@ void KillMgr::FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hin
|
||||
{
|
||||
Entity* killer = dead_hum->room->GetEntityByUniId(info->killer_id);
|
||||
if (killer) {
|
||||
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(info->weapon_id);
|
||||
const mt::Equip* equip_meta = mt::Equip::GetById(info->weapon_id);
|
||||
if (equip_meta) {
|
||||
hint_info.weapon_text_icon = equip_meta->pb->text_icon();
|
||||
hint_info.weapon_text_icon = equip_meta->text_icon();
|
||||
}
|
||||
hint_info.killer_name = killer->GetName();
|
||||
if (info->killer_id == dead_hum->GetUniId()) {
|
||||
//${dead.name} 自杀
|
||||
hint_info.hint_template = MetaMgr::Instance()->GetTextElements
|
||||
hint_info.hint_template = mt::Text::GetTextElements
|
||||
("battle_server_dead_text_specate");
|
||||
} else {
|
||||
//${killer.name} 使用 ${weapon.text_icon} 干掉了 ${dead.name}
|
||||
hint_info.hint_template = MetaMgr::Instance()->GetTextElements
|
||||
hint_info.hint_template = mt::Text::GetTextElements
|
||||
("battle_server_dead_text_weapon");
|
||||
}
|
||||
} else {
|
||||
@ -114,5 +114,4 @@ void KillMgr::FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hin
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1,9 +1,129 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <regex>
|
||||
|
||||
#include <a8/mutable_xobject.h>
|
||||
|
||||
#include "mt/Text.h"
|
||||
|
||||
IMPL_TABLE(mt::Text)
|
||||
|
||||
static void ParseElemets(const std::string& textid,
|
||||
const std::string& text,
|
||||
std::vector<std::tuple<int, std::string>>& elements)
|
||||
{
|
||||
auto parsevar_cb =
|
||||
[] (const std::string& var_name, std::vector<std::tuple<int, std::string>>& elements)
|
||||
{
|
||||
if (var_name == "${master.name}") {
|
||||
elements.push_back(std::make_tuple(kFieldIdxMasterName, ""));
|
||||
} else if (var_name == "${killer.name}") {
|
||||
elements.push_back(std::make_tuple(kFieldIdxKillerName, ""));
|
||||
} else if (var_name == "${dead.name}") {
|
||||
elements.push_back(std::make_tuple(kFieldIdxDeadName, ""));
|
||||
} else if (var_name == "${weapon.name}") {
|
||||
elements.push_back(std::make_tuple(kFieldIdxWeaponName, ""));
|
||||
} else if (var_name == "${weapon.text_icon}") {
|
||||
elements.push_back(std::make_tuple(kFieldIdxWeaponTextIcon, ""));
|
||||
} else if (var_name.find("${image.id:") == 0) {
|
||||
std::vector<std::string> strings;
|
||||
a8::Split(var_name, strings, ':');
|
||||
std::string id = strings[1].substr(0, strings[1].length() - 1);
|
||||
elements.push_back(std::make_tuple(kImageElement, id));
|
||||
} else {
|
||||
A8_ABORT();
|
||||
}
|
||||
};
|
||||
|
||||
std::regex re(R"(\$\{.*?\})", std::regex_constants::ECMAScript);
|
||||
|
||||
const char* pcurr = text.c_str();
|
||||
const char* pend = text.c_str() + text.length();
|
||||
while (pcurr < pend) {
|
||||
#if 1
|
||||
int pos = 0;
|
||||
int length = 0;
|
||||
bool match_ok = false;
|
||||
std::string m_str;
|
||||
{
|
||||
const char* tmp_curr = pcurr;
|
||||
while (*tmp_curr) {
|
||||
if (tmp_curr[0] == '$' && tmp_curr[1] == '{') {
|
||||
int i = 2;
|
||||
while (tmp_curr[i] != '}') {
|
||||
if (tmp_curr[i] == '\0') {
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (tmp_curr[i] == '}') {
|
||||
pos = tmp_curr - pcurr;
|
||||
length = i + 1;
|
||||
m_str = std::string(tmp_curr, length);
|
||||
match_ok = true;
|
||||
break;
|
||||
} else {
|
||||
++tmp_curr;
|
||||
}
|
||||
} else {
|
||||
++tmp_curr;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match_ok) {
|
||||
if (pos > 0) {
|
||||
auto& e = a8::FastAppend(elements);
|
||||
e = std::make_tuple(kTextElement, std::string(pcurr, pos));
|
||||
}
|
||||
parsevar_cb(m_str, elements);
|
||||
pcurr += pos + length;
|
||||
} else {
|
||||
auto& e = a8::FastAppend(elements);
|
||||
e = std::make_tuple(kTextElement, std::string(pcurr, pend - pcurr));
|
||||
pcurr = pend;
|
||||
}
|
||||
#else
|
||||
std::cmatch m;
|
||||
if (std::regex_search(pcurr, m, re)) {
|
||||
if (m.position() > 0) {
|
||||
auto& e = a8::FastAppend(elements);
|
||||
e = std::make_tuple(kTextElement, std::string(pcurr, m.position()));
|
||||
}
|
||||
|
||||
parsevar_cb(m.str(), elements);
|
||||
pcurr += m.position() + m.length();
|
||||
} else {
|
||||
auto& e = a8::FastAppend(elements);
|
||||
e = std::make_tuple(kTextElement, std::string(pcurr, pend - pcurr));
|
||||
pcurr = pend;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
a8::MutableXObject* obj = a8::MutableXObject::NewObject();
|
||||
a8::MutableXObject* arr = a8::MutableXObject::NewArray();
|
||||
for (auto& e : elements) {
|
||||
a8::MutableXObject* obj_el = a8::MutableXObject::NewObject();
|
||||
obj_el->SetVal("type", std::get<0>(e));
|
||||
obj_el->SetVal("val", std::get<1>(e));
|
||||
arr->Push(*obj_el);
|
||||
}
|
||||
obj->SetVal("text", text);
|
||||
obj->SetVal("elemets", *arr);
|
||||
#if 0
|
||||
a8::UdpLog::Instance()->Info
|
||||
("load textid:%s %s",
|
||||
{
|
||||
textid,
|
||||
obj->ToJsonStr()
|
||||
}
|
||||
);
|
||||
#endif
|
||||
delete obj;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mt
|
||||
{
|
||||
#if 0
|
||||
|
@ -14,6 +14,8 @@ namespace mt
|
||||
public:
|
||||
|
||||
static std::string GetText(const std::string& textid, const std::string& def_text = "") {};
|
||||
static std::vector<std::tuple<int, std::string>>* GetTextElements(const std::string& textid) {}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user