Just breaking stuff

This commit is contained in:
2023-03-14 22:27:46 -07:00
parent 795e69237c
commit 09cb20271b
156 changed files with 4218 additions and 4389 deletions

View File

@ -0,0 +1,30 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Build Project
add_executable(${DAWN_TARGET_NAME})
# Includes
target_include_directories(${DAWN_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
# Subdirs
add_subdirectory(components)
add_subdirectory(game)
add_subdirectory(save)
# Assets
set(DIR_GAME_ASSETS games/platformergame)
tool_language(language_en ${DIR_GAME_ASSETS}/locale/en.csv)
tool_texture(texture_test texture_test.png)
tool_tileset(tileset_aqua texture_aqua ${DIR_GAME_ASSETS}/tileset/s4m_ur4i_minivania_tilemap_aqua.png 32 32)
add_dependencies(${DAWN_TARGET_NAME}
language_en
texture_test
tileset_aqua
)

View File

@ -0,0 +1,10 @@
# 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
PlayerController.cpp
)

View File

@ -0,0 +1,35 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PlayerController.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
PlayerController::PlayerController(SceneItem *i) : SceneItemComponent(i) {}
void PlayerController::onSceneUpdate() {
auto im = &getGame()->inputManager;
auto delta = getGame()->timeManager.delta;
glm::vec2 iMove = im->getAxis2D(
INPUT_BIND_NEGATIVE_X, INPUT_BIND_POSITIVE_X,
INPUT_BIND_NEGATIVE_Y, INPUT_BIND_POSITIVE_Y
);
glm::vec2 pos = this->transform->getLocalPosition();
this->transform->setLocalPosition(
this->transform->getLocalPosition() + glm::vec3(iMove * delta * 20.0f, 0)
);
}
void PlayerController::onStart() {
assertNotNull(this->camera);
getScene()->eventSceneUnpausedUpdate.addListener(this, &PlayerController::onSceneUpdate);
}
PlayerController::~PlayerController() {
getScene()->eventSceneUnpausedUpdate.removeListener(this, &PlayerController::onSceneUpdate);
}

View File

@ -0,0 +1,23 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/components/Components.hpp"
namespace Dawn {
class PlayerController : public SceneItemComponent {
protected:
void onSceneUpdate();
public:
Camera *camera = nullptr;
PlayerController(SceneItem *item);
void onStart() override;
~PlayerController();
};
}

View File

@ -0,0 +1,10 @@
# 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
DawnGame.cpp
)

View File

@ -0,0 +1,40 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "DawnGame.hpp"
#include "scenes/TestScene.hpp"
using namespace Dawn;
DawnGame::DawnGame(DawnHost *host) :
host(host),
renderManager(this),
inputManager(this),
localeManager(this),
saveManager(this)
{
}
int32_t DawnGame::init() {
this->assetManager.init();
this->localeManager.init();
this->renderManager.init();
this->scene = new TestScene(this);
return DAWN_GAME_INIT_RESULT_SUCCESS;
}
int32_t DawnGame::update(float_t delta) {
this->assetManager.update();
this->inputManager.update();
this->timeManager.update(delta);
if(this->scene != nullptr) this->scene->update();
this->renderManager.update();
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
}

View File

@ -0,0 +1,27 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "game/_DawnGame.hpp"
#include "scene/components/Components.hpp"
#include "save/DawnGameSaveManager.hpp"
namespace Dawn {
class DawnGame : public IDawnGame {
public:
DawnHost *host;
RenderManager renderManager;
AssetManager assetManager;
InputManager inputManager;
TimeManager timeManager;
LocaleManager localeManager;
DawnGameSaveManager saveManager;
PhysicsManager physicsManager;
DawnGame(DawnHost *host);
int32_t init() override;
int32_t update(float_t delta) override;
};
}

View File

@ -0,0 +1,14 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "input/InputManager.hpp"
#define INPUT_BIND(n) ((inputbind_t)n)
#define INPUT_BIND_ACCEPT INPUT_BIND(1)
#define INPUT_BIND_NEGATIVE_X INPUT_BIND(2)
#define INPUT_BIND_POSITIVE_X INPUT_BIND(3)
#define INPUT_BIND_NEGATIVE_Y INPUT_BIND(4)
#define INPUT_BIND_POSITIVE_Y INPUT_BIND(5)

View File

@ -0,0 +1,46 @@
// 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/components/Components.hpp"
#include "components/PlayerController.hpp"
namespace Dawn {
class PlayerPrefab : public SceneItemPrefab<PlayerPrefab> {
public:
static std::vector<Asset*> prefabAssets(AssetManager *man) {
std::vector<Asset*> assets;
assets.push_back(man->get<TilesetAsset>("tileset_aqua"));
assets.push_back(man->get<TextureAsset>("texture_aqua"));
return assets;
}
//
MeshHost *meshHost;
TiledSprite *tiledSprite;
Material *material;
MeshRenderer *meshRenderer;
PlayerController *playerController;
PlayerPrefab(Scene *s, sceneitemid_t i) : SceneItemPrefab(s, i) {}
void prefabInit(AssetManager *man) override {
auto tileset = man->get<TilesetAsset>("tileset_aqua");
auto texture = man->get<TextureAsset>("texture_aqua");
meshHost = addComponent<MeshHost>();
tiledSprite = addComponent<TiledSprite>();
material = addComponent<Material>();
meshRenderer = addComponent<MeshRenderer>();
playerController = addComponent<PlayerController>();
tiledSprite->setTilesetAndSize(&tileset->tileset);
tiledSprite->setTile(896);
material->textureValues[material->getShader()->getParameterByName("u_Text")] = &texture->texture;
}
};
}

View File

@ -0,0 +1,10 @@
# 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
DawnGameSaveManager.cpp
)

View File

@ -0,0 +1,28 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "DawnGameSaveManager.hpp"
using namespace Dawn;
DawnGameSaveManager::DawnGameSaveManager(DawnGame *game) : SaveManager(game) {
}
bool_t DawnGameSaveManager::validateSave(struct SaveFile raw) {
if(!raw.has(POKER_SAVE_KEY_EXAMPLE)) return true;
this->currentSave.copy(raw, POKER_SAVE_KEY_EXAMPLE);
return false;
}
void DawnGameSaveManager::setExample(int32_t val) {
savedata_t value;
value.i32 = val;
this->currentSave.set(POKER_SAVE_KEY_EXAMPLE, value);
}
int32_t DawnGameSaveManager::getExample() {
return this->currentSave.get(POKER_SAVE_KEY_EXAMPLE).i32;
}

View File

@ -0,0 +1,22 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "save/SaveManager.hpp"
#define POKER_SAVE_KEY_EXAMPLE "poker.example"
namespace Dawn {
class DawnGameSaveManager : public SaveManager {
protected:
virtual bool_t validateSave(struct SaveFile raw) override;
public:
DawnGameSaveManager(DawnGame *game);
void setExample(int32_t value);
int32_t getExample();
};
}

View File

@ -0,0 +1,33 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/Scene.hpp"
#include "prefabs/PlayerPrefab.hpp"
namespace Dawn {
class TestScene : public Scene {
protected:
void stage() override {
auto camera = Camera::create(this);
camera->type = CAMERA_TYPE_ORTHONOGRAPHIC;
camera->item->addComponent<PixelPerfectCamera>();
camera->transform->lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0));
auto player = PlayerPrefab::create(this);
player->playerController->camera = camera;
}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, PlayerPrefab::getRequiredAssets(assMan));
return assets;
}
public:
TestScene(DawnGame *game) : Scene(game) {}
};
}

View File

