diff --git a/src/csvloader.cpp b/src/csvloader.cpp index ceb9a78..5f9f2d4 100644 --- a/src/csvloader.cpp +++ b/src/csvloader.cpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace qi = boost::spirit::qi; @@ -47,6 +48,7 @@ namespace curry { //auto csv_parser = *((qi::int_ % ',') >> -qi::eol) >> qi::eoi; CSVJointData out_csv; std::size_t row_count = 0; + TileIndex largest_tile_idx = 0; for (auto& csv_path : parCsvPath) { std::ifstream f_map(csv_path); @@ -66,6 +68,9 @@ namespace curry { oss << "Error parsing csv \"" << csv_path << "\""; throw std::runtime_error(oss.str()); } + if (not curr_data.empty()) { + largest_tile_idx = std::max(*std::max_element(curr_data.begin(), curr_data.end()), largest_tile_idx); + } out_csv.tables.emplace_back(std::move(curr_data)); } @@ -76,6 +81,17 @@ namespace curry { else { out_csv.height = out_csv.width = 0; } + + out_csv.tile_properties.resize(static_cast(largest_tile_idx) + 1); + +#if !defined(NDEBUG) + for (const auto& table : out_csv.tables) { + for (const auto& val : table) { + const auto casted_val = static_cast(val); + assert(val < 0 or casted_val < out_csv.tile_properties.size()); + } + } +#endif return out_csv; } } //namespace curry diff --git a/src/csvloader.hpp b/src/csvloader.hpp index 587e9cb..ce3672d 100644 --- a/src/csvloader.hpp +++ b/src/csvloader.hpp @@ -20,6 +20,7 @@ #pragma once #include "tileindextype.hpp" +#include "tileproperty.hpp" #include #include #include @@ -31,6 +32,7 @@ namespace curry { CSVJointData (const CSVJointData&) = delete; std::vector> tables; + std::vector tile_properties; //not filled in with real values uint16_t width; uint16_t height; }; diff --git a/src/ingamescene.cpp b/src/ingamescene.cpp index d2a15cd..e08062e 100644 --- a/src/ingamescene.cpp +++ b/src/ingamescene.cpp @@ -85,6 +85,7 @@ namespace curry { vec2us world_size(tiles.width, tiles.height); m_local_data->world.set_layers(world_size, tiles.tables); + m_local_data->world.set_tile_properties(tiles.tile_properties); #if !defined(NDEBUG) std::cout << "World size set to " << world_size << '\n'; #endif diff --git a/src/tileproperty.hpp b/src/tileproperty.hpp new file mode 100644 index 0000000..35717fa --- /dev/null +++ b/src/tileproperty.hpp @@ -0,0 +1,31 @@ +/* + Copyright 2016, 2017 Michele "King_DuckZ" Santullo + + This file is part of MyCurry. + + MyCurry is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + MyCurry is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with MyCurry. If not, see . +*/ + +#pragma once + +namespace curry { + struct TileProperty { + TileProperty() : + walkable(true) + { + } + + bool walkable; + }; +} //namespace curry diff --git a/src/worldgrid.cpp b/src/worldgrid.cpp index 6e845c8..6195993 100644 --- a/src/worldgrid.cpp +++ b/src/worldgrid.cpp @@ -118,6 +118,17 @@ namespace curry { m_world_size_watchers.Remove(parTicket); } + void WorldGrid::set_tile_properties (const std::vector& parProperties) { + m_tile_properties.resize(parProperties.size()); + std::copy(parProperties.begin(), parProperties.end(), m_tile_properties.begin()); + } + + const TileProperty& WorldGrid::tile_property (const TileIndex* parIndex) { + assert(parIndex); + assert(static_cast(*parIndex) < m_tile_properties.size()); + return m_tile_properties[static_cast(*parIndex)]; + } + vec2i world_size_pixel (const WorldGrid& parWorld) { return parWorld.tile_size() * parWorld.world_size(); } diff --git a/src/worldgrid.hpp b/src/worldgrid.hpp index 1dd94af..dc67973 100644 --- a/src/worldgrid.hpp +++ b/src/worldgrid.hpp @@ -22,6 +22,7 @@ #include "vector.hpp" #include "tileindextype.hpp" #include "observersmanager.hpp" +#include "tileproperty.hpp" #include #include @@ -40,6 +41,8 @@ namespace curry { const TileIndex* tile (const vec2us& parIndex) const; void add_layer (vec2us parWorldSize, const std::vector& parLayer); void set_layers (vec2us parWorldSize, const std::vector>& parLayers); + void set_tile_properties (const std::vector& parProperties); + const TileProperty& tile_property (const TileIndex* parIndex); void unload_layers(); WorldSizeWatcherTicket register_observer (WorldSizeNotifiable* parWatcher); void unregister_observer (WorldSizeWatcherTicket parTicket); @@ -51,6 +54,7 @@ namespace curry { cloonel::ObserversManager m_world_size_watchers; std::vector m_layers; + std::vector m_tile_properties; vec2us m_tile_size; vec2us m_world_size; uint16_t m_layer_count;