mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-22 09:22:18 -05:00
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:
parent
52a976489b
commit
37f31116b3
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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];
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user