]> git.localhorst.tv Git - blobs.git/commitdiff
load resources from data file
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 17 Nov 2017 19:17:55 +0000 (20:17 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 17 Nov 2017 19:17:55 +0000 (20:17 +0100)
assets
src/app/Assets.hpp
src/app/app.cpp
src/world/Resources.hpp [deleted file]

diff --git a/assets b/assets
index f9f068f73b2fb5b0c134b40b16ed00118d775268..b63c91ead8b510b614efccc97b4000fc3aca9c87 160000 (submodule)
--- a/assets
+++ b/assets
@@ -1 +1 @@
-Subproject commit f9f068f73b2fb5b0c134b40b16ed00118d775268
+Subproject commit b63c91ead8b510b614efccc97b4000fc3aca9c87
index 68606cb62e070b4956c7e440b8a5c13d9166a6e5..3cfc1334371f7e2e491d3053113c6c0dd672a396 100644 (file)
@@ -50,6 +50,7 @@ struct Assets {
        Assets(Assets &&) = delete;
        Assets &operator =(Assets &&) = delete;
 
+       void ReadResources(io::TokenStreamReader &);
        void ReadTileTypes(io::TokenStreamReader &);
 
        void LoadTileTexture(const std::string &name, graphics::ArrayTexture &, int layer) const;
index 45a57cfde2bdc3458ffe2e7948561fb19d541258..ccccd9a6c15c5b2590e8a27b0274c74541c1451e 100644 (file)
@@ -175,14 +175,11 @@ Assets::Assets()
 , data_path(path + "data/")
 , skin_path(path + "skins/")
 , tile_path(path + "tiles/") {
-       data.resources.Add({ "air", "Air", 0 });
-       data.resources.Add({ "biomass", "Biomass", 0 });
-       data.resources.Add({ "dirt", "Dirt", 0 });
-       data.resources.Add({ "ice", "Ice", 0 });
-       data.resources.Add({ "rock", "Rock", 0 });
-       data.resources.Add({ "sand", "Sand", 0 });
-       data.resources.Add({ "water", "Water", 0 });
-       data.resources.Add({ "wood", "Wood", 0 });
+       {
+               std::ifstream resource_file(data_path + "resources");
+               io::TokenStreamReader resource_reader(resource_file);
+               ReadResources(resource_reader);
+       }
 
        {
                std::ifstream tile_file(data_path + "tiles");
@@ -224,6 +221,37 @@ Assets::Assets()
 Assets::~Assets() {
 }
 
+void Assets::ReadResources(io::TokenStreamReader &in) {
+       while (in.HasMore()) {
+               string name;
+               in.ReadIdentifier(name);
+               in.Skip(io::Token::EQUALS);
+
+               int id = 0;
+               if (data.resources.Has(name)) {
+                       id = data.resources[name].id;
+               } else {
+                       world::Resource res;
+                       res.name = name;
+                       id = data.resources.Add(res);
+               }
+
+               in.Skip(io::Token::ANGLE_BRACKET_OPEN);
+               while (in.Peek().type != io::Token::ANGLE_BRACKET_CLOSE) {
+                       in.ReadIdentifier(name);
+                       in.Skip(io::Token::EQUALS);
+                       if (name == "label") {
+                               in.ReadString(data.resources[id].label);
+                       } else {
+                               throw std::runtime_error("unknown resource property '" + name + "'");
+                       }
+                       in.Skip(io::Token::SEMICOLON);
+               }
+               in.Skip(io::Token::ANGLE_BRACKET_CLOSE);
+               in.Skip(io::Token::SEMICOLON);
+       }
+}
+
 void Assets::ReadTileTypes(io::TokenStreamReader &in) {
        while (in.HasMore()) {
                string name;
diff --git a/src/world/Resources.hpp b/src/world/Resources.hpp
deleted file mode 100644 (file)
index af30af0..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef BLOBS_WORLD_RESOURCES_HPP_
-#define BLOBS_WORLD_RESOURCES_HPP_
-
-
-namespace blobs {
-namespace world {
-
-struct Resource;
-
-class Resources {
-
-};
-
-}
-}
-
-#endif