It works!!! All tiles are currently blue, and basically all tile features need to be re-implemented, however.
This commit is contained in:
@@ -59,10 +59,15 @@ namespace CaveGame::Client
|
||||
void Draw() { }
|
||||
protected:
|
||||
static constexpr int slot_count = 10;
|
||||
Core::TileID slots[slot_count] = {
|
||||
Core::TileID::GRASS, Core::TileID::STONE, Core::TileID::WATER, Core::TileID::LAVA, Core::TileID::GREEN_MOSS, Core::TileID::SAND,
|
||||
Core::TileID::CLAY, Core::TileID::OAK_PLANK, Core::TileID::COBBLESTONE, Core::TileID::STONE_BRICK
|
||||
};
|
||||
Core::TileID slots[slot_count]{};
|
||||
/*= {
|
||||
//Core::TileID::GRASS, Core::TileID::STONE, Core::TileID::WATER, Core::TileID::LAVA, Core::TileID::GREEN_MOSS, Core::TileID::SAND,
|
||||
//Core::TileID::CLAY, Core::TileID::OAK_PLANK, Core::TileID::COBBLESTONE, Core::TileID::STONE_BRICK
|
||||
};*/
|
||||
/*TileID Slot(int index)
|
||||
{
|
||||
switch(index)
|
||||
}*/
|
||||
int slot_index = 1;
|
||||
JUI::Rect* hotbar_elements[10];
|
||||
JUI::TextRect* item_label;
|
||||
|
@@ -140,7 +140,7 @@ void CaveGame::Client::GameSession::WorldEditToolControlsUpdate(float elapsed){
|
||||
|
||||
|
||||
|
||||
WorldEditToolDrawTiles(TileID::AIR);
|
||||
WorldEditToolDrawTiles(Tiles()["air"].numeric_id);
|
||||
} else {
|
||||
if (following)
|
||||
following = false;
|
||||
|
@@ -1,11 +1,26 @@
|
||||
#include <Client/Hotbar.hpp>
|
||||
#include <JUI/Widgets/ListLayout.hpp>
|
||||
#include <JUI/Widgets/Image.hpp>
|
||||
#include <Core/TileRegistry.hpp>
|
||||
|
||||
using namespace JUI::UDimLiterals;
|
||||
using namespace CaveGame::Core;
|
||||
|
||||
void CaveGame::Client::TileHotbar::Load(CaveGame::Client::LocalWorld *world) {
|
||||
|
||||
|
||||
|
||||
slots[0] = Tiles()["grass"].numeric_id;
|
||||
slots[1] = Tiles()["stone"].numeric_id;
|
||||
slots[2] = Tiles()["water"].numeric_id;
|
||||
slots[3] = Tiles()["lava"].numeric_id;
|
||||
slots[4] = Tiles()["green-moss"].numeric_id;
|
||||
slots[5] = Tiles()["sand"].numeric_id;
|
||||
slots[6] = Tiles()["clay"].numeric_id;
|
||||
slots[7] = Tiles()["oak-plank"].numeric_id;
|
||||
slots[8] = Tiles()["cobblestone"].numeric_id;
|
||||
slots[9] = Tiles()["stone-brick"].numeric_id;
|
||||
|
||||
hotbar_root = new JUI::Rect();
|
||||
hotbar_root->BGColor(Colors::LightGray);
|
||||
hotbar_root->BorderColor(Colors::White);
|
||||
@@ -33,7 +48,7 @@ void CaveGame::Client::TileHotbar::Load(CaveGame::Client::LocalWorld *world) {
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
auto item = GetByNumeric(slots[i]);
|
||||
auto item = Tiles().Get(slots[i]);
|
||||
|
||||
auto* cell = new JUI::Rect(layout);
|
||||
cell->Name("hotbar_" + std::to_string(i));
|
||||
@@ -46,7 +61,7 @@ void CaveGame::Client::TileHotbar::Load(CaveGame::Client::LocalWorld *world) {
|
||||
cell->BorderMode(JUI::BorderMode::Outline);
|
||||
cell->PaddingBottom(10_px);
|
||||
cell->PaddingRight(5_px);
|
||||
cell->BGColor(item->base_color);
|
||||
cell->BGColor(item.color);
|
||||
|
||||
// Add tile-sample rendertarget as item icon.
|
||||
auto* img = new JUI::Image(cell);
|
||||
@@ -59,9 +74,9 @@ void CaveGame::Client::TileHotbar::Load(CaveGame::Client::LocalWorld *world) {
|
||||
auto* tile_icon_canvas = new RenderTarget(canvas_texture, {0, 0, 0, 0});
|
||||
|
||||
JGL::J2D::Begin(tile_icon_canvas, true);
|
||||
for (int x = 0; x < icon_size; x++)
|
||||
for (int y = 0; y < icon_size; y++)
|
||||
world->RenderTile(item->NumericID(), x, y, x, y);
|
||||
//for (int x = 0; x < icon_size; x++)
|
||||
// for (int y = 0; y < icon_size; y++)
|
||||
// world->RenderTile(item->NumericID(), x, y, x, y);
|
||||
JGL::J2D::End();
|
||||
|
||||
delete tile_icon_canvas;
|
||||
@@ -119,8 +134,8 @@ void CaveGame::Client::TileHotbar::Update(float elapsed) {
|
||||
|
||||
// Update item name label.
|
||||
Core::TileID active_item = slots[slot_index];
|
||||
auto* data = GetByNumeric(active_item);
|
||||
item_label->SetContent(data->Name());
|
||||
//auto* data = Tiles().Get(active_item);
|
||||
//item_label->SetContent(data->Name());
|
||||
|
||||
// Set appearance of selected slot.
|
||||
hotbar_elements[slot_index]->CornerRounding(8);
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include <fstream>
|
||||
#include <Core/Loggers.hpp>
|
||||
#include <JUI/Widgets/Scene.hpp>
|
||||
#include <Core/TileRegistry.hpp>
|
||||
|
||||
namespace CaveGame::Client {
|
||||
using namespace CaveGame::Core;
|
||||
@@ -221,28 +222,25 @@ namespace CaveGame::Client {
|
||||
|
||||
void LocalWorld::RenderTile(const TileID& t_id, int wx, int wy, int tx, int ty)
|
||||
{
|
||||
using namespace CaveGame::Core;
|
||||
// TODO: Migrate custom tile render code to an override Draw method in tile classes?
|
||||
// TODO: See class Tile::Draw to see why this is halted.
|
||||
|
||||
if (t_id == TileID::AIR || t_id == TileID::VOID) // Air
|
||||
if (t_id == Tiles()["air"].numeric_id || t_id == Tiles()["void"].numeric_id)
|
||||
return;
|
||||
|
||||
|
||||
Color4 t_color;
|
||||
|
||||
|
||||
Core::Tile* t_data = Core::GetByNumeric(t_id);
|
||||
Core::Tile t_data = Tiles()[t_id];
|
||||
|
||||
if (t_id == TileID::COBBLESTONE) {
|
||||
if (t_id == Tiles()["cobblestone"].numeric_id) {
|
||||
float val = generator.Perlin(wx, wy, 4, 4, 0.25f, 1.5f);
|
||||
|
||||
/*if (val > 0.60f || val < -0.60f)
|
||||
t_color = Core::Tiles::Cobblestone.color_pallet[1];
|
||||
else*/
|
||||
|
||||
|
||||
unsigned int rand = generator.ColorMap(Tiles::Stone.color_pallet.size(), wx, wy);
|
||||
t_color = t_data->color_pallet[rand];
|
||||
unsigned int rand = generator.ColorMap(Tiles()["stone"].pallet->size(), wx, wy);
|
||||
t_color = t_data.pallet->operator[](rand);
|
||||
|
||||
if (val > 0.40f || val < -0.40f) {
|
||||
t_color.r += 32;
|
||||
@@ -257,7 +255,7 @@ namespace CaveGame::Client {
|
||||
|
||||
|
||||
//Core::Tiles::Cobblestone.color_pallet
|
||||
} else if (t_id == TileID::OAK_PLANK) {
|
||||
} else if (t_id == Tiles()["oak-plank"].numeric_id) {
|
||||
|
||||
// TODO: Make each plank have a slightly different base color.
|
||||
|
||||
@@ -303,7 +301,7 @@ namespace CaveGame::Client {
|
||||
}
|
||||
|
||||
t_color = {base_r, base_g, base_b};
|
||||
} else if (t_id == TileID::STONE_BRICK) {
|
||||
} else if (t_id == Tiles()["stone-brick"].numeric_id) {
|
||||
|
||||
|
||||
uint8_t shift = generator.ColorMap(30, wx, wy);
|
||||
@@ -335,11 +333,11 @@ namespace CaveGame::Client {
|
||||
base_b -= 55;
|
||||
}
|
||||
t_color = {base_r, base_g, base_b};
|
||||
} else if (t_data->has_color_pallet) {
|
||||
unsigned int rand = generator.ColorMap(t_data->color_pallet.size(), wx, wy);
|
||||
t_color = t_data->color_pallet[rand];
|
||||
} else if (t_data.pallet.has_value()) {
|
||||
unsigned int rand = generator.ColorMap(t_data.pallet->size(), wx, wy);
|
||||
t_color = t_data.pallet.value()[rand];
|
||||
} else {
|
||||
t_color = t_data->base_color;
|
||||
t_color = t_data.color;
|
||||
}
|
||||
|
||||
JGL::J2D::DrawPoint(t_color, tx, ty);
|
||||
@@ -373,8 +371,8 @@ namespace CaveGame::Client {
|
||||
|
||||
|
||||
|
||||
if (t_id == TileID::AIR || t_id == TileID::VOID) // Air
|
||||
continue;
|
||||
//if (t_id == TileID::AIR || t_id == TileID::VOID) // Air
|
||||
//continue;
|
||||
|
||||
RenderTile(t_id, wx, wy, x, y);
|
||||
|
||||
|
@@ -6,13 +6,9 @@
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"pallet": [],
|
||||
"hardcoded-id": 65536,
|
||||
"random-ticc-func": "spread-self",
|
||||
"spreads-to": "dirt",
|
||||
"decays-to": "",
|
||||
"draw-func": ""
|
||||
"color": "#FFFFFFFF",
|
||||
"hardcoded-id": 65535,
|
||||
"render": false
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "air",
|
||||
@@ -20,9 +16,9 @@
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"pallet": [],
|
||||
"hardcoded-id": 0
|
||||
"color": "#FFFFFFFF",
|
||||
"hardcoded-id": 0,
|
||||
"render": false
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "stone",
|
||||
@@ -30,8 +26,8 @@
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"pallet": []
|
||||
"color": [112, 128, 144],
|
||||
"pallet": [[112, 122, 148], [119, 136, 153], [121, 115, 138]]
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "dirt",
|
||||
@@ -39,8 +35,8 @@
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"pallet": []
|
||||
"color": [210, 105, 30],
|
||||
"pallet": [[210, 125, 30], [195, 105, 40], [210, 105, 30]]
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "mud",
|
||||
@@ -48,21 +44,54 @@
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"pallet": []
|
||||
"color": [139, 69, 19]
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "limestone",
|
||||
"display-name" : "Mud",
|
||||
"display-name" : "Limestone",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"pallet": []
|
||||
"color": [238, 232, 170]
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "basalt",
|
||||
"display-name" : "Mud",
|
||||
"display-name" : "Basalt",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": [105, 105, 105]
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "cobblestone",
|
||||
"display-name" : "Cobblestone",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": [112, 128, 144],
|
||||
"pallet": [[64, 64, 64], [92, 92, 92], [112, 128, 144], [119, 136, 153]],
|
||||
"drops" : null
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "red-moss",
|
||||
"display-name" : "Red Moss",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#CC4444"
|
||||
},
|
||||
|
||||
{
|
||||
"mnemonic-id" : "brown-moss",
|
||||
"display-name" : "Brown Moss",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#BB7755"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "green-moss",
|
||||
"display-name" : "Green Moss",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
@@ -70,70 +99,254 @@
|
||||
"pallet": []
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "cobblestone",
|
||||
"display-name" : "",
|
||||
"mnemonic-id" : "lava-moss",
|
||||
"display-name" : "Lava Moss",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "granite",
|
||||
"display-name" : "Granite",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"pallet": [],
|
||||
"random-ticc-func": "zzyyzz",
|
||||
"forced-ticc-func": "zzyyzz",
|
||||
"drops" : null
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "red-moss",
|
||||
"display-name" : "Mud",
|
||||
"mnemonic-id" : "marble",
|
||||
"display-name" : "Marble",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "grass",
|
||||
"display-name" : "Grass",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": [124, 252, 0],
|
||||
"pallet": [[126, 252, 5], [122, 238, 0], [124, 248, 12]]
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "glowy-grass",
|
||||
"display-name" : "Glowy Grass",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "vine",
|
||||
"display-name" : "Vine",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "sand",
|
||||
"display-name" : "Sand",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": [238, 232, 170],
|
||||
"pallet": [[238, 232, 170], [232, 238, 160], [218, 212, 175]]
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "white-sand",
|
||||
"display-name" : "White Sand",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "red-sand",
|
||||
"display-name" : "Red Sand",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "black-sand",
|
||||
"display-name" : "Black Sand",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "sandstone",
|
||||
"display-name" : "Sandstone",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "white-sandstone",
|
||||
"display-name" : "White Sandstone",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "black-sandstone",
|
||||
"display-name" : "Black Sandstone",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "ash",
|
||||
"display-name" : "Ash",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "clay",
|
||||
"display-name" : "Clay",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "silt",
|
||||
"display-name" : "Silt",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "snow",
|
||||
"display-name" : "Snow",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "ice",
|
||||
"display-name" : "Ice",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "slush",
|
||||
"display-name" : "Slush",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"pallet": []
|
||||
},
|
||||
|
||||
{
|
||||
"mnemonic-id" : "brown-moss",
|
||||
"display-name" : "",
|
||||
"solid": true,
|
||||
"mnemonic-id" : "stone-brick",
|
||||
"display-name" : "Gray Brick",
|
||||
"solid": false,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"pallet": []
|
||||
},
|
||||
|
||||
{
|
||||
"mnemonic-id" : "water",
|
||||
"display-name" : "Water",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": true,
|
||||
"color": "#0000FF",
|
||||
"pallet": [],
|
||||
"random-ticc-func": "zzyyzz",
|
||||
"forced-ticc-func": "zzyyzz",
|
||||
"drops" : null
|
||||
},
|
||||
|
||||
{
|
||||
"mnemonic-id" : "blood",
|
||||
"display-name" : "Blood",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": true,
|
||||
"color": "#0000FF",
|
||||
"pallet": [],
|
||||
"random-ticc-func": "zzyyzz",
|
||||
"forced-ticc-func": "zzyyzz",
|
||||
"drops" : null
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "green-moss",
|
||||
"display-name" : "",
|
||||
"mnemonic-id" : "sludge",
|
||||
"display-name" : "Sludge",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"does-forced-ticc": true,
|
||||
"color": "#0000FF",
|
||||
"pallet": [],
|
||||
"random-ticc-func": "zzyyzz",
|
||||
"forced-ticc-func": "zzyyzz",
|
||||
"drops" : null
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "lava-moss",
|
||||
"display-name" : "",
|
||||
"mnemonic-id" : "lava",
|
||||
"display-name" : "Lava",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"does-forced-ticc": true,
|
||||
"color": "#0000FF",
|
||||
"pallet": [],
|
||||
"random-ticc-func": "zzyyzz",
|
||||
"forced-ticc-func": "zzyyzz",
|
||||
"drops" : null
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "granite",
|
||||
"display-name" : "",
|
||||
"mnemonic-id" : "ectoplasm",
|
||||
"display-name" : "Ectoplasm",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": false,
|
||||
"color": "#FFFFFF",
|
||||
"does-forced-ticc": true,
|
||||
"color": "#0000FF",
|
||||
"pallet": [],
|
||||
"random-ticc-func": "zzyyzz",
|
||||
"forced-ticc-func": "zzyyzz",
|
||||
"drops" : null
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "milk",
|
||||
"display-name" : "Milk",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": true,
|
||||
"color": "#0000FF",
|
||||
"pallet": [],
|
||||
"random-ticc-func": "zzyyzz",
|
||||
"forced-ticc-func": "zzyyzz",
|
||||
"drops" : null
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "honey",
|
||||
"display-name" : "Honey",
|
||||
"solid": true,
|
||||
"does-random-ticc": false,
|
||||
"does-forced-ticc": true,
|
||||
"color": "#0000FF",
|
||||
"pallet": [],
|
||||
"random-ticc-func": "zzyyzz",
|
||||
"forced-ticc-func": "zzyyzz",
|
||||
|
@@ -68,44 +68,69 @@ namespace CaveGame::ClientApp
|
||||
}
|
||||
}
|
||||
|
||||
void ReadTileDataAndRegister()
|
||||
Color4 parse_color(const JJX::json::value& v)
|
||||
{
|
||||
Core::Tile tile;
|
||||
|
||||
using namespace JJX;
|
||||
std::string content = read_file("assets/data/tiles.json");
|
||||
|
||||
auto [data, parse_error] = json::parse(content);
|
||||
|
||||
if (data.type == json::value_type::array)
|
||||
Color4 retval;
|
||||
if (v.type == JJX::json::value_type::string)
|
||||
return Color4::FromHex(v.string.value());
|
||||
else if (v.type == JJX::json::value_type::array)
|
||||
{
|
||||
auto arr_data = json::array_val(data);
|
||||
for (auto& t : arr_data.array.value()) {
|
||||
std::cout << (int)t.type << std::endl;
|
||||
|
||||
auto tile_meta_json = json::object_val(t);
|
||||
|
||||
tile.mnemonic_id = tile_meta_json["mnemonic-id"];
|
||||
json::value color_field = tile_meta_json["color"];
|
||||
|
||||
if (color_field.type == json::value_type::string)
|
||||
tile.color = Color4::FromHexA(color_field.string.value());
|
||||
else if (color_field.type == json::value_type::array)
|
||||
{
|
||||
auto color_array = json::array_val(color_field);
|
||||
auto color_array = JJX::json::array_val(v);
|
||||
int r = color_array[0].number.value();
|
||||
int g = color_array[1].number.value();
|
||||
int b = color_array[2].number.value();
|
||||
int a = 255;
|
||||
if (color_array.array.value().size() == 4)
|
||||
a = color_array[3].number.value();
|
||||
tile.color = Color4(r, g, b, a);
|
||||
return Color4(r, g, b, a);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ReadTileDataAndRegister()
|
||||
{
|
||||
|
||||
|
||||
using namespace JJX;
|
||||
std::string content = read_file("assets/data/tiles.json");
|
||||
|
||||
auto [data, parse_error] = json::parse(content);
|
||||
|
||||
if (data.type == json::value_type::array) {
|
||||
auto arr_data = json::array_val(data);
|
||||
for (auto& t : arr_data.array.value()) {
|
||||
Core::Tile tile;
|
||||
Core::Item tile_item;
|
||||
|
||||
auto tile_meta_json = json::object_val(t);
|
||||
|
||||
if (tile_meta_json.object->contains("hardcoded-id"))
|
||||
tile.assigned_numeric_id = tile_meta_json["hardcoded-id"].number;
|
||||
|
||||
tile.mnemonic_id = tile_meta_json["mnemonic-id"];
|
||||
tile.display_name = tile_meta_json["display-name"];
|
||||
|
||||
tile_item.mnemonic = std::format("{}-tile", tile.mnemonic_id);
|
||||
tile_item.display_name = tile.display_name;
|
||||
|
||||
tile.color = parse_color(tile_meta_json["color"]);
|
||||
|
||||
if (tile_meta_json.object->contains("pallet") && tile_meta_json["pallet"].array->size() > 0) {
|
||||
std::vector<Color4> pallet;
|
||||
auto pallet_meta = json::array_val(tile_meta_json["pallet"]);
|
||||
|
||||
for (auto& c : pallet_meta.array.value())
|
||||
pallet.push_back(parse_color(c));
|
||||
|
||||
tile.pallet = pallet;
|
||||
}
|
||||
|
||||
Tiles().Register(tile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Core::Tiles().Register(tile);
|
||||
|
||||
}
|
||||
|
||||
CaveGameWindow::CaveGameWindow(const std::string& title, int width, int height): ReWindow::OpenGLWindow(title, width, height, 2, 1)
|
||||
@@ -383,7 +408,7 @@ namespace CaveGame::ClientApp
|
||||
u16 id = game_ctx->GetTileIDUnderMouse();
|
||||
Core::Tile data = Tiles().Get(id);
|
||||
|
||||
debug_lines.push_back(std::format("tile: {} id: {}", data->MnemonicID(), (unsigned int)data->NumericID()));
|
||||
//debug_lines.push_back(std::format("tile: {} id: {}", data->MnemonicID(), (unsigned int)data->NumericID()));
|
||||
debug_lines.push_back(std::format("entities: {}", game_ctx->World()->GetCurrentEntityCount()));
|
||||
debug_lines.push_back(std::format("tile_simulation: {}", game_ctx->World()->GetTileSimulationEnabled()));
|
||||
debug_lines.push_back(std::format("rendertargets: {}", game_ctx->World()->GetRenderTargetCount()));
|
||||
@@ -678,10 +703,10 @@ namespace CaveGame::ClientApp
|
||||
}
|
||||
|
||||
bool CaveGameWindow::ItemListCmd(const CommandArgs &args) {
|
||||
auto item_list = Core::GetAllItems();
|
||||
auto item_list = Items().GetItemMap();
|
||||
|
||||
for (auto [name, item] : item_list) {
|
||||
if (item != nullptr)
|
||||
//if (item != nullptr)
|
||||
Log(std::format("Mnemonic: {}", name));
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "Sprite.hpp"
|
||||
#include "Entity.hpp"
|
||||
#include <JGL/types/RenderTarget.h>
|
||||
#include <Core/TileRegistry.hpp>
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
@@ -28,7 +29,7 @@ namespace CaveGame::Core
|
||||
for (int y = -radius; y <= radius; y++) {
|
||||
float dist = Vector2::LengthSquared(Vector2(x, y));
|
||||
if (dist <= radius*radius) {
|
||||
wrld->SetTile(position.x + x, position.y + y, TileID::AIR);
|
||||
wrld->SetTile(position.x + x, position.y + y, Tiles()["air"].numeric_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ namespace CaveGame::Core
|
||||
[[nodiscard]] virtual TileID GetTile(int x, int y) const = 0;
|
||||
|
||||
virtual void SetTile(int x, int y, TileID tile, bool flag_update = true) = 0;
|
||||
virtual void SetTile(int x, int y, const std::string& tile_name, bool flag_update = true) = 0;
|
||||
//virtual void SetTile(int x, int y, const std::string& tile_name, bool flag_update = true) = 0;
|
||||
virtual void SwapTile(int source_x, int source_y, int dest_x, int dest_y, bool flag_update = true) = 0;
|
||||
[[nodiscard]] virtual bool GetTileUpdateFlag(int x, int y) const = 0;
|
||||
virtual void SetTileUpdateFlag(int x, int y, bool flag = true) = 0;
|
||||
|
@@ -86,8 +86,6 @@ namespace CaveGame::Core
|
||||
std::optional<Color4> sprite_color;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
@@ -37,5 +37,5 @@ namespace CaveGame::Core
|
||||
std::unordered_map<std::string, Item> registered_items;
|
||||
};
|
||||
|
||||
using Items = ItemRegistry;
|
||||
static ItemRegistry& Items() { return ItemRegistry::Instance();}
|
||||
}
|
@@ -13,7 +13,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/Entity.hpp>
|
||||
|
||||
#include <Core/TileRegistry.hpp>
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
@@ -46,7 +46,7 @@ namespace CaveGame::Core
|
||||
|
||||
TileID id = map->GetTile(tileBoxPos.x, tileBoxPos.y);
|
||||
|
||||
if (id == TileID::VOID) {
|
||||
if (id == Tiles()["void"].numeric_id) {
|
||||
if (freeze_in_void)
|
||||
{
|
||||
velocity = {0,0};
|
||||
@@ -57,7 +57,7 @@ namespace CaveGame::Core
|
||||
}
|
||||
|
||||
|
||||
if (id == TileID::AIR)
|
||||
if (id == Tiles()["air"].numeric_id)
|
||||
continue;
|
||||
|
||||
coll_tests++;
|
||||
|
@@ -29,7 +29,6 @@ public:
|
||||
static T instance;
|
||||
return instance;
|
||||
}
|
||||
static T& operator()() { return Instance();}
|
||||
protected:
|
||||
Singleton() = default;
|
||||
virtual ~Singleton() = default;
|
||||
|
@@ -28,51 +28,38 @@ namespace CaveGame::Core {
|
||||
|
||||
//using TileID = uint16_t;
|
||||
|
||||
|
||||
/// A Singleton that stores tile data.
|
||||
class TileRegistry : public Singleton<TileRegistry> {
|
||||
|
||||
public:
|
||||
static constexpr int MaxTiles = 65535;
|
||||
static constexpr int MaxTiles = 65536;
|
||||
|
||||
///
|
||||
void Register(Tile data);
|
||||
|
||||
void Register(TileID ID, const Tile& data);
|
||||
const Tile &Get(const std::string &mnemonic);
|
||||
|
||||
const Tile& Get(const std::string& mnemonic);
|
||||
const Tile& Get(u16 ID);
|
||||
const Tile &Get(u16 id);
|
||||
|
||||
// TODO: Why convert to vector?
|
||||
std::vector<Tile> GetTileList() {
|
||||
return {std::begin(registered_tiles), std::end(registered_tiles)};
|
||||
}
|
||||
std::vector<Tile> GetTileList();
|
||||
|
||||
const std::array<Tile, MaxTiles>& GetTileArray() { return registered_tiles; }
|
||||
const std::array<Tile, MaxTiles>& GetTileArray();
|
||||
bool Exists(const std::string& mnemonic);
|
||||
bool Exists(u16 ID);
|
||||
const Tile& GetByMnemonicID(const std::string& mnemonic)
|
||||
{
|
||||
return registered_tiles[MnemonicToNumeric(mnemonic)];
|
||||
}
|
||||
const Tile& GetByNumericID(uint16_t ID)
|
||||
{
|
||||
return registered_tiles[ID];
|
||||
}
|
||||
bool Exists(u16 id);
|
||||
const Tile& GetByMnemonicID(const std::string& mnemonic);
|
||||
const Tile& GetByNumericID(uint16_t ID);
|
||||
|
||||
uint16_t MnemonicToNumeric(const std::string& mnemonic);
|
||||
std::string NumericToMnemonic(uint16_t ID)
|
||||
{
|
||||
return id_to_name_mapping[ID];
|
||||
}
|
||||
const Tile& operator[](const std::string& mnemonic)
|
||||
{
|
||||
return GetByMnemonicID(mnemonic);
|
||||
}
|
||||
const Tile& operator[](u16 ID)
|
||||
{
|
||||
return GetByNumericID(ID);
|
||||
}
|
||||
std::string NumericToMnemonic(uint16_t ID);
|
||||
const Tile& operator[](const std::string& mnemonic);
|
||||
const Tile& operator[](u16 ID);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void Register(TileID ID, const Tile &data);
|
||||
|
||||
protected:
|
||||
|
||||
std::array<bool, MaxTiles> consumed_ids{};
|
||||
@@ -83,5 +70,6 @@ namespace CaveGame::Core {
|
||||
private:
|
||||
};
|
||||
|
||||
using Tiles = TileRegistry;
|
||||
/// Convenient access to the tile registry.
|
||||
static TileRegistry& Tiles() { return TileRegistry::Instance();}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace CaveGame::Core {
|
||||
|
||||
void Tile::DecayTo(ITileMap *world, TileState state, int x, int y, TileID TDecaysTo) {
|
||||
/*void Tile::DecayTo(ITileMap *world, TileState state, int x, int y, TileID TDecaysTo) {
|
||||
world->SetTile(x, y, TDecaysTo);
|
||||
}
|
||||
|
||||
@@ -284,5 +284,5 @@ namespace CaveGame::Core {
|
||||
|
||||
WaterTile::WaterTile() : LiquidTile() {}
|
||||
|
||||
WaterTile::WaterTile(TileID id, const std::string &name, const Color4 &color) : LiquidTile(id, name, color) {}
|
||||
WaterTile::WaterTile(TileID id, const std::string &name, const Color4 &color) : LiquidTile(id, name, color) {}*/
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
#include <Core/TileRegistry.hpp>
|
||||
#include <Core/Loggers.hpp>
|
||||
#include <format>
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
@@ -18,18 +20,67 @@ namespace CaveGame::Core
|
||||
// If no ID is hardcoded, assign one from an increasing index.
|
||||
data.numeric_id = current_index;
|
||||
|
||||
registered_tiles[current_index] = data;
|
||||
|
||||
// We also cache LUTs for fast access of name and integer ID from each other
|
||||
id_to_name_mapping[current_index] = data.mnemonic_id;
|
||||
name_to_id_mapping[data.mnemonic_id] = current_index;
|
||||
consumed_ids[current_index] = true;
|
||||
Register(current_index, data);
|
||||
|
||||
current_index++;
|
||||
|
||||
}
|
||||
|
||||
void TileRegistry::Register(TileID ID, const Tile& data)
|
||||
{
|
||||
Logs::Info(std::format("\tid:{} mnemonic:{} display-name:{}", data.numeric_id, data.mnemonic_id, data.display_name));
|
||||
|
||||
registered_tiles[ID] = data;
|
||||
|
||||
// We also cache LUTs for fast access of name and integer ID from each other
|
||||
id_to_name_mapping[ID] = data.mnemonic_id;
|
||||
name_to_id_mapping[data.mnemonic_id] = ID;
|
||||
consumed_ids[ID] = true;
|
||||
}
|
||||
|
||||
uint16_t TileRegistry::MnemonicToNumeric(const std::string &mnemonic) {
|
||||
return name_to_id_mapping[mnemonic];
|
||||
}
|
||||
|
||||
const Tile &TileRegistry::Get(const std::string &mnemonic) {
|
||||
if (!name_to_id_mapping.contains(mnemonic))
|
||||
throw std::runtime_error(std::format("No tile found named {}", mnemonic));
|
||||
u16 id = name_to_id_mapping[mnemonic];
|
||||
|
||||
return registered_tiles[id];
|
||||
}
|
||||
|
||||
const Tile &TileRegistry::Get(u16 id) {
|
||||
return registered_tiles[id];
|
||||
}
|
||||
|
||||
const Tile &TileRegistry::operator[](u16 ID) {
|
||||
return GetByNumericID(ID);
|
||||
}
|
||||
|
||||
const Tile &TileRegistry::operator[](const std::string &mnemonic) {
|
||||
return GetByMnemonicID(mnemonic);
|
||||
}
|
||||
|
||||
std::string TileRegistry::NumericToMnemonic(uint16_t ID) {
|
||||
return id_to_name_mapping[ID];
|
||||
}
|
||||
|
||||
const Tile &TileRegistry::GetByNumericID(uint16_t ID) {
|
||||
return registered_tiles[ID];
|
||||
}
|
||||
|
||||
const Tile &TileRegistry::GetByMnemonicID(const std::string &mnemonic) {
|
||||
return registered_tiles[MnemonicToNumeric(mnemonic)];
|
||||
}
|
||||
|
||||
std::vector<Tile> TileRegistry::GetTileList() {
|
||||
return {std::begin(registered_tiles), std::end(registered_tiles)};
|
||||
}
|
||||
|
||||
const std::array<Tile, TileRegistry::MaxTiles> &TileRegistry::GetTileArray() { return registered_tiles; }
|
||||
|
||||
bool TileRegistry::Exists(const std::string &mnemonic) { return name_to_id_mapping.contains(mnemonic); }
|
||||
|
||||
bool TileRegistry::Exists(u16 id) { return id_to_name_mapping.contains(id); }
|
||||
}
|
@@ -5,12 +5,10 @@
|
||||
#include <format>
|
||||
#include <chrono>
|
||||
#include <Core/Loggers.hpp>
|
||||
|
||||
#include <Core/TileRegistry.hpp>
|
||||
#include <JJX/JJX.hpp>
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
|
||||
namespace CaveGame::Core {
|
||||
void World::DoTileTiccs(float elapsed) {
|
||||
for (const auto& [coords, chunk] : loaded_chunks) {
|
||||
|
||||
@@ -72,7 +70,7 @@ namespace CaveGame::Core
|
||||
if (HasChunkAtCell(chunkCoords))
|
||||
return loaded_chunks.at(chunkCoords)->GetTile(tileCoords.x, tileCoords.y);
|
||||
|
||||
return TileID::VOID;
|
||||
return Tiles()["void"].numeric_id;
|
||||
}
|
||||
|
||||
void World::SetTile(int x, int y, TileID t, bool flag_update) {
|
||||
@@ -351,7 +349,7 @@ namespace CaveGame::Core
|
||||
|
||||
|
||||
void World::DoForcedTileTicks() {
|
||||
Tile* tile = nullptr;
|
||||
Tile tile;
|
||||
|
||||
for (auto& [coords, chunk] : loaded_chunks) {
|
||||
chunk->SwapTileUpdateBuffers();
|
||||
@@ -368,16 +366,16 @@ namespace CaveGame::Core
|
||||
|
||||
TileID at = chunk->GetTile(x, y);
|
||||
|
||||
if (at == TileID::AIR)
|
||||
if (at == Tiles()["air"].numeric_id)
|
||||
continue;
|
||||
|
||||
tile = GetByNumeric(at);
|
||||
tile = Tiles().Get(at);
|
||||
|
||||
if (tile != nullptr) {
|
||||
if (tile->DoesForcedTicc()) {
|
||||
tile->ForcedTicc(this, 0, wx, wy);
|
||||
//if (tile != nullptr) {
|
||||
if (tile.does_forced_ticc) {
|
||||
// tile->ForcedTicc(this, 0, wx, wy);
|
||||
//chunk->SetTileUpdateFlag(x, y, true);
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -408,18 +406,18 @@ namespace CaveGame::Core
|
||||
|
||||
TileID at = chunk->GetTile(x, y);
|
||||
|
||||
if (at == TileID::AIR)
|
||||
continue;
|
||||
//if (at == TileID::AIR)
|
||||
// continue;
|
||||
|
||||
tile = GetByNumeric(at);
|
||||
// tile = GetByNumeric(at);
|
||||
|
||||
/*
|
||||
if (tile != nullptr)
|
||||
if (tile->DoesRandomTicc())
|
||||
tile->RandomTicc(this, 0, wx, wy);
|
||||
*/
|
||||
if ((tile != nullptr) && (tile->DoesRandomTicc()))
|
||||
tile->RandomTicc(this, 0, wx, wy);
|
||||
//if ((tile != nullptr) && (tile->DoesRandomTicc()))
|
||||
// tile->RandomTicc(this, 0, wx, wy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -465,12 +463,12 @@ namespace CaveGame::Core
|
||||
|
||||
TileID at = chunk->GetTile(x, y);
|
||||
|
||||
if (at == TileID::AIR)
|
||||
continue;
|
||||
//if (at == TileID::AIR)
|
||||
// continue;
|
||||
|
||||
tile = GetByNumeric(at);
|
||||
if ((tile != nullptr) && (tile->DoesRandomTicc()))
|
||||
tile->RandomTicc(this, 0, wx, wy);
|
||||
//tile = GetByNumeric(at);
|
||||
//if ((tile != nullptr) && (tile->DoesRandomTicc()))
|
||||
// tile->RandomTicc(this, 0, wx, wy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -491,13 +489,13 @@ namespace CaveGame::Core
|
||||
continue;
|
||||
|
||||
TileID at = chunk->GetTile(x, y);
|
||||
if (at == TileID::AIR)
|
||||
continue;
|
||||
//if (at == TileID::AIR)
|
||||
// continue;
|
||||
|
||||
tile = GetByNumeric(at);
|
||||
if (tile != nullptr)
|
||||
if (tile->DoesForcedTicc())
|
||||
tile->ForcedTicc(this, 0, wx, wy);
|
||||
//tile = GetByNumeric(at);
|
||||
//if (tile != nullptr)
|
||||
// if (tile->DoesForcedTicc())
|
||||
// tile->ForcedTicc(this, 0, wx, wy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user