From 98dd680a641a2cbe0f1f93202a5beffdfd35c9f7 Mon Sep 17 00:00:00 2001 From: Wolfgang Aigner Date: Thu, 6 Apr 2023 18:44:07 +0200 Subject: Changed type of cost in Good.hpp/.cpp + codestyle --- extension/src/openvic2/Good.cpp | 2 +- extension/src/openvic2/Good.hpp | 10 ++++++---- extension/src/openvic2/LoadGoods.cpp | 13 +++++++------ extension/src/openvic2/LoadGoods.hpp | 6 +++--- 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 #include +#include 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 #include #include #include @@ -40,7 +41,7 @@ std::vector LoadGoods::load_goods_from_disk(godot::String const& file_path return goods; } -bool LoadGoods::extract_property_from_json(const godot::Variant& variant, std::vector& goods, int32_t index) { +bool LoadGoods::extract_property_from_json(godot::Variant const& variant, std::vector& 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(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(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(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(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(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 #include -#include "Good.hpp" +#include namespace OpenVic2 { class LoadGoods { private: - static bool extract_property_from_json(const godot::Variant& variant, std::vector& goods, int32_t index); + static bool extract_property_from_json(godot::Variant const& variant, std::vector& goods, int32_t index); public: static std::vector load_goods_from_disk(godot::String const& file_path); -- cgit v1.2.3-56-ga3b1