mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
feat(editor): add WEMO (Emote Definition) — 101st open format
Novel replacement for the EmotesText.dbc + EmotesTextSound + EmotesTextData trio that maps /slash-emote commands (/dance, /wave, /laugh, etc.) to their visible chat text, animation ID, and per-race voice clip. Each entry binds one slashCommand to an animationId (refs WANI), soundId (refs WSND), targetMessage / noTargetMessage formats, emote kind (Social / Combat / RolePlay / System), sex filter (Both / Male / Female), required race bit, and a TTS hint (Talk / Whisper / Yell / Silent) for accessibility text-to-speech engines. Three preset emitters covering the canonical emote buckets: makeBasic (8 universal social emotes — wave / bow / laugh / cheer / cry / sleep / kneel / applaud), makeCombat (5 combat-themed — roar / threaten / charge / victory / surrender), makeRolePlay (6 RP-focused — bonk / ponder / soothe / plead / shoo / scoff). Animation IDs match AnimationData.dbc convention so existing WoW client mods continue to play the right anims. Validator catches authoring bugs unique to slash-command parsing: leading '/' on slashCommand (chat parser strips it before lookup so the entry would be doubly-prefixed), uppercase letters (parser case-folds before lookup so the entry is unreachable), duplicate slash commands (parser dispatches by exact match — ambiguity would crash the chat input handler), %s token counts that don't match target/no-target distinction. Also expanded --catalog-pluck's foreign-key filter to include animationId / soundId / particleId / ribbonId / vehicleId / seatId / currencyId / trainerId / vendorId / mailTemplateId — caught during smoke-test where pluck mis-identified WEMO entries by animationId instead of emoteId. Same class of bug as the WHRT areaId fix. Format count 100 -> 101. CLI flag count 1126 -> 1131.
This commit is contained in:
parent
4aa7b56e13
commit
c9b822002f
11 changed files with 827 additions and 0 deletions
327
tools/editor/cli_emotes_catalog.cpp
Normal file
327
tools/editor/cli_emotes_catalog.cpp
Normal file
|
|
@ -0,0 +1,327 @@
|
|||
#include "cli_emotes_catalog.hpp"
|
||||
#include "cli_arg_parse.hpp"
|
||||
#include "cli_box_emitter.hpp"
|
||||
|
||||
#include "pipeline/wowee_emotes.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace wowee {
|
||||
namespace editor {
|
||||
namespace cli {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string stripWemoExt(std::string base) {
|
||||
stripExt(base, ".wemo");
|
||||
return base;
|
||||
}
|
||||
|
||||
const char* emoteKindName(uint8_t k) {
|
||||
using E = wowee::pipeline::WoweeEmotes;
|
||||
switch (k) {
|
||||
case E::Social: return "social";
|
||||
case E::Combat: return "combat";
|
||||
case E::RolePlay: return "roleplay";
|
||||
case E::System: return "system";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char* sexFilterName(uint8_t s) {
|
||||
using E = wowee::pipeline::WoweeEmotes;
|
||||
switch (s) {
|
||||
case E::SexBoth: return "both";
|
||||
case E::MaleOnly: return "male";
|
||||
case E::FemaleOnly: return "female";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char* ttsHintName(uint8_t h) {
|
||||
using E = wowee::pipeline::WoweeEmotes;
|
||||
switch (h) {
|
||||
case E::TtsTalk: return "talk";
|
||||
case E::TtsWhisper: return "whisper";
|
||||
case E::TtsYell: return "yell";
|
||||
case E::TtsSilent: return "silent";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
bool saveOrError(const wowee::pipeline::WoweeEmotes& c,
|
||||
const std::string& base, const char* cmd) {
|
||||
if (!wowee::pipeline::WoweeEmotesLoader::save(c, base)) {
|
||||
std::fprintf(stderr, "%s: failed to save %s.wemo\n",
|
||||
cmd, base.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printGenSummary(const wowee::pipeline::WoweeEmotes& c,
|
||||
const std::string& base) {
|
||||
std::printf("Wrote %s.wemo\n", base.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" emotes : %zu\n", c.entries.size());
|
||||
}
|
||||
|
||||
int handleGenBasic(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string name = "BasicSocialEmotes";
|
||||
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||||
base = stripWemoExt(base);
|
||||
auto c = wowee::pipeline::WoweeEmotesLoader::makeBasic(name);
|
||||
if (!saveOrError(c, base, "gen-emo")) return 1;
|
||||
printGenSummary(c, base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleGenCombat(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string name = "CombatEmotes";
|
||||
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||||
base = stripWemoExt(base);
|
||||
auto c = wowee::pipeline::WoweeEmotesLoader::makeCombat(name);
|
||||
if (!saveOrError(c, base, "gen-emo-combat")) return 1;
|
||||
printGenSummary(c, base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleGenRolePlay(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string name = "RolePlayEmotes";
|
||||
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||||
base = stripWemoExt(base);
|
||||
auto c = wowee::pipeline::WoweeEmotesLoader::makeRolePlay(name);
|
||||
if (!saveOrError(c, base, "gen-emo-rp")) return 1;
|
||||
printGenSummary(c, base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleInfo(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
bool jsonOut = consumeJsonFlag(i, argc, argv);
|
||||
base = stripWemoExt(base);
|
||||
if (!wowee::pipeline::WoweeEmotesLoader::exists(base)) {
|
||||
std::fprintf(stderr, "WEMO not found: %s.wemo\n", base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeEmotesLoader::load(base);
|
||||
if (jsonOut) {
|
||||
nlohmann::json j;
|
||||
j["wemo"] = base + ".wemo";
|
||||
j["name"] = c.name;
|
||||
j["count"] = c.entries.size();
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
arr.push_back({
|
||||
{"emoteId", e.emoteId},
|
||||
{"name", e.name},
|
||||
{"description", e.description},
|
||||
{"slashCommand", e.slashCommand},
|
||||
{"animationId", e.animationId},
|
||||
{"soundId", e.soundId},
|
||||
{"targetMessage", e.targetMessage},
|
||||
{"noTargetMessage", e.noTargetMessage},
|
||||
{"emoteKind", e.emoteKind},
|
||||
{"emoteKindName", emoteKindName(e.emoteKind)},
|
||||
{"sex", e.sex},
|
||||
{"sexName", sexFilterName(e.sex)},
|
||||
{"requiredRace", e.requiredRace},
|
||||
{"ttsHint", e.ttsHint},
|
||||
{"ttsHintName", ttsHintName(e.ttsHint)},
|
||||
{"iconColorRGBA", e.iconColorRGBA},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::printf("%s\n", j.dump(2).c_str());
|
||||
return 0;
|
||||
}
|
||||
std::printf("WEMO: %s.wemo\n", base.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" emotes : %zu\n", c.entries.size());
|
||||
if (c.entries.empty()) return 0;
|
||||
std::printf(" id /command kind anim snd sex tts \n");
|
||||
for (const auto& e : c.entries) {
|
||||
std::printf(" %4u /%-12s %-8s %4u %4u %-5s %-7s\n",
|
||||
e.emoteId, e.slashCommand.c_str(),
|
||||
emoteKindName(e.emoteKind),
|
||||
e.animationId, e.soundId,
|
||||
sexFilterName(e.sex),
|
||||
ttsHintName(e.ttsHint));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleValidate(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
bool jsonOut = consumeJsonFlag(i, argc, argv);
|
||||
base = stripWemoExt(base);
|
||||
if (!wowee::pipeline::WoweeEmotesLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"validate-wemo: WEMO not found: %s.wemo\n", base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeEmotesLoader::load(base);
|
||||
std::vector<std::string> errors;
|
||||
std::vector<std::string> warnings;
|
||||
if (c.entries.empty()) {
|
||||
warnings.push_back("catalog has zero entries");
|
||||
}
|
||||
std::vector<uint32_t> idsSeen;
|
||||
std::set<std::string> commandsSeen;
|
||||
for (size_t k = 0; k < c.entries.size(); ++k) {
|
||||
const auto& e = c.entries[k];
|
||||
std::string ctx = "entry " + std::to_string(k) +
|
||||
" (id=" + std::to_string(e.emoteId);
|
||||
if (!e.name.empty()) ctx += " " + e.name;
|
||||
ctx += ")";
|
||||
if (e.emoteId == 0)
|
||||
errors.push_back(ctx + ": emoteId is 0");
|
||||
if (e.name.empty())
|
||||
errors.push_back(ctx + ": name is empty");
|
||||
if (e.slashCommand.empty()) {
|
||||
errors.push_back(ctx +
|
||||
": slashCommand is empty — chat parser "
|
||||
"would fail to dispatch");
|
||||
}
|
||||
// Slash command should not start with '/' (the
|
||||
// chat parser strips it before the lookup).
|
||||
if (!e.slashCommand.empty() &&
|
||||
e.slashCommand[0] == '/') {
|
||||
errors.push_back(ctx + ": slashCommand starts "
|
||||
"with '/' — store it bare (chat parser "
|
||||
"strips the leading slash before lookup)");
|
||||
}
|
||||
// Lowercase only — chat commands are
|
||||
// case-folded before lookup, so an uppercase
|
||||
// letter would be unreachable.
|
||||
for (char ch : e.slashCommand) {
|
||||
if (ch >= 'A' && ch <= 'Z') {
|
||||
errors.push_back(ctx + ": slashCommand '" +
|
||||
e.slashCommand +
|
||||
"' contains uppercase — chat parser "
|
||||
"lowercases input before lookup so "
|
||||
"this entry would be unreachable");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (e.emoteKind > 3) {
|
||||
errors.push_back(ctx + ": emoteKind " +
|
||||
std::to_string(e.emoteKind) +
|
||||
" out of range (must be 0..3)");
|
||||
}
|
||||
if (e.sex > 2) {
|
||||
errors.push_back(ctx + ": sex " +
|
||||
std::to_string(e.sex) +
|
||||
" out of range (must be 0..2)");
|
||||
}
|
||||
if (e.ttsHint > 3) {
|
||||
errors.push_back(ctx + ": ttsHint " +
|
||||
std::to_string(e.ttsHint) +
|
||||
" out of range (must be 0..3)");
|
||||
}
|
||||
// If targetMessage references a target slot, it
|
||||
// should contain TWO %s tokens (actor + target);
|
||||
// noTargetMessage should contain exactly ONE.
|
||||
auto countPercentS = [](const std::string& s) {
|
||||
int n = 0;
|
||||
for (size_t k = 0; k + 1 < s.size(); ++k) {
|
||||
if (s[k] == '%' && s[k + 1] == 's') ++n;
|
||||
}
|
||||
return n;
|
||||
};
|
||||
int tgtTokens = countPercentS(e.targetMessage);
|
||||
int noTgtTokens = countPercentS(e.noTargetMessage);
|
||||
if (!e.targetMessage.empty() && tgtTokens < 2) {
|
||||
warnings.push_back(ctx +
|
||||
": targetMessage has " +
|
||||
std::to_string(tgtTokens) +
|
||||
" %s token(s) — expected 2 (actor name + "
|
||||
"target name)");
|
||||
}
|
||||
if (!e.noTargetMessage.empty() && noTgtTokens != 1) {
|
||||
warnings.push_back(ctx +
|
||||
": noTargetMessage has " +
|
||||
std::to_string(noTgtTokens) +
|
||||
" %s token(s) — expected exactly 1 (actor "
|
||||
"name)");
|
||||
}
|
||||
// Slash commands must be unique — chat parser
|
||||
// dispatches by exact match.
|
||||
if (!e.slashCommand.empty() &&
|
||||
!commandsSeen.insert(e.slashCommand).second) {
|
||||
errors.push_back(ctx + ": duplicate slashCommand "
|
||||
"'" + e.slashCommand + "' — chat parser "
|
||||
"would dispatch ambiguously");
|
||||
}
|
||||
for (uint32_t prev : idsSeen) {
|
||||
if (prev == e.emoteId) {
|
||||
errors.push_back(ctx + ": duplicate emoteId");
|
||||
break;
|
||||
}
|
||||
}
|
||||
idsSeen.push_back(e.emoteId);
|
||||
}
|
||||
bool ok = errors.empty();
|
||||
if (jsonOut) {
|
||||
nlohmann::json j;
|
||||
j["wemo"] = base + ".wemo";
|
||||
j["ok"] = ok;
|
||||
j["errors"] = errors;
|
||||
j["warnings"] = warnings;
|
||||
std::printf("%s\n", j.dump(2).c_str());
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
std::printf("validate-wemo: %s.wemo\n", base.c_str());
|
||||
if (ok && warnings.empty()) {
|
||||
std::printf(" OK — %zu emotes, all emoteIds + "
|
||||
"slash commands unique\n",
|
||||
c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
if (!warnings.empty()) {
|
||||
std::printf(" warnings (%zu):\n", warnings.size());
|
||||
for (const auto& w : warnings)
|
||||
std::printf(" - %s\n", w.c_str());
|
||||
}
|
||||
if (!errors.empty()) {
|
||||
std::printf(" ERRORS (%zu):\n", errors.size());
|
||||
for (const auto& e : errors)
|
||||
std::printf(" - %s\n", e.c_str());
|
||||
}
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool handleEmotesCatalog(int& i, int argc, char** argv, int& outRc) {
|
||||
if (std::strcmp(argv[i], "--gen-emo") == 0 && i + 1 < argc) {
|
||||
outRc = handleGenBasic(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--gen-emo-combat") == 0 && i + 1 < argc) {
|
||||
outRc = handleGenCombat(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--gen-emo-rp") == 0 && i + 1 < argc) {
|
||||
outRc = handleGenRolePlay(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--info-wemo") == 0 && i + 1 < argc) {
|
||||
outRc = handleInfo(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--validate-wemo") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace cli
|
||||
} // namespace editor
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue