aboutsummaryrefslogtreecommitdiff
path: root/extension
diff options
context:
space:
mode:
author Wolfgang Aigner <wolfgang.aigner@yahoo.de>2023-04-06 18:44:07 +0200
committer Wolfgang Aigner <wolfgang.aigner@yahoo.de>2023-04-06 18:44:07 +0200
commit98dd680a641a2cbe0f1f93202a5beffdfd35c9f7 (patch)
tree1041c2aa577c3523faf37f362f1b50614004c242 /extension
parent383583733b2f4cd8c5e632c160afdb987b8615af (diff)
Changed type of cost in Good.hpp/.cpp + codestyle
Diffstat (limited to 'extension')
-rw-r--r--extension/src/openvic2/Good.cpp2
-rw-r--r--extension/src/openvic2/Good.hpp10
-rw-r--r--extension/src/openvic2/LoadGoods.cpp13
-rw-r--r--extension/src/openvic2/LoadGoods.hpp6
4 files changed, 17 insertions, 14 deletions
diff --git a/extension/src/openvic2/Good.cpp b/extension/src/openvic2/Good.cpp
index 3424099..ecd2bfb 100644
--- a/extension/src/openvic2/Good.cpp
+++ b/extension/src/openvic2/Good.cpp
@@ -4,7 +4,7 @@ using namespace OpenVic2;;
Good::Good() = default;
-Good::Good(const godot::String& identifier, const godot::String& category, float_t cost, const godot::String& colour,
+Good::Good(const godot::String& identifier, const godot::String& category, price_t cost, const godot::String& colour,
bool isAvailable, bool isTradable, bool isMoney, bool hasOverseasPenalty) {
this->identifier = identifier;
this->category = category;
diff --git a/extension/src/openvic2/Good.hpp b/extension/src/openvic2/Good.hpp
index 615b82c..dd2e8a8 100644
--- a/extension/src/openvic2/Good.hpp
+++ b/extension/src/openvic2/Good.hpp
@@ -1,14 +1,16 @@
#pragma once
-#include <godot_cpp/variant/string.hpp>
#include <string>
+#include <godot_cpp/variant/string.hpp>
namespace OpenVic2 {
class Good {
public:
+ using price_t = float;
+
godot::String identifier;
godot::String category;
- float_t cost;
+ price_t cost;
godot::String colour;
bool isAvailableAtStart;
bool isTradable;
@@ -16,8 +18,8 @@ namespace OpenVic2 {
bool hasOverseasPenalty;
Good();
- Good(const godot::String& identifier, const godot::String& category, float_t cost, const godot::String& colour,
- bool isAvailable, bool isTradable, bool isMoney, bool hasOverseasPenalty);
+ Good(const godot::String& identifier, const godot::String& category, price_t cost, const godot::String& colour,
+ bool isAvailable, bool isTradable, bool isMoney, bool hasOverseasPenalty);
~Good();
};
} \ No newline at end of file
diff --git a/extension/src/openvic2/LoadGoods.cpp b/extension/src/openvic2/LoadGoods.cpp
index a47f03f..12d8d0d 100644
--- a/extension/src/openvic2/LoadGoods.cpp
+++ b/extension/src/openvic2/LoadGoods.cpp
@@ -1,5 +1,6 @@
#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>
@@ -40,7 +41,7 @@ std::vector<Good> LoadGoods::load_goods_from_disk(godot::String const& file_path
return goods;
}
-bool LoadGoods::extract_property_from_json(const godot::Variant& variant, std::vector<Good>& goods, int32_t index) {
+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) {
@@ -52,7 +53,7 @@ bool LoadGoods::extract_property_from_json(const godot::Variant& variant, std::v
UtilityFunctions::push_error("Could not extract property category of type string from goods.json");
return false;
}
- float_t cost = (float_t)variant.get_named(JSON_PROPERTY_NAME("cost"), valid);
+ 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;
@@ -62,22 +63,22 @@ bool LoadGoods::extract_property_from_json(const godot::Variant& variant, std::v
UtilityFunctions::push_error("Could not extract property colour of type string from goods.json");
return false;
}
- bool isAvailableAtStart = (bool)variant.get_named(JSON_PROPERTY_NAME("isAvailableAtStart"), valid);
+ 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 = (bool)variant.get_named(JSON_PROPERTY_NAME("isTradeable"), valid);
+ 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 = (bool)variant.get_named(JSON_PROPERTY_NAME("isMoney"), valid);
+ 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 = (bool)variant.get_named(JSON_PROPERTY_NAME("hasOverseasPenalty"), valid);
+ 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;
diff --git a/extension/src/openvic2/LoadGoods.hpp b/extension/src/openvic2/LoadGoods.hpp
index 41dd75e..38b8c7b 100644
--- a/extension/src/openvic2/LoadGoods.hpp
+++ b/extension/src/openvic2/LoadGoods.hpp
@@ -1,13 +1,13 @@
#pragma once
+#include "Good.hpp"
-#include <godot_cpp/classes/object.hpp>
#include <vector>
-#include "Good.hpp"
+#include <godot_cpp/classes/object.hpp>
namespace OpenVic2 {
class LoadGoods {
private:
- static bool extract_property_from_json(const godot::Variant& variant, std::vector<Good>& goods, int32_t index);
+ static bool extract_property_from_json(godot::Variant const& variant, std::vector<Good>& goods, int32_t index);
public:
static std::vector<Good> load_goods_from_disk(godot::String const& file_path);