Fix game settings not properly loading for the emscripten version.

mac-build
sigonasr2 9 months ago
parent ddddd966aa
commit 9b21d447da
  1. 5
      Adventures in Lestoria/AdventuresInLestoria.cpp
  2. 27
      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()
{
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);
@ -3552,7 +3553,6 @@ void AiL::GetAnyKeyRelease(Key key){
#pragma region New keyboard input binding listener
using A=Attribute;
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.
using A=Attribute;
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))){
InputGroup::menuNamesToInputGroups[Menu::menus[NEW_INPUT]->S(A::KEYBIND)]->AddKeybind(Input{MOUSE,mouseButton});
Menu::alreadyClicked=true;
for(auto&[menuType,menu]:Menu::menus){
menu->helpDisplay.Initialize(menu->inputGroups);
}
Menu::CloseMenu();
}
}else{

@ -96,7 +96,10 @@ void GameSettings::Initialize(){
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")){
GameSettings::SetScreenShake(loadSystemFile["Screen Shake"].GetBool());
@ -129,21 +132,27 @@ void GameSettings::Initialize(){
if(loadSystemFile.HasProperty("SFX Level"))Audio::SetSFXVolume(loadSystemFile["SFX Level"].GetReal());
#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 menuColCount=2;
for(int row=0;row<menuRowCount;row++){
for(int col=0;col<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.
std::string keyName="Menu Keyboard Input_"+"Inputs.Menu Input Names"_s[inputID];
if(loadSystemFile.HasProperty(keyName)){
InputGroup&group=Component<InputDisplayComponent>(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput();
group.SetNewPrimaryKeybind({KEY,loadSystemFile[keyName].GetInt()});
if(loadSystemFile.HasProperty("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)){
InputGroup&group=Component<InputDisplayComponent>(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput();
group.SetNewPrimaryKeybind({KEY,loadSystemFile[keyName].GetInt()});
}
}
keyName="Menu Controller Input_"+"Inputs.Menu Input Names"_s[inputID];
if(loadSystemFile.HasProperty(keyName)){
InputGroup&group=Component<InputDisplayComponent>(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput();
group.SetNewPrimaryKeybind({CONTROLLER,loadSystemFile[keyName].GetInt()});
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)){
InputGroup&group=Component<InputDisplayComponent>(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput();
group.SetNewPrimaryKeybind({CONTROLLER,loadSystemFile[keyName].GetInt()});
}
}
}
}

@ -197,6 +197,9 @@ InputGroup::InputGroup(){}
void InputGroup::AddKeybind(Input bind){
keys.insert(bind);
keyOrder.push_back(bind);
for(auto&[menuType,menu]:Menu::menus){
menu->ReInitializeInputGroup();
}
}
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){
std::cout<<"Successfully saved system file!"<<std::endl;
},[](void*arg){
std::cout<<"Successfully saved system file!"<<std::endl;
std::cout<<"Failed to save system file!"<<std::endl;
});
systemfile.close();

Loading…
Cancel
Save