Add reset/randomize all SFX and Cosmetic commands to console (#2378)

* add reset/randomize all commands to debug console for sfx and cosmetic editor

* fix cvar func
This commit is contained in:
Adam Bird 2023-01-22 03:51:23 -05:00 committed by GitHub
parent 52a976489b
commit 37f31116b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 132 additions and 31 deletions

View File

@ -1798,3 +1798,25 @@ void InitCosmeticsEditor() {
SohImGui::RequestCvarSaveOnNextTick();
ApplyOrResetCustomGfxPatches();
}
void CosmeticsEditor_RandomizeAll() {
for (auto& [id, cosmeticOption] : cosmeticOptions) {
if (!CVarGetInteger(cosmeticOption.lockedCvar, 0)) {
RandomizeColor(cosmeticOption);
}
}
SohImGui::RequestCvarSaveOnNextTick();
ApplyOrResetCustomGfxPatches();
}
void CosmeticsEditor_ResetAll() {
for (auto& [id, cosmeticOption] : cosmeticOptions) {
if (!CVarGetInteger(cosmeticOption.lockedCvar, 0)) {
ResetColor(cosmeticOption);
}
}
SohImGui::RequestCvarSaveOnNextTick();
ApplyOrResetCustomGfxPatches();
}

View File

@ -25,3 +25,5 @@ static ImGuiTableColumnFlags FlagsCell = ImGuiTableColumnFlags_WidthStretch | Im
void InitCosmeticsEditor();//Init the menu itself
ImVec4 GetRandomValue(int MaximumPossible);
void CosmeticsEditor_RandomizeAll();
void CosmeticsEditor_ResetAll();

View File

@ -8,6 +8,8 @@
#include <string>
#include "soh/OTRGlobals.h"
#include <soh/Enhancements/item-tables/ItemTableManager.h>
#include "soh/Enhancements/cosmetics/CosmeticsEditor.h"
#include "soh/Enhancements/sfx-editor/SfxEditor.h"
#define Path _Path
@ -906,6 +908,42 @@ static bool CuccoStormHandler(std::shared_ptr<Ship::Console> Console, const std:
return CMD_SUCCESS;
}
static bool CosmeticsHandler(std::shared_ptr<Ship::Console> Console, const std::vector<std::string>& args) {
if (args.size() != 2) {
SohImGui::GetConsole()->SendErrorMessage("[SOH] Unexpected arguments passed");
return CMD_FAILED;
}
if (args[1].compare("reset") == 0) {
CosmeticsEditor_ResetAll();
} else if (args[1].compare("randomize") == 0) {
CosmeticsEditor_RandomizeAll();
} else {
SohImGui::GetConsole()->SendErrorMessage("[SOH] Invalid argument passed, must be 'reset' or 'randomize'");
return CMD_FAILED;
}
return CMD_SUCCESS;
}
static bool SfxHandler(std::shared_ptr<Ship::Console> Console, const std::vector<std::string>& args) {
if (args.size() != 2) {
SohImGui::GetConsole()->SendErrorMessage("[SOH] Unexpected arguments passed");
return CMD_FAILED;
}
if (args[1].compare("reset") == 0) {
SfxEditor_ResetAll();
} else if (args[1].compare("randomize") == 0) {
SfxEditor_RandomizeAll();
} else {
SohImGui::GetConsole()->SendErrorMessage("[SOH] Invalid argument passed, must be 'reset' or 'randomize'");
return CMD_FAILED;
}
return CMD_SUCCESS;
}
#define VARTYPE_INTEGER 0
#define VARTYPE_FLOAT 1
#define VARTYPE_STRING 2
@ -1159,5 +1197,13 @@ void DebugConsole_Init(void) {
CMD_REGISTER("cucco_storm", { CuccoStormHandler, "Cucco Storm" });
CMD_REGISTER("cosmetics", { CosmeticsHandler, "Change cosmetics.", {
{ "reset|randomize", Ship::ArgumentType::TEXT },
}});
CMD_REGISTER("sfx", { SfxHandler, "Change SFX.", {
{ "reset|randomize", Ship::ArgumentType::TEXT },
}});
CVarLoad();
}

View File

@ -203,22 +203,49 @@ void UpdateCurrentBGM(u16 seqKey, SeqType seqType) {
}
}
void RandomizeGroup(const std::map<u16, std::tuple<std::string, std::string, SeqType>>& map, SeqType type) {
std::vector<u16> values;
for (const auto& [value, seqData] : map) {
if (std::get<2>(seqData) & type) {
values.push_back(value);
}
}
Shuffle(values);
for (const auto& [defaultValue, seqData] : map) {
const auto& [name, sfxKey, seqType] = seqData;
const std::string cvarKey = "gSfxEditor_" + sfxKey;
if (seqType & type) {
// Only save authentic sequence CVars
if (((seqType & SEQ_BGM_CUSTOM) || seqType == SEQ_FANFARE) && defaultValue >= MAX_AUTHENTIC_SEQID) {
continue;
}
const int randomValue = values.back();
CVarSetInteger(cvarKey.c_str(), randomValue);
values.pop_back();
}
}
}
void ResetGroup(const std::map<u16, std::tuple<std::string, std::string, SeqType>>& map, SeqType type) {
for (const auto& [defaultValue, seqData] : map) {
const auto& [name, sfxKey, seqType] = seqData;
if (seqType == type) {
// Only save authentic sequence CVars
if (seqType == SEQ_FANFARE && defaultValue >= MAX_AUTHENTIC_SEQID) {
continue;
}
const std::string cvarKey = "gSfxEditor_" + sfxKey;
CVarSetInteger(cvarKey.c_str(), defaultValue);
}
}
}
void Draw_SfxTab(const std::string& tabId, const std::map<u16, std::tuple<std::string, std::string, SeqType>>& map, SeqType type) {
const std::string hiddenTabId = "##" + tabId;
const std::string resetAllButton = "Reset All" + hiddenTabId;
const std::string randomizeAllButton = "Randomize All" + hiddenTabId;
if (ImGui::Button(resetAllButton.c_str())) {
for (const auto& [defaultValue, seqData] : map) {
const auto& [name, sfxKey, seqType] = seqData;
if (seqType == type) {
// Only save authentic sequence CVars
if (seqType == SEQ_FANFARE && defaultValue >= MAX_AUTHENTIC_SEQID) {
continue;
}
const std::string cvarKey = "gSfxEditor_" + sfxKey;
CVarSetInteger(cvarKey.c_str(), defaultValue);
}
}
ResetGroup(map, type);
SohImGui::RequestCvarSaveOnNextTick();
if (type == SEQ_BGM_WORLD) {
ReplayCurrentBGM();
@ -226,26 +253,7 @@ void Draw_SfxTab(const std::string& tabId, const std::map<u16, std::tuple<std::s
}
ImGui::SameLine();
if (ImGui::Button(randomizeAllButton.c_str())) {
std::vector<u16> values;
for (const auto& [value, seqData] : map) {
if (std::get<2>(seqData) & type) {
values.push_back(value);
}
}
Shuffle(values);
for (const auto& [defaultValue, seqData] : map) {
const auto& [name, sfxKey, seqType] = seqData;
const std::string cvarKey = "gSfxEditor_" + sfxKey;
if (seqType & type) {
// Only save authentic sequence CVars
if (((seqType & SEQ_BGM_CUSTOM) || seqType == SEQ_FANFARE) && defaultValue >= MAX_AUTHENTIC_SEQID) {
continue;
}
const int randomValue = values.back();
CVarSetInteger(cvarKey.c_str(), randomValue);
values.pop_back();
}
}
RandomizeGroup(map, type);
SohImGui::RequestCvarSaveOnNextTick();
if (type == SEQ_BGM_WORLD) {
ReplayCurrentBGM();
@ -476,6 +484,26 @@ void InitSfxEditor() {
SohImGui::AddWindow("Enhancements", "SFX Editor", DrawSfxEditor);
}
std::vector<SeqType> allTypes = { SEQ_BGM_WORLD, SEQ_BGM_EVENT, SEQ_BGM_BATTLE, SEQ_OCARINA, SEQ_FANFARE, SEQ_INSTRUMENT, SEQ_SFX };
void SfxEditor_RandomizeAll() {
for (auto type : allTypes) {
RandomizeGroup(sfxEditorSequenceMap, type);
}
SohImGui::RequestCvarSaveOnNextTick();
ReplayCurrentBGM();
}
void SfxEditor_ResetAll() {
for (auto type : allTypes) {
ResetGroup(sfxEditorSequenceMap, type);
}
SohImGui::RequestCvarSaveOnNextTick();
ReplayCurrentBGM();
}
extern "C" void SfxEditor_AddSequence(char *otrPath, uint16_t seqNum) {
std::vector<std::string> splitName = StringHelper::Split(std::string(otrPath), "/");
std::string fileName = splitName[splitName.size() - 1];

View File

@ -2,6 +2,9 @@
#include "stdint.h"
void InitSfxEditor();
void SfxEditor_RandomizeAll();
void SfxEditor_ResetAll();
#ifndef __cplusplus
const char* SfxEditor_GetSequenceName(u16 seqId);
void SfxEditor_AddSequence(char *otrPath, uint16_t seqNum);