From 562e6644ef02968826b86f26796d103e2337f1b7 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 21 Dec 2022 09:54:12 -0800 Subject: [PATCH] Prefabs not working --- src/dawn/scene/Prefab.hpp | 28 ++++++++++++++----- .../prefabs/VisualNovelTextboxPrefab.hpp | 4 +-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/dawn/scene/Prefab.hpp b/src/dawn/scene/Prefab.hpp index 11fba03f..74b8f238 100644 --- a/src/dawn/scene/Prefab.hpp +++ b/src/dawn/scene/Prefab.hpp @@ -11,6 +11,10 @@ namespace Dawn { class Prefab { + protected: + virtual std::vector prefabAssets(AssetManager *man) = 0; + virtual SceneItem * prefabItem(Scene *scene) = 0; + public: /** * Returns a list of assets that this prefab requires to be loaded for the @@ -19,7 +23,10 @@ namespace Dawn { * @param man Asset Manager to retreive the assets from. * @return List of required assets, includes sibling/child assets. */ - static virtual std::vector getAssets(AssetManager *man) = 0; + template + static std::vector getAssets(AssetManager *man) { + return T::prefabAssets(man); + } /** * Create a scene item from this prefab. @@ -27,23 +34,30 @@ namespace Dawn { * @param scene Scene to add the item to. * @return The created scene item for this prefab. */ - static virtual SceneItem * create(Scene *scene) = 0; + template + static SceneItem * create(Scene *scene) { + return T::prefabItem(scene); + } }; - template class UIPrefab : public Prefab { - public: + protected: /** @deprecated */ - static SceneItem * create(Scene *scene) override { + SceneItem * prefabItem(Scene *scene) override { assertUnreachable(); } + virtual void prefabUIApply(T *existing) = 0; + + public: /** * Applies a UI Prefab styling to an existing UI Element. * * @param existing Existing item to apply styling to. */ - static virtual void uiApply(T *existing) = 0; + static virtual void uiApply(T *existing) { + V::prefabUIApply(existing); + } /** * Creates a UI Item from this prefab. @@ -53,7 +67,7 @@ namespace Dawn { */ static virtual T * uiCreate(UICanvas *canvas) { auto item = canvas->addElement(); - uiApply(item); + V::uiApply(item); return item; } } diff --git a/src/dawnbarrygame/prefabs/VisualNovelTextboxPrefab.hpp b/src/dawnbarrygame/prefabs/VisualNovelTextboxPrefab.hpp index 771d570c..c6627822 100644 --- a/src/dawnbarrygame/prefabs/VisualNovelTextboxPrefab.hpp +++ b/src/dawnbarrygame/prefabs/VisualNovelTextboxPrefab.hpp @@ -10,7 +10,7 @@ namespace Dawn { class VisualNovelTextboxPrefab : public UIPrefab { public: - static std::vector getAssets(AssetManager *man) { + static std::vector prefabAssets(AssetManager *man) { std::vector assets{ man->get("truetype_ark") }; @@ -18,7 +18,7 @@ namespace Dawn { return assets; } - static void uiApply(VisualNovelTextbox *textbox) override { + static void prefabUIApply(VisualNovelTextbox *textbox) override { assertNotNull(textbox); auto assetFont = textbox->getGame()->assetManager.get("truetype_ark");