From: Daniel Karbach Date: Fri, 17 Nov 2017 19:17:55 +0000 (+0100) Subject: load resources from data file X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=5e82e61db8b9ed5b9a30c9706620b62b844ac734;p=blobs.git load resources from data file --- diff --git a/assets b/assets index f9f068f..b63c91e 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit f9f068f73b2fb5b0c134b40b16ed00118d775268 +Subproject commit b63c91ead8b510b614efccc97b4000fc3aca9c87 diff --git a/src/app/Assets.hpp b/src/app/Assets.hpp index 68606cb..3cfc133 100644 --- a/src/app/Assets.hpp +++ b/src/app/Assets.hpp @@ -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; diff --git a/src/app/app.cpp b/src/app/app.cpp index 45a57cf..ccccd9a 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -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 index af30af0..0000000 --- a/src/world/Resources.hpp +++ /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