commit c3846a75
Can now save multiple worlds
Changed files
| M | src/saland/Game.cpp before |
| M | src/saland/GameRegion.cpp before |
| M | src/saland/GameRegion.hpp before |
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp
index 66ae41e..9d2f836 100644
--- a/src/saland/Game.cpp
+++ b/src/saland/Game.cpp
@@ -75,12 +75,13 @@ struct Game::GameImpl {
int world_mouse_y = 0;
char direction = 0;
Uint32 lastUpdate = 0;
+ std::string worldName = "world1";
sago::SagoTextField bottomField;
};
void Game::ResetWorld(int x, int y) {
data->gameRegion.SaveRegion();
- data->gameRegion.Init(x, y);
+ data->gameRegion.Init(x, y, data->worldName);
data->human.reset(new Human());
data->gameRegion.placeables.push_back(data->human);
b2BodyDef myBodyDef;
diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp
index 2945cdf..506d8d1 100644
--- a/src/saland/GameRegion.cpp
+++ b/src/saland/GameRegion.cpp
@@ -24,18 +24,18 @@ https://github.com/sago007/saland
#include "GameRegion.hpp"
GameRegion::GameRegion() {
- Init(0, 0);
+ Init(0, 0, "world1");
}
-static std::string createFileName(int x, int y) {
- std::string ret = std::string("maps/m")+std::to_string(x)+"x"+std::to_string(y)+".tmx" ;
+static std::string createFileName(int x, int y,const std::string& worldName) {
+ std::string ret = std::string("worlds/")+worldName+"/"+std::string("maps/m")+std::to_string(x)+"x"+std::to_string(y)+".tmx" ;
return ret;
}
-void GameRegion::Init(int x, int y) {
+void GameRegion::Init(int x, int y, const std::string& worldName) {
region_x = x;
region_y = y;
- mapFileName = createFileName(region_x, region_y);
+ mapFileName = createFileName(region_x, region_y, worldName);
std::string loadMap = mapFileName;
if (!sago::FileExists(loadMap.c_str())) {
loadMap = "maps/sample1.tmx";
diff --git a/src/saland/GameRegion.hpp b/src/saland/GameRegion.hpp
index 0093111..1ff33ff 100644
--- a/src/saland/GameRegion.hpp
+++ b/src/saland/GameRegion.hpp
@@ -31,7 +31,7 @@ https://github.com/sago007/saland
class GameRegion {
public:
GameRegion();
- void Init(int x, int y);
+ void Init(int x, int y, const std::string& worldName);
std::vector<std::shared_ptr<Placeable> > placeables;
std::shared_ptr<b2World> physicsBox;
void SaveRegion();