]> git.localhorst.tv Git - blobs.git/blobdiff - src/app/app.cpp
load resource colors
[blobs.git] / src / app / app.cpp
index ccccd9a6c15c5b2590e8a27b0274c74541c1451e..f2d0e5904d209ccba1113692877974e36e884ac8 100644 (file)
@@ -173,8 +173,15 @@ void State::OnQuit() {
 Assets::Assets()
 : path("assets/")
 , data_path(path + "data/")
+, font_path(path + "fonts/")
 , skin_path(path + "skins/")
-, tile_path(path + "tiles/") {
+, tile_path(path + "tiles/")
+, random(0x6283B64CEFE47925)
+, 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);
@@ -182,11 +189,12 @@ Assets::Assets()
        }
 
        {
-               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);
@@ -204,6 +212,7 @@ Assets::Assets()
        LoadTileTexture("tundra",   textures.tiles, 11);
        LoadTileTexture("water",    textures.tiles, 12);
        LoadTileTexture("wheat",    textures.tiles, 13);
+       textures.tiles.FilterTrilinear();
 
        textures.skins.Bind();
        textures.skins.Reserve(256, 256, 9, format);
@@ -216,6 +225,7 @@ Assets::Assets()
        LoadSkinTexture("7", textures.skins, 6);
        LoadSkinTexture("8", textures.skins, 7);
        LoadSkinTexture("9", textures.skins, 8);
+       textures.skins.FilterTrilinear();
 }
 
 Assets::~Assets() {
@@ -242,6 +252,23 @@ void Assets::ReadResources(io::TokenStreamReader &in) {
                        in.Skip(io::Token::EQUALS);
                        if (name == "label") {
                                in.ReadString(data.resources[id].label);
+                       } else if (name == "density") {
+                               data.resources[id].density = in.GetDouble();
+                       } 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 if (name == "base_color") {
+                               in.ReadVec(data.resources[id].base_color);
                        } else {
                                throw std::runtime_error("unknown resource property '" + name + "'");
                        }
@@ -259,12 +286,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);
@@ -272,9 +299,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) {
@@ -294,7 +321,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);
                                        }