X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fapp.cpp;h=b4ede47f0db1d6bfc96a692da7018ccd45869502;hb=8a3907bb0bed257bf5d6f40f39f15114e8345913;hp=45a57cfde2bdc3458ffe2e7948561fb19d541258;hpb=3da087f7eaafc560675e85862d92f584c437355c;p=blobs.git diff --git a/src/app/app.cpp b/src/app/app.cpp index 45a57cf..b4ede47 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -173,23 +173,27 @@ void State::OnQuit() { Assets::Assets() : path("assets/") , data_path(path + "data/") +, font_path(path + "fonts/") , 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 }); +, tile_path(path + "tiles/") +, fonts{ + graphics::Font(font_path + "DejaVuSans.ttf", 32), + graphics::Font(font_path + "DejaVuSans.ttf", 24), + graphics::Font(font_path + "DejaVuSans.ttf", 16) +} { + { + std::ifstream resource_file(data_path + "resources"); + io::TokenStreamReader resource_reader(resource_file); + ReadResources(resource_reader); + } { - std::ifstream tile_file(data_path + "tiles"); + std::ifstream tile_file(data_path + "tile_types"); io::TokenStreamReader tile_reader(tile_file); ReadTileTypes(tile_reader); } + graphics::Format format; textures.tiles.Bind(); textures.tiles.Reserve(256, 256, 14, format); @@ -224,6 +228,50 @@ 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 if (name == "state") { + in.ReadIdentifier(name); + if (name == "solid") { + data.resources[id].state = world::Resource::SOLID; + } else if (name == "liquid") { + data.resources[id].state = world::Resource::LIQUID; + } else if (name == "gas") { + data.resources[id].state = world::Resource::GAS; + } else if (name == "plasma") { + data.resources[id].state = world::Resource::PLASMA; + } else { + throw std::runtime_error("unknown resource state '" + name + "'"); + } + } 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; @@ -231,12 +279,12 @@ void Assets::ReadTileTypes(io::TokenStreamReader &in) { in.Skip(io::Token::EQUALS); int id = 0; - if (data.tiles.Has(name)) { - id = data.tiles[name].id; + if (data.tile_types.Has(name)) { + id = data.tile_types[name].id; } else { world::TileType type; type.name = name; - id = data.tiles.Add(type); + id = data.tile_types.Add(type); } in.Skip(io::Token::ANGLE_BRACKET_OPEN); @@ -244,9 +292,9 @@ void Assets::ReadTileTypes(io::TokenStreamReader &in) { in.ReadIdentifier(name); in.Skip(io::Token::EQUALS); if (name == "label") { - in.ReadString(data.tiles[id].label); + in.ReadString(data.tile_types[id].label); } else if (name == "texture") { - data.tiles[id].texture = in.GetInt(); + data.tile_types[id].texture = in.GetInt(); } else if (name == "yield") { in.Skip(io::Token::BRACKET_OPEN); while (in.Peek().type != io::Token::BRACKET_CLOSE) { @@ -266,7 +314,7 @@ void Assets::ReadTileTypes(io::TokenStreamReader &in) { in.Skip(io::Token::SEMICOLON); } in.Skip(io::Token::ANGLE_BRACKET_CLOSE); - data.tiles[id].resources.push_back(yield); + data.tile_types[id].resources.push_back(yield); if (in.Peek().type == io::Token::COMMA) { in.Skip(io::Token::COMMA); }