Added Core::GetAllTiles(), added tile display_name property.
This commit is contained in:
@@ -204,6 +204,8 @@ namespace CaveGame::Core {
|
||||
///
|
||||
void RegisterTile(Tile* data);
|
||||
|
||||
std::vector<Tile*> GetAllTiles();
|
||||
|
||||
Tile* GetByNumeric(TileID id);
|
||||
|
||||
Tile* GetByName(const std::string& name);
|
||||
@@ -215,6 +217,7 @@ namespace CaveGame::Core {
|
||||
protected:
|
||||
TileID numeric_id = TileID::VOID;
|
||||
std::string mnemonic_id;
|
||||
std::string display_name = "";
|
||||
public:
|
||||
Color4 base_color;
|
||||
std::vector<Color4> color_pallet;
|
||||
@@ -235,7 +238,7 @@ namespace CaveGame::Core {
|
||||
|
||||
[[nodiscard]] TileID NumericID() const;
|
||||
[[nodiscard]] std::string MnemonicID() const;
|
||||
std::string Name() const { return mnemonic_id; }
|
||||
std::string Name() const;
|
||||
virtual bool DoesRandomTicc() const { return false; }
|
||||
virtual bool DoesForcedTicc() const { return false;}
|
||||
virtual bool Solid() const { return false;}
|
||||
|
@@ -1,11 +1,45 @@
|
||||
#include <Core/Loggers.hpp>
|
||||
#include <Core/Tile.hpp>
|
||||
#include <array>
|
||||
#include "Core/Item.hpp"
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
|
||||
std::array<Tile*, 65536> registered_tiles{};
|
||||
|
||||
std::vector<Tile*> GetAllTiles() {
|
||||
return {std::begin(registered_tiles), std::end(registered_tiles)};
|
||||
}
|
||||
|
||||
Tile *GetByNumeric(TileID id) {
|
||||
// TODO: Optimize with additional mapping!!
|
||||
//if (registered_tiles.at((uint16_t)id))
|
||||
return registered_tiles[(uint16_t)id];
|
||||
//for(auto& tile : registered_tiles)
|
||||
//if (tile->numeric_id == id)
|
||||
//return tile;
|
||||
//throw std::runtime_error("ID not in tile registry!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void RegisterTile(Tile *data) {
|
||||
|
||||
if (data == nullptr)
|
||||
return;
|
||||
|
||||
uint16_t index = (uint16_t)data->NumericID();
|
||||
registered_tiles[index] = data;
|
||||
|
||||
|
||||
//std::string name = std::format("{}_tile", data->MnemonicID());
|
||||
|
||||
//Core::Item item_for_this_tile = Core::Item(name);
|
||||
//item_for_this_tile->mnemonic = name;
|
||||
//item_for_this_tile->display_name = std::format("{} Tile", data->MnemonicID());
|
||||
|
||||
//RegisterItem(name, item_for_this_tile);
|
||||
}
|
||||
|
||||
void Tile::DecayTo(ITileMap *world, TileState state, int x, int y, TileID TDecaysTo) {
|
||||
world->SetTile(x, y, TDecaysTo);
|
||||
@@ -274,21 +308,15 @@ namespace CaveGame::Core
|
||||
|
||||
std::string Tile::MnemonicID() const { return mnemonic_id; }
|
||||
|
||||
Tile *GetByNumeric(TileID id) {
|
||||
// TODO: Optimize with additional mapping!!
|
||||
//if (registered_tiles.at((uint16_t)id))
|
||||
return registered_tiles[(uint16_t)id];
|
||||
//for(auto& tile : registered_tiles)
|
||||
//if (tile->numeric_id == id)
|
||||
//return tile;
|
||||
//throw std::runtime_error("ID not in tile registry!");
|
||||
return nullptr;
|
||||
std::string Tile::Name() const {
|
||||
// Use the mnemonic ID if no display name is set.
|
||||
if (display_name.empty())
|
||||
return mnemonic_id;
|
||||
return display_name;
|
||||
}
|
||||
|
||||
void RegisterTile(Tile *data) {
|
||||
uint16_t index = (uint16_t)data->NumericID();
|
||||
registered_tiles[index] = data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
WaterTile::WaterTile() : LiquidTile() {}
|
||||
|
||||
|
Reference in New Issue
Block a user