The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'! https://forums.lestoria.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
AdventuresInLestoria/Adventures in Lestoria/GameSettings.cpp

195 lines
8.4 KiB

#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#include "GameSettings.h"
#include "olcUTIL_DataFile.h"
#include "config.h"
#include "Checkbox.h"
#include "MenuIconButton.h"
#include "InputDisplayComponent.h"
INCLUDE_DATA
bool GameSettings::screenShake=true;
bool GameSettings::showMaxHealth=false;
bool GameSettings::showMaxMana=false;
bool GameSettings::rumble=true;
bool GameSettings::terrainCollisionBoxes=true;
bool GameSettings::keyboardAutoAim=false;
bool GameSettings::vsync=true;
const bool GameSettings::OVERRIDE=true;
vi2d GameSettings::windowPos{30,30};
IconType GameSettings::iconType=IconType::XB;
const bool GameSettings::ShowMaxHealth(){
return showMaxHealth;
}
const bool GameSettings::ShowMaxMana(){
return showMaxMana;
}
const bool GameSettings::ScreenShakeEnabled(){
return screenShake;
}
const bool GameSettings::RumbleEnabled(const bool override){
return rumble&&(override||GameState::STATE!=GameState::states[States::MAIN_MENU]);
}
const bool GameSettings::TerrainCollisionBoxesEnabled(){
return terrainCollisionBoxes;
}
const bool GameSettings::KeyboardAutoAimEnabled(){
return keyboardAutoAim;
}
const vi2d GameSettings::GetWindowPos(){
return windowPos;
}
const IconType GameSettings::GetIconType(){
return iconType;
}
const bool GameSettings::VSyncEnabled(){
return vsync;
}
void GameSettings::SetMaxHealthDisplay(bool maxHealthDisplayed){
showMaxHealth=maxHealthDisplayed;
}
void GameSettings::SetMaxManaDisplay(bool maxManaDisplayed){
showMaxMana=maxManaDisplayed;
}
void GameSettings::SetScreenShake(bool screenShakeEnabled){
screenShake=screenShakeEnabled;
}
void GameSettings::SetRumble(bool rumbleEnabled){
rumble=rumbleEnabled;
}
void GameSettings::SetTerrainCollisionBoxes(bool terrainCollisionBoxesEnabled){
terrainCollisionBoxes=terrainCollisionBoxesEnabled;
}
void GameSettings::SetKeyboardAutoAim(bool autoAimEnabled){
keyboardAutoAim=autoAimEnabled;
}
void GameSettings::SetWindowPos(vi2d windowPos){
GameSettings::windowPos=windowPos;
}
void GameSettings::SetIconType(IconType type){
iconType=type;
}
void GameSettings::SetVSync(const bool vSyncEnabled){
vsync=vSyncEnabled;
}
void GameSettings::Initialize(){
utils::datafile loadSystemFile;
std::string loadSystemFilename="save_file_path"_S+"system.conf";
if(std::filesystem::exists(loadSystemFilename)){
LOG("Reading system data file...");
utils::datafile::Read(loadSystemFile,loadSystemFilename);
}
if(loadSystemFile.HasProperty("Show Max Health")){
GameSettings::SetMaxHealthDisplay(loadSystemFile["Show Max Health"].GetBool());
Component<Checkbox>(SETTINGS,"Show Max HP Checkbox")->SetChecked(loadSystemFile["Show Max Health"].GetBool());
}
if(loadSystemFile.HasProperty("Show Max Mana")){
GameSettings::SetMaxManaDisplay(loadSystemFile["Show Max Mana"].GetBool());
Component<Checkbox>(SETTINGS,"Show Max Mana Checkbox")->SetChecked(loadSystemFile["Show Max Mana"].GetBool());
}
if(loadSystemFile.HasProperty("Screen Shake")){
GameSettings::SetScreenShake(loadSystemFile["Screen Shake"].GetBool());
Component<Checkbox>(SETTINGS,"Screen Shake Checkbox")->SetChecked(loadSystemFile["Screen Shake"].GetBool());
}
if(loadSystemFile.HasProperty("Controller Rumble")){
GameSettings::SetRumble(loadSystemFile["Controller Rumble"].GetBool());
Component<Checkbox>(SETTINGS,"Controller Rumble Checkbox")->SetChecked(loadSystemFile["Controller Rumble"].GetBool());
}
if(loadSystemFile.HasProperty("Terrain Collision Boxes")){
GameSettings::SetTerrainCollisionBoxes(loadSystemFile["Terrain Collision Boxes"].GetBool());
Component<Checkbox>(SETTINGS,"Terrain Collision Boxes Checkbox")->SetChecked(loadSystemFile["Terrain Collision Boxes"].GetBool());
}
if(loadSystemFile.HasProperty("Keyboard Auto-Aim")){
GameSettings::SetKeyboardAutoAim(loadSystemFile["Keyboard Auto-Aim"].GetBool());
Component<Checkbox>(SETTINGS,"Keyboard Play Auto-Aim Checkbox")->SetChecked(loadSystemFile["Keyboard Auto-Aim"].GetBool());
}
if(loadSystemFile.HasProperty("VSync")){
GameSettings::SetVSync(loadSystemFile["VSync"].GetBool());
Component<Checkbox>(SETTINGS,"VSync Checkbox")->SetChecked(loadSystemFile["VSync"].GetBool());
game->SetVSync(GameSettings::VSyncEnabled());
}
if(loadSystemFile.HasProperty("Controller Icons")){
const int maxIterations=10;
int iterationCount=0;
IconType targetIconType=IconType(loadSystemFile["Controller Icons"].GetInt());
while(iterationCount<maxIterations&&GameSettings::GetIconType()!=targetIconType){
Component<MenuIconButton>(SETTINGS,"Button Set Toggle Box")->Click();
iterationCount++;
}
if(iterationCount>=maxIterations)ERR("WARNING! Reached the max iteration count while cycling through controller icons! Failed to reach target icon set. THIS SHOULD NOT BE HAPPENING!")
}
if(loadSystemFile.HasProperty("BGM Level"))Audio::SetBGMVolume(loadSystemFile["BGM Level"].GetReal());
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.
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()});
}
}
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()});
}
}
}
}
#pragma endregion
}