@ -0,0 +1,34 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Add Common Engine Parts
set(DAWN_VISUAL_NOVEL true CACHE INTERNAL ${DAWN_CACHE_TARGET})
# Build Project
add_executable(${DAWN_TARGET_NAME})
# Includes
target_include_directories(${DAWN_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
# Subdirs
add_subdirectory(game)
add_subdirectory(ui)
add_subdirectory(visualnovel)
add_subdirectory(prefabs)
add_subdirectory(save)
add_subdirectory(scenes)
# Assets
set(DIR_GAME_ASSETS games/pokergame)
tool_texture(texture_test texture_test.png)
tool_language(locale_poker ${DIR_GAME_ASSETS}/locale/locale.xml)
tool_tileset(tileset_death texture_death ${DIR_GAME_ASSETS}/characters/death/sheet.png 1 3)
tool_tileset(tileset_penny texture_penny ${DIR_GAME_ASSETS}/characters/penny/sheet.png 1 3)
tool_truetype(truetype_bizudp ${DIR_GAME_ASSETS}/font/BIZUDPGothic-Regular.ttf truetype_bizudp 2048 2048 120)
tool_audio(audio_test borrowed/sample_short.wav)
tool_vnscene(Scene_1 ${DIR_GAME_ASSETS}/vn/Scene_1.xml)

View File

@ -0,0 +1,10 @@
# 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
DawnGame.cpp
)

View File

@ -0,0 +1,59 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "DawnGame.hpp"
#include "scenes/Scene_1.hpp"
using namespace Dawn;
DawnGame::DawnGame(DawnHost *host) :
host(host),
renderManager(this),
inputManager(this),
localeManager(this),
saveManager(this),
audioManager(this)
{
}
int32_t DawnGame::init() {
this->assetManager.init();
this->localeManager.init();
this->renderManager.init();
this->audioManager.init();
this->scene = new Scene_1(this);
return DAWN_GAME_INIT_RESULT_SUCCESS;
}
int32_t DawnGame::update(float_t delta) {
if(this->sceneToCutTo != nullptr) {
if(this->sceneToCutTo == this->scene) {
delete this->scene;
this->scene = nullptr;
} else {
delete this->scene;
this->scene = this->sceneToCutTo;
}
this->sceneToCutTo = nullptr;
}
this->assetManager.update();
this->inputManager.update();
this->timeManager.update(delta);
if(this->scene != nullptr) this->scene->update();
this->renderManager.update();
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
}
void DawnGame::sceneCutover(Scene *scene) {
if(scene == nullptr) scene = this->scene;
this->sceneToCutTo = scene;
}

View File

@ -0,0 +1,31 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "game/_DawnGame.hpp"
#include "scene/components/Components.hpp"
#include "save/PokerSaveManager.hpp"
namespace Dawn {
class DawnGame : public IDawnGame {
private:
Scene *sceneToCutTo = nullptr;
public:
DawnHost *host;
RenderManager renderManager;
AssetManager assetManager;
InputManager inputManager;
TimeManager timeManager;
LocaleManager localeManager;
PokerSaveManager saveManager;
AudioManager audioManager;
DawnGame(DawnHost *host);
int32_t init() override;
int32_t update(float_t delta) override;
void sceneCutover(Scene *scene) override;
};
}

View File

@ -0,0 +1,15 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "input/InputManager.hpp"
#define dbind(n) ((inputbind_t)n)
#define INPUT_BIND_ACCEPT dbind(1)
#define INPUT_BIND_NEGATIVE_X dbind(2)
#define INPUT_BIND_POSITIVE_X dbind(3)
#define INPUT_BIND_NEGATIVE_Y dbind(4)
#define INPUT_BIND_POSITIVE_Y dbind(5)

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 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));
}
};
}

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_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;
}

View 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) {}
};
}

View 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));
}
};
}

View 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));
}
};
}

View File

@ -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
);
}
};
}

View File

@ -0,0 +1,10 @@
# 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
PokerSaveManager.cpp
)

View File

@ -0,0 +1,28 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PokerSaveManager.hpp"
using namespace Dawn;
PokerSaveManager::PokerSaveManager(DawnGame *game) : SaveManager(game) {
}
bool_t PokerSaveManager::validateSave(struct SaveFile raw) {
if(!raw.has(POKER_SAVE_KEY_EXAMPLE)) return true;
this->currentSave.copy(raw, POKER_SAVE_KEY_EXAMPLE);
return false;
}
void PokerSaveManager::setExample(int32_t val) {
savedata_t value;
value.i32 = val;
this->currentSave.set(POKER_SAVE_KEY_EXAMPLE, value);
}
int32_t PokerSaveManager::getExample() {
return this->currentSave.get(POKER_SAVE_KEY_EXAMPLE).i32;
}

View File

@ -0,0 +1,22 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "save/SaveManager.hpp"
#define POKER_SAVE_KEY_EXAMPLE "poker.example"
namespace Dawn {
class PokerSaveManager : public SaveManager {
protected:
virtual bool_t validateSave(struct SaveFile raw) override;
public:
PokerSaveManager(DawnGame *game);
void setExample(int32_t value);
int32_t getExample();
};
}

View File

@ -0,0 +1,10 @@
# 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
PokerVNScene.cpp
)

View File

@ -0,0 +1,39 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PokerVNScene.hpp"
using namespace Dawn;
PokerVNScene::PokerVNScene(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> PokerVNScene::getRequiredAssets() {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, SimpleVNScene::getRequiredAssets());
vectorAppend(&assets, PokerPlayerDisplay::getAssets(assMan));
return assets;
}
void PokerVNScene::vnStage() {
auto pokerGameItem = this->createSceneItem();
this->pokerGame = pokerGameItem->addComponent<PokerGame>();
this->pokerPlayers = this->getPokerPlayers();
auto it = this->pokerPlayers.begin();
int32_t i = 0;
while(it != this->pokerPlayers.end()) {
auto player = *it;
// auto uiPlayer = canvas->addElement<PokerPlayerDisplay>();
// uiPlayer->setTransform(UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START, glm::vec4(i * 220, 0, 220, 200), 0);
// uiPlayer->setPlayer(player);
++it;
++i;
}
}

View File

@ -0,0 +1,39 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "poker/PokerGame.hpp"
#include "visualnovel/events/PokerBetLoopEvent.hpp"
#include "visualnovel/events/PokerInitialEvent.hpp"
#include "ui/PokerPlayerDisplay.hpp"
namespace Dawn {
class PokerVNScene : public SimpleVNScene {
protected:
void vnStage() override;
std::vector<Asset*> getRequiredAssets() override;
/**
* Returns the Poker Players that are in this poker scene.
*
* @return List of Poker Players.
*/
virtual std::vector<PokerPlayer*> getPokerPlayers() = 0;
public:
PokerGame *pokerGame;
std::vector<PokerPlayer*> pokerPlayers;
std::map<PokerPlayer*, PokerPlayerDisplay*> pokerPlayerDisplays;
/**
* Create a simple Poker Visual Novel Scene. Simplifies some of the less
* interesting parts of a poker VN game.
*
* @param game Game that this poker scene belongs to.
*/
PokerVNScene(DawnGame *game);
};
}

View File

