JSON tile metadata parse test, WIP.

This commit is contained in:
2025-03-19 15:45:54 -04:00
parent 9a10ff81d0
commit dfb60a45c4

View File

@@ -41,14 +41,55 @@ std::string read_file(const std::string& file_path)
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");
std::string content = read_file("assets/data/tiles/base_tiles.json");
//auto [text, parse_error] = json::parse(content);
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.