Change GetSelectedOptionText to contextSelection and clean up some junk (#4613)

* Change GetSelectedOptionText to contextSelection and clean up some junk

* more cleanup

* readd a fail alert as an assert
This commit is contained in:
Pepper0ni 2024-12-04 18:01:25 +00:00 committed by GitHub
parent 9b169af3f5
commit c3e4579cba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 142 deletions

View File

@ -856,11 +856,6 @@ static void AssumedFill(const std::vector<RandomizerGet>& items, const std::vect
SPDLOG_DEBUG(Rando::StaticData::RetrieveItem(item).GetName().GetEnglish()); SPDLOG_DEBUG(Rando::StaticData::RetrieveItem(item).GetName().GetEnglish());
SPDLOG_DEBUG(". TRYING AGAIN...\n"); SPDLOG_DEBUG(". TRYING AGAIN...\n");
#ifdef ENABLE_DEBUG
Regions::DumpWorldGraph(Rando::StaticData::RetrieveItem(item).GetName().GetEnglish());
PlacementLog_Write();
#endif
// reset any locations that got an item // reset any locations that got an item
for (RandomizerCheck loc : attemptedLocations) { for (RandomizerCheck loc : attemptedLocations) {
ctx->GetItemLocation(loc)->SetPlacedItem(RG_NONE); ctx->GetItemLocation(loc)->SetPlacedItem(RG_NONE);

View File

@ -80,14 +80,6 @@ int Playthrough_Init(uint32_t seed, std::set<RandomizerCheck> excludedLocations,
SPDLOG_ERROR("Writing Spoiler Log Failed"); SPDLOG_ERROR("Writing Spoiler Log Failed");
} }
StopPerformanceTimer(PT_SPOILER_LOG); StopPerformanceTimer(PT_SPOILER_LOG);
#ifdef ENABLE_DEBUG
SPDLOG_INFO("Writing Placement Log...");
if (PlacementLog_Write()) {
SPDLOG_INFO("Writing Placement Log Done");
} else {
SPDLOG_ERROR("Writing Placement Log Failed");
}
#endif
} }
ctx->playthroughLocations.clear(); ctx->playthroughLocations.clear();

View File

@ -6,7 +6,6 @@
#include "../entrance.h" #include "../entrance.h"
#include "random.hpp" #include "random.hpp"
#include "../trial.h" #include "../trial.h"
#include "tinyxml2.h"
#include "utils.hpp" #include "utils.hpp"
#include "hints.hpp" #include "hints.hpp"
#include "pool_functions.hpp" #include "pool_functions.hpp"
@ -56,9 +55,6 @@ void GenerateHash() {
int number = std::stoi(hash.substr(j, 2)); int number = std::stoi(hash.substr(j, 2));
ctx->hashIconIndexes[i] = number; ctx->hashIconIndexes[i] = number;
} }
// Clear out spoiler log data here, in case we aren't going to re-generate it
// spoilerData = { 0 };
} }
static auto GetGeneralPath() { static auto GetGeneralPath() {
@ -79,7 +75,6 @@ static void WriteLocation(
Rando::Location* location = Rando::StaticData::GetLocation(locationKey); Rando::Location* location = Rando::StaticData::GetLocation(locationKey);
Rando::ItemLocation* itemLocation = Rando::Context::GetInstance()->GetItemLocation(locationKey); Rando::ItemLocation* itemLocation = Rando::Context::GetInstance()->GetItemLocation(locationKey);
// auto node = parentNode->InsertNewChildElement("location");
switch (gSaveContext.language) { switch (gSaveContext.language) {
case LANGUAGE_ENG: case LANGUAGE_ENG:
default: default:
@ -89,35 +84,6 @@ static void WriteLocation(
jsonData["playthrough"][sphere][location->GetName()] = itemLocation->GetPlacedItemName().GetFrench(); jsonData["playthrough"][sphere][location->GetName()] = itemLocation->GetPlacedItemName().GetFrench();
break; break;
} }
// node->SetAttribute("name", location->GetName().c_str());
// node->SetText(location->GetPlacedItemName().GetEnglish().c_str());
// if (withPadding) {
// constexpr int16_t LONGEST_NAME = 56; // The longest name of a location.
// constexpr int16_t PRICE_ATTRIBUTE = 12; // Length of a 3-digit price attribute.
// // Insert a padding so we get a kind of table in the XML document.
// int16_t requiredPadding = LONGEST_NAME - location->GetName().length();
// if (location->GetRCType() == RCTYPE_SHOP) {
// // Shop items have short location names, but come with an additional price attribute.
// requiredPadding -= PRICE_ATTRIBUTE;
// }
// if (requiredPadding >= 0) {
// std::string padding(requiredPadding, ' ');
// node->SetAttribute("_", padding.c_str());
// }
// }
// if (location->GetRCType() == RCTYPE_SHOP) {
// char price[6];
// sprintf(price, "%03d", location->GetPrice());
// node->SetAttribute("price", price);
// }
// if (!location->IsAddedToPool()) {
// #ifdef ENABLE_DEBUG
// node->SetAttribute("not-added", true);
// #endif
// }
} }
//Writes a shuffled entrance to the specified node //Writes a shuffled entrance to the specified node
@ -186,7 +152,6 @@ static void WriteSettings() {
// Writes the excluded locations to the spoiler log, if there are any. // Writes the excluded locations to the spoiler log, if there are any.
static void WriteExcludedLocations() { static void WriteExcludedLocations() {
// auto parentNode = spoilerLog.NewElement("excluded-locations");
auto ctx = Rando::Context::GetInstance(); auto ctx = Rando::Context::GetInstance();
for (size_t i = 1; i < ctx->GetSettings()->GetExcludeLocationsOptions().size(); i++) { for (size_t i = 1; i < ctx->GetSettings()->GetExcludeLocationsOptions().size(); i++) {
@ -197,15 +162,8 @@ static void WriteExcludedLocations() {
jsonData["excludedLocations"].push_back(RemoveLineBreaks(location->GetName())); jsonData["excludedLocations"].push_back(RemoveLineBreaks(location->GetName()));
// tinyxml2::XMLElement* node = spoilerLog.NewElement("location");
// node->SetAttribute("name", RemoveLineBreaks(location->GetName()).c_str());
// parentNode->InsertEndChild(node);
} }
} }
// if (!parentNode->NoChildren()) {
// spoilerLog.RootElement()->InsertEndChild(parentNode);
// }
} }
// Writes the starting inventory to the spoiler log, if there is any. // Writes the starting inventory to the spoiler log, if there is any.
@ -222,55 +180,19 @@ static void WriteStartingInventory() {
} }
//Writes the enabled tricks to the spoiler log, if there are any. //Writes the enabled tricks to the spoiler log, if there are any.
static void WriteEnabledTricks(tinyxml2::XMLDocument& spoilerLog) { static void WriteEnabledTricks() {
//auto parentNode = spoilerLog.NewElement("enabled-tricks");
auto ctx = Rando::Context::GetInstance(); auto ctx = Rando::Context::GetInstance();
for (const auto& setting : ctx->GetSettings()->GetOptionGroup(RSG_TRICKS).GetOptions()) { for (const auto& setting : ctx->GetSettings()->GetOptionGroup(RSG_TRICKS).GetOptions()) {
if (setting->GetContextOptionIndex() != RO_GENERIC_ON/* || !setting->IsCategory(OptionCategory::Setting)*/) { if (setting->GetContextOptionIndex() != RO_GENERIC_ON) {
continue; continue;
} }
jsonData["enabledTricks"].push_back(RemoveLineBreaks(setting->GetName()).c_str()); jsonData["enabledTricks"].push_back(RemoveLineBreaks(setting->GetName()).c_str());
//auto node = parentNode->InsertNewChildElement("trick");
//node->SetAttribute("name", RemoveLineBreaks(setting->GetName()).c_str());
} }
// if (!parentNode->NoChildren()) {
// spoilerLog.RootElement()->InsertEndChild(parentNode);
//}
} }
// Writes the enabled glitches to the spoiler log, if there are any.
// TODO: Implement Glitches
// static void WriteEnabledGlitches(tinyxml2::XMLDocument& spoilerLog) {
// auto parentNode = spoilerLog.NewElement("enabled-glitches");
// for (const auto& setting : Settings::glitchCategories) {
// if (setting->Value<uint8_t>() == 0) {
// continue;
// }
// auto node = parentNode->InsertNewChildElement("glitch-category");
// node->SetAttribute("name", setting->GetName().c_str());
// node->SetText(setting->GetSelectedOptionText().c_str());
// }
// for (const auto& setting : Settings::miscGlitches) {
// if (!setting->Value<bool>()) {
// continue;
// }
// auto node = parentNode->InsertNewChildElement("misc-glitch");
// node->SetAttribute("name", RemoveLineBreaks(setting->GetName()).c_str());
// }
// if (!parentNode->NoChildren()) {
// spoilerLog.RootElement()->InsertEndChild(parentNode);
// }
// }
// Writes the Master Quest dungeons to the spoiler log, if there are any. // Writes the Master Quest dungeons to the spoiler log, if there are any.
static void WriteMasterQuestDungeons(tinyxml2::XMLDocument& spoilerLog) { static void WriteMasterQuestDungeons() {
auto ctx = Rando::Context::GetInstance(); auto ctx = Rando::Context::GetInstance();
for (const auto* dungeon : ctx->GetDungeons()->GetDungeonList()) { for (const auto* dungeon : ctx->GetDungeons()->GetDungeonList()) {
std::string dungeonName; std::string dungeonName;
@ -294,7 +216,6 @@ static void WriteRequiredTrials() {
// Writes the intended playthrough to the spoiler log, separated into spheres. // Writes the intended playthrough to the spoiler log, separated into spheres.
static void WritePlaythrough() { static void WritePlaythrough() {
// auto playthroughNode = spoilerLog.NewElement("playthrough");
auto ctx = Rando::Context::GetInstance(); auto ctx = Rando::Context::GetInstance();
for (uint32_t i = 0; i < ctx->playthroughLocations.size(); ++i) { for (uint32_t i = 0; i < ctx->playthroughLocations.size(); ++i) {
@ -306,8 +227,6 @@ static void WritePlaythrough() {
WriteLocation(sphereString, key, true); WriteLocation(sphereString, key, true);
} }
} }
// spoilerLog.RootElement()->InsertEndChild(playthroughNode);
} }
//Write the randomized entrance playthrough to the spoiler log, if applicable //Write the randomized entrance playthrough to the spoiler log, if applicable
@ -389,11 +308,6 @@ static void WriteAllLocations() {
const char* SpoilerLog_Write() { const char* SpoilerLog_Write() {
auto ctx = Rando::Context::GetInstance(); auto ctx = Rando::Context::GetInstance();
auto spoilerLog = tinyxml2::XMLDocument(false);
spoilerLog.InsertEndChild(spoilerLog.NewDeclaration());
auto rootNode = spoilerLog.NewElement("spoiler-log");
spoilerLog.InsertEndChild(rootNode);
jsonData.clear(); jsonData.clear();
@ -413,11 +327,8 @@ const char* SpoilerLog_Write() {
WriteSettings(); WriteSettings();
WriteExcludedLocations(); WriteExcludedLocations();
WriteStartingInventory(); WriteStartingInventory();
WriteEnabledTricks(spoilerLog); //RANDOTODO clean up spoilerLog refernces WriteEnabledTricks();
//if (Settings::Logic.Is(LOGIC_GLITCHED)) { WriteMasterQuestDungeons();
// WriteEnabledGlitches(spoilerLog);
//}
WriteMasterQuestDungeons(spoilerLog);
WriteRequiredTrials(); WriteRequiredTrials();
WritePlaythrough(); WritePlaythrough();
@ -466,30 +377,3 @@ void PlacementLog_Clear() {
placementtxt = ""; placementtxt = "";
} }
// RANDOTODO: Do we even use this?
bool PlacementLog_Write() {
auto placementLog = tinyxml2::XMLDocument(false);
placementLog.InsertEndChild(placementLog.NewDeclaration());
auto rootNode = placementLog.NewElement("placement-log");
placementLog.InsertEndChild(rootNode);
// rootNode->SetAttribute("version", Settings::version.c_str());
// rootNode->SetAttribute("seed", Settings::seed);
// WriteSettings(placementLog, true); // Include hidden settings.
// WriteExcludedLocations(placementLog);
// WriteStartingInventory(placementLog);
WriteEnabledTricks(placementLog);
//WriteEnabledGlitches(placementLog);
WriteMasterQuestDungeons(placementLog);
//WriteRequiredTrials(placementLog);
placementtxt = "\n" + placementtxt;
auto node = rootNode->InsertNewChildElement("log");
auto contentNode = node->InsertNewText(placementtxt.c_str());
contentNode->SetCData(true);
return true;
}

View File

@ -672,11 +672,8 @@ bool EntranceShuffler::PlaceOneWayPriorityEntrance(
} }
} }
} }
#ifdef ENABLE_DEBUG SPDLOG_DEBUG("ERROR: Unable to place priority one-way entrance for " + priorityName + "\n");
auto message = "ERROR: Unable to place priority one-way entrance for " + priorityName + "\n"; assert(false);
SPDLOG_DEBUG(message);
PlacementLog_Write();
#endif
return false; return false;
} }

View File

@ -55,7 +55,7 @@ uint8_t Option::GetContextOptionIndex() const {
} }
const std::string& Option::GetSelectedOptionText() const { const std::string& Option::GetSelectedOptionText() const {
return options[menuSelection]; return options[contextSelection];
} }
const std::string& Option::GetCVarName() const { const std::string& Option::GetCVarName() const {