aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2/LoadGoods.cpp
diff options
context:
space:
mode:
author ClarkeCode <clarke.john.robert@gmail.com>2023-04-28 19:18:50 +0200
committer ClarkeCode <clarke.john.robert@gmail.com>2023-04-28 19:18:50 +0200
commitb6f9d6433c4ace514fa991cea628c2598c3bc65c (patch)
tree9bc6f54549bc1dff9fac15f10e240203c6865605 /extension/src/openvic2/LoadGoods.cpp
parenta7b0da7fd988a9a96e625c0914ae698afb5674bf (diff)
Temporarily removed; will be re-added after C++ code moved to submodule
Diffstat (limited to 'extension/src/openvic2/LoadGoods.cpp')
-rw-r--r--extension/src/openvic2/LoadGoods.cpp88
1 files changed, 0 insertions, 88 deletions
diff --git a/extension/src/openvic2/LoadGoods.cpp b/extension/src/openvic2/LoadGoods.cpp
deleted file mode 100644
index 12d8d0d..0000000
--- a/extension/src/openvic2/LoadGoods.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-#include "LoadGoods.hpp"
-
-#include <cstdint>
-#include <godot_cpp/variant/utility_functions.hpp>
-#include <godot_cpp/classes/file_access.hpp>
-#include <godot_cpp/classes/json.hpp>
-
-using namespace OpenVic2;
-using namespace godot;
-
-#define JSON_PROPERTY_NAME(x) godot::StringName(x)
-
-std::vector<Good> LoadGoods::load_goods_from_disk(godot::String const& file_path) {
- std::vector<Good> goods;
- Ref<FileAccess> file = FileAccess::open(file_path, FileAccess::ModeFlags::READ);
- Error err = FileAccess::get_open_error();
- if (err != OK || file.is_null()) {
- UtilityFunctions::push_error("Failed to open good configuration file: ", file_path);
- return std::vector<Good>();
- }
- godot::String file_content = file->get_as_text();
- JSON parsed_goods;
- err = parsed_goods.parse(file_content);
- if (err != OK) {
- UtilityFunctions::push_error("Failed to parse goods.json");
- return std::vector<Good>();
- }
- Variant v_goods = parsed_goods.get_data().get("goods", nullptr);
- if (v_goods.get_type() != Variant::ARRAY) {
- UtilityFunctions::push_error("Failed to parse goods.json: Top level property is not an array");
- return std::vector<Good>();
- }
- godot::Array v_goods_array = (godot::Array)v_goods;
- int32_t count = v_goods_array.size();
- goods.resize(count);
- for (size_t i = 0; i < count; i++) {
- if(!extract_property_from_json(v_goods_array[i], goods, i)) {
- return std::vector<Good>();
- }
- }
- return goods;
-}
-
-bool LoadGoods::extract_property_from_json(godot::Variant const& variant, std::vector<Good>& goods, int32_t index) {
- bool valid;
- String id = variant.get_named(JSON_PROPERTY_NAME("id"), valid);
- if(!valid) {
- UtilityFunctions::push_error("Could not extract property id of type string from goods.json");
- return false;
- }
- String category = variant.get_named(JSON_PROPERTY_NAME("category"), valid);
- if(!valid) {
- UtilityFunctions::push_error("Could not extract property category of type string from goods.json");
- return false;
- }
- float cost = static_cast<float>(variant.get_named(JSON_PROPERTY_NAME("cost"), valid));
- if(!valid) {
- UtilityFunctions::push_error("Could not extract property cost of type float from goods.json");
- return false;
- }
- String colour = variant.get_named(JSON_PROPERTY_NAME("colour"), valid);
- if(!valid) {
- UtilityFunctions::push_error("Could not extract property colour of type string from goods.json");
- return false;
- }
- bool isAvailableAtStart = static_cast<bool>(variant.get_named(JSON_PROPERTY_NAME("isAvailableAtStart"), valid));
- if(!valid) {
- UtilityFunctions::push_error("Could not extract property isAvailableAtStart of type bool from goods.json");
- return false;
- }
- bool isTradable = static_cast<bool>(variant.get_named(JSON_PROPERTY_NAME("isTradeable"), valid));
- if(!valid) {
- UtilityFunctions::push_error("Could not extract property isTradable of type bool from goods.json");
- return false;
- }
- bool isMoney = static_cast<bool>(variant.get_named(JSON_PROPERTY_NAME("isMoney"), valid));
- if(!valid) {
- UtilityFunctions::push_error("Could not extract property isMoney of type bool from goods.json");
- return false;
- }
- bool hasOverseasPenalty = static_cast<bool>(variant.get_named(JSON_PROPERTY_NAME("hasOverseasPenalty"), valid));
- if(!valid) {
- UtilityFunctions::push_error("Could not extract property hasOverseaPenalty of type bool from goods.json");
- return false;
- }
- goods.at(index) = Good(id, category, cost, colour, isAvailableAtStart, isTradable, isMoney, hasOverseasPenalty);
- return true;
-} \ No newline at end of file