Started work on prefabs.

This commit is contained in:
2022-12-19 22:41:16 -08:00
parent 53ebbf0699
commit d619e33763
24 changed files with 403 additions and 15 deletions

60
src/dawn/scene/Prefab.hpp Normal file
View File

@ -0,0 +1,60 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "SceneItem.hpp"
#include "SceneItemComponent.hpp"
#include "scene/components/Components.hpp"
#include "util/array.hpp"
namespace Dawn {
class Prefab {
public:
/**
* Returns a list of assets that this prefab requires to be loaded for the
* instanciation to work.
*
* @param man Asset Manager to retreive the assets from.
* @return List of required assets, includes sibling/child assets.
*/
static virtual std::vector<Asset*> getAssets(AssetManager *man) = 0;
/**
* Create a scene item from this prefab.
*
* @param scene Scene to add the item to.
* @return The created scene item for this prefab.
*/
static virtual SceneItem * create(Scene *scene) = 0;
};
template<class T>
class UIPrefab : public Prefab {
public:
/** @deprecated */
static SceneItem * create(Scene *scene) override {
assertUnreachable();
}
/**
* 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;
/**
* Creates a UI Item from this prefab.
*
* @param canvas Canvas to create this item on to.
* @return Pointer to the created UI Item.
*/
static virtual T * uiCreate(UICanvas *canvas) {
auto item = canvas->addElement<T>();
uiApply(item);
return item;
}
}
}