@ -0,0 +1,45 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_11.hpp"
namespace Dawn {
class Scene_10 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_11(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_10(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.10.1"))
->then(new VisualNovelCallbackEvent<Scene_10>(vnManager, this, &Scene_10::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,45 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_12.hpp"
namespace Dawn {
class Scene_11 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_12(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_11(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.11.1"))
->then(new VisualNovelCallbackEvent<Scene_11>(vnManager, this, &Scene_11::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,66 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "PokerVNScene.hpp"
#include "prefabs/characters/PennyPrefab.hpp"
#include "scenes/Scene_13.hpp"
namespace Dawn {
class Scene_12 : public PokerVNScene {
protected:
PennyPrefab *penny;
PennyPrefab *julie;
PennyPrefab *sammy;
PennyPrefab *lucy;
void vnStage() override {
penny = PennyPrefab::create(this);
julie = PennyPrefab::create(this);
sammy = PennyPrefab::create(this);
lucy = PennyPrefab::create(this);
PokerVNScene::vnStage();
}
void onSceneEnded() {
auto scene = new Scene_13(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
std::vector<PokerPlayer *> getPokerPlayers() override {
return std::vector<PokerPlayer*>{
this->penny->getComponent<PokerPlayer>(),
this->julie->getComponent<PokerPlayer>(),
this->sammy->getComponent<PokerPlayer>(),
this->lucy->getComponent<PokerPlayer>()
};
}
public:
Scene_12(DawnGame *game) : PokerVNScene(game) {}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, PokerVNScene::getRequiredAssets());
vectorAppend(&assets, PennyPrefab::getRequiredAssets(assMan));
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelTextboxEvent(vnManager, "scene.12.1");
start
->then(new VisualNovelCallbackEvent<Scene_12>(vnManager, this, &Scene_12::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,45 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_14.hpp"
namespace Dawn {
class Scene_13 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_14(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_13(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.13.1"))
->then(new VisualNovelCallbackEvent<Scene_13>(vnManager, this, &Scene_13::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,45 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_15.hpp"
namespace Dawn {
class Scene_14 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_15(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_14(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.14.1"))
->then(new VisualNovelCallbackEvent<Scene_14>(vnManager, this, &Scene_14::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,45 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_16.hpp"
namespace Dawn {
class Scene_15 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_16(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_15(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.15.1"))
->then(new VisualNovelCallbackEvent<Scene_15>(vnManager, this, &Scene_15::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,45 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_17.hpp"
namespace Dawn {
class Scene_16 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_17(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_16(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.16.1"))
->then(new VisualNovelCallbackEvent<Scene_16>(vnManager, this, &Scene_16::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,66 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "PokerVNScene.hpp"
#include "prefabs/characters/PennyPrefab.hpp"
#include "scenes/Scene_18.hpp"
namespace Dawn {
class Scene_17 : public PokerVNScene {
protected:
PennyPrefab *penny;
PennyPrefab *julie;
PennyPrefab *sammy;
PennyPrefab *lucy;
void vnStage() override {
penny = PennyPrefab::create(this);
julie = PennyPrefab::create(this);
sammy = PennyPrefab::create(this);
lucy = PennyPrefab::create(this);
PokerVNScene::vnStage();
}
void onSceneEnded() {
auto scene = new Scene_18(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
std::vector<PokerPlayer *> getPokerPlayers() override {
return std::vector<PokerPlayer*>{
this->penny->getComponent<PokerPlayer>(),
this->julie->getComponent<PokerPlayer>(),
this->sammy->getComponent<PokerPlayer>(),
this->lucy->getComponent<PokerPlayer>()
};
}
public:
Scene_17(DawnGame *game) : PokerVNScene(game) {}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, PokerVNScene::getRequiredAssets());
vectorAppend(&assets, PennyPrefab::getRequiredAssets(assMan));
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelTextboxEvent(vnManager, "scene.17.1");
start
->then(new VisualNovelCallbackEvent<Scene_17>(vnManager, this, &Scene_17::onSceneEnded))
;
return start;
}
};
}

View 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 "visualnovel/scene/SimpleVNScene.hpp"
namespace Dawn {
class Scene_18 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
}
public:
Scene_18(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.18.1"))
->then(new VisualNovelCallbackEvent<Scene_18>(vnManager, this, &Scene_18::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_3.hpp"
namespace Dawn {
class Scene_2 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_3(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_2(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.2.1"))
->then(new VisualNovelCallbackEvent<Scene_2>(vnManager, this, &Scene_2::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_4.hpp"
namespace Dawn {
class Scene_3 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_4(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_3(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.3.1"))
->then(new VisualNovelCallbackEvent<Scene_3>(vnManager, this, &Scene_3::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,66 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "PokerVNScene.hpp"
#include "prefabs/characters/PennyPrefab.hpp"
#include "scenes/Scene_5.hpp"
namespace Dawn {
class Scene_4 : public PokerVNScene {
protected:
PennyPrefab *penny;
PennyPrefab *julie;
PennyPrefab *sammy;
PennyPrefab *lucy;
void vnStage() override {
penny = PennyPrefab::create(this);
julie = PennyPrefab::create(this);
sammy = PennyPrefab::create(this);
lucy = PennyPrefab::create(this);
PokerVNScene::vnStage();
}
void onSceneEnded() {
auto scene = new Scene_5(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
std::vector<PokerPlayer *> getPokerPlayers() override {
return std::vector<PokerPlayer*>{
this->penny->getComponent<PokerPlayer>(),
this->julie->getComponent<PokerPlayer>(),
this->sammy->getComponent<PokerPlayer>(),
this->lucy->getComponent<PokerPlayer>()
};
}
public:
Scene_4(DawnGame *game) : PokerVNScene(game) {}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, PokerVNScene::getRequiredAssets());
vectorAppend(&assets, PennyPrefab::getRequiredAssets(assMan));
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelTextboxEvent(vnManager, "scene.4.1");
start
->then(new VisualNovelCallbackEvent<Scene_4>(vnManager, this, &Scene_4::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_6.hpp"
namespace Dawn {
class Scene_5 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_6(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_5(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.5.1"))
->then(new VisualNovelCallbackEvent<Scene_5>(vnManager, this, &Scene_5::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_7.hpp"
namespace Dawn {
class Scene_6 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_7(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_6(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.6.1"))
->then(new VisualNovelCallbackEvent<Scene_6>(vnManager, this, &Scene_6::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,45 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_8.hpp"
namespace Dawn {
class Scene_7 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_8(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_7(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.7.1"))
->then(new VisualNovelCallbackEvent<Scene_7>(vnManager, this, &Scene_7::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,66 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "PokerVNScene.hpp"
#include "prefabs/characters/PennyPrefab.hpp"
#include "scenes/Scene_9.hpp"
namespace Dawn {
class Scene_8 : public PokerVNScene {
protected:
PennyPrefab *penny;
PennyPrefab *julie;
PennyPrefab *sammy;
PennyPrefab *lucy;
void vnStage() override {
penny = PennyPrefab::create(this);
julie = PennyPrefab::create(this);
sammy = PennyPrefab::create(this);
lucy = PennyPrefab::create(this);
PokerVNScene::vnStage();
}
void onSceneEnded() {
auto scene = new Scene_9(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
std::vector<PokerPlayer *> getPokerPlayers() override {
return std::vector<PokerPlayer*>{
this->penny->getComponent<PokerPlayer>(),
this->julie->getComponent<PokerPlayer>(),
this->sammy->getComponent<PokerPlayer>(),
this->lucy->getComponent<PokerPlayer>()
};
}
public:
Scene_8(DawnGame *game) : PokerVNScene(game) {}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, PokerVNScene::getRequiredAssets());
vectorAppend(&assets, PennyPrefab::getRequiredAssets(assMan));
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelTextboxEvent(vnManager, "scene.8.1");
start
->then(new VisualNovelCallbackEvent<Scene_8>(vnManager, this, &Scene_8::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,45 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
#include "scenes/Scene_10.hpp"
namespace Dawn {
class Scene_9 : public SimpleVNScene {
protected:
void vnStage() override {
}
void onSceneEnded() {
auto scene = new Scene_10(this->game);
game->assetManager.queueSwap(
scene->getRequiredAssets(), this->getRequiredAssets()
);
game->assetManager.syncLoad();
scene->stage();
this->game->sceneCutover(scene);
}
public:
Scene_9(DawnGame *game) : SimpleVNScene(game) {
}
std::vector<Asset*> getRequiredAssets() override {
std::vector<Asset*> assets = SimpleVNScene::getRequiredAssets();
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelPauseEvent(vnManager, 0.1f);
start
->then(new VisualNovelTextboxEvent(vnManager, "scene.9.1"))
->then(new VisualNovelCallbackEvent<Scene_9>(vnManager, this, &Scene_9::onSceneEnded))
;
return start;
}
};
}

View File

@ -0,0 +1,57 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "PokerVNScene.hpp"
#include "prefabs/characters/PennyPrefab.hpp"
namespace Dawn {
class TestScene : public PokerVNScene {
protected:
PennyPrefab *penny;
PennyPrefab *julie;
PennyPrefab *sammy;
PennyPrefab *lucy;
void vnStage() override {
penny = PennyPrefab::create(this);
julie = PennyPrefab::create(this);
sammy = PennyPrefab::create(this);
lucy = PennyPrefab::create(this);
PokerVNScene::vnStage();
}
std::vector<PokerPlayer *> getPokerPlayers() override {
return std::vector<PokerPlayer*>{
this->penny->getComponent<PokerPlayer>(),
this->julie->getComponent<PokerPlayer>(),
this->sammy->getComponent<PokerPlayer>(),
this->lucy->getComponent<PokerPlayer>()
};
}
public:
TestScene(DawnGame *game) : PokerVNScene(game) {}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, PokerVNScene::getRequiredAssets());
vectorAppend(&assets, PennyPrefab::getRequiredAssets(assMan));
assets.push_back(assMan->get<TextureAsset>("texture_tavern_night"));
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto texture = this->game->assetManager.get<TextureAsset>("texture_tavern_night");
auto start = new VisualNovelChangeSimpleBackgroundEvent(
vnManager, &texture->texture
);
start->then(new VisualNovelTextboxEvent(vnManager, penny->getComponent<VisualNovelCharacter>(), "1234"));
return start;
}
};
}

View File

@ -0,0 +1,10 @@
# 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
PokerPlayerDisplay.cpp
)

View File

@ -0,0 +1,32 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "ui/UIBorder.hpp"
#include "asset/assets/TextureAsset.hpp"
#include "game/DawnGame.hpp"
namespace Dawn {
class PokerGameBorder {
public:
static std::vector<Asset*> getAssets(AssetManager *man) {
return std::vector<Asset*>{
man->get<TextureAsset>("texture_test")
};
}
static void apply(UIBorder *border) {
auto text = border->getGame()->assetManager.get<TextureAsset>("texture_test");
border->texture = &text->texture;
border->setBorderSize(glm::vec2(16, 16));
}
static UIBorder * create(UICanvas *canvas) {
auto border = canvas->addElement<UIBorder>();
PokerGameBorder::apply(border);
return border;
}
};
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "ui/PokerGameBorder.hpp"
#include "visualnovel/ui/VisualNovelTextbox.hpp"
#include "asset/assets/TrueTypeAsset.hpp"
namespace Dawn {
class PokerGameTextbox {
public:
static std::vector<Asset*> getAssets(AssetManager *man) {
assertNotNull(man);
std::vector<Asset*> assets;
vectorAppend(&assets, &PokerGameBorder::getAssets(man));
assets.push_back(man->get<TrueTypeAsset>("truetype_ark"));
return assets;
}
static void apply(VisualNovelTextbox *textbox) {
assertNotNull(textbox);
auto assetFont = textbox->getGame()->assetManager.get<TrueTypeAsset>("truetype_ark");
PokerGameBorder::apply(&textbox->border);
textbox->setFont(&assetFont->font);
textbox->setFontSize(40);
textbox->setLabelPadding(glm::vec2(10, 8));
}
static VisualNovelTextbox * create(UICanvas *canvas) {
assertNotNull(canvas);
auto textbox = canvas->addElement<VisualNovelTextbox>();
PokerGameTextbox::apply(textbox);
textbox->setTransform(
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END,
glm::vec4(0, 238, 0, 0),
0.0f
);
return textbox;
}
};
}

View File

@ -0,0 +1,101 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PokerPlayerDisplay.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
PokerPlayerDisplay::PokerPlayerDisplay(UICanvas *canvas) :
UIEmpty(canvas),
labelName(canvas),
labelChips(canvas),
borderInner(canvas),
border(canvas),
animChips(&animChipsValue)
{
this->font = getGame()->assetManager.get<TrueTypeAsset>("truetype_ark");
// Border
this->addChild(&this->border);
PokerGameBorder::apply(&this->border);
this->border.setTransform(
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
glm::vec4(0, 0, 0, 0),
0.0f
);
// Border Inner
this->addChild(&this->borderInner);
this->borderInner.setTransform(
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
glm::vec4(this->border.getBorderSize(), this->border.getBorderSize()),
0.0f
);
// Player Name
this->borderInner.addChild(&this->labelName);
this->labelName.setText("undefined");
this->labelName.setFont(&this->font->font);
this->labelName.setFontSize(40);
this->labelName.setTransform(
UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START,
glm::vec4(0, 0, 0, 0),
0.0f
);
// Chips label
this->borderInner.addChild(&this->labelChips);
this->labelChips.setFont(&this->font->font);
this->labelChips.setFontSize(40);
this->labelChips.setTransform(
UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START,
glm::vec4(0, this->labelName.getContentHeight(), 0, 0),
0.0f
);
// Anim
this->animChips.easing = &easeOutQuart;
// Events
getScene()->eventSceneUnpausedUpdate.addListener(this, &PokerPlayerDisplay::onSceneUpdate);
}
void PokerPlayerDisplay::setPlayer(PokerPlayer *player) {
assertNull(this->player);
this->player = player;
player->eventChipsChanged.addListener(this, &PokerPlayerDisplay::onPlayerChipsChanged);
this->labelName.setText("undefined");
this->animChips.clear();
this->animChips.restart();
this->animChipsValue = player->chips;
this->updatePositions();
}
void PokerPlayerDisplay::onSceneUpdate() {
this->animChips.tick(getGame()->timeManager.delta);
// std::stringstream stream;
// stream.precision(0);
// stream << "$";
// stream << this->animChipsValue;
this->labelChips.setText("undefined");
}
void PokerPlayerDisplay::onPlayerChipsChanged() {
std::cout << "Chips" << player->chips << std::endl;
this->animChips.clear();
this->animChips.addKeyframe(0.0f, this->animChipsValue);
this->animChips.addKeyframe(1.0f, this->player->chips);
this->animChips.restart();
}
PokerPlayerDisplay::~PokerPlayerDisplay() {
this->canvas->getScene()->eventSceneUnpausedUpdate.removeListener(this, &PokerPlayerDisplay::onSceneUpdate);
}

View File

@ -0,0 +1,48 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "ui/UILabel.hpp"
#include "ui/UIEmpty.hpp"
#include "ui/UIBorder.hpp"
#include "poker/PokerPlayer.hpp"
#include "asset/AssetManager.hpp"
#include "asset/assets/TrueTypeAsset.hpp"
#include "display/animation/SimpleAnimation.hpp"
#include "ui/PokerGameBorder.hpp"
namespace Dawn {
class PokerPlayerDisplay : public UIEmpty {
private:
SimpleAnimation<int32_t> animChips;
int32_t animChipsValue;
protected:
PokerPlayer *player = nullptr;
UILabel labelName;
UILabel labelChips;
UIEmpty borderInner;
UIBorder border;
TrueTypeAsset *font;
void onPlayerChipsChanged();
void onSceneUpdate();
public:
static std::vector<Asset*> getAssets(AssetManager *assMan) {
std::vector<Asset*> assets;
assets = PokerGameBorder::getAssets(assMan);
assets.push_back(assMan->get<TrueTypeAsset>("truetype_alice"));
return assets;
}
PokerPlayerDisplay(UICanvas *canvas);
void setPlayer(PokerPlayer *player);
~PokerPlayerDisplay();
};
}

View File

@ -0,0 +1,13 @@
# 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
VNPlayer.cpp
)
# Subdirs
add_subdirectory(events)

View File

@ -0,0 +1,12 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNPlayer.hpp"
using namespace Dawn;
VNPlayer::VNPlayer(SceneItem *item) : SceneItemComponent(item) {
}

View File

@ -0,0 +1,18 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "scene/SceneItemComponent.hpp"
namespace Dawn {
class VNPlayer : public SceneItemComponent {
protected:
public:
VNPlayer(SceneItem *item);
};
}

View File

@ -0,0 +1,10 @@
# 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
PokerBetLoopEvent.cpp
)

View File

@ -0,0 +1,64 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PokerBetLoopEvent.hpp"
#include "PokerInitialEvent.hpp"
using namespace Dawn;
void PokerBetLoopEvent::onStart(IVisualNovelEvent *prev) {
PokerGameEvent::onStart(prev);
std::cout << "Bet Loop, bet" << std::endl;
auto evt2 = new PokerDetermineBetterEvent(this->manager);
auto betting = this->then(evt2);
betting
// ->whenEveryoneFolded(new VisualNovelTextboxEvent(this->manager, "Everyone Folded"))
->then(new PokerWinnerEvent(this->manager))
->then(new PokerInitialEvent(this->manager))
;
betting
// ->whenBettingFinished(new VisualNovelTextboxEvent(this->manager, "Betting Finished"))
->then(new PokerWinnerEvent(this->manager))
->then(new PokerInitialEvent(this->manager))
;
betting
->whenTurn(new PokerTurnEvent(this->manager))
// ->then(new VisualNovelTextboxEvent(this->manager, "Turn Time"))
->then(new PokerNewBettingRoundEvent(this->manager))
->then(new PokerBetLoopEvent(this->manager))
;
betting
// ->whenHumanBet(new VisualNovelTextboxEvent(this->manager, "Human Bet"))
->then(new PokerBetLoopEvent(this->manager))
;
// AI Betting
auto aiBet = betting
// ->whenAiBet(new VisualNovelTextboxEvent(this->manager, "AI Bet"))
->then(new PokerAIBetEvent(this->manager))
;
aiBet
// ->whenFolded(new VisualNovelTextboxEvent(this->manager, "Folded"))
->then(new PokerBetLoopEvent(this->manager))
;
aiBet
// ->whenAllIn(new VisualNovelTextboxEvent(this->manager, "All In"))
->then(new PokerBetLoopEvent(this->manager))
;
aiBet
// ->whenBetting(new VisualNovelTextboxEvent(this->manager, "Betting"))
->then(new PokerBetLoopEvent(this->manager))
;
aiBet
// ->whenCalling(new VisualNovelTextboxEvent(this->manager, "Calling"))
->then(new PokerBetLoopEvent(this->manager))
;
aiBet
// ->whenChecking(new VisualNovelTextboxEvent(this->manager, "Checking"))
->then(new PokerBetLoopEvent(this->manager))
;
}

View File

@ -0,0 +1,36 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "poker/visualnovel/PokerNewGameEvent.hpp"
#include "poker/visualnovel/PokerNewRoundEvent.hpp"
#include "poker/visualnovel/PokerTakeBlindsEvent.hpp"
#include "poker/visualnovel/PokerDealEvent.hpp"
#include "poker/visualnovel/PokerTurnEvent.hpp"
#include "poker/visualnovel/PokerDetermineBetterEvent.hpp"
#include "poker/visualnovel/PokerAIBetEvent.hpp"
#include "poker/visualnovel/PokerNewBettingRoundEvent.hpp"
#include "poker/visualnovel/PokerWinnerEvent.hpp"
#define POKER_DEAL_EVENT_CARD_COUNT 2
namespace Dawn {
class PokerBetLoopEvent : public PokerGameEvent {
protected:
void onStart(IVisualNovelEvent *previous) override;
bool_t onUpdate() override {
return false;
}
void onEnd() override {
std::cout << "Bet lop fin" << std::endl;
}
public:
PokerBetLoopEvent(VisualNovelManager *manager) : PokerGameEvent(manager) {
}
};
}

View File

@ -0,0 +1,43 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "poker/visualnovel/PokerNewRoundEvent.hpp"
#include "poker/visualnovel/PokerDealEvent.hpp"
#include "poker/visualnovel/PokerTakeBlindsEvent.hpp"
#include "PokerBetLoopEvent.hpp"
#include "visualnovel/events/VisualNovelTextboxEvent.hpp"
#define POKER_DEAL_EVENT_CARD_COUNT 2
namespace Dawn {
class PokerInitialEvent : public PokerGameEvent {
protected:
void onStart(IVisualNovelEvent *previous) override {
PokerGameEvent::onStart(previous);
this
->then(new PokerNewRoundEvent(this->manager))
// ->then(new VisualNovelTextboxEvent(this->manager, "Round Started"))
->then(new PokerTakeBlindsEvent(this->manager))
// ->then(new VisualNovelTextboxEvent(this->manager, "Blinds Taken"))
->then(new PokerDealEvent(this->manager))
// ->then(new VisualNovelTextboxEvent(this->manager, "Cards Dealt"))
->then(new PokerBetLoopEvent(this->manager))
;
}
bool_t onUpdate() override {
return false;
}
void onEnd() override {
}
public:
PokerInitialEvent(VisualNovelManager *manager) : PokerGameEvent(manager) {
}
};
}

View File

@ -0,0 +1,25 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Build Project
add_executable(${DAWN_TARGET_NAME})
# Includes
target_include_directories(${DAWN_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
# Subdirs
add_subdirectory(components)
add_subdirectory(game)
add_subdirectory(save)
# Assets
set(DIR_GAME_ASSETS games/tictactoe)
tool_language(locale_en ${DIR_GAME_ASSETS}/locale/en.xml)
tool_tileset(tileset_xo texture_xo ${DIR_GAME_ASSETS}/xo.png 1 4)
tool_truetype(truetype_bizudp ${DIR_GAME_ASSETS}/font/BIZUDPGothic-Bold.ttf truetype_bizudp 2048 2048 120)

View File

@ -0,0 +1,12 @@
# 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
TicTacToeGame.cpp
TicTacToeScoreboard.cpp
TicTacToeTile.cpp
)

View File

@ -0,0 +1,138 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TicTacToeGame.hpp"
#include "game/DawnGame.hpp"
#include "scene/components/example/ExampleSpin.hpp"
#include "scene/components/physics/3d/CubeCollider.hpp"
#include "state/StateProvider.hpp"
using namespace Dawn;
TicTacToeGame::TicTacToeGame(SceneItem *item) :
SceneItemComponent(item),
winner(TIC_TAC_TOE_EMPTY),
nextMove(TIC_TAC_TOE_NOUGHT),
gameOver(false),
scoreCross(0),
scoreNought(0)
{
}
void TicTacToeGame::onStart() {
// Map tiles by tile number = tile
auto ts = getScene()->findComponents<TicTacToeTile>();
auto itTiles = ts.begin();
while(itTiles != ts.end()) {
this->tiles[(*itTiles)->tile] = *itTiles;
++itTiles;
}
useInterval([&]{
std::cout << "Interval" << std::endl;
}, 1.0f, this);
useEffect([&]{
if(!gameOver) return;
auto board = this->getBoard();
std::vector<uint8_t> winningCombo;
winner = ticTacToeDetermineWinner(board, &winningCombo);
switch(winner) {
case TIC_TAC_TOE_CROSS:
scoreCross++;
break;
case TIC_TAC_TOE_NOUGHT:
scoreNought++;
break;
default:
break;
}
}, gameOver);
useEvent([&](float_t delta) {
// Only allow player input if it's their turn.
if(gameOver) return;
Camera *camera = getScene()->findComponent<Camera>();
if(camera == nullptr) return;
TicTacToeTile *hovered = nullptr;
bool_t isPlayerMove = nextMove == TIC_TAC_TOE_NOUGHT;
// Get hovered tile (for player move only)
if(isPlayerMove) {
// Get mouse in screen space.
auto mouse = getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y);
mouse *= 2.0f;
mouse -= glm::vec2(1, 1);
struct Ray3D ray;
ray.origin = camera->transform->getWorldPosition();
ray.direction = camera->getRayDirectionFromScreenSpace(mouse);
// Find the hovered tile (if any)
auto results = getPhysics()->raycast3DAll(ray);
auto itResult = results.begin();
while(itResult != results.end()) {
auto result = *itResult;
auto tile = result.collider->item->getComponent<TicTacToeTile>();
if(tile == nullptr) {
++itResult;
continue;
}
hovered = tile;
break;
}
}
// Now update the hover state(s)
auto itTiles = tiles.begin();
while(itTiles != tiles.end()) {
auto t = itTiles->second;
if(t == hovered) {
t->hovered = true;
} else {
t->hovered = false;
}
++itTiles;
}
if(isPlayerMove) {
if(getGame()->inputManager.isPressed(INPUT_BIND_MOUSE_CLICK) && hovered != nullptr) {
this->makeMove(hovered->tile, nextMove);
}
} else if(nextMove != TIC_TAC_TOE_NOUGHT) {
auto board = this->getBoard();
auto move = ticTacToeGetAiMove(board, nextMove);
this->makeMove(move, nextMove);
}
// Did game just end?
gameOver = ticTacToeIsGameOver(this->getBoard());
}, getScene()->eventSceneUpdate);
}
std::map<uint8_t, enum TicTacToeTileState> TicTacToeGame::getBoard() {
std::map<uint8_t, enum TicTacToeTileState> tileMap;
auto itTiles = tiles.begin();
while(itTiles != tiles.end()) {
auto t = itTiles->second;
tileMap[t->tile] = t->tileState;
++itTiles;
}
return tileMap;
}
void TicTacToeGame::makeMove(uint8_t tile, enum TicTacToeTileState player) {
this->tiles[tile]->tileState = player;
nextMove = player == TIC_TAC_TOE_NOUGHT ? TIC_TAC_TOE_CROSS : TIC_TAC_TOE_NOUGHT;
}

View File

@ -0,0 +1,28 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "TicTacToeTile.hpp"
#include "physics/3d/Ray3D.hpp"
namespace Dawn {
class TicTacToeGame : public SceneItemComponent {
public:
enum TicTacToeTileState winner;
StateProperty<bool_t> gameOver;
std::map<int32_t, TicTacToeTile*> tiles;
StateProperty<enum TicTacToeTileState> nextMove;
StateProperty<int32_t> scoreCross;
StateProperty<int32_t> scoreNought;
TicTacToeGame(SceneItem *item);
std::map<uint8_t, enum TicTacToeTileState> getBoard();
void makeMove(uint8_t tile, enum TicTacToeTileState player);
void onStart() override;
};
}

View File

@ -0,0 +1,25 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TicTacToeScoreboard.hpp"
using namespace Dawn;
TicTacToeScoreboard::TicTacToeScoreboard(SceneItem *item) :
SceneItemComponent(item)
{
}
void TicTacToeScoreboard::onStart() {
auto game = getScene()->findComponent<TicTacToeGame>();
assertNotNull(game);
useEffect([&]{
auto label = item->getComponent<UILabel>();
assertNotNull(label);
label->text = std::to_string(game->scoreNought) + " - " + std::to_string(game->scoreCross);
}, { &game->scoreCross, &game->scoreNought })();
}

View File

@ -0,0 +1,20 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "components/TicTacToeGame.hpp"
#include "scene/components/ui/UILabel.hpp"
namespace Dawn {
class TicTacToeScoreboard : public SceneItemComponent {
protected:
TicTacToeGame *game = nullptr;
public:
TicTacToeScoreboard(SceneItem *item);
void onStart() override;
};
}

View File

@ -0,0 +1,31 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TicTacToeTile.hpp"
#include "scene/SceneItem.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
TicTacToeTile::TicTacToeTile(SceneItem *item) :
SceneItemComponent(item),
tileState(TIC_TAC_TOE_EMPTY),
hovered(false)
{
}
void TicTacToeTile::onStart() {
auto cb = [&]{
auto sprite = this->item->getComponent<TiledSprite>();
if(this->hovered && tileState == TIC_TAC_TOE_EMPTY) {
sprite->setTile(0x03);
} else {
sprite->setTile(tileState);
}
};
useEffect(cb, tileState);
useEffect(cb, hovered)();
}

View File

@ -0,0 +1,21 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "scene/components/display/TiledSprite.hpp"
#include "games/tictactoe/TicTacToeLogic.hpp"
namespace Dawn {
class TicTacToeTile : public SceneItemComponent {
public:
StateProperty<enum TicTacToeTileState> tileState;
StateProperty<bool_t> hovered;
uint8_t tile;
TicTacToeTile(SceneItem *item);
void onStart() override;
};
}

View File

@ -0,0 +1,10 @@
# 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
DawnGame.cpp
)

View File

@ -0,0 +1,45 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "DawnGame.hpp"
#include "scenes/TicTacToeScene.hpp"
using namespace Dawn;
DawnGame::DawnGame(DawnHost *host) :
host(host),
renderManager(this),
inputManager(this),
localeManager(this),
saveManager(this)
{
}
int32_t DawnGame::init() {
this->assetManager.init();
this->localeManager.init();
this->renderManager.init();
this->scene = new TicTacToeScene(this);
return DAWN_GAME_INIT_RESULT_SUCCESS;
}
int32_t DawnGame::update(float_t delta) {
this->assetManager.update();
this->inputManager.update();
this->timeManager.update(delta);
if(this->scene != nullptr) this->scene->update();
this->renderManager.update();
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
}
void DawnGame::sceneCutover(Scene *scene) {
if(scene == nullptr) scene = this->scene;
this->sceneToCutTo = scene;
}

View 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 "game/_DawnGame.hpp"
#include "save/DawnGameSaveManager.hpp"
namespace Dawn {
class DawnGame : public IDawnGame {
private:
Scene *sceneToCutTo = nullptr;
public:
DawnHost *host;
RenderManager renderManager;
AssetManager assetManager;
InputManager inputManager;
TimeManager timeManager;
LocaleManager localeManager;
DawnGameSaveManager saveManager;
DawnGame(DawnHost *host);
int32_t init() override;
int32_t update(float_t delta) override;
void sceneCutover(Scene *scene) override;
};
}

View File

@ -0,0 +1,19 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "input/InputManager.hpp"
#define INPUT_BIND(n) ((inputbind_t)n)
#define INPUT_BIND_ACCEPT INPUT_BIND(1)
#define INPUT_BIND_NEGATIVE_X INPUT_BIND(2)
#define INPUT_BIND_POSITIVE_X INPUT_BIND(3)
#define INPUT_BIND_NEGATIVE_Y INPUT_BIND(4)
#define INPUT_BIND_POSITIVE_Y INPUT_BIND(5)
#define INPUT_BIND_MOUSE_X INPUT_BIND(6)
#define INPUT_BIND_MOUSE_Y INPUT_BIND(7)
#define INPUT_BIND_MOUSE_CLICK INPUT_BIND(8)
#define INPUT_BIND_CANCEL INPUT_BIND(9)

View File

@ -0,0 +1,32 @@
// 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/components/ui/UILabel.hpp"
namespace Dawn {
class SimpleLabel : public SceneItemPrefab<SimpleLabel> {
public:
static std::vector<Asset*> prefabAssets(AssetManager *ass) {
return { ass->get<TrueTypeAsset>("truetype_bizudp") };
}
//
UILabel *label;
SimpleLabel(Scene *s, sceneitemid_t i) :
SceneItemPrefab<SimpleLabel>(s, i)
{
}
void prefabInit(AssetManager *man) override {
auto font = man->get<TrueTypeAsset>("truetype_bizudp");
label = this->addComponent<UILabel>();
label->font = &font->font;
}
};
}

View File

@ -0,0 +1,62 @@
// 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/components/display/TiledSprite.hpp"
#include "scene/components/display/MeshHost.hpp"
#include "scene/components/display/MeshRenderer.hpp"
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
#include "scene/components/physics/3d/CubeCollider.hpp"
#include "components/TicTacToeTile.hpp"
namespace Dawn {
class TicTacToeTilePrefab : public SceneItemPrefab<TicTacToeTilePrefab> {
public:
static std::vector<Asset*> prefabAssets(AssetManager *ass) {
return std::vector<Asset*>{
ass->get<TextureAsset>("texture_xo"),
ass->get<TilesetAsset>("tileset_xo")
};
}
//
MeshHost *meshHost;
TiledSprite *sprite;
MeshRenderer *meshRenderer;
SimpleTexturedMaterial *material;
TicTacToeTile *ticTacToe;
CubeCollider *collider;
TicTacToeTilePrefab(Scene *s, sceneitemid_t i) :
SceneItemPrefab<TicTacToeTilePrefab>(s,i)
{
}
void prefabInit(AssetManager *man) override {
auto tileset = man->get<TilesetAsset>("tileset_xo");
auto texture = man->get<TextureAsset>("texture_xo");
meshHost = this->addComponent<MeshHost>();
meshRenderer = this->addComponent<MeshRenderer>();
material = this->template addComponent<SimpleTexturedMaterial>();
material->texture = &texture->texture;
sprite = this->addComponent<TiledSprite>();
sprite->setTileset(&tileset->tileset);
sprite->setSize(glm::vec2(1, 1));
sprite->setTile(0x01);
collider = this->addComponent<CubeCollider>();
collider->min = glm::vec3(-0.5f, -0.5f, -0.1f);
collider->max = glm::vec3( 0.5f, 0.5f, 0.1f);
ticTacToe = this->addComponent<TicTacToeTile>();
}
};
}

View File

@ -0,0 +1,10 @@
# 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
DawnGameSaveManager.cpp
)

View File

@ -0,0 +1,28 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "DawnGameSaveManager.hpp"
using namespace Dawn;
DawnGameSaveManager::DawnGameSaveManager(DawnGame *game) : SaveManager(game) {
}
bool_t DawnGameSaveManager::validateSave(struct SaveFile raw) {
if(!raw.has(POKER_SAVE_KEY_EXAMPLE)) return true;
this->currentSave.copy(raw, POKER_SAVE_KEY_EXAMPLE);
return false;
}
void DawnGameSaveManager::setExample(int32_t val) {
savedata_t value;
value.i32 = val;
this->currentSave.set(POKER_SAVE_KEY_EXAMPLE, value);
}
int32_t DawnGameSaveManager::getExample() {
return this->currentSave.get(POKER_SAVE_KEY_EXAMPLE).i32;
}

View File

@ -0,0 +1,22 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "save/SaveManager.hpp"
#define POKER_SAVE_KEY_EXAMPLE "poker.example"
namespace Dawn {
class DawnGameSaveManager : public SaveManager {
protected:
virtual bool_t validateSave(struct SaveFile raw) override;
public:
DawnGameSaveManager(DawnGame *game);
void setExample(int32_t value);
int32_t getExample();
};
}

View File

@ -0,0 +1,72 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/Scene.hpp"
#include "prefabs/SimpleSpinningCubePrefab.hpp"
#include "prefabs/TicTacToeTilePrefab.hpp"
#include "display/mesh/TriangleMesh.hpp"
#include "components/TicTacToeScoreboard.hpp"
#include "prefabs/SimpleLabel.hpp"
#include "scene/components/ui/menu/UISimpleMenu.hpp"
namespace Dawn {
class TicTacToeScene : public Scene {
protected:
Camera *camera;
std::function<void()> evtUnsub;
UICanvas *canvas;
void stage() override {
camera = Camera::create(this);
camera->transform->lookAt(glm::vec3(0, 0, 8), glm::vec3(0, 0, 0));
float_t s = 2.0f;
camera->orthoTop = s;
camera->orthoBottom = -s;
float_t ratio = 1.0f / 9.0f * 16.0f;
camera->orthoLeft = -s * ratio;
camera->orthoRight = s * ratio;
auto gameItem = this->createSceneItem();
auto game = gameItem->addComponent<TicTacToeGame>();
uint8_t i = 0;
for(int32_t x = -1; x <= 1; x++) {
for(int32_t y = -1; y <= 1; y++) {
auto tile = TicTacToeTilePrefab::create(this);
tile->transform.setLocalPosition(glm::vec3(x * 1, y * 1, 0));
tile->ticTacToe->tile = i++;
}
}
auto canvasItem = this->createSceneItem();
canvas = canvasItem->addComponent<UICanvas>();
auto labelScore = SimpleLabel::prefabCreate(this);
labelScore->addComponent<TicTacToeScoreboard>();
labelScore->transform.setParent(canvas->transform);
labelScore->label->fontSize = 36.0f;
labelScore->label->alignX = UI_COMPONENT_ALIGN_MIDDLE;
labelScore->label->alignment = glm::vec4(
0, 16, 0, 0
);
}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
assets.push_back(assMan->get<TrueTypeAsset>("truetype_bizudp"));
vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
vectorAppend(&assets, TicTacToeTilePrefab::getRequiredAssets(assMan));
return assets;
}
public:
TicTacToeScene(DawnGame *game) : Scene(game) {}
};
}

View File

@ -0,0 +1,36 @@
# Copyright (c) 2023 Dominic Msters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
project(sceneitemcomponentgen VERSION 1.0)
add_executable(sceneitemcomponentgen)
# Sources
target_sources(sceneitemcomponentgen
PRIVATE
${DAWN_SHARED_SOURCES}
${DAWN_TOOL_SOURCES}
SceneItemComponentRegister.cpp
)
# Includes
target_include_directories(sceneitemcomponentgen
PUBLIC
${DAWN_SHARED_INCLUDES}
${DAWN_TOOL_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}
)
# Definitions
target_compile_definitions(sceneitemcomponentgen
PUBLIC
DAWN_TOOL_INSTANCE=SceneItemComponentRegister
DAWN_TOOL_HEADER="SceneItemComponentRegister.hpp"
)
# Libraries
target_link_libraries(sceneitemcomponentgen
PUBLIC
${DAWN_BUILD_HOST_LIBS}
)

View File

@ -0,0 +1,119 @@
/**
* Copyright (c) 2023 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "SceneItemComponentRegister.hpp"
using namespace Dawn;
void SceneItemComponentRootGen::generate(
std::vector<std::string> *out,
std::vector<struct SceneItemComponent> *info,
std::string tabs = ""
) {
line(out, "#include \"scene/SceneItemComponentList.hpp\"", tabs);
line(out, "", tabs);
auto it = info->begin();
while(it != info->end()) {
auto c = *it;
line(out, "#include \"" + c.header + "\"", tabs);
++it;
}
line(out, "", tabs);
line(out, "using namespace Dawn;", tabs);
line(out, "", tabs);
line(out, "SceneItemComponentList::SceneItemComponentList() {", tabs);
it = info->begin();
while(it != info->end()) {
auto c = *it;
line(out, "this->append<" + c.clazz + ">();", tabs + " ");
++it;
}
line(out, "}", tabs);
}
std::vector<std::string> SceneItemComponentRegister::getRequiredFlags() {
return std::vector<std::string>{ "input", "output" };
}
int32_t SceneItemComponentRegister::start() {
File fileIn(flags["input"]);
if(!fileIn.exists()) {
std::cout << "Input scene item component file does not exist." << std::endl;
return 1;
}
std::string buffer;
if(!fileIn.readString(&buffer)) {
std::cout << "Failed to read input scene item component file" << std::endl;
return 1;
}
std::vector<struct SceneItemComponent> components;
struct SceneItemComponent sci;
size_t i = 0;
std::string t;
uint8_t state = 0x00;
while(i < buffer.size()) {
char c = buffer[i++];
if(c != ';') {
t.push_back(c);
continue;
}
switch(state) {
case 0x00:
sci.clazz = t;
t.clear();
state = 0x01;
break;
case 0x01:
sci.header = t;
t.clear();
state = 0x00;
components.push_back(sci);
break;
default:
assertUnreachable();
}
}
if(state == 0x01) {
sci.header = t;
components.push_back(sci);
} else {
assertUnreachable();
}
std::vector<std::string> lines;
SceneItemComponentRootGen::generate(&lines, &components, "");
// Generate buffer
std::string bufferOut;
auto itLine = lines.begin();
while(itLine != lines.end()) {
bufferOut += *itLine + "\n";
++itLine;
}
File fileOut(flags["output"]);
if(!fileOut.mkdirp()) {
std::cout << "Failed to create Scene Item Component List Dir" << std::endl;
return 1;
}
if(!fileOut.writeString(bufferOut)) {
std::cout << "Failed to write SceneItemComponentList file" << std::endl;
return 1;
}
return 0;
}

View File

@ -0,0 +1,33 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/DawnTool.hpp"
#include "util/File.hpp"
#include "util/CodeGen.hpp"
namespace Dawn {
struct SceneItemComponent {
std::string clazz;
std::string header;
};
class SceneItemComponentRootGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
std::vector<struct SceneItemComponent> *info,
std::string tabs
);
};
class SceneItemComponentRegister : public DawnTool {
protected:
std::vector<std::string> getRequiredFlags() override;
public:
int32_t start() override;
};
}

View File

@ -0,0 +1,9 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(DAWN_BUILDING dawnplatformergame CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_WIN32 true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_NAME "PlatformerGame" CACHE INTERNAL ${DAWN_CACHE_TARGET})

View File

@ -0,0 +1,9 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(DAWN_BUILDING dawnpokergame CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_LINUX64 true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_NAME "PlatformerGame" CACHE INTERNAL ${DAWN_CACHE_TARGET})

View File

@ -0,0 +1,9 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(DAWN_BUILDING dawnpokergame CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_WIN32 true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_NAME "PokerGame" CACHE INTERNAL ${DAWN_CACHE_TARGET})

View File

@ -0,0 +1,9 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(DAWN_BUILDING dawnpokergame CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_WIN32 true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_SDL2 true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_NAME "PokerGame" CACHE INTERNAL ${DAWN_CACHE_TARGET})

View File

@ -0,0 +1,9 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(DAWN_BUILDING dawntictactoe CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_LINUX64 true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_NAME "TicTacToe" CACHE INTERNAL ${DAWN_CACHE_TARGET})

View File

@ -0,0 +1,38 @@
# Copyright (c) 2023 Dominic Msters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
project(uigen VERSION 1.0)
add_executable(uigen)
# Sources
target_sources(uigen
PRIVATE
${DAWN_SHARED_SOURCES}
${DAWN_TOOL_SOURCES}
UIGen.cpp
)
# Includes
target_include_directories(uigen
PUBLIC
${DAWN_SHARED_INCLUDES}
${DAWN_TOOL_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}
)
# Definitions
target_compile_definitions(uigen
PUBLIC
${DAWN_SHARED_DEFINITIONS}
DAWN_TOOL_INSTANCE=UIGen
DAWN_TOOL_HEADER="UIGen.hpp"
)
# Libraries
target_link_libraries(uigen
PUBLIC
${DAWN_BUILD_HOST_LIBS}
)

60
archive/uigen/UIGen.cpp Normal file
View File

@ -0,0 +1,60 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UIGen.hpp"
using namespace Dawn;
std::vector<std::string> UIGen::getRequiredFlags() {
return std::vector<std::string>{ "input", "output" };
}
int32_t UIGen::start() {
std::cout << "UI Gen tool is basically unfinished unfortunately" << std::endl;
return 1;
// Open input file.
File file(flags["input"]);
std::string buffer;
if(!file.readString(&buffer)) {
std::cout << "Failed to read " << file.filename << std::endl;
return 1;
}
// Parse XML
Xml xml = Xml::load(buffer);
std::string error;
struct RootInformation info;
auto ret = (RootParser()).parse(&xml, &info, &error);
if(ret != 0) {
std::cout << error << std::endl;
return ret;
}
std::vector<std::string> lines;
RootGen::generate(&lines, &info, "");
// Generate buffer
std::string bufferOut;
auto itLine = lines.begin();
while(itLine != lines.end()) {
bufferOut += *itLine + "\n";
++itLine;
}
// Finished with XML data, now we can write data out.
File fileOut(flags["output"] + ".hpp");
if(!fileOut.mkdirp()) {
std::cout << "Failed to make scene output dir" << std::endl;
return 1;
}
if(!fileOut.writeString(bufferOut)) {
std::cout << "Failed to generate scene " << fileOut.filename << std::endl;
return 1;
}
return 0;
}

20
archive/uigen/UIGen.hpp Normal file
View File

@ -0,0 +1,20 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/DawnTool.hpp"
#include "util/File.hpp"
#include "parse/root.hpp"
#include "util/Language.cpp"
namespace Dawn {
class UIGen : public DawnTool {
protected:
std::vector<std::string> getRequiredFlags() override;
public:
int32_t start();
};
}

View File

@ -0,0 +1,67 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "label.hpp"
namespace Dawn {
struct ChildInfo;
struct ChildrenInfo {
std::vector<struct ChildInfo> children;
};
struct ChildInfo {
enum ChildType type;
struct ChildrenInfo children;
std::string ref;
bool_t hasRef = false;
struct LabelInfo label;
};
class ChildrenParser : public XmlParser<struct ChildrenInfo> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>();
}
std::map<std::string, std::string> getOptionalAttributes() {
return std::map<std::string, std::string>();
}
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct ChildrenInfo *out,
std::string *error
) {
// Parse children of self.
int32_t ret = 0;
auto itChildren = node->children.begin();
while(itChildren != node->children.end()) {
auto c = *itChildren;
struct ChildInfo child;
if(c->node == "label") {
child.type = CHILD_TYPE_LABEL;
ret = (LabelParser()).parse(c, &child.label, error);
} else {
*error = "Unrecognized UI Element " + c->node;
return 1;
}
if(ret != 0) return ret;
// Now Parse children of children
ret = (ChildrenParser()).parse(c, &child.children, error);
if(ret != 0) return ret;
++itChildren;
}
return ret;
}
};
}

View File

@ -0,0 +1,31 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
#include "util/CodeGen.hpp"
namespace Dawn {
enum AlignType {
UI_COMPONENT_ALIGN_START,
UI_COMPONENT_ALIGN_MIDDLE,
UI_COMPONENT_ALIGN_END,
UI_COMPONENT_ALIGN_STRETCH
};
struct Alignment {
float_t x0 = 0;
float_t y0 = 0;
float_t x1 = 0;
float_t y1 = 0;
enum AlignType xAlign = UI_COMPONENT_ALIGN_START;
enum AlignType yAlign = UI_COMPONENT_ALIGN_START;
};
enum ChildType {
CHILD_TYPE_LABEL
};
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "common.hpp"
namespace Dawn {
struct LabelInfo {
std::string text = "";
std::string fontSize = "";
};
class LabelParser : public XmlParser<struct LabelInfo> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>();
}
std::map<std::string, std::string> getOptionalAttributes() {
return {
{ "fontSize", "" }
};
}
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct LabelInfo *out,
std::string *error
) {
int32_t ret = 0;
if(values["fontSize"].size() > 0) {
out->fontSize = values["fontSize"];
}
if(node->value.size() > 0) {
out->text = node->value;
}
return ret;
}
};
}

View File

@ -0,0 +1,83 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "parse/elements/children.hpp"
namespace Dawn {
struct RootInformation {
std::vector<std::string> includes;
struct ChildrenInfo children;
};
class RootParser : public XmlParser<struct RootInformation> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>();
}
std::map<std::string, std::string> getOptionalAttributes() {
return std::map<std::string, std::string>();
}
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct RootInformation *out,
std::string *error
) {
int32_t ret;
if(node->node != "root") {
*error = "Root node is of an invalid type";
return 1;
}
ret = (ChildrenParser()).parse(node, &out->children, error);
if(ret != 0) return ret;
return ret;
}
};
class RootGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
struct RootInformation *info,
std::string tabs = ""
) {
struct ClassGenInfo clazz;
clazz.clazz = "SimpleTestUI";
clazz.extend = "SceneItemPrefab<" + clazz.clazz + ">";
clazz.constructorArgs = "Scene *s, sceneitemid_t i";
clazz.extendArgs = "s, i";
clazz.includes.push_back("#include \"prefab/SceneItemPrefab.hpp\"");
// Assets
struct MethodGenInfo assetsInfo;
assetsInfo.name = "prefabAssets";
assetsInfo.isStatic = true;
assetsInfo.type = "std::vector<Asset*>";
assetsInfo.args = "AssetManager *ass";
line(&assetsInfo.body, "return {", "");
line(&assetsInfo.body, "};", "");
methodGen(&clazz.publicCode, assetsInfo);
line(&clazz.publicCode, "", "");
// Init
struct MethodGenInfo prefabInfo;
prefabInfo.name = "prefabInit";
prefabInfo.args = "AssetManager *ass";
prefabInfo.isOverride = true;
methodGen(&clazz.publicCode, prefabInfo);
classGen(out, clazz);
}
};
}

View File

@ -0,0 +1,39 @@
# Copyright (c) 2023 Dominic Msters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# VN Scene Generator Tool
project(vnscenegen VERSION 1.1)
add_executable(vnscenegen)
# Sources
target_sources(vnscenegen
PRIVATE
${DAWN_SHARED_SOURCES}
${DAWN_TOOL_SOURCES}
VnSceneGen.cpp
)
# Includes
target_include_directories(vnscenegen
PUBLIC
${DAWN_SHARED_INCLUDES}
${DAWN_TOOL_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}
)
# Definitions
target_compile_definitions(vnscenegen
PUBLIC
${DAWN_SHARED_DEFINITIONS}
DAWN_TOOL_INSTANCE=VnSceneGen
DAWN_TOOL_HEADER="VnSceneGen.hpp"
)
# Libraries
target_link_libraries(vnscenegen
PUBLIC
${DAWN_BUILD_HOST_LIBS}
)

View File

@ -0,0 +1,60 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VnSceneGen.hpp"
using namespace Dawn;
std::vector<std::string> VnSceneGen::getRequiredFlags() {
return std::vector<std::string>{ "input", "output", "language-out" };
}
int32_t VnSceneGen::start() {
// Open input file.
File file(flags["input"]);
std::string buffer;
if(!file.readString(&buffer)) {
std::cout << "Failed to read scene " << file.filename << std::endl;
return 1;
}
// Parse XML
Xml xml = Xml::load(buffer);
std::string error;
struct RootInformation info;
auto ret = (RootParser()).parse(&xml, &info, &error);
if(ret != 0) {
std::cout << error << std::endl;
return ret;
}
std::vector<std::string> lines;
RootGen::generate(&lines, &info, "");
// Generate buffer
std::string bufferOut;
auto itLine = lines.begin();
while(itLine != lines.end()) {
bufferOut += *itLine + "\n";
++itLine;
}
// Finished with XML data, now we can write data out.
File fileOut(flags["output"] + ".hpp");
if(!fileOut.mkdirp()) {
std::cout << "Failed to make scene output dir" << std::endl;
return 1;
}
if(!fileOut.writeString(bufferOut)) {
std::cout << "Failed to generate scene " << fileOut.filename << std::endl;
return 1;
}
// Now dump out the language strings to be picked up later.
ret = languageSaveStrings(flags["language-out"], info.strings);
if(ret != 0) return ret;
return 0;
}

View File

@ -0,0 +1,20 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/DawnTool.hpp"
#include "util/File.hpp"
#include "parse/root.hpp"
#include "util/Language.cpp"
namespace Dawn {
class VnSceneGen : public DawnTool {
protected:
std::vector<std::string> getRequiredFlags() override;
public:
int32_t start();
};
}

View File

@ -0,0 +1,56 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
#include "util/CodeGen.hpp"
namespace Dawn {
struct AssetInformation {
std::string type;
std::string name;
};
class AssetParser : public XmlParser<struct AssetInformation> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>{
"name",
"type"
};
}
std::map<std::string, std::string> getOptionalAttributes() {
return std::map<std::string, std::string>();
}
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct AssetInformation *out,
std::string *error
) {
out->name = values["name"];
out->type = values["type"];
return 0;
}
std::string convert(struct AssetInformation info) {
std::string out;
return out;
}
};
class AssetGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
struct AssetInformation *info,
std::string tabs
) {
return line(out, "// Asset will be generated here", tabs);
}
};
}

Some files were not shown because too many files have changed in this diff Show More