Metin2 game client (P0–P11) + mobile asset pipeline
Networked client on the existing Godot 4.7 + libgr2 renderer:
- net: m2dev wire protocol (libsodium KX + XChaCha20), auth/select/game
phases, EntityStore world model, ~all GC/CG headers. char create/delete,
private shop / mall / cube, SHOP_GC_START_EX, guild, party (+ CG_PARTY_SET_STATE),
quests, dragon soul, refine, safebox, exchange.
- UI: in-game windows migrated 1:1 from the reference uiscript/root .py —
char status (/stat), inventory+equipment, select-item ([SELECT_ITEM] quest
token), system-option + game-option + ESC system menu, private-shop 39-grid,
party info board, shop tabs, atlas, minimap, quickbar, chat, …
- EterGrnLib polish: GR2 material blend/two-sided, LOD crossfade, motion-event
dispatch, contact shadow, ray-AABB picking, weapon grip pre-transform.
Portable asset IO (A1) — all extension/libgr2/formats/mtproto reads routed
through godot::FileAccess (res:// PCK works on iOS/Android); standalone-lib
*_path() kept for the non-Godot CTests. AssetResolver + PropertyRegistry
switched to a baked index (bake_asset_index.gd) instead of std::filesystem.
Mobile builds: build-{android,ios}.sh, export-android.sh, pack-assets.sh,
gen-debug-keystore.sh. Assets ship as a zip mounted at runtime by
project/asset_pack.gd (adb push now; HTTP download is a drop-in later).
ctest 10/10, 34 GDScript suites, macOS/iOS/Android all build.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013EJxkHiNKS4kybHS3XKyAJ
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
#include "m2_tokvec.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
namespace fmt {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string lower(std::string s) {
|
||||
std::transform(s.begin(), s.end(), s.begin(),
|
||||
[](unsigned char c) { return (char)std::tolower(c); });
|
||||
return s;
|
||||
}
|
||||
|
||||
bool ieq(const std::string& a, const char* b) {
|
||||
return lower(a) == b;
|
||||
}
|
||||
|
||||
// 一行 -> token 列表。`"..."` 单 token;`#` / `//` 到行尾注释。
|
||||
std::vector<std::string> tokenize_line(const std::string& line) {
|
||||
std::vector<std::string> out;
|
||||
size_t i = 0, n = line.size();
|
||||
while (i < n) {
|
||||
char c = line[i];
|
||||
if (c == '#' || (c == '/' && i + 1 < n && line[i + 1] == '/')) break;
|
||||
if (std::isspace((unsigned char)c)) { ++i; continue; }
|
||||
if (c == '"') {
|
||||
++i;
|
||||
std::string s;
|
||||
while (i < n && line[i] != '"') s += line[i++];
|
||||
if (i < n) ++i; // 收尾引号
|
||||
out.push_back(s);
|
||||
continue;
|
||||
}
|
||||
std::string s;
|
||||
while (i < n && !std::isspace((unsigned char)line[i]))
|
||||
s += line[i++];
|
||||
out.push_back(s);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool TokVecMap::has(const std::string& key) const { return m.count(key) != 0; }
|
||||
|
||||
const std::vector<std::string>* TokVecMap::find(const std::string& key) const {
|
||||
auto it = m.find(lower(key));
|
||||
return it == m.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
std::string TokVecMap::str(const std::string& key, const std::string& def) const {
|
||||
auto* v = find(key);
|
||||
return (v && !v->empty()) ? (*v)[0] : def;
|
||||
}
|
||||
|
||||
long TokVecMap::inum(const std::string& key, long def) const {
|
||||
auto* v = find(key);
|
||||
return (v && !v->empty()) ? std::strtol((*v)[0].c_str(), nullptr, 10) : def;
|
||||
}
|
||||
|
||||
double TokVecMap::num(const std::string& key, double def) const {
|
||||
auto* v = find(key);
|
||||
return (v && !v->empty()) ? std::strtod((*v)[0].c_str(), nullptr) : def;
|
||||
}
|
||||
|
||||
bool parse_tokvec(const std::string& text, TokVecMap& out, std::string* err) {
|
||||
out = TokVecMap{};
|
||||
std::istringstream in(text);
|
||||
std::string line;
|
||||
|
||||
std::string block_key; // 非空 = 正在收块
|
||||
std::vector<std::string> block_tokens;
|
||||
std::vector<std::string> seen_dups;
|
||||
|
||||
auto commit = [&](const std::string& key, std::vector<std::string> toks) {
|
||||
std::string k = lower(key);
|
||||
if (out.m.count(k)) {
|
||||
out.dup_count++;
|
||||
if (std::find(seen_dups.begin(), seen_dups.end(), k) == seen_dups.end()) {
|
||||
seen_dups.push_back(k);
|
||||
out.dup_keys.push_back(k);
|
||||
}
|
||||
return; // 保留第一个
|
||||
}
|
||||
out.m.emplace(std::move(k), std::move(toks));
|
||||
};
|
||||
|
||||
while (std::getline(in, line)) {
|
||||
if (!line.empty() && line.back() == '\r') line.pop_back();
|
||||
auto toks = tokenize_line(line);
|
||||
if (toks.empty()) continue;
|
||||
|
||||
if (!block_key.empty()) {
|
||||
if (ieq(toks[0], "end")) {
|
||||
commit(block_key, std::move(block_tokens));
|
||||
block_key.clear();
|
||||
block_tokens.clear();
|
||||
} else {
|
||||
for (auto& t : toks) block_tokens.push_back(std::move(t));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ieq(toks[0], "start")) {
|
||||
if (toks.size() < 2) {
|
||||
if (err) *err = "Start 缺块名";
|
||||
return false;
|
||||
}
|
||||
block_key = toks[1];
|
||||
block_tokens.clear();
|
||||
continue;
|
||||
}
|
||||
|
||||
// 顶层 `key v1 v2 ...`
|
||||
std::string key = toks[0];
|
||||
std::vector<std::string> vals(toks.begin() + 1, toks.end());
|
||||
commit(key, std::move(vals));
|
||||
}
|
||||
|
||||
if (!block_key.empty()) {
|
||||
// 文件在块中截断 —— 宽容收尾但记 err
|
||||
commit(block_key, std::move(block_tokens));
|
||||
if (err) *err = "文件在 Start '" + block_key + "' 块中截断(缺 End)";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static FileReader g_file_reader = nullptr;
|
||||
void set_file_reader(FileReader r) { g_file_reader = r; }
|
||||
|
||||
bool read_file(const std::string& path, std::string& out) {
|
||||
if (g_file_reader) return g_file_reader(path, out);
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
if (!f) return false;
|
||||
std::ostringstream ss;
|
||||
ss << f.rdbuf();
|
||||
out = ss.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_tokvec_file(const std::string& path, TokVecMap& out, std::string* err) {
|
||||
std::string text;
|
||||
if (!read_file(path, text)) {
|
||||
if (err) *err = "打不开文件: " + path;
|
||||
return false;
|
||||
}
|
||||
return parse_tokvec(text, out, err);
|
||||
}
|
||||
|
||||
} // namespace fmt
|
||||
Reference in New Issue
Block a user