Just breaking stuff
This commit is contained in:
82
archive/dawnpokergame/prefabs/characters/CharacterPrefab.hpp
Normal file
82
archive/dawnpokergame/prefabs/characters/CharacterPrefab.hpp
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "prefab/SceneItemPrefab.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "scene/components/display/MeshRenderer.hpp"
|
||||
#include "scene/components/display/AnimationController.hpp"
|
||||
#include "scene/components/display/MeshHost.hpp"
|
||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||
#include "scene/components/audio/AudioSource.hpp"
|
||||
#include "visualnovel/components/VisualNovelCharacter.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
template<class O>
|
||||
class CharacterPrefab : public SceneItemPrefab<O> {
|
||||
protected:
|
||||
/**
|
||||
* Character Prefab will request you to initialize your characters'
|
||||
* emotions here, including loading assets,
|
||||
*
|
||||
* @return struct VisualNovelCharacterEmotion
|
||||
*/
|
||||
virtual struct VisualNovelCharacterEmotion defineAndGetInitialEmotion(
|
||||
AssetManager *assMan
|
||||
) = 0;
|
||||
|
||||
|
||||
public:
|
||||
static std::vector<Asset*> prefabAssets(AssetManager *assMan) {
|
||||
return std::vector<Asset*>{
|
||||
assMan->get<TextureAsset>(O::getCharacterTexture()),
|
||||
assMan->get<TilesetAsset>(O::getCharacterTileset())
|
||||
};
|
||||
}
|
||||
|
||||
// Instance
|
||||
VisualNovelCharacter *vnCharacter;
|
||||
AnimationController *animation;
|
||||
TextureAsset *characterTexture;
|
||||
TilesetAsset *characterTileset;
|
||||
MeshRenderer *meshRenderer;
|
||||
MeshHost *meshHost;
|
||||
SimpleTexturedMaterial *material;
|
||||
TiledSprite *tiledSprite;
|
||||
AudioSource *audioSource;
|
||||
|
||||
CharacterPrefab(Scene *s, sceneitemid_t i) : SceneItemPrefab<O>(s, i) {}
|
||||
|
||||
void prefabInit(AssetManager *man) override {
|
||||
characterTexture = man->get<TextureAsset>(O::getCharacterTexture());
|
||||
characterTileset = man->get<TilesetAsset>(O::getCharacterTileset());
|
||||
|
||||
// Emotions
|
||||
auto emotion = this->defineAndGetInitialEmotion(man);
|
||||
|
||||
// Components
|
||||
meshRenderer = this->template addComponent<MeshRenderer>();
|
||||
meshHost = this->template addComponent<MeshHost>();
|
||||
|
||||
material = this->template addComponent<SimpleTexturedMaterial>();
|
||||
material->texture = &characterTexture->texture;
|
||||
|
||||
vnCharacter = this->template addComponent<VisualNovelCharacter>();
|
||||
vnCharacter->nameKey = O::getLanguagePrefix() + ".name";
|
||||
|
||||
animation = this->template addComponent<AnimationController>();
|
||||
|
||||
tiledSprite = this->template addComponent<TiledSprite>();
|
||||
tiledSprite->setTileset(&characterTileset->tileset);
|
||||
float_t ratio = characterTileset->tileset.getTileWidth() / characterTileset->tileset.getTileHeight();
|
||||
tiledSprite->setSize(glm::vec2(ratio, 1.0f));
|
||||
tiledSprite->setTile(emotion.tile);
|
||||
|
||||
audioSource = this->template addComponent<AudioSource>();
|
||||
|
||||
this->transform.setLocalPosition(glm::vec3(0, 0, 0));
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user