Load and read data from save file for load file screen

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent d1d27b8a41
commit e1f7312c07
  1. BIN
      C++ProjectTemplate
  2. 41
      main.cpp
  3. 1
      object.h
  4. 2
      save0
  5. 1
      states.h

Binary file not shown.

@ -33,6 +33,12 @@
using namespace olc; using namespace olc;
struct SaveFileData{
int frameTime;
std::string playerName;
int chapterNumber;
};
std::vector<Object*> OBJECTS; std::vector<Object*> OBJECTS;
const vd2d NO_NEIGHBOR = {-999,-999}; const vd2d NO_NEIGHBOR = {-999,-999};
SeasonI*GAME; SeasonI*GAME;
@ -59,7 +65,7 @@ int MAP_WIDTH=-1;
int MAP_HEIGHT=-1; int MAP_HEIGHT=-1;
Map*CURRENT_MAP=nullptr; Map*CURRENT_MAP=nullptr;
std::map<MapName::Map,Map*> MAPS; std::map<MapName::Map,Map*> MAPS;
int GAME_STATE = GameState::EDITOR; int GAME_STATE=GameState::FILE_LOAD_SELECT;
vi2d SELECTED_TILE={0,0}; vi2d SELECTED_TILE={0,0};
vi2d HIGHLIGHTED_TILE={0,0}; vi2d HIGHLIGHTED_TILE={0,0};
int EDITING_LAYER=layer::DYNAMIC; int EDITING_LAYER=layer::DYNAMIC;
@ -168,6 +174,8 @@ bool SELECTING_A_MAP_FOR_TRIGGER=false;
Trigger*LAST_PLACED_TRIGGER=nullptr; Trigger*LAST_PLACED_TRIGGER=nullptr;
Map* ORIGINATING_MAP=nullptr; Map* ORIGINATING_MAP=nullptr;
std::array<std::string,7> PARTY_MEMBER_NAMES={"PLAYER","NESS","PAULA","JEFF","ANNA","KING","POO"}; std::array<std::string,7> PARTY_MEMBER_NAMES={"PLAYER","NESS","PAULA","JEFF","ANNA","KING","POO"};
std::array<SaveFileData,3> SAVE_FILE_DATA={{}};
int CHAPTER_NUMBER=0;
/* /*
[Choice1,Choice2,Choice3] [Choice1,Choice2,Choice3]
@ -309,6 +317,25 @@ bool SeasonI::OnUserCreate(){
AddItemToPlayerInventory(ItemName::TEE_BALL_BAT); AddItemToPlayerInventory(ItemName::TEE_BALL_BAT);
AddItemToPlayerInventory(ItemName::FREEZE_PACKET); AddItemToPlayerInventory(ItemName::FREEZE_PACKET);
for (int i=0;i<3;i++) {
if (std::filesystem::exists("save"+std::to_string(i))) {
std::ifstream f("save"+std::to_string(i));
std::string data;
std::getline(f,data);
int commaPos=data.find_last_of(" ",data.size()-2)+1;
std::string chapterNumber=data.substr(commaPos,data.size());
int prevCommaPos=commaPos;
commaPos=data.find_last_of(" ",commaPos-2)+1;
std::string playerName=data.substr(commaPos,prevCommaPos-commaPos);
prevCommaPos=commaPos;
commaPos=data.find_last_of(" ",commaPos-2)+1;
std::string fileTime=data.substr(commaPos,prevCommaPos-commaPos);
//printf("File time detected is %s\n",fileTime.c_str());
SAVE_FILE_DATA[i]={frameTime:stoi(fileTime),playerName:playerName,chapterNumber:stoi(chapterNumber)};
}
}
return true; return true;
} }
#endif #endif
@ -2709,6 +2736,12 @@ void SeasonI::drawGame(){
} }
switch (GAME_STATE) { switch (GAME_STATE) {
case GameState::FILE_LOAD_SELECT:{
DrawDialogBox({4,4},{(int)(WIDTH-8),HEIGHT/4},Pixel(70, 33, 105,220),Pixel(62, 54, 69,220),Pixel(185, 148, 255,220));
for (int i=0;i<3;i++) {
DrawStringDecal({8.f,(float)(8+i*12)},SAVE_FILE_DATA[i].playerName+" Chapter "+std::to_string(SAVE_FILE_DATA[i].chapterNumber)+" "+std::to_string(SAVE_FILE_DATA[i].frameTime));
}
}break;
case GameState::GAME_WORLD: case GameState::GAME_WORLD:
case GameState::OVERWORLD_MENU: case GameState::OVERWORLD_MENU:
case GameState::OVERWORLD_POWER_MENU: case GameState::OVERWORLD_POWER_MENU:
@ -5226,6 +5259,9 @@ void SeasonI::SaveGameSaveData(int saveSlot) {
file<<GAME_FLAGS[i]<<" "; file<<GAME_FLAGS[i]<<" ";
} }
file<<CURRENT_MAP->myID<<" "; file<<CURRENT_MAP->myID<<" ";
file<<frameCount<<" ";
file<<PARTY_MEMBER_NAMES[0]<<" ";
file<<CHAPTER_NUMBER<<" ";
file.close(); file.close();
} }
@ -5314,6 +5350,9 @@ void SeasonI::LoadGameSaveData(int saveSlot) {
for (int i=0;i<playerCount;i++) { for (int i=0;i<playerCount;i++) {
PARTY_MEMBER_OBJ[i]->SetPos(positions[i]); PARTY_MEMBER_OBJ[i]->SetPos(positions[i]);
} }
frameCount=ReadIntFromStream(file);
ReadStringFromStream(file);
CHAPTER_NUMBER=ReadIntFromStream(file);
} }
#ifndef TEST_SUITE #ifndef TEST_SUITE

@ -73,7 +73,6 @@ class Object{
:Object(id,name,{gridx*32-(spr->sprSize.x*0.5)*(scale.x-1),gridy*32-(spr->sprSize.y-4)*(scale.y-1)},spr,scale,color,animationSpd,temp,data) {} :Object(id,name,{gridx*32-(spr->sprSize.x*0.5)*(scale.x-1),gridy*32-(spr->sprSize.y-4)*(scale.y-1)},spr,scale,color,animationSpd,temp,data) {}
Object(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0}) Object(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0})
:spr(spr),pos(pos),id(id),name(name),color(color),animationSpd(animationSpd),temp(temp),extraData(data),startPos(pos) { :spr(spr),pos(pos),id(id),name(name),color(color),animationSpd(animationSpd),temp(temp),extraData(data),startPos(pos) {
printf("Extra data:%d %d %lf\n",extraData.moveFreq,extraData.moveTime,extraData.moveSpd);
SetScale(scale); SetScale(scale);
} }
virtual Object* CreateType(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0})=0; virtual Object* CreateType(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0})=0;

@ -1 +1 @@
120 120 PLAYER 30 30 8 8 4 0 0 0 0 0 0 0 11 9 10 13 14 15 16 17 33 29 21 25 1 6 4 3 -1 -1 -1 147 231 120 120 NESS 30 30 8 8 4 0 0 0 0 0 0 0 6 33 34 29 30 31 32 0 3 -1 -1 -1 150 259 120 120 PAULA 30 30 8 8 4 0 0 0 0 0 0 0 6 21 22 23 24 37 38 0 3 -1 -1 -1 138 261 120 120 JEFF 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 48 0 ANNA 30 0 0 0 4 0 0 0 0 0 0 0 0 0 3 -1 -1 -1 126 273 0 0 KING 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 0 0 POO 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 0 512 1 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 120 120 PLAYER 30 30 8 8 4 0 0 0 0 0 0 0 11 9 10 13 14 15 16 17 33 29 21 25 1 6 4 3 -1 -1 -1 343 200 120 120 NESS 30 30 8 8 4 0 0 0 0 0 0 0 6 33 34 29 30 31 32 0 3 -1 -1 -1 343 200 120 120 PAULA 30 30 8 8 4 0 0 0 0 0 0 0 6 21 22 23 24 37 38 0 3 -1 -1 -1 343 200 120 120 JEFF 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 120 120 ANNA 30 30 8 8 4 0 0 0 0 0 0 0 4 21 25 26 29 0 3 -1 -1 -1 343 200 120 120 KING 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 120 120 POO 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 67 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 6 8 3 3 3 10 10 10 10 12 12 12 0 0 0 0 0 0 0 0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