Fix game settings not properly loading for the emscripten version.

pull/35/head
sigonasr2 9 months ago
parent a506c47aea
commit 79d50fdf96
  1. 5
      Adventures in Lestoria/AdventuresInLestoria.cpp
  2. 13
      Adventures in Lestoria/GameSettings.cpp
  3. 3
      Adventures in Lestoria/Key.cpp
  4. 2
      Adventures in Lestoria/SaveFile.cpp

@ -150,6 +150,7 @@ float AiL::SIZE_CHANGE_SPEED=1;
AiL::AiL() AiL::AiL()
{ {
utils::datafile::Read(DATA,"assets/config/configuration.txt"); utils::datafile::Read(DATA,"assets/config/configuration.txt");
std::filesystem::create_directories("save_file_path"_S);
_DEBUG_MAP_LOAD_INFO=bool("debug_map_load_info"_I); _DEBUG_MAP_LOAD_INFO=bool("debug_map_load_info"_I);
@ -3552,7 +3553,6 @@ void AiL::GetAnyKeyRelease(Key key){
#pragma region New keyboard input binding listener #pragma region New keyboard input binding listener
using A=Attribute; using A=Attribute;
if(Menu::IsMenuOpen()&&Menu::stack.back()==Menu::menus[NEW_INPUT]){ if(Menu::IsMenuOpen()&&Menu::stack.back()==Menu::menus[NEW_INPUT]){
if(Menu::menus[NEW_INPUT]->B(A::IS_KEYBOARD)){//We are requesting a brand new input. if(Menu::menus[NEW_INPUT]->B(A::IS_KEYBOARD)){//We are requesting a brand new input.
using A=Attribute; using A=Attribute;
if(InputGroup::menuNamesToInputGroups.count(Menu::menus[NEW_INPUT]->S(A::KEYBIND))){ if(InputGroup::menuNamesToInputGroups.count(Menu::menus[NEW_INPUT]->S(A::KEYBIND))){
@ -3607,9 +3607,6 @@ void AiL::GetAnyMouseRelease(int32_t mouseButton){
if(InputGroup::menuNamesToInputGroups.count(Menu::menus[NEW_INPUT]->S(A::KEYBIND))){ if(InputGroup::menuNamesToInputGroups.count(Menu::menus[NEW_INPUT]->S(A::KEYBIND))){
InputGroup::menuNamesToInputGroups[Menu::menus[NEW_INPUT]->S(A::KEYBIND)]->AddKeybind(Input{MOUSE,mouseButton}); InputGroup::menuNamesToInputGroups[Menu::menus[NEW_INPUT]->S(A::KEYBIND)]->AddKeybind(Input{MOUSE,mouseButton});
Menu::alreadyClicked=true; Menu::alreadyClicked=true;
for(auto&[menuType,menu]:Menu::menus){
menu->helpDisplay.Initialize(menu->inputGroups);
}
Menu::CloseMenu(); Menu::CloseMenu();
} }
}else{ }else{

@ -96,7 +96,10 @@ void GameSettings::Initialize(){
std::string loadSystemFilename="save_file_path"_S+"system.conf"; std::string loadSystemFilename="save_file_path"_S+"system.conf";
if(std::filesystem::exists(loadSystemFilename))utils::datafile::Read(loadSystemFile,loadSystemFilename); if(std::filesystem::exists(loadSystemFilename)){
std::cout<<"Reading system data file..."<<std::endl;
utils::datafile::Read(loadSystemFile,loadSystemFilename);
}
if(loadSystemFile.HasProperty("Screen Shake")){ if(loadSystemFile.HasProperty("Screen Shake")){
GameSettings::SetScreenShake(loadSystemFile["Screen Shake"].GetBool()); GameSettings::SetScreenShake(loadSystemFile["Screen Shake"].GetBool());
@ -129,23 +132,29 @@ void GameSettings::Initialize(){
if(loadSystemFile.HasProperty("SFX Level"))Audio::SetSFXVolume(loadSystemFile["SFX Level"].GetReal()); if(loadSystemFile.HasProperty("SFX Level"))Audio::SetSFXVolume(loadSystemFile["SFX Level"].GetReal());
#pragma region Load up Menu Keybinds #pragma region Load up Menu Keybinds
//NOTE: We are shadowing code from InputKeyboardWindow! If at some point the retrival method for getting input displays changes, we likely will be changing the code here as well!
//ALSO NOTE: The menu inputs are saved to the system file while gameplay inputs are per-character and saved to the character settings file!
const int menuRowCount=DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()%2==0?DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()/2:DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()/2+1; const int menuRowCount=DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()%2==0?DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()/2:DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()/2+1;
const int menuColCount=2; const int menuColCount=2;
for(int row=0;row<menuRowCount;row++){ for(int row=0;row<menuRowCount;row++){
for(int col=0;col<menuColCount;col++){ for(int col=0;col<menuColCount;col++){
int inputID=row*menuColCount+col; int inputID=row*menuColCount+col;
if(DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()%2==1&&col==1&&row==menuRowCount-1)continue; //We only continue on a blank space when we have an odd number of elements. if(DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()%2==1&&col==1&&row==menuRowCount-1)continue; //We only continue on a blank space when we have an odd number of elements.
if(loadSystemFile.HasProperty("Menu Keyboard Input_"+"Inputs.Menu Input Names"_s[inputID])){
std::string keyName="Menu Keyboard Input_"+"Inputs.Menu Input Names"_s[inputID]; std::string keyName="Menu Keyboard Input_"+"Inputs.Menu Input Names"_s[inputID];
if(loadSystemFile.HasProperty(keyName)){ if(loadSystemFile.HasProperty(keyName)){
InputGroup&group=Component<InputDisplayComponent>(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput(); InputGroup&group=Component<InputDisplayComponent>(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput();
group.SetNewPrimaryKeybind({KEY,loadSystemFile[keyName].GetInt()}); group.SetNewPrimaryKeybind({KEY,loadSystemFile[keyName].GetInt()});
} }
keyName="Menu Controller Input_"+"Inputs.Menu Input Names"_s[inputID]; }
if(loadSystemFile.HasProperty("Menu Controller Input_"+"Inputs.Menu Input Names"_s[inputID])){
std::string keyName="Menu Controller Input_"+"Inputs.Menu Input Names"_s[inputID];
if(loadSystemFile.HasProperty(keyName)){ if(loadSystemFile.HasProperty(keyName)){
InputGroup&group=Component<InputDisplayComponent>(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput(); InputGroup&group=Component<InputDisplayComponent>(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput();
group.SetNewPrimaryKeybind({CONTROLLER,loadSystemFile[keyName].GetInt()}); group.SetNewPrimaryKeybind({CONTROLLER,loadSystemFile[keyName].GetInt()});
} }
} }
} }
}
#pragma endregion #pragma endregion
} }

@ -197,6 +197,9 @@ InputGroup::InputGroup(){}
void InputGroup::AddKeybind(Input bind){ void InputGroup::AddKeybind(Input bind){
keys.insert(bind); keys.insert(bind);
keyOrder.push_back(bind); keyOrder.push_back(bind);
for(auto&[menuType,menu]:Menu::menus){
menu->ReInitializeInputGroup();
}
} }
void InputGroup::ClearAllKeybinds(){ void InputGroup::ClearAllKeybinds(){

@ -261,7 +261,7 @@ const void SaveFile::SaveGame(){
emscripten_idb_async_store("/assets",("save_file_path"_S+"system.conf").c_str(),systemContents.data(),systemContents.length(),0,[](void*arg){ emscripten_idb_async_store("/assets",("save_file_path"_S+"system.conf").c_str(),systemContents.data(),systemContents.length(),0,[](void*arg){
std::cout<<"Successfully saved system file!"<<std::endl; std::cout<<"Successfully saved system file!"<<std::endl;
},[](void*arg){ },[](void*arg){
std::cout<<"Successfully saved system file!"<<std::endl; std::cout<<"Failed to save system file!"<<std::endl;
}); });
systemfile.close(); systemfile.close();

Loading…
Cancel
Save