module; #include #include export module io; import utils; import AssetData; import std; using json = nlohmann::json; export namespace ee_data { NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( Subject, tag, color, regions ) } export namespace ee_data { NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( GameState, subjects ) } export namespace ee_assets { NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( AssetSave, content ) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( AssetMaterial, vertexShaderAssetID, fragmentShaderAssetID ) } export namespace ee_sdk { std::optional ReadJson(const std::filesystem::path &assetPath) { std::ifstream fin(assetPath); if (!fin.is_open()) { LOG(ERROR, "Could not open output file: [%s]", assetPath.c_str()); return std::nullopt; } json data = json::parse(fin); fin.close(); return data; } std::optional> ReadBinary(const std::filesystem::path &assetPath) { std::ifstream fin(assetPath, std::ios::binary); if (!fin.is_open()) { LOG(ERROR, "Could not open output file: [%s]", assetPath.c_str()); return std::nullopt; } std::vector data; // Read size fin.seekg(0, std::ios::end); const std::streamsize size = fin.tellg(); fin.seekg(0, std::ios::beg); data.reserve(size); // Read content fin.read(reinterpret_cast(data.data()), size); fin.close(); return data; } template void WriteAsset(const std::filesystem::path &assetPath, const TAsset &asset) { std::ofstream fout(assetPath, std::ios::binary); if (!fout.is_open()) { LOG(ERROR, "Could not open input file: [%s]", assetPath.c_str()); return; } const std::vector data = rfl::capnproto::write(asset); fout.write(data.data(), data.size()); fout.close(); } constexpr std::uint32_t colorToHex( const std::uint8_t r, const std::uint8_t g, const std::uint8_t b, const bool isBGR = false ) { if (isBGR) { return static_cast(b) << 16 | static_cast(g) << 8 | static_cast(r); } return static_cast(r) << 16 | static_cast(g) << 8 | static_cast(b); } }