#include "Common.h" #include "Registry.h" #include "rapidjson/document.h" #include "rapidjson/filereadstream.h" #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" #include #include #include #include namespace Feather { IDMapper Registry::BLOCK_STATES; void Registry::Init() { static bool initialized = false; if (initialized) return; Log::Info("Loading data/blocks.json..."); { using namespace rapidjson; std::string text; FILE* fp = fopen("data/blocks.json", "rb"); if (!fp) { Log::Error("Failed to read data/blocks.json"); return; } fseek(fp, 0, SEEK_END); text.resize(ftell(fp)); rewind(fp); fread(&text[0], 1, text.size(), fp); fclose(fp); Document doc; doc.Parse(text.c_str()); for (auto& block : doc.GetObject()) { //Log::Info("{}: {} states", m.name.GetString(), m.value["states"].Size()); for (auto& stateData : block.value["states"].GetArray()) { std::string* name = new std::string(block.name.GetString()); BlockState state(*name); BLOCK_STATES.AddMapping(stateData["id"].GetInt(), state); } } Log::Info("Loaded {} block states.", BLOCK_STATES.Size()); //StringBuffer buf; //Writer writer(buf); //doc.Accept(writer); // FIXME: why does this crash //Log::Info(text); } } }