add TextDice to disassembly

This commit is contained in:
Martin Michelsen
2023-10-09 11:06:47 -07:00
parent 41c07a3da8
commit 40da9e5604
4 changed files with 88 additions and 13 deletions
+37 -3
View File
@@ -1980,7 +1980,9 @@ CardIndex::CardIndex(
const string& filename,
const string& decompressed_filename,
const string& text_filename,
const string& decompressed_text_filename) {
const string& decompressed_text_filename,
const string& dice_text_filename,
const string& decompressed_dice_text_filename) {
unordered_map<uint32_t, vector<string>> card_tags;
unordered_map<uint32_t, string> card_text;
try {
@@ -2078,6 +2080,30 @@ CardIndex::CardIndex(
static_game_data_log.warning("Failed to load card text: %s", e.what());
}
unordered_map<uint32_t, pair<string, string>> card_dice_text;
try {
string text_bin_data;
if (!decompressed_dice_text_filename.empty() && isfile(decompressed_dice_text_filename)) {
text_bin_data = load_file(decompressed_dice_text_filename);
} else if (!dice_text_filename.empty() && isfile(dice_text_filename)) {
text_bin_data = prs_decompress(load_file(dice_text_filename));
}
if (!text_bin_data.empty()) {
StringReader r(text_bin_data);
while (!r.eof()) {
uint32_t card_id = r.get_u32l();
string dice_caption = r.read(0xFE);
string dice_text = r.read(0xFE);
strip_trailing_zeroes(dice_caption);
strip_trailing_zeroes(dice_text);
card_dice_text.emplace(card_id, make_pair(std::move(dice_caption), std::move(dice_text)));
}
}
} catch (const exception& e) {
static_game_data_log.warning("Failed to load card dice text: %s", e.what());
}
try {
string decompressed_data;
this->mtime_for_card_definitions = stat(filename).st_mtime;
@@ -2109,7 +2135,7 @@ CardIndex::CardIndex(
continue;
}
shared_ptr<CardEntry> entry(new CardEntry({defs[x], {}, {}}));
shared_ptr<CardEntry> entry(new CardEntry({defs[x], "", "", "", {}}));
if (!this->card_definitions.emplace(entry->def.card_id, entry).second) {
throw runtime_error(string_printf(
"duplicate card id: %08" PRIX32, entry->def.card_id.load()));
@@ -2127,7 +2153,7 @@ CardIndex::CardIndex(
entry->def.mv.decode_code();
entry->def.decode_range();
if (!text_filename.empty()) {
if (!text_filename.empty() || !decompressed_text_filename.empty()) {
try {
entry->text = std::move(card_text.at(defs[x].card_id));
} catch (const out_of_range&) {
@@ -2137,6 +2163,14 @@ CardIndex::CardIndex(
} catch (const out_of_range&) {
}
}
if (!dice_text_filename.empty() || !decompressed_dice_text_filename.empty()) {
try {
auto& dice_text_it = card_dice_text.at(defs[x].card_id);
entry->dice_caption = std::move(dice_text_it.first);
entry->dice_text = std::move(dice_text_it.second);
} catch (const out_of_range&) {
}
}
}
if (this->compressed_card_definitions.empty()) {
+5 -1
View File
@@ -1338,11 +1338,15 @@ public:
const std::string& filename,
const std::string& decompressed_filename,
const std::string& text_filename = "",
const std::string& deecompressed_text_filename = "");
const std::string& deecompressed_text_filename = "",
const std::string& dice_text_filename = "",
const std::string& deecompressed_dice_text_filename = "");
struct CardEntry {
CardDefinition def;
std::string text;
std::string dice_caption;
std::string dice_text;
std::vector<std::string> debug_tags; // Empty unless debug == true
};
+32 -7
View File
@@ -1686,7 +1686,13 @@ int main(int argc, char** argv) {
}
case Behavior::SHOW_EP3_CARDS: {
Episode3::CardIndex card_index("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd", "system/ep3/card-text.mnr", "system/ep3/card-text.mnrd");
Episode3::CardIndex card_index(
"system/ep3/card-definitions.mnr",
"system/ep3/card-definitions.mnrd",
"system/ep3/card-text.mnr",
"system/ep3/card-text.mnrd",
"system/ep3/card-dice-text.mnr",
"system/ep3/card-dice-text.mnrd");
unique_ptr<TextArchive> text_english;
try {
JSON json = JSON::parse(load_file("system/ep3/text-english.json"));
@@ -1702,17 +1708,36 @@ int main(int argc, char** argv) {
if (one_line) {
fprintf(stdout, "%s\n", s.c_str());
} else {
string tags = entry->debug_tags.empty() ? "(none)" : join(entry->debug_tags, ", ");
string text = entry->text.empty() ? "(No text available)" : str_replace_all(entry->text, "\n", "\n ");
strip_trailing_whitespace(text);
fprintf(stdout, "%s\n Tags: %s\n Text:\n %s\n\n", s.c_str(), tags.c_str(), text.c_str());
fprintf(stdout, "%s\n", s.c_str());
if (!entry->debug_tags.empty()) {
string tags = join(entry->debug_tags, ", ");
fprintf(stdout, " Tags: %s\n", tags.c_str());
}
if (!entry->dice_caption.empty()) {
fprintf(stdout, " Dice caption: %s\n", entry->dice_caption.c_str());
}
if (!entry->dice_caption.empty()) {
fprintf(stdout, " Dice text: %s\n", entry->dice_text.c_str());
}
if (!entry->text.empty()) {
string text = str_replace_all(entry->text, "\n", "\n ");
strip_trailing_whitespace(text);
fprintf(stdout, " Text:\n %s\n", text.c_str());
}
fputc('\n', stdout);
}
}
break;
}
case Behavior::GENERATE_EP3_CARDS_HTML: {
Episode3::CardIndex card_index("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd", "system/ep3/card-text.mnr", "system/ep3/card-text.mnrd");
Episode3::CardIndex card_index(
"system/ep3/card-definitions.mnr",
"system/ep3/card-definitions.mnrd",
"system/ep3/card-text.mnr",
"system/ep3/card-text.mnrd",
"system/ep3/card-dice-text.mnr",
"system/ep3/card-dice-text.mnrd");
unique_ptr<TextArchive> text_english;
try {
JSON json = JSON::parse(load_file("system/ep3/text-english.json"));
@@ -1843,7 +1868,7 @@ int main(int argc, char** argv) {
case Behavior::SHOW_EP3_MAPS: {
config_log.info("Collecting Episode 3 data");
Episode3::MapIndex map_index("system/ep3/maps");
Episode3::CardIndex card_index("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd", "system/ep3/card-text.mnr", "system/ep3/card-text.mnrd");
Episode3::CardIndex card_index("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd");
auto map_ids = map_index.all_numbers();
log_info("%zu maps", map_ids.size());
+14 -2
View File
@@ -898,9 +898,21 @@ void ServerState::load_ep3_data() {
config_log.info("Collecting Episode 3 maps");
this->ep3_map_index.reset(new Episode3::MapIndex("system/ep3/maps"));
config_log.info("Loading Episode 3 card definitions");
this->ep3_card_index.reset(new Episode3::CardIndex("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd", "system/ep3/card-text.mnr", "system/ep3/card-text.mnrd"));
this->ep3_card_index.reset(new Episode3::CardIndex(
"system/ep3/card-definitions.mnr",
"system/ep3/card-definitions.mnrd",
"system/ep3/card-text.mnr",
"system/ep3/card-text.mnrd",
"system/ep3/card-dice-text.mnr",
"system/ep3/card-dice-text.mnrd"));
config_log.info("Loading Episode 3 trial card definitions");
this->ep3_card_index_trial.reset(new Episode3::CardIndex("system/ep3/card-definitions-trial.mnr", "system/ep3/card-definitions-trial.mnrd", "system/ep3/card-text-trial.mnr", "system/ep3/card-text-trial.mnrd"));
this->ep3_card_index_trial.reset(new Episode3::CardIndex(
"system/ep3/card-definitions-trial.mnr",
"system/ep3/card-definitions-trial.mnrd",
"system/ep3/card-text-trial.mnr",
"system/ep3/card-text-trial.mnrd",
"system/ep3/card-dice-text-trial.mnr",
"system/ep3/card-dice-text-trial.mnrd"));
config_log.info("Loading Episode 3 COM decks");
this->ep3_com_deck_index.reset(new Episode3::COMDeckIndex("system/ep3/com-decks.json"));