Various changes

This commit is contained in:
2023-01-29 15:13:24 -08:00
parent a06d24aad8
commit 9c7c0401a6
42 changed files with 410 additions and 447 deletions

View File

@ -0,0 +1,6 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
add_subdirectory(characters)

View File

@ -0,0 +1,11 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
CharacterPrefab.cpp
DeathPrefab.cpp
)

View File

@ -0,0 +1,8 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "CharacterPrefab.hpp"
using namespace Dawn;

View 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 T>
class CharacterPrefab : public SceneItemPrefab<T> {
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>(T::getCharacterTexture()),
assMan->get<TilesetAsset>(T::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(s, i) {}
void prefabInit(AssetManager *man) override {
characterTexture = man->get<TextureAsset>(T::getCharacterTexture());
characterTileset = man->get<TilesetAsset>(T::getCharacterTileset());
// Emotions
auto emotion = this->defineAndGetInitialEmotion(man);
// Components
meshRenderer = this->addComponent<MeshRenderer>();
meshHost = this->addComponent<MeshHost>();
material = this->addComponent<SimpleTexturedMaterial>();
material->texture = &characterTexture->texture;
vnCharacter = this->addComponent<VisualNovelCharacter>();
vnCharacter->nameKey = T::getLanguagePrefix() + ".name";
animation = this->addComponent<AnimationController>();
tiledSprite = this->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->addComponent<AudioSource>();
this->transform.setLocalPosition(glm::vec3(0, 0, 0));
}
};
}

View File

@ -0,0 +1,32 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "DeathPrefab.hpp"
using namespace Dawn;
std::string DeathPrefab::getCharacterTexture() {
return "texture_penny";
}
std::string DeathPrefab::getCharacterTileset() {
return "tileset_penny";
}
std::string DeathPrefab::getLanguagePrefix() {
return "character.death";
}
struct VisualNovelCharacterEmotion DeathPrefab::defineAndGetInitialEmotion(
AssetManager *man
) {
this->emotionHappy.tile = 0;
this->emotionConcerned.tile = 1;
this->emotionSurprised.tile = 2;
return this->emotionHappy;
}

View File

@ -4,61 +4,25 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "prefab/SceneItemPrefab.hpp"
#include "asset/AssetManager.hpp"
#include "poker/PokerPlayer.hpp"
#include "scene/components/Components.hpp"
#include "visualnovel/components/VisualNovelCharacter.hpp"
#include "display/animation/TiledSpriteAnimation.hpp"
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
#include "prefabs/characters/CharacterPrefab.hpp"
namespace Dawn {
class DeathPrefab : public SceneItemPrefab<DeathPrefab> {
class DeathPrefab : public CharacterPrefab<DeathPrefab> {
protected:
struct VisualNovelCharacterEmotion defineAndGetInitialEmotion(
AssetManager *man
) override;
public:
VisualNovelCharacter *vnCharacter;
AnimationController *animation;
static std::string getCharacterTexture();
static std::string getCharacterTileset();
static std::string getLanguagePrefix();
struct VisualNovelCharacterEmotion emotionHappy;
struct VisualNovelCharacterEmotion emotionConcerned;
struct VisualNovelCharacterEmotion emotionSurprised;
struct VisualNovelCharacterEmotion emotionDefault;
static std::vector<Asset*> prefabAssets(AssetManager *assMan) {
return std::vector<Asset*>{
assMan->get<TextureAsset>("texture_death"),
assMan->get<TilesetAsset>("tileset_death"),
assMan->get<AudioAsset>("audio_test")
};
}
DeathPrefab(Scene *scene, sceneitemid_t id) : SceneItemPrefab(scene, id)
{
}
void prefabInit(AssetManager *man) override {
auto textureAsset = man->get<TextureAsset>("texture_death");
auto tilesetAsset = man->get<TilesetAsset>("tileset_death");
auto audioAsset = man->get<AudioAsset>("audio_test");
// Emotions
this->emotionDefault.talkSound = audioAsset;
auto meshRenderer = this->addComponent<MeshRenderer>();
auto meshHost = this->addComponent<MeshHost>();
auto material = this->addComponent<SimpleTexturedMaterial>();
material->texture = &textureAsset->texture;
vnCharacter = this->addComponent<VisualNovelCharacter>();
vnCharacter->nameKey = "character.death.name";
animation = this->addComponent<AnimationController>();
auto tiledSprite = this->addComponent<TiledSprite>();
tiledSprite->setTilesetAndSize(&tilesetAsset->tileset);
tiledSprite->setTile(0);
this->addComponent<AudioSource>();
this->transform.setLocalPosition(glm::vec3(0, 0, 0));
}
DeathPrefab(Scene *s, sceneitemid_t i) : CharacterPrefab(s,i) {}
};
}

View File

@ -19,19 +19,32 @@ namespace Dawn {
PokerPlayer *pokerPlayer;
SimpleTexturedMaterial *material;
struct VisualNovelCharacterEmotion emotionHappy;
struct VisualNovelCharacterEmotion emotionSurprised;
struct VisualNovelCharacterEmotion emotionConcerned;
static std::vector<Asset*> prefabAssets(AssetManager *assMan) {
return std::vector<Asset*>{
assMan->get<TextureAsset>("texture_death"),
assMan->get<TilesetAsset>("tileset_death")
assMan->get<TextureAsset>("texture_penny"),
assMan->get<TilesetAsset>("tileset_penny")
};
}
PennyPrefab(Scene *scene, sceneitemid_t id) : SceneItemPrefab(scene, id){}
void prefabInit(AssetManager *man) override {
auto textureAsset = man->get<TextureAsset>("texture_death");
auto tilesetAsset = man->get<TilesetAsset>("tileset_death");
// Assets
auto textureAsset = man->get<TextureAsset>("texture_penny");
auto tilesetAsset = man->get<TilesetAsset>("tileset_penny");
// Emotions
this->emotionHappy.tile = 0;
this->emotionSurprised.tile = 1;
this->emotionConcerned.tile = 2;
// Components
auto meshRenderer = this->addComponent<MeshRenderer>();
auto meshHost = this->addComponent<MeshHost>();
@ -50,11 +63,6 @@ namespace Dawn {
tiledSprite->setTile(0);
this->transform.setLocalPosition(glm::vec3(0, 0, 0));
// auto anim = new TiledSpriteAnimation(tiledSprite);
// anim->addSequentialKeyframes(0.1f, 0, 22);
// anim->loop = true;
// animation->animation = anim;
}
};
}