From 982605ee21941358080b9e20c9b9b2c2006f2d6a Mon Sep 17 00:00:00 2001
From: Clyne Sullivan <clyne@bitgloo.com>
Date: Tue, 10 Sep 2019 20:13:52 -0400
Subject: added Text component and skeleton system

---
 src/components/Text.hpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/text.cpp            | 18 +++++++++++++
 src/text.hpp            | 49 +++++++++++++++++++++++++++++++++++
 3 files changed, 136 insertions(+)
 create mode 100644 src/components/Text.hpp
 create mode 100644 src/text.cpp
 create mode 100644 src/text.hpp

diff --git a/src/components/Text.hpp b/src/components/Text.hpp
new file mode 100644
index 0000000..002d19a
--- /dev/null
+++ b/src/components/Text.hpp
@@ -0,0 +1,69 @@
+/**
+ * @file Text.hpp
+ * Allows text to be shown with an entity.
+ *
+ * Copyright (C) 2019 Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef COMPONENT_TEXT_HPP_
+#define COMPONENT_TEXT_HPP_
+
+#include "Component.hpp"
+
+struct Text : Component<Text>
+{
+public:
+    // TODO include font info?
+
+    std::string text;
+    double offsetX, offsetY;
+
+    Text(const std::string& _text) :
+        text(_text), offsetX(0), offsetY(0) {}
+    Text(const std::string& _text, double _x, double _y) :
+        text(_text), x(_x), y(_y) {}
+
+    Text FromLua(sol::object ref)
+    {
+        if (ref.get_type() == sol::type::table) {
+            sol::table tab = ref;
+            if (tab["text"] != nullptr)
+                this->text = tab["text"];
+            if (tab["x"] != nullptr)
+                this->x = tab["x"];
+            if (tab["y"] != nullptr)
+                this->y = tab["y"];
+        } else {
+            throw std::string("Text table not formatted properly");
+        }
+        return *this;
+    }
+
+    void serialize(cereal::JSONOutputArchive& ar) final {
+        ar(CEREAL_NVP(text), CEREAL_NVP(x), CEREAL_NVP(y));
+    }
+
+    void serialize(cereal::JSONInputArchive& ar) final {
+        ar(CEREAL_NVP(text), CEREAL_NVP(x), CEREAL_NVP(y));
+    }
+
+    std::string serializeName(void) const final {
+        return "Text";
+    }
+};
+
+#endif // COMPONENT_TEXT_HPP_
+
diff --git a/src/text.cpp b/src/text.cpp
new file mode 100644
index 0000000..2f5d3c3
--- /dev/null
+++ b/src/text.cpp
@@ -0,0 +1,18 @@
+#include "text.hpp"
+
+void TextSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
+                           [[maybe_unused]] entityx::EventManager& events)
+{
+    // TODO load freetype
+}
+    
+/**
+ * Draws the text for all entities.
+ */
+void TextSystem::update([[maybe_unused]] entityx::EntityManager& entites,
+                        [[maybe_unused]] entityx::EventManager& events,
+                        [[maybe_unused]] entityx::TimeDelta dt)
+{
+    // TODO render each Text component's text
+}
+
diff --git a/src/text.hpp b/src/text.hpp
new file mode 100644
index 0000000..183e655
--- /dev/null
+++ b/src/text.hpp
@@ -0,0 +1,49 @@
+/**
+ * @file text.hpp
+ * Manages entity text.
+ *
+ * Copyright (C) 2019 Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SYSTEM_TEXT_HPP_
+#define SYSTEM_TEXT_HPP_
+
+#include <entityx/entityx.h>
+#include <sol/sol.hpp>
+
+/**
+ * @class PhysicsSystem
+ * Handles the position and velocity updating of all entities
+ */
+class TextSystem : public entityx::System<TextSystem>
+{
+public:
+    /**
+     * Prepares the system for running.
+     */
+    void configure(entityx::EntityManager& entities,
+                   entityx::EventManager& events) final;
+    
+    /**
+     * Draws the text for all entities.
+     */
+    void update(entityx::EntityManager& entites,
+                entityx::EventManager& events,
+                entityx::TimeDelta dt) final;
+};
+
+#endif // SYSTEM_TEXT_HPP_
+
-- 
cgit v1.2.3