Just breaking stuff
This commit is contained in:
6
archive/dawnpokergame/prefabs/CMakeLists.txt
Normal file
6
archive/dawnpokergame/prefabs/CMakeLists.txt
Normal 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)
|
11
archive/dawnpokergame/prefabs/characters/CMakeLists.txt
Normal file
11
archive/dawnpokergame/prefabs/characters/CMakeLists.txt
Normal 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
|
||||
)
|
@ -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;
|
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));
|
||||
}
|
||||
};
|
||||
}
|
32
archive/dawnpokergame/prefabs/characters/DeathPrefab.cpp
Normal file
32
archive/dawnpokergame/prefabs/characters/DeathPrefab.cpp
Normal 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_death";
|
||||
}
|
||||
|
||||
std::string DeathPrefab::getCharacterTileset() {
|
||||
return "tileset_death";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
29
archive/dawnpokergame/prefabs/characters/DeathPrefab.hpp
Normal file
29
archive/dawnpokergame/prefabs/characters/DeathPrefab.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "prefabs/characters/CharacterPrefab.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class DeathPrefab : public CharacterPrefab<DeathPrefab> {
|
||||
protected:
|
||||
|
||||
struct VisualNovelCharacterEmotion defineAndGetInitialEmotion(
|
||||
AssetManager *man
|
||||
) override;
|
||||
|
||||
public:
|
||||
static std::string getCharacterTexture();
|
||||
static std::string getCharacterTileset();
|
||||
static std::string getLanguagePrefix();
|
||||
|
||||
struct VisualNovelCharacterEmotion emotionHappy;
|
||||
struct VisualNovelCharacterEmotion emotionConcerned;
|
||||
struct VisualNovelCharacterEmotion emotionSurprised;
|
||||
struct VisualNovelCharacterEmotion emotionUnset;
|
||||
|
||||
DeathPrefab(Scene *s, sceneitemid_t i) : CharacterPrefab(s,i) {}
|
||||
};
|
||||
}
|
68
archive/dawnpokergame/prefabs/characters/PennyPrefab.hpp
Normal file
68
archive/dawnpokergame/prefabs/characters/PennyPrefab.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
// 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 "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"
|
||||
|
||||
namespace Dawn {
|
||||
class PennyPrefab : public SceneItemPrefab<PennyPrefab> {
|
||||
public:
|
||||
VisualNovelCharacter *vnCharacter;
|
||||
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_penny"),
|
||||
assMan->get<TilesetAsset>("tileset_penny")
|
||||
};
|
||||
}
|
||||
|
||||
PennyPrefab(Scene *scene, sceneitemid_t id) : SceneItemPrefab(scene, id){}
|
||||
|
||||
void prefabInit(AssetManager *man) override {
|
||||
// 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>();
|
||||
|
||||
material = this->addComponent<SimpleTexturedMaterial>();
|
||||
material->texture = &textureAsset->texture;
|
||||
|
||||
auto animation = this->addComponent<AnimationController>();
|
||||
|
||||
pokerPlayer = this->addComponent<PokerPlayer>();
|
||||
|
||||
vnCharacter = this->addComponent<VisualNovelCharacter>();
|
||||
vnCharacter->nameKey = "character.penny.name";
|
||||
|
||||
auto tiledSprite = this->addComponent<TiledSprite>();
|
||||
tiledSprite->setTilesetAndSize(&tilesetAsset->tileset);
|
||||
tiledSprite->setTile(0);
|
||||
|
||||
this->transform.setLocalPosition(glm::vec3(0, 0, 0));
|
||||
}
|
||||
};
|
||||
}
|
25
archive/dawnpokergame/prefabs/ui/UIBorderPrefab.hpp
Normal file
25
archive/dawnpokergame/prefabs/ui/UIBorderPrefab.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "prefab/UIPrefab.hpp"
|
||||
#include "ui/UIBorder.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIBorderPrefab : public UIPrefab<UIBorder, UIBorderPrefab> {
|
||||
public:
|
||||
static std::vector<Asset*> prefabAssets(AssetManager *man) {
|
||||
std::vector<Asset*> assets;
|
||||
assets.push_back(man->get<TextureAsset>("texture_test"));
|
||||
return assets;
|
||||
}
|
||||
|
||||
static void prefabApply(AssetManager *man, UIBorder *border) {
|
||||
auto text = man->get<TextureAsset>("texture_test");
|
||||
border->texture = &text->texture;
|
||||
border->setBorderSize(glm::vec2(4, 4));
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "prefabs/ui/UIBorderPrefab.hpp"
|
||||
#include "visualnovel/ui/VisualNovelTextbox.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VisualNovelTextboxPrefab :
|
||||
public UIPrefab<VisualNovelTextbox, VisualNovelTextboxPrefab>
|
||||
{
|
||||
public:
|
||||
static std::vector<Asset*> prefabAssets(AssetManager *man) {
|
||||
std::vector<Asset*> assets;
|
||||
assets.push_back(man->get<TrueTypeAsset>("truetype_bizudp"));
|
||||
vectorAppend(&assets, UIBorderPrefab::getRequiredAssets(man));
|
||||
return assets;
|
||||
}
|
||||
|
||||
static void prefabApply(AssetManager *man, VisualNovelTextbox *textbox) {
|
||||
auto assetFont = man->get<TrueTypeAsset>("truetype_bizudp");
|
||||
UIBorderPrefab::apply(&textbox->border);
|
||||
textbox->setFont(&assetFont->font);
|
||||
textbox->setFontSize(36.0f);
|
||||
textbox->setLabelPadding(glm::vec2(2, 2));
|
||||
textbox->label.textColor = COLOR_WHITE;
|
||||
|
||||
textbox->setTransform(
|
||||
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END,
|
||||
glm::vec4(
|
||||
0,
|
||||
(assetFont->font.getLineHeight(textbox->getFontSize()) * 4) +
|
||||
(textbox->border.getBorderSize().y * 2.0f) +
|
||||
(textbox->getLabelPadding().y * 2.0f),
|
||||
0, 0
|
||||
),
|
||||
0.0f
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user