Starting new VN Structure
This commit is contained in:
11
archive/visualnovel/components/CMakeLists.txt
Normal file
11
archive/visualnovel/components/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
SimpleVisualNovelBackground.cpp
|
||||
VisualNovelCharacter.cpp
|
||||
)
|
@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SimpleVisualNovelBackground.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
SimpleVisualNovelBackground * SimpleVisualNovelBackground::create(Scene *s) {
|
||||
auto item = s->createSceneItem();
|
||||
// item->addComponent<MeshRenderer>();
|
||||
item->addComponent<MeshHost>();
|
||||
item->addComponent<SimpleTexturedMaterial>();
|
||||
auto background = item->addComponent<SimpleVisualNovelBackground>();
|
||||
return background;
|
||||
}
|
||||
|
||||
SimpleVisualNovelBackground::SimpleVisualNovelBackground(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::vector<SceneItemComponent*> SimpleVisualNovelBackground::getDependencies(){
|
||||
return std::vector<SceneItemComponent*>{
|
||||
this->material = this->item->getComponent<SimpleTexturedMaterial>(),
|
||||
this->meshHost = this->item->getComponent<MeshHost>()
|
||||
};
|
||||
}
|
||||
|
||||
void SimpleVisualNovelBackground::setTexture(Texture *texture) {
|
||||
assertNotNull(texture);
|
||||
this->material->texture = texture;
|
||||
|
||||
// Since we go both negative and positive, actual height is doubled
|
||||
float_t aspect = (float_t)texture->getWidth() / (float_t)texture->getHeight();
|
||||
float_t height = 0.5f;
|
||||
|
||||
QuadMesh::bufferQuadMeshWithZ(&this->meshHost->mesh,
|
||||
glm::vec2(-aspect * height, -height), glm::vec2(0, 1),
|
||||
glm::vec2( aspect * height, height), glm::vec2(1, 0),
|
||||
0.0f, 0, 0
|
||||
);
|
||||
}
|
||||
|
||||
void SimpleVisualNovelBackground::onStart() {
|
||||
assertNotNull(this->material);
|
||||
assertNotNull(this->meshHost);
|
||||
|
||||
QuadMesh::initQuadMesh(&this->meshHost->mesh,
|
||||
glm::vec2(-1, -1), glm::vec2(0, 1),
|
||||
glm::vec2(1, 1), glm::vec2(1, 0),
|
||||
0.0f
|
||||
);
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/components/Components.hpp"
|
||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleVisualNovelBackground : public SceneItemComponent {
|
||||
public:
|
||||
SimpleTexturedMaterial *material;
|
||||
MeshHost *meshHost;
|
||||
|
||||
/**
|
||||
* Create a simple Visual Novel Background prefab.
|
||||
*
|
||||
* @param scene Scene to add this background to.
|
||||
* @return Created background Scene Item.
|
||||
*/
|
||||
static SimpleVisualNovelBackground * create(Scene *scene);
|
||||
|
||||
/**
|
||||
* Construct a Simple Visual Novel Background. Simple Background is used
|
||||
* for a quick up and running Visual Novel scene, but does not have any
|
||||
* special effects or controls beyond updating a texture and mesh.
|
||||
*
|
||||
* @param item Scene Item this background belongs to.
|
||||
*/
|
||||
SimpleVisualNovelBackground(SceneItem *item);
|
||||
|
||||
std::vector<SceneItemComponent*> getDependencies() override;
|
||||
void onStart() override;
|
||||
|
||||
/**
|
||||
* Set the texture for the background. Auto updates the material and the
|
||||
* dimensions of the internal quad.
|
||||
*
|
||||
* @param texture Texture to use.
|
||||
*/
|
||||
void setTexture(Texture *texture);
|
||||
};
|
||||
}
|
25
archive/visualnovel/components/VisualNovelCharacter.cpp
Normal file
25
archive/visualnovel/components/VisualNovelCharacter.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VisualNovelCharacter.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
VisualNovelCharacter::VisualNovelCharacter(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<SceneItemComponent*> VisualNovelCharacter::getDependencies() {
|
||||
return std::vector<SceneItemComponent*>{
|
||||
(this->material = this->item->getComponent<SimpleTexturedMaterial>()),
|
||||
(this->tiledSprite = this->item->getComponent<TiledSprite>())
|
||||
};
|
||||
}
|
||||
|
||||
void VisualNovelCharacter::onStart() {
|
||||
assertNotNull(this->material);
|
||||
assertNotNull(this->tiledSprite);
|
||||
}
|
37
archive/visualnovel/components/VisualNovelCharacter.hpp
Normal file
37
archive/visualnovel/components/VisualNovelCharacter.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "asset/assets/AudioAsset.hpp"
|
||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||
#include "scene/components/display/TiledSprite.hpp"
|
||||
#include "scene/components/audio/AudioSource.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct VisualNovelCharacterEmotion {
|
||||
int32_t tile = 0;
|
||||
AudioAsset *talkSound = nullptr;
|
||||
AudioAsset *emotionSound = nullptr;
|
||||
};
|
||||
|
||||
class VisualNovelCharacter : public SceneItemComponent {
|
||||
public:
|
||||
std::string nameKey = "character.unknown";
|
||||
SimpleTexturedMaterial *material = nullptr;
|
||||
TiledSprite *tiledSprite = nullptr;
|
||||
|
||||
/**
|
||||
* Visual Novel Character Component. Mostly logic-less but provides nice
|
||||
* interfaces for sibling components.
|
||||
*
|
||||
* @param item Item that this component belongs to.
|
||||
*/
|
||||
VisualNovelCharacter(SceneItem *item);
|
||||
|
||||
std::vector<SceneItemComponent*> getDependencies() override;
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user