]> git.localhorst.tv Git - blank.git/blobdiff - src/app/runtime.cpp
make buttons configurable
[blank.git] / src / app / runtime.cpp
index 5dce72159a439203843581f84cb14fc86fdda08a..d77cf47c228fbbdbc573f1e5e26f2473f2ab00ed 100644 (file)
@@ -1,13 +1,15 @@
 #include "Application.hpp"
 #include "Environment.hpp"
-#include "PreloadState.hpp"
 #include "Runtime.hpp"
 #include "WorldState.hpp"
 
 #include "init.hpp"
+#include "../io/filesystem.hpp"
+#include "../io/WorldSave.hpp"
 
 #include <cctype>
 #include <cstdlib>
+#include <fstream>
 #include <iostream>
 #include <SDL.h>
 
@@ -49,7 +51,9 @@ Environment::Environment(Window &win, const string &asset_path)
 , window(win)
 , assets(asset_path)
 , counter() {
-
+       viewport.Clear();
+       window.Flip();
+       keymap.LoadDefault();
 }
 
 
@@ -112,6 +116,14 @@ void Runtime::ReadArgs(int argc, const char *const *argv) {
                                                } else {
                                                        config.save_path = argv[i];
                                                }
+                                       } else if (strcmp(param, "world-name") == 0) {
+                                               ++i;
+                                               if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
+                                                       cerr << "missing argument to --world-name" << endl;
+                                                       error = true;
+                                               } else {
+                                                       config.world_name = argv[i];
+                                               }
                                        } else {
                                                cerr << "unknown option " << arg << endl;
                                                error = true;
@@ -148,8 +160,7 @@ void Runtime::ReadArgs(int argc, const char *const *argv) {
                                                                cerr << "missing argument to -s" << endl;
                                                                error = true;
                                                        } else {
-                                                               config.world.gen.solid_seed = strtoul(argv[i], nullptr, 10);
-                                                               config.world.gen.type_seed = config.world.gen.solid_seed;
+                                                               config.world.gen.seed = strtoul(argv[i], nullptr, 10);
                                                        }
                                                        break;
                                                case 't':
@@ -224,14 +235,28 @@ int Runtime::Execute() {
        Environment env(init.window, config.asset_path);
        env.viewport.VSync(config.vsync);
 
+       std::string keys_path = config.save_path + "keys.conf";
+       if (!is_file(keys_path)) {
+               std::ofstream file(keys_path);
+               env.keymap.Save(file);
+       } else {
+               std::ifstream file(keys_path);
+               env.keymap.Load(file);
+       }
+
+
+       WorldSave save(config.save_path + config.world_name + '/');
+       if (save.Exists()) {
+               save.Read(config.world);
+       } else {
+               save.Write(config.world);
+       }
+
        Application app(env);
 
-       WorldState world_state(env, config.interface, config.world);
+       WorldState world_state(env, config.interface, config.world, save);
        app.PushState(&world_state);
 
-       PreloadState preloader(env, world_state.GetWorld().Loader());
-       app.PushState(&preloader);
-
        switch (mode) {
                default:
                case NORMAL: