aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nemrav <>2024-09-04 23:03:04 +0200
committer Nemrav <>2024-09-04 23:03:04 +0200
commit9d30f3eeeff56297f61a33348658b970cf191964 (patch)
tree0f14f1158b064e5d15f04384472e02141abe57b6
parent31c9050bc15a208e73e406bc52aa5d1b3200f2e0 (diff)
GFXObjects in progress
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp22
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp2
-rw-r--r--src/openvic-simulation/interface/GFXObject.cpp175
-rw-r--r--src/openvic-simulation/interface/GFXObject.hpp70
-rw-r--r--src/openvic-simulation/types/unlabelledVec.hpp36
5 files changed, 195 insertions, 110 deletions
diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp
index ad130ad..1339dd3 100644
--- a/src/openvic-simulation/dataloader/NodeTools.cpp
+++ b/src/openvic-simulation/dataloader/NodeTools.cpp
@@ -276,6 +276,28 @@ node_callback_t NodeTools::expect_fvec2(callback_t<fvec2_t> callback) {
return _expect_vec2<fixed_point_t, expect_fixed_point>(callback);
}
+node_callback_t NodeTools::expect_v2_vector3(callback_t<V2Vector3> callback) {
+ return [callback](ast::NodeCPtr node) -> bool {
+
+ int components = 0;
+ fixed_point_t x = 0;
+ fixed_point_t y = 0;
+ fixed_point_t z = 0;
+
+ bool ret = expect_list_of_length(3, expect_fixed_point(
+ [&components,&x,&y,&z](fixed_point_t val) -> bool {
+ if(components == 0) x = val;
+ else if(components == 1) y = val;
+ else z = val;
+ components++;
+ return true;
+ }))(node);
+
+ ret &= callback(V2Vector3(x,y,z));
+ return ret;
+ };
+}
+
node_callback_t NodeTools::expect_assign(key_value_callback_t callback) {
return _expect_type<ast::AssignStatement>([callback](ast::AssignStatement const* assign_node) -> bool {
std::string_view left;
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 79fb0ea..6464e72 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -14,6 +14,7 @@
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/IndexedMap.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
+#include "openvic-simulation/types/unlabelledVec.hpp"
#include "openvic-simulation/types/Vector.hpp"
#include "openvic-simulation/utility/Getters.hpp"
#include "openvic-simulation/utility/TslHelper.hpp"
@@ -160,6 +161,7 @@ namespace OpenVic {
node_callback_t expect_ivec2(callback_t<ivec2_t> callback);
node_callback_t expect_fvec2(callback_t<fvec2_t> callback);
+ node_callback_t expect_v2_vector3(callback_t<V2Vector3> callback);
node_callback_t expect_assign(key_value_callback_t callback);
using length_callback_t = std::function<size_t(size_t)>;
diff --git a/src/openvic-simulation/interface/GFXObject.cpp b/src/openvic-simulation/interface/GFXObject.cpp
index 05527e6..bd23cce 100644
--- a/src/openvic-simulation/interface/GFXObject.cpp
+++ b/src/openvic-simulation/interface/GFXObject.cpp
@@ -11,34 +11,10 @@ node_callback_t Object::expect_objects(length_callback_t length_callback, callba
"EMFXActorType", ZERO_OR_MORE, _expect_instance<Object, Actor>(callback),
/* arrows.gfx */
- "arrowType", ZERO_OR_MORE, expect_dictionary_keys(
- "name", ONE_EXACTLY, success_callback,
- "size", ONE_EXACTLY, success_callback,
- "textureFile", ONE_EXACTLY, success_callback,
- "bodytexture", ONE_EXACTLY, success_callback,
- "color", ONE_EXACTLY, success_callback,
- "colortwo", ONE_EXACTLY, success_callback,
- "endAt", ONE_EXACTLY, success_callback,
- "height", ONE_EXACTLY, success_callback,
- "type", ONE_EXACTLY, success_callback,
- "heading", ONE_EXACTLY, success_callback,
- "effect", ONE_EXACTLY, success_callback
- ),
+ "arrowType", ZERO_OR_MORE, _expect_instance<Object, ArrowType>(callback),
/* battlearrow.gfx */
- "battlearrow", ZERO_OR_MORE, expect_dictionary_keys(
- "name", ONE_EXACTLY, success_callback,
- "textureFile", ONE_EXACTLY, success_callback,
- "textureFile1", ONE_EXACTLY, success_callback,
- "start", ONE_EXACTLY, success_callback,
- "stop", ONE_EXACTLY, success_callback,
- "x", ONE_EXACTLY, success_callback,
- "y", ONE_EXACTLY, success_callback,
- "font", ONE_EXACTLY, success_callback,
- "scale", ONE_EXACTLY, success_callback,
- "nofade", ZERO_OR_ONE, success_callback,
- "textureloop", ZERO_OR_ONE, success_callback
- ),
+ "battlearrow", ZERO_OR_MORE, _expect_instance<Object, BattleArrow>(callback),
"mapinfo", ZERO_OR_MORE, _expect_instance<Object, MapInfo>(callback),
/* mapitems.gfx */
@@ -48,20 +24,8 @@ node_callback_t Object::expect_objects(length_callback_t length_callback, callba
"unitstatsBillboardType", ZERO_OR_MORE, _expect_instance<Object, UnitStatsBillboard>(callback),
/* core.gfx */
- "animatedmaptext", ZERO_OR_MORE, expect_dictionary_keys(
- "name", ONE_EXACTLY, success_callback,
- "speed", ONE_EXACTLY, success_callback,
- "position", ZERO_OR_ONE, success_callback,
- "scale", ZERO_OR_ONE, success_callback,
- "textblock", ONE_EXACTLY, expect_dictionary_keys(
- "text", ONE_EXACTLY, success_callback,
- "color", ONE_EXACTLY, success_callback,
- "font", ONE_EXACTLY, success_callback,
- "position", ONE_EXACTLY, success_callback,
- "size", ONE_EXACTLY, success_callback,
- "format", ONE_EXACTLY, success_callback
- )
- ),
+ "animatedmaptext", ZERO_OR_MORE, _expect_instance<Object, AnimatedMapText>(callback),
+
"flagType", ZERO_OR_MORE, expect_dictionary_keys(
"name", ONE_EXACTLY, success_callback,
"size", ONE_EXACTLY, success_callback
@@ -172,51 +136,54 @@ bool Actor::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) {
return ret;
}
- /* arrows.gfx */
- /*"arrowType", ZERO_OR_MORE, expect_dictionary_keys(
- "name", ONE_EXACTLY, success_callback,
- "size", ONE_EXACTLY, success_callback,
- "textureFile", ONE_EXACTLY, success_callback,
- "bodytexture", ONE_EXACTLY, success_callback,
- "color", ONE_EXACTLY, success_callback,
- "colortwo", ONE_EXACTLY, success_callback,
- "endAt", ONE_EXACTLY, success_callback,
- "height", ONE_EXACTLY, success_callback,
- "type", ONE_EXACTLY, success_callback,
- "heading", ONE_EXACTLY, success_callback,
- "effect", ONE_EXACTLY, success_callback
- ),*/
-
-BattleArrow::BattleArrow() : texture_file {}, scale { 1 } {}
+/* arrows.gfx */
+//todo: verify the texture files labels are correct
+ArrowType::ArrowType() : size { 5 }, texture_file {}, body_texture_file {},
+back_colour {}, progress_colour {}, end_at { 1 }, height { 1 }, arrow_type { 0 },
+heading { 1 }, effect_file {} {}
-bool BattleArrow::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) {
+bool ArrowType::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) {
bool ret = Object::_fill_key_map(key_map);
- /*ret &= add_key_map_entries(key_map,
- "textureFile", ZERO_OR_ONE, expect_string(assign_variable_callback_string(texture_file)),
- "textureFile2", ZERO_OR_ONE, expect_string(assign_variable_callback_string(back_texture_file)),
- "scale", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(scale))
- );*/
+ ret &= add_key_map_entries(key_map,
+ "size", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(size)),
+ "textureFile", ONE_EXACTLY, expect_string(assign_variable_callback_string(texture_file)),
+ "bodytexture", ONE_EXACTLY, expect_string(assign_variable_callback_string(body_texture_file)),
+ "color", ONE_EXACTLY, expect_colour(assign_variable_callback(back_colour)),
+ "colortwo", ONE_EXACTLY, expect_colour(assign_variable_callback(progress_colour)),
+ "endAt", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(end_at)),
+ "height", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(height)),
+ "type", ONE_EXACTLY, expect_int64(assign_variable_callback(arrow_type)),
+ "heading", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(heading)),
+ "effect", ONE_EXACTLY, expect_string(assign_variable_callback_string(effect_file))
+ );
return ret;
}
-/*
- battlearrow.gfx
- "battlearrow", ZERO_OR_MORE, expect_dictionary_keys(
- "name", ONE_EXACTLY, success_callback,
- "textureFile", ONE_EXACTLY, success_callback,
- "textureFile1", ONE_EXACTLY, success_callback,
- "start", ONE_EXACTLY, success_callback,
- "stop", ONE_EXACTLY, success_callback,
- "x", ONE_EXACTLY, success_callback,
- "y", ONE_EXACTLY, success_callback,
- "font", ONE_EXACTLY, success_callback,
- "scale", ONE_EXACTLY, success_callback,
- "nofade", ZERO_OR_ONE, success_callback,
- "textureloop", ZERO_OR_ONE, success_callback
- ),
-*/
+/* battlearrow.gfx */
+//todo: verify textureFile and textureFile1
+BattleArrow::BattleArrow() : texture_file {}, back_texture_file {}, start { 1 }, stop { 1 },
+ x { 1 }, y { 1 }, font {}, scale { 1 }, no_fade { false }, texture_loop {} {}
+
+bool BattleArrow::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) {
+ bool ret = Object::_fill_key_map(key_map);
+
+ ret &= add_key_map_entries(key_map,
+ "textureFile", ONE_EXACTLY, expect_string(assign_variable_callback_string(texture_file)),
+ "textureFile1", ONE_EXACTLY, expect_string(assign_variable_callback_string(back_texture_file)),
+ "start", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(start)),
+ "stop", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(stop)),
+ "x", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(x)),
+ "y", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(y)),
+ "font", ONE_EXACTLY, expect_string(assign_variable_callback_string(font)),
+ "scale", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(scale)),
+ "nofade", ZERO_OR_ONE, expect_bool(assign_variable_callback(no_fade)),
+ "textureloop", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(texture_loop))
+ );
+
+ return ret;
+}
MapInfo::MapInfo() : texture_file {}, scale { 1 } {}
@@ -258,13 +225,10 @@ bool Projection::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) {
return ret;
}
-Billboard::Offset::Offset(fixed_point_t x, fixed_point_t y, fixed_point_t z) :
- x { 0 }, y { 0 }, z { 0 } {}
Billboard::Billboard() :
texture_file {}, scale { 1 }, no_of_frames { 1 }, font_size { 7 },
- offset {0,0,0},
- font {} {}
+ offset {}, font {} {}
//TODO: billboard was a <StringMapCaseInsensitive> on its dictionnary, how do we preserve this?
bool Billboard::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) {
@@ -280,15 +244,7 @@ bool Billboard::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) {
"noOfFrames", ZERO_OR_ONE, expect_int64(assign_variable_callback(no_of_frames)),
"scale", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(scale)),
"font_size", ZERO_OR_ONE, expect_int64(assign_variable_callback(font_size)),
- "offset2", ZERO_OR_ONE,expect_list_of_length(3, expect_fixed_point(
- [&components,&x,&y,&z](fixed_point_t val) -> bool {
- if(components == 0) x = val;
- else if(components == 1) y = val;
- else z = val;
- components++;
- return true;
- })
- ),
+ "offset2", ZERO_OR_ONE, expect_v2_vector3(assign_variable_callback(offset)),
"font", ZERO_OR_ONE, expect_string(assign_variable_callback_string(font))
);
@@ -299,7 +255,6 @@ bool Billboard::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) {
return ret;
}
-// Projection type
UnitStatsBillboard::UnitStatsBillboard() :
texture_file {}, mask_file {}, effect_file {}, scale { 1 },
no_of_frames { 1 }, font_size { 7 }, font {} {}
@@ -323,7 +278,6 @@ bool UnitStatsBillboard::_fill_key_map(NodeTools::case_insensitive_key_map_t& ke
}
-// Projection type
ProgressBar3d::ProgressBar3d() : back_colour {}, progress_colour {}, size {}, effect_file {} {}
//TODO: Verify there aren't more, unused properties?
@@ -339,3 +293,38 @@ bool ProgressBar3d::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map
return ret;
}
+
+
+/* core.gfx */
+AnimatedMapText::TextBlock::TextBlock() :
+text {}, colour {}, font {}, text_position {}, size {}, format {} {}
+
+AnimatedMapText::AnimatedMapText() :
+speed { 1 }, scale { 1 }, position {}, textblock {} {}
+
+//TODO: Verify there aren't more, unused properties?
+bool AnimatedMapText::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) {
+ bool ret = Object::_fill_key_map(key_map);
+
+ //TODO: we should probably extract format_t to a datatype file for both here and GFXSprite to interit from
+ using enum format_t;
+ static const string_map_t<format_t> format_map = {
+ { "left", left }, { "right", right }, { "centre", centre }, { "center", centre }, { "justified", justified }
+ };
+
+ ret &= add_key_map_entries(key_map,
+ "speed", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(speed)),
+ "position", ZERO_OR_ONE, expect_v2_vector3(assign_variable_callback(position)),
+ "scale", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(scale)),
+ "textblock", ONE_EXACTLY, expect_dictionary_keys(
+ "text", ONE_EXACTLY, expect_string(assign_variable_callback_string(textblock.text)),
+ "color", ONE_EXACTLY, expect_colour(assign_variable_callback(textblock.colour)),
+ "font", ONE_EXACTLY, expect_string(assign_variable_callback_string(textblock.font)),
+ "position", ONE_EXACTLY, expect_fvec2(assign_variable_callback(textblock.text_position)),
+ "size", ONE_EXACTLY, expect_fvec2(assign_variable_callback(textblock.size)),
+ "format", ONE_EXACTLY, expect_identifier(expect_mapped_string(format_map, assign_variable_callback(textblock.format)))
+ )
+ );
+
+ return ret;
+} \ No newline at end of file
diff --git a/src/openvic-simulation/interface/GFXObject.hpp b/src/openvic-simulation/interface/GFXObject.hpp
index a633cb5..233a1fd 100644
--- a/src/openvic-simulation/interface/GFXObject.hpp
+++ b/src/openvic-simulation/interface/GFXObject.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "openvic-simulation/interface/LoadBase.hpp"
+#include <openvic-simulation/types/unlabelledVec.hpp>
namespace OpenVic::GFX {
@@ -118,11 +119,11 @@ namespace OpenVic::GFX {
fixed_point_t PROPERTY(start);
fixed_point_t PROPERTY(stop);
- uint64_t PROPERTY(x);
- uint64_t PROPERTY(y);
+ fixed_point_t PROPERTY(x);
+ fixed_point_t PROPERTY(y);
std::string PROPERTY(font);
- uint64_t PROPERTY(scale);
+ fixed_point_t PROPERTY(scale);
bool PROPERTY(no_fade);
fixed_point_t PROPERTY(texture_loop);
@@ -191,26 +192,13 @@ namespace OpenVic::GFX {
friend std::unique_ptr<Billboard> std::make_unique<Billboard>();
public:
- struct Offset {
- friend class Billboard;
-
- private:
- fixed_point_t PROPERTY(x);
- fixed_point_t PROPERTY(y);
- fixed_point_t PROPERTY(z);
-
- Offset(fixed_point_t new_x, fixed_point_t new_y, fixed_point_t new_z);
-
- public:
- Offset(Offset&&) = default;
- };
private:
std::string PROPERTY(texture_file);
fixed_point_t PROPERTY(scale);
int64_t PROPERTY(no_of_frames);
int64_t PROPERTY(font_size); //TODO: is this fixed point?
- Offset PROPERTY(offset);
+ V2Vector3 PROPERTY(offset);
std::string PROPERTY(font);
protected:
@@ -275,6 +263,54 @@ namespace OpenVic::GFX {
};
/* Core.gfx */
+ class AnimatedMapText final : public Object {
+ friend std::unique_ptr<AnimatedMapText> std::make_unique<AnimatedMapText>();
+
+ //TODO: This format_t enum is the same as in GFXSprite, should this all be extracted
+ //to another datatype file?
+ enum class format_t {
+ left, centre, right, justified
+ };
+
+ public:
+ struct TextBlock {
+ friend class AnimatedMapText;
+ //format_t taken from GUI's AlignedElement, this is overall very similar
+
+
+ private:
+ std::string PROPERTY(text);
+ colour_t PROPERTY(colour);
+ std::string PROPERTY(font);
+
+ fvec2_t PROPERTY(text_position);
+ fvec2_t PROPERTY(size);
+ //expect_fvec2(assign_variable_callback(position)),
+
+ format_t PROPERTY(format);
+ TextBlock();
+
+ public:
+ TextBlock(TextBlock&&) = default;
+ };
+
+ private:
+ fixed_point_t PROPERTY(speed);
+ fixed_point_t PROPERTY(scale);
+ V2Vector3 PROPERTY(position);
+ TextBlock PROPERTY(textblock);
+
+ protected:
+ AnimatedMapText();
+
+ bool _fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) override;
+
+ public:
+ AnimatedMapText(AnimatedMapText&&) = default;
+ virtual ~AnimatedMapText() = default;
+
+ OV_DETAIL_GET_TYPE
+ };
} \ No newline at end of file
diff --git a/src/openvic-simulation/types/unlabelledVec.hpp b/src/openvic-simulation/types/unlabelledVec.hpp
new file mode 100644
index 0000000..4719726
--- /dev/null
+++ b/src/openvic-simulation/types/unlabelledVec.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
+
+namespace OpenVic {
+ //used in a couple places for GFXObjects
+
+ struct V2Vector3 {
+ fixed_point_t x;
+ fixed_point_t y;
+ fixed_point_t z;
+
+ //V2Vector3(fixed_point_t new_x = 0, fixed_point_t new_y = 0, fixed_point_t new_z = 0);
+ V2Vector3(fixed_point_t new_x = 0, fixed_point_t new_y = 0, fixed_point_t new_z = 0) :
+ x { new_x }, y { new_y }, z { new_z } {}
+
+ //V2Vector3(V2Vector3&&) = default; //move constructor
+ virtual ~V2Vector3() = default;
+ };
+ //used for lightTypes
+ struct V2Vector4 {
+ fixed_point_t x;
+ fixed_point_t y;
+ fixed_point_t z;
+ fixed_point_t w;
+
+ V2Vector4(fixed_point_t new_x = 0, fixed_point_t new_y = 0, fixed_point_t new_z = 0, fixed_point_t new_w = 0);
+
+ //V2Vector4(V2Vector4&&) = default; //move constructor
+ virtual ~V2Vector4() = default;
+ };
+}
+
+//TODO: Should we bother with more functions (to bring this in line with Vector.hpp)
+//or are we just immediately converting this stuff to godot::Vector3, Vector4 anyways?
+