Large Refactor, half-finished, will not compile or run currently.

This commit is contained in:
2025-03-20 23:52:51 -04:00
parent dfb60a45c4
commit e0367b971c
17 changed files with 423 additions and 227 deletions

View File

@@ -1,17 +1,22 @@
[
{
"mnemonic-id" : "void",
"display-name" : "VOID",
"mnemonic-id": "void",
"display-name": "Void",
"item-tooltip": "How did you even get this?",
"solid": true,
"does-random-ticc": false,
"does-forced-ticc": false,
"color": "#FFFFFF",
"pallet": [],
"hardcoded-id": 65536
"hardcoded-id": 65536,
"random-ticc-func": "spread-self",
"spreads-to": "dirt",
"decays-to": "",
"draw-func": ""
},
{
"mnemonic-id" : "air",
"display-name" : "AIR",
"display-name" : "Air",
"solid": true,
"does-random-ticc": false,
"does-forced-ticc": false,
@@ -21,7 +26,7 @@
},
{
"mnemonic-id" : "stone",
"display-name" : "",
"display-name" : "Stone",
"solid": true,
"does-random-ticc": false,
"does-forced-ticc": false,
@@ -29,7 +34,43 @@
"pallet": []
},
{
"mnemonic-id" : "stone",
"mnemonic-id" : "dirt",
"display-name" : "Dirt",
"solid": true,
"does-random-ticc": false,
"does-forced-ticc": false,
"color": "#FFFFFF",
"pallet": []
},
{
"mnemonic-id" : "mud",
"display-name" : "Mud",
"solid": true,
"does-random-ticc": false,
"does-forced-ticc": false,
"color": "#FFFFFF",
"pallet": []
},
{
"mnemonic-id" : "limestone",
"display-name" : "Mud",
"solid": true,
"does-random-ticc": false,
"does-forced-ticc": false,
"color": "#FFFFFF",
"pallet": []
},
{
"mnemonic-id" : "basalt",
"display-name" : "Mud",
"solid": true,
"does-random-ticc": false,
"does-forced-ticc": false,
"color": "#FFFFFF",
"pallet": []
},
{
"mnemonic-id" : "cobblestone",
"display-name" : "",
"solid": true,
"does-random-ticc": false,
@@ -41,7 +82,53 @@
"drops" : null
},
{
"mnemonic-id" : "stone",
"mnemonic-id" : "red-moss",
"display-name" : "Mud",
"solid": true,
"does-random-ticc": false,
"does-forced-ticc": false,
"color": "#FFFFFF",
"pallet": []
},
{
"mnemonic-id" : "brown-moss",
"display-name" : "",
"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" : "green-moss",
"display-name" : "",
"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" : "lava-moss",
"display-name" : "",
"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" : "granite",
"display-name" : "",
"solid": true,
"does-random-ticc": false,

View File

@@ -29,6 +29,7 @@
#include <Core/Player.hpp>
#include <Core/Explosion.hpp>
namespace CaveGame::ClientApp {
using CaveGame::Client::Scene;

View File

@@ -23,75 +23,9 @@
#include <JGL/logger/logger.h>
#include <JJX/JSON.hpp>
std::string read_file(const std::string& file_path)
{
std::ifstream file(file_path, std::ios::binary);
if (!file)
throw std::runtime_error("We couldn't find the file: " + file_path);
std::streamsize file_size;
file.seekg(0, std::ios::end);
file_size = file.tellg();
file.seekg(0, std::ios::beg);
std::string file_content(file_size, '\0');
file.read(&file_content[0], file_size);
file.close();
return file_content;
}
struct tile_meta
{
std::string mnemonic;
std::optional<std::vector<Color4>> pallet;
Color4 color;
bool solid;
bool does_random_ticc;
bool does_forced_ticc;
};
int main(int argc, char** argv) {
std::vector<tile_meta> tile_dataset;
using namespace JJX;
std::string content = read_file("assets/data/tiles/base_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()) {
std::cout << (int)t.type << std::endl;
auto tile_meta_json = json::object_val(t);
tile_meta data;
data.mnemonic = tile_meta_json["mnemonic-id"];
json::value color_field = tile_meta_json["color"];
if (color_field.type == json::value_type::string)
data.color = Color4::FromHexA(color_field.string.value());
else if (color_field.type == json::value_type::array)
{
auto color_array = json::array_val(color_field);
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();
data.color = Color4(r, g, b, a);
}
tile_dataset.push_back(data);
}
}
// Hide logs from engine components so we can focus on CaveGame.
JGL::Logger::Warning.EnableConsole(false);
JGL::Logger::Debug.EnableConsole(false);

View File

@@ -8,11 +8,74 @@
#include <ReWindow/InputService.h>
#include <Core/Macros.hpp>
#include <jstick.hpp>
#include <Core/TileRegistry.hpp>
#include <JJX/JSON.hpp>
namespace CaveGame::ClientApp
{
std::string read_file(const std::string& file_path)
{
std::ifstream file(file_path, std::ios::binary);
if (!file)
throw std::runtime_error("We couldn't find the file: " + file_path);
std::streamsize file_size;
file.seekg(0, std::ios::end);
file_size = file.tellg();
file.seekg(0, std::ios::beg);
std::string file_content(file_size, '\0');
file.read(&file_content[0], file_size);
file.close();
return file_content;
}
void ReadTileDataAndRegister()
{
Core::Tile tile;
using namespace JJX;
std::string content = read_file("assets/data/tiles/base_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()) {
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);
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);
}
}
}
Core::Tiles().Register(tile);
}
CaveGameWindow::CaveGameWindow(const std::string& title, int width, int height): ReWindow::OpenGLWindow(title, width, height, 2, 1)
{
Logs::Info("Parsing Tile Data.");
ReadTileDataAndRegister();
Logs::Info("Creating game window.");
CreateContexts();
@@ -281,8 +344,8 @@ namespace CaveGame::ClientApp
if (current_scene == GameSession()) {
Core::TileID id = game_ctx->GetTileUnderMouse();
Core::Tile* data = Core::GetByNumeric(id);
Core::TileID id = game_ctx->GetTileIDUnderMouse();
Core::Tile& data = Core::Tiles::GetInstance()->GetByNumericID(id);
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()));
@@ -567,11 +630,12 @@ namespace CaveGame::ClientApp
void CaveGameWindow::MarkReadyToClose(bool close) { wanna_die = close;}
bool CaveGameWindow::TileListCmd(const CommandArgs &args) {
auto tile_list = Core::GetAllTiles();
auto tile_list = Core::Tiles::GetInstance()->GetTileList();
for (const Core::Tile& tile : tile_list) {
Log(std::format("ID: {}, Mnemonic: {}, DisplayName: {}", tile.numeric_id, tile.mnemonic_id, tile.display_name));
//if (tile != nullptr)
for (Core::Tile* tile : tile_list) {
if (tile != nullptr)
Log(std::format("ID: {}, Mnemonic: {}, DisplayName: {}", (int)tile->NumericID(), tile->MnemonicID(), tile->Name()));
}
return true;