aboutsummaryrefslogtreecommitdiff
path: root/source/30-game
diff options
context:
space:
mode:
Diffstat (limited to 'source/30-game')
-rw-r--r--source/30-game/Ires.cpp49
-rw-r--r--source/30-game/main.cpp4
2 files changed, 35 insertions, 18 deletions
diff --git a/source/30-game/Ires.cpp b/source/30-game/Ires.cpp
index 4f8da85..0529395 100644
--- a/source/30-game/Ires.cpp
+++ b/source/30-game/Ires.cpp
@@ -148,17 +148,26 @@ std::unique_ptr<IresObject> IresObject::ReadFull(IresLoadingContext& ctx, const
}
std::unique_ptr<IresObject> IresObject::ReadBasic(const rapidjson::Value& value) {
- auto rvType = rapidjson::GetProperty(value, rapidjson::kStringType, "Type"sv);
- if (!rvType) return nullptr;
- auto kind = Metadata::EnumFromString<Kind>(rapidjson::AsStringView(*rvType));
- assert(kind.has_value());
- auto ires = Create(kind.value());
- if (!ires) return nullptr;
-
- auto rvUid = rapidjson::GetProperty(value, rapidjson::kArrayType, "Uid"sv);
- if (!rvUid) return nullptr;
- ires->mUid.Read(*rvUid);
+ std::unique_ptr<IresObject> ires;
+ Uid uid;
+ for (auto it = value.MemberBegin(); it != value.MemberEnd(); ++it) {
+ if (it->name == "Type"_rj_sv) {
+ if (it->value.GetType() != rapidjson::kStringType)
+ return nullptr;
+ auto kind = Metadata::EnumFromString<Kind>(rapidjson::AsStringView(it->value));
+ if (!kind.has_value())
+ return nullptr;
+ if ((ires = Create(*kind)) == nullptr)
+ return nullptr;
+ } else if (it->name == "Uid"_rj_sv) {
+ // FIXME this needs to do type checks
+ uid.Read(it->value);
+ }
+ }
+ if (ires == nullptr || uid.IsNull())
+ return nullptr;
+ ires->mUid = uid;
return ires;
}
@@ -226,7 +235,9 @@ void IresManager::DiscoverFiles(const fs::path& dir) {
fprintf(stderr, "Ires file [" PLATFORM_PATH_STR "] Failed to open file.", item.path().c_str());
continue;
}
- DEFER { fclose(file); };
+ DEFER {
+ fclose(file);
+ };
char readerBuffer[65536];
rapidjson::FileReadStream stream(file, readerBuffer, sizeof(readerBuffer));
@@ -236,7 +247,7 @@ void IresManager::DiscoverFiles(const fs::path& dir) {
auto ires = IresObject::ReadBasic(root);
if (!ires) {
- fprintf(stderr, "Ires file: [" PLATFORM_PATH_STR "] Failed to parse header.", item.path().c_str());
+ fprintf(stderr, "Ires file: [" PLATFORM_PATH_STR "] Failed to parse header.\n", item.path().c_str());
continue;
}
@@ -271,7 +282,7 @@ void IresManager::DiscoverFiles(const fs::path& dir) {
auto& ires = cand->ires;
if (!IresObject::ReadPartial(ctx, ires.Get(), cand->data)) {
- fprintf(stderr, "Ires file: [" PLATFORM_PATH_STR "] Failed to parse object data.", cand->path.c_str());
+ fprintf(stderr, "Ires file: [" PLATFORM_PATH_STR "] Failed to parse object data.\n", cand->path.c_str());
continue;
}
@@ -305,7 +316,9 @@ std::pair<IresObject*, bool> IresManager::Add(IresObject* ires) {
IresObject* IresManager::Load(const fs::path& filePath) {
auto file = Utils::OpenCstdioFile(filePath, Utils::Read);
if (!file) return nullptr;
- DEFER { fclose(file); };
+ DEFER {
+ fclose(file);
+ };
char readerBuffer[65536];
rapidjson::FileReadStream stream(file, readerBuffer, sizeof(readerBuffer));
@@ -366,7 +379,9 @@ bool IresManager::Rename(IresObject* ires, std::string newName) {
void IresManager::Reload(IresObject* ires) {
auto file = Utils::OpenCstdioFile(GetDesignatedPath(ires), Utils::Read);
if (!file) return;
- DEFER { fclose(file); };
+ DEFER {
+ fclose(file);
+ };
char readerBuffer[65536];
rapidjson::FileReadStream stream(file, readerBuffer, sizeof(readerBuffer));
@@ -388,7 +403,9 @@ void IresManager::Save(IresObject* ires, const fs::path& filePath) {
auto file = Utils::OpenCstdioFile(filePath, Utils::WriteTruncate);
if (!file) return;
- DEFER { fclose(file); };
+ DEFER {
+ fclose(file);
+ };
char writerBuffer[65536];
rapidjson::FileWriteStream stream(file, writerBuffer, sizeof(writerBuffer));
diff --git a/source/30-game/main.cpp b/source/30-game/main.cpp
index 77c4674..30ba9a6 100644
--- a/source/30-game/main.cpp
+++ b/source/30-game/main.cpp
@@ -133,8 +133,8 @@ int main(int argc, char* argv[]) {
constexpr auto kOpenGLDebug = "opengl-debug";
constexpr auto kImGuiBackend = "imgui-backend";
- constexpr auto kGameDataDir = "game-data-directory";
- constexpr auto kGameAssetDir = "game-asset-directory";
+ constexpr auto kGameDataDir = "game-data-dir";
+ constexpr auto kGameAssetDir = "game-asset-dir";
cxxopts::Options options(std::string(AppConfig::kAppName), "");
// clang-format off