Added load file information on load screen. metadata file no longer counts towards file count. Added loadout data to the save file.

pull/28/head
sigonasr2 11 months ago
parent 8c986f17db
commit 3e5e78a606
  1. BIN
      Crawler/C++ Header File (OLC-3).zip
  2. BIN
      Crawler/C++ Source File (OLC-3).zip
  3. 3
      Crawler/Crawler.cpp
  4. 1
      Crawler/Crawler.h
  5. 51
      Crawler/LoadFileButton.h
  6. 6
      Crawler/LoadGameWindow.cpp
  7. 24
      Crawler/SaveFile.cpp
  8. 2
      Crawler/Version.h
  9. 2
      Crawler/assets/saves/metadata.dat

@ -2555,6 +2555,9 @@ void Crawler::ResetGame(){
player->ResetAccumulatedXP(); player->ResetAccumulatedXP();
player->totalXPEarned=0; player->totalXPEarned=0;
player->SetMoney(100U); player->SetMoney(100U);
for(int i=0;i<loadout.size();i++){
game->ClearLoadoutItem(i);
}
Unlock::unlocks.clear(); Unlock::unlocks.clear();
Unlock::Initialize(); Unlock::Initialize();
State_OverworldMap::SetStageMarker("Stage I-I"); State_OverworldMap::SetStageMarker("Stage I-I");

@ -58,6 +58,7 @@ class Crawler : public olc::PixelGameEngine
{ {
friend class GameState; friend class GameState;
friend class State_GameRun; friend class State_GameRun;
friend class SaveFile;
friend class sig::Animation; friend class sig::Animation;
std::unique_ptr<Player>player; std::unique_ptr<Player>player;
public: public:

@ -38,24 +38,63 @@ All rights reserved.
#pragma once #pragma once
#include "MenuComponent.h" #include "MenuComponent.h"
#include "ClassInfo.h"
INCLUDE_ANIMATION_DATA
class LoadFileButton:public MenuComponent{ class LoadFileButton:public MenuComponent{
double playTime; double playTime=-1;
int chapter; int chapter=-1;
int level; int level=-1;
std::string className; std::string className="";
std::string saveFileName; std::string saveFileName="";
int saveFileID; int saveFileID=-1;
float animationTime=0;
public: public:
inline LoadFileButton(geom2d::rect<float>rect,const utils::datafile&metadata,const int saveFileID,MenuFunc onClick,ButtonAttr attributes) inline LoadFileButton(geom2d::rect<float>rect,const utils::datafile&metadata,const int saveFileID,MenuFunc onClick,ButtonAttr attributes)
:MenuComponent(rect,"",onClick,attributes),playTime(metadata.GetReal(0U)),chapter(metadata.GetInt(1U)),level(metadata.GetInt(2U)),className(metadata.GetString(3U)),saveFileName(metadata.GetString(4U)),saveFileID(saveFileID){ :MenuComponent(rect,"",onClick,attributes),playTime(metadata.GetReal(0U)),chapter(metadata.GetInt(1U)),level(metadata.GetInt(2U)),className(metadata.GetString(3U)),saveFileName(metadata.GetString(4U)),saveFileID(saveFileID){
showDefaultLabel=false; showDefaultLabel=false;
} }
inline void Update(Crawler*game)override{
MenuComponent::Update(game);
if(playTime==-1){
grayedOut=true;
}
animationTime+=game->GetElapsedTime();
}
inline void DrawDecal(ViewPort&window,bool focused){ inline void DrawDecal(ViewPort&window,bool focused){
MenuComponent::DrawDecal(window,focused); MenuComponent::DrawDecal(window,focused);
if(playTime==-1){
window.DrawShadowStringPropDecal(rect.pos+vf2d{2,2},"UNKNOWN");
}else{
window.DrawShadowStringPropDecal(rect.pos+vf2d{2,2},saveFileName);
const std::map<std::string,std::string>classAnimations={
{Warrior::name,Warrior::walk_s},
{Ranger::name,Ranger::walk_s},
{Wizard::name,Wizard::walk_s},
{Thief::name,Thief::walk_s},
{Trapper::name,Trapper::walk_s},
{Witch::name,Witch::walk_s},
};
std::string chapterText=std::format("Ch.{}",chapter);
vf2d chapterTextSize=game->GetTextSize(chapterText);
window.DrawShadowStringDecal(rect.pos+vf2d{rect.size.x-chapterTextSize.x-2,2},chapterText);
const Animate2D::Frame&frame=ANIMATION_DATA[classAnimations.at(className)].GetFrame(animationTime);
geom2d::rect<int>sprRect=frame.GetSourceRect();
window.DrawPartialDecal(rect.pos+vf2d{rect.size.x-26,rect.size.y-36},sprRect.size,frame.GetSourceImage()->Decal(),sprRect.pos,sprRect.size);
std::string levelClassText=std::format("Lv{} {}",level,className);
vf2d levelClassTextSize=game->GetTextSize(levelClassText);
window.DrawShadowStringDecal(rect.pos+vf2d{rect.size.x-levelClassTextSize.x-2,rect.size.y-10},levelClassText);
window.DrawShadowStringDecal(rect.pos+vf2d{2,12},util::timerStr(playTime));
}
} }
inline const int&getSaveFileID()const{ inline const int&getSaveFileID()const{

@ -40,7 +40,9 @@ All rights reserved.
#include "ScrollableWindowComponent.h" #include "ScrollableWindowComponent.h"
void Menu::InitializeLoadGameWindow(){ void Menu::InitializeLoadGameWindow(){
Menu*loadGameWindow=CreateMenu(LOAD_GAME,CENTERED,vi2d{96,96}); Menu*loadGameWindow=CreateMenu(LOAD_GAME,CENTERED,vi2d{96,120});
loadGameWindow->ADD("Game Files List",ScrollableWindowComponent)({{-8,0},{112,104}})END; loadGameWindow->ADD("Game Files Label",MenuLabel)({{-8,-12},{112,12}},"Load Game",1.0f,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
loadGameWindow->ADD("Game Files List",ScrollableWindowComponent)({{-8,4},{112,116}})END;
loadGameWindow->ADD("Go Back Button",MenuComponent)({{24,124},{48,12}},"Back",[](MenuFuncData menu){Menu::CloseMenu();return true;})END;
} }

@ -53,15 +53,18 @@ std::string SaveFile::saveFileName="";
const size_t SaveFile::GetSaveFileCount(){ const size_t SaveFile::GetSaveFileCount(){
size_t count=0; size_t count=0;
if(std::filesystem::exists("save_file_path"_S)){
for(auto&path:std::filesystem::directory_iterator("save_file_path"_S)){ for(auto&path:std::filesystem::directory_iterator("save_file_path"_S)){
if(path.is_regular_file()){ if(path.is_regular_file()&&path.path()!="metadata.dat"){
count++; count++;
} }
} }
}
return count; return count;
} }
const void SaveFile::SaveGame(){ const void SaveFile::SaveGame(){
std::filesystem::create_directories("save_file_path"_S);
utils::datafile saveFile; utils::datafile saveFile;
utils::datafile::INITIAL_SETUP_COMPLETE=false; utils::datafile::INITIAL_SETUP_COMPLETE=false;
for(size_t itemCount=0;auto&[cat,items]:Inventory::sortedInv){ for(size_t itemCount=0;auto&[cat,items]:Inventory::sortedInv){
@ -70,6 +73,11 @@ const void SaveFile::SaveGame(){
saveFile["Items"][std::format("Item[{}]",itemCount)]["Enhancement Level"].SetInt(item->EnhancementLevel()); saveFile["Items"][std::format("Item[{}]",itemCount)]["Enhancement Level"].SetInt(item->EnhancementLevel());
saveFile["Items"][std::format("Item[{}]",itemCount)]["Item Name"].SetString(item->ActualName()); saveFile["Items"][std::format("Item[{}]",itemCount)]["Item Name"].SetString(item->ActualName());
saveFile["Items"][std::format("Item[{}]",itemCount)]["Equip Slot"].SetInt(int(Inventory::GetSlotEquippedIn(item))); saveFile["Items"][std::format("Item[{}]",itemCount)]["Equip Slot"].SetInt(int(Inventory::GetSlotEquippedIn(item)));
uint8_t loadoutSlotNumber=255;
for(int i=0;i<game->loadout.size();i++){
if(item==game->GetLoadoutItem(i)){loadoutSlotNumber=i;break;}
}
saveFile["Items"][std::format("Item[{}]",itemCount)]["LoadoutSlot"].SetInt(loadoutSlotNumber);
for(const auto&[attr,val]:item->RandomStats()){ for(const auto&[attr,val]:item->RandomStats()){
saveFile["Items"][std::format("Item[{}]",itemCount)]["Attributes"][std::string(attr.ActualName())].SetReal(val); saveFile["Items"][std::format("Item[{}]",itemCount)]["Attributes"][std::string(attr.ActualName())].SetReal(val);
} }
@ -94,7 +102,9 @@ const void SaveFile::SaveGame(){
utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
utils::datafile metadata; utils::datafile metadata;
if(std::filesystem::exists("save_file_path"_S+"metadata.dat")){
utils::datafile::Read(metadata,"save_file_path"_S+"metadata.dat"); utils::datafile::Read(metadata,"save_file_path"_S+"metadata.dat");
}
metadata.GetProperty(std::format("save{}",saveFileID)).SetReal(game->GetRuntime(),0U); metadata.GetProperty(std::format("save{}",saveFileID)).SetReal(game->GetRuntime(),0U);
metadata.GetProperty(std::format("save{}",saveFileID)).SetInt(game->GetCurrentChapter(),1U); metadata.GetProperty(std::format("save{}",saveFileID)).SetInt(game->GetCurrentChapter(),1U);
metadata.GetProperty(std::format("save{}",saveFileID)).SetInt(game->GetPlayer()->Level(),2U); metadata.GetProperty(std::format("save{}",saveFileID)).SetInt(game->GetPlayer()->Level(),2U);
@ -106,7 +116,9 @@ const void SaveFile::SaveGame(){
} }
const void SaveFile::LoadGame(){ const void SaveFile::LoadGame(){
std::filesystem::create_directories("save_file_path"_S);
utils::datafile loadFile; utils::datafile loadFile;
if(std::filesystem::exists("save_file_path"_S+std::format("save.{:04}",saveFileID))){
utils::datafile::Read(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); utils::datafile::Read(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
game->ResetGame(); game->ResetGame();
for(auto&[key,data]:loadFile["Items"].GetOrderedKeys()){ for(auto&[key,data]:loadFile["Items"].GetOrderedKeys()){
@ -117,6 +129,13 @@ const void SaveFile::LoadGame(){
newItem.lock()->randomizedStats.A(attr)=data.GetReal(); newItem.lock()->randomizedStats.A(attr)=data.GetReal();
} }
} }
if(data.HasProperty("LoadoutSlot")){
uint8_t loadoutSlot=data["LoadoutSlot"].GetInt();
if(loadoutSlot!=255){
game->SetLoadoutItem(loadoutSlot,newItem.lock()->ActualName());
}
}
EquipSlot slot=EquipSlot(loadFile.GetProperty(std::format("Items.{}.Equip Slot",key)).GetInt()); EquipSlot slot=EquipSlot(loadFile.GetProperty(std::format("Items.{}.Equip Slot",key)).GetInt());
if(slot!=EquipSlot::NONE){ //This should be equipped somewhere! if(slot!=EquipSlot::NONE){ //This should be equipped somewhere!
Inventory::EquipItem(newItem,slot); Inventory::EquipItem(newItem,slot);
@ -140,6 +159,9 @@ const void SaveFile::LoadGame(){
game->GetPlayer()->RecalculateEquipStats(); game->GetPlayer()->RecalculateEquipStats();
GameState::ChangeState(States::OVERWORLD_MAP,0.5f); GameState::ChangeState(States::OVERWORLD_MAP,0.5f);
}else{
std::cout<<std::format("WARNING! File {} does not exist for loading!","save_file_path"_S+std::format("save.{:04}",saveFileID))<<std::endl;
}
} }
const std::string_view SaveFile::GetSaveFileName(){ const std::string_view SaveFile::GetSaveFileName(){

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 5262 #define VERSION_BUILD 5279
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -0,0 +1,2 @@
save0 = 534.977882, 1, 2, Ranger, Sig
save1 = 107.824620, 1, 1, Wizard, WIZ
Loading…
Cancel
Save