Starting new VN Structure
This commit is contained in:
1 parent
26efdfe314
commit
1c21c15261
77 files changed
+929
-27
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,101 @@
|
||||
<vnscene name="ExampleScene">
|
||||
<item ref="eth" prefab="preafbs/charactersEthereality" />
|
||||
<item ref="craig" prefab="preafbs/characters/Craig" />
|
||||
<item ref="bg" prefab="preafbs/backgrounds/School" />
|
||||
<item ref="square" prefab="prefabs/visualnovel/VisualNovelSquare" />
|
||||
<property type="" ref="easeOut" value="easeOutQuad" />
|
||||
|
||||
<events>
|
||||
<!-- Set the default values -->
|
||||
<position item="bg" x="0" y="0" z="0" />
|
||||
<position item="craig" x="0" y="0" z="1" />
|
||||
<position item="eth" x="0" y="0" z="1" />
|
||||
<position item="square" x="0" y="0" z="10" />
|
||||
|
||||
<set property="square->material->color" value="COLOR_BLACK" />
|
||||
<set property="craig->material->color.a" value="0" />
|
||||
|
||||
<!-- Fade out the black overlay -->
|
||||
<animate item="square->material->color.a" from="1" to="0" time="1" curve="easeOut" />
|
||||
|
||||
<!-- Example Text, also showing how in future we can support multiple languages -->
|
||||
<text character="eth">
|
||||
<string lang="en">Hi, I'm Ethereality.</string>
|
||||
</text>
|
||||
|
||||
<!-- Fade in craig -->
|
||||
<animate item="craig->material->color.a" from="0" to="1" time="1" curve="easeOut" />
|
||||
<text character="craig">
|
||||
<string lang="en">Hi, I'm Craig.</string>
|
||||
</text>
|
||||
|
||||
<!--
|
||||
Because each event stops things happening until it's complete, let's
|
||||
assume we want to do two things at once, say move and fade out a character
|
||||
at the same time. This will make craig exit screen left.
|
||||
-->
|
||||
<parallel>
|
||||
<animate item="craig->material->color.a" from="1" to="0" time="1" curve="easeOut" />
|
||||
<animate item="craig" x="-2" time="1" curve="easeOut" />
|
||||
</parallel>
|
||||
|
||||
<!-- Now Craig is gone, so sad, let's now fade the screen out and present some choices -->
|
||||
<animate item="square->material->color.a" from="0" to="1" time="1" curve="easeOut" />
|
||||
|
||||
<!-- Here I am creating a marker -->
|
||||
<marker name="craigCool" />
|
||||
|
||||
<choices character="eth" key="isCraigCool">
|
||||
<title>
|
||||
<string lang="en">Do you think Craig is cool?</string>
|
||||
</title>
|
||||
<choice value="no">
|
||||
<string lang="en">Yes</string>
|
||||
</choice>
|
||||
<choice value="yes">
|
||||
<string lang="en">No</string>
|
||||
</choice>
|
||||
<choice value="maybe">
|
||||
<string lang="en">Maybe</string>
|
||||
</choice>
|
||||
</choices>
|
||||
|
||||
<!--
|
||||
Now we have a choice, we can use the key to get the value of the choice
|
||||
and do something with it. In this case, we'll just show a different
|
||||
message depending on the choice.
|
||||
|
||||
If the user selects "Maybe", we basically just display a message and then
|
||||
go back to the choices indefinitely.
|
||||
-->
|
||||
<if key="isCraigCool" value="maybe">
|
||||
<text character="eth">
|
||||
<string lang="en">Are you unsure?</string>
|
||||
</text>
|
||||
<goto-marker name="craigCool" />
|
||||
</if>
|
||||
|
||||
<if key="isCraigCool" value="yes">
|
||||
<text character="eth">
|
||||
<string lang="en">I agree, Craig is cool.</string>
|
||||
</text>
|
||||
</if>
|
||||
<if key="isCraigCool" value="no">
|
||||
<text character="eth">
|
||||
<string lang="en">I disagree, Craig is cool.</string>
|
||||
</text>
|
||||
</if>
|
||||
|
||||
<!-- We can also modify values/set values too. -->
|
||||
<choice-set key="isCraigCool" value="yes" />
|
||||
|
||||
<!-- We can also wait some time -->
|
||||
<wait time="1" />
|
||||
|
||||
<!--
|
||||
Now change scenes. Changing scenes is handled in-engine to stop the game
|
||||
crashing from a lack of memory.
|
||||
-->
|
||||
<scene-change name="scenes/ExampleScene2" />
|
||||
</events>
|
||||
</vnscene>
|
||||
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
set(DAWN_BUILDING dawnliminal 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 "Liminal" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_VISUAL_NOVEL true CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
@@ -4,9 +4,9 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(poker)
|
||||
# add_subdirectory(poker)
|
||||
add_subdirectory(tictactoe)
|
||||
|
||||
if(DAWN_VISUAL_NOVEL)
|
||||
add_subdirectory(visualnovel)
|
||||
add_subdirectory(vn)
|
||||
endif()
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(components)
|
||||
add_subdirectory(events)
|
||||
@@ -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
|
||||
VNManager.cpp
|
||||
)
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNManager.hpp"
|
||||
#include "games/vn/events/VNEvent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
VNManager::VNManager(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
}
|
||||
|
||||
void VNManager::onStart() {
|
||||
if(this->currentEvent != nullptr) {
|
||||
this->currentEvent->start(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void VNManager::setEvent(VNEvent *event) {
|
||||
this->currentEvent = event;
|
||||
}
|
||||
|
||||
void VNManager::nextEvent() {
|
||||
if(this->currentEvent == nullptr) return;
|
||||
auto old = this->currentEvent;
|
||||
old->end();
|
||||
this->currentEvent = old->getNextEvent();
|
||||
if(this->currentEvent != nullptr) this->currentEvent->start(old);
|
||||
}
|
||||
|
||||
void VNManager::onDispose() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VNEvent;
|
||||
|
||||
class VNManager : public SceneItemComponent {
|
||||
protected:
|
||||
std::vector<VNEvent*> events;
|
||||
VNEvent *currentEvent = nullptr;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a visual novel manager, scene item component.
|
||||
*
|
||||
* @param item Item that the VN manager belongs to.
|
||||
*/
|
||||
VNManager(SceneItem *item);
|
||||
|
||||
/**
|
||||
* Creats an event for you to decide how to queue.
|
||||
*/
|
||||
template<class T>
|
||||
T * createEvent() {
|
||||
auto event = new T();
|
||||
event->init(this);
|
||||
this->events.push_back(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the currently active visual novel event. This is assumed to be
|
||||
* the only way to handle events (no multiples currently).
|
||||
*
|
||||
* @param event Event to set.
|
||||
*/
|
||||
void setEvent(VNEvent *event);
|
||||
|
||||
void nextEvent();
|
||||
|
||||
// template <class T>
|
||||
// T * setEvent(T *event) {
|
||||
// auto oldCurrent = this->currentEvent;
|
||||
// this->currentEvent = event;
|
||||
// if(this->hasInitialized && event != nullptr) event->start(oldCurrent);
|
||||
// delete oldCurrent;
|
||||
// return event;
|
||||
// }
|
||||
|
||||
void onStart() override;
|
||||
void onDispose() override;
|
||||
|
||||
friend class VNEvent;
|
||||
};
|
||||
}
|
||||
@@ -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
|
||||
VNEvent.cpp
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "VNEvent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VNDummyEvent : public VNEvent {
|
||||
protected:
|
||||
void onStart() override {
|
||||
std::cout << "Test" << std::endl;
|
||||
this->next();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNEvent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void VNEvent::init(VNManager *manager) {
|
||||
this->manager = manager;
|
||||
}
|
||||
|
||||
void VNEvent::start(VNEvent *previous) {
|
||||
this->onStart();
|
||||
}
|
||||
|
||||
Scene * VNEvent::getScene() {
|
||||
return this->manager->getScene();
|
||||
}
|
||||
|
||||
VNEvent * VNEvent::getNextEvent() {
|
||||
return this->doNext;
|
||||
}
|
||||
|
||||
void VNEvent::next() {
|
||||
assertNotNull(this->manager);
|
||||
assertTrue(this->manager->currentEvent == this);
|
||||
this->manager->nextEvent();
|
||||
}
|
||||
|
||||
void VNEvent::end() {
|
||||
this->unsubscribeAllEvents();
|
||||
this->onEnd();
|
||||
}
|
||||
|
||||
void VNEvent::onStart() {}
|
||||
void VNEvent::onEnd() {}
|
||||
@@ -0,0 +1,79 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "games/vn/components/VNManager.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VNEvent : public StateOwner {
|
||||
protected:
|
||||
VNManager *manager = nullptr;
|
||||
VNEvent *doNext = nullptr;
|
||||
VNEvent *previous = nullptr;
|
||||
|
||||
/**
|
||||
* Initializes the event. This is called by the VNManager, and should not
|
||||
* be called by anything else.
|
||||
* @param manager The VNManager that is running this event.
|
||||
*/
|
||||
void init(VNManager *manager);
|
||||
|
||||
/**
|
||||
* Invoked by the VNManager, this is the start of the event.
|
||||
* @param previous The previous event that was running before this one.
|
||||
*/
|
||||
void start(VNEvent *previous);
|
||||
|
||||
/**
|
||||
* Invoked by the VNManager, this is the end of the event. Perform the
|
||||
* necessary cleanup, but remember that events may be re-started again
|
||||
* later.
|
||||
*/
|
||||
void end();
|
||||
|
||||
/**
|
||||
* Overrideable method that is called when the event is started.
|
||||
*/
|
||||
virtual void onStart();
|
||||
|
||||
/**
|
||||
* Overrideable method that is called when the event is ended.
|
||||
*/
|
||||
virtual void onEnd();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns the scene this event is running in.
|
||||
* @return Pointer to the scene.
|
||||
*/
|
||||
Scene * getScene();
|
||||
|
||||
/**
|
||||
* End this event and move on to the next event.
|
||||
*/
|
||||
void next();
|
||||
|
||||
/**
|
||||
* Returns the next event to be executed after this one. Can be overridden
|
||||
* to return a different event other than the doNext event.
|
||||
* @return Pointer to the next event.
|
||||
*/
|
||||
virtual VNEvent * getNextEvent();
|
||||
|
||||
/**
|
||||
* Chains an event to be executed after this event has finished.
|
||||
*
|
||||
* @param next Event to process next.
|
||||
* @return Whatever you pass in to next.
|
||||
*/
|
||||
template<class T>
|
||||
T * then(T *next) {
|
||||
this->doNext = next;
|
||||
return next;
|
||||
}
|
||||
|
||||
friend class VNManager;
|
||||
};
|
||||
}
|
||||
@@ -6,8 +6,8 @@
|
||||
#pragma once
|
||||
#include "prefab/SceneItemPrefab.hpp"
|
||||
#include "display/mesh/CubeMesh.hpp"
|
||||
#include "scene/components/display/MeshRenderer.hpp"
|
||||
#include "scene/components/display/CubeMeshHost.hpp"
|
||||
#include "scene/components/display/mesh/MeshRenderer.hpp"
|
||||
#include "scene/components/display/mesh/CubeMeshHost.hpp"
|
||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||
#include "scene/components/example/ExampleSpin.hpp"
|
||||
#include "scene/components/physics/3d/CubeCollider.hpp"
|
||||
|
||||
+36
-20
@@ -44,6 +44,36 @@ namespace Dawn {
|
||||
private:
|
||||
std::vector<IStateEvent*> eventsSubscribed;
|
||||
std::vector<IStateOwnerEventLegacy*> eventLegacyBridge;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Removes all currently subscribed effects and events.
|
||||
*/
|
||||
void unsubscribeAllEvents() {
|
||||
auto providers = this->_stateProviderListeners;
|
||||
auto itProvider = providers.begin();
|
||||
while(itProvider != providers.end()) {
|
||||
(*itProvider)();
|
||||
++itProvider;
|
||||
}
|
||||
|
||||
auto it = this->eventsSubscribed.begin();
|
||||
while(it != this->eventsSubscribed.end()) {
|
||||
(*it)->_stateOwnerDestroyed(this);
|
||||
++it;
|
||||
}
|
||||
|
||||
auto itBridge = this->eventLegacyBridge.begin();
|
||||
while(itBridge != this->eventLegacyBridge.end()) {
|
||||
(*itBridge)->removeListener();
|
||||
delete *itBridge;
|
||||
++itBridge;
|
||||
}
|
||||
|
||||
this->_stateProviderListeners.clear();
|
||||
this->eventsSubscribed.clear();
|
||||
this->eventLegacyBridge.clear();
|
||||
}
|
||||
|
||||
public:
|
||||
std::vector<std::function<void()>> _stateProviderListeners;
|
||||
@@ -123,7 +153,11 @@ namespace Dawn {
|
||||
auto itProp = props.begin();
|
||||
while(itProp != props.end()) {
|
||||
auto property = *itProp;
|
||||
if(property->owner == nullptr) { property->owner = this; } else { assertTrue(property->owner == this); }
|
||||
if(property->owner == nullptr) {
|
||||
property->owner = this;
|
||||
} else {
|
||||
assertTrue(property->owner == this);
|
||||
}
|
||||
property->_effectListners.push_back(fn);
|
||||
++itProp;
|
||||
}
|
||||
@@ -230,25 +264,7 @@ namespace Dawn {
|
||||
* useEffects or useEvents.
|
||||
*/
|
||||
virtual ~StateOwner() {
|
||||
auto providers = this->_stateProviderListeners;
|
||||
auto itProvider = providers.begin();
|
||||
while(itProvider != providers.end()) {
|
||||
(*itProvider)();
|
||||
++itProvider;
|
||||
}
|
||||
|
||||
auto it = this->eventsSubscribed.begin();
|
||||
while(it != this->eventsSubscribed.end()) {
|
||||
(*it)->_stateOwnerDestroyed(this);
|
||||
++it;
|
||||
}
|
||||
|
||||
auto itBridge = this->eventLegacyBridge.begin();
|
||||
while(itBridge != this->eventLegacyBridge.end()) {
|
||||
(*itBridge)->removeListener();
|
||||
delete *itBridge;
|
||||
++itBridge;
|
||||
}
|
||||
this->unsubscribeAllEvents();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# 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(game)
|
||||
add_subdirectory(save)
|
||||
@@ -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
|
||||
LiminalGame.cpp
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "scenes/HelloWorldScene.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Scene * Dawn::dawnGameGetInitialScene(DawnGame *game) {
|
||||
return new HelloWorldScene(game);
|
||||
}
|
||||
@@ -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)
|
||||
@@ -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
|
||||
LiminalSave.cpp
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "save/SaveManager.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
bool_t Dawn::saveValidateFile(struct SaveFile raw) {
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// 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 "scene/components/display/Camera.hpp"
|
||||
#include "prefabs/SimpleSpinningCubePrefab.hpp"
|
||||
#include "games/vn/components/VNManager.hpp"
|
||||
#include "games/vn/events/VNDummyEvent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class HelloWorldScene : public Scene {
|
||||
protected:
|
||||
Camera *camera;
|
||||
UICanvas *canvas;
|
||||
|
||||
void stage() override {
|
||||
canvas = UICanvas::create(this);
|
||||
|
||||
camera = Camera::create(this);
|
||||
camera->fov = 0.436332f;
|
||||
camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));
|
||||
|
||||
auto cube = SimpleSpinningCubePrefab::create(this);
|
||||
|
||||
auto vnItem = this->createSceneItem();
|
||||
auto vnManager = vnItem->addComponent<VNManager>();
|
||||
|
||||
auto eventTest = vnManager->createEvent<VNDummyEvent>();
|
||||
eventTest
|
||||
->then(vnManager->createEvent<VNDummyEvent>())
|
||||
->then(vnManager->createEvent<VNDummyEvent>())
|
||||
;
|
||||
vnManager->setEvent(eventTest);
|
||||
}
|
||||
|
||||
std::vector<Asset*> getRequiredAssets() override {
|
||||
auto assMan = &this->game->assetManager;
|
||||
std::vector<Asset*> assets;
|
||||
return assets;
|
||||
}
|
||||
|
||||
public:
|
||||
HelloWorldScene(DawnGame *game) : Scene(game) {}
|
||||
};
|
||||
}
|
||||
@@ -40,8 +40,6 @@ void HurtHazard::onStart() {
|
||||
otherHealth->damage({
|
||||
.amount = damage
|
||||
});
|
||||
|
||||
std::cout << "Trigger" << std::endl;
|
||||
}, this->trigger->eventTriggerEnter);
|
||||
}, this->trigger)();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "EntityInteractable.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
EntityInteractable::EntityInteractable(SceneItem* item) : SceneItemComponent(item) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void EntityInteractable::interact() {
|
||||
std::cout << "Interact!" << std::endl;
|
||||
}
|
||||
@@ -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 "scene/components/physics/2d/TriggerController2D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class EntityInteractable : public SceneItemComponent {
|
||||
public:
|
||||
EntityInteractable(SceneItem *item);
|
||||
|
||||
/**
|
||||
* Called when one entity interacts with this entity.
|
||||
*/
|
||||
void interact();
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "EntityInteractor.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
EntityInteractor::EntityInteractor(SceneItem* item) :
|
||||
trigger(nullptr),
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
}
|
||||
|
||||
void EntityInteractor::onStart() {
|
||||
this->evtTriggerEnter = [&]{};
|
||||
|
||||
useEffect([&]{
|
||||
this->evtTriggerEnter();
|
||||
if(this->trigger == nullptr) return;
|
||||
|
||||
this->evtTriggerEnter = useEvent([&](EntityInteractable *interactable) {
|
||||
interactable->interact();
|
||||
}, this->trigger->eventTriggerEnter);
|
||||
}, this->trigger)();
|
||||
}
|
||||
@@ -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 "EntityInteractable.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class EntityInteractor : public SceneItemComponent {
|
||||
private:
|
||||
std::function<void()> evtTriggerEnter;
|
||||
|
||||
public:
|
||||
// @optional
|
||||
StateProperty<TriggerController2D*> trigger;
|
||||
|
||||
EntityInteractor(SceneItem* item);
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
||||
@@ -20,4 +20,5 @@ include(util/CMakeLists.txt)
|
||||
|
||||
# Tools
|
||||
add_subdirectory(prefabtool)
|
||||
add_subdirectory(texturetool)
|
||||
add_subdirectory(texturetool)
|
||||
# add_subdirectory(vnscenetool)
|
||||
@@ -0,0 +1,63 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Texture Build Tool
|
||||
project(vnscenetool VERSION 1.0)
|
||||
add_executable(vnscenetool)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(events)
|
||||
|
||||
# Sources
|
||||
target_sources(vnscenetool
|
||||
PRIVATE
|
||||
${DAWN_SHARED_SOURCES}
|
||||
${DAWN_TOOL_SOURCES}
|
||||
VNSceneTool.cpp
|
||||
VNSceneParser.cpp
|
||||
VNSceneEventsParser.cpp
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(vnscenetool
|
||||
PUBLIC
|
||||
${DAWN_SHARED_INCLUDES}
|
||||
${DAWN_TOOL_INCLUDES}
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Definitions
|
||||
target_compile_definitions(vnscenetool
|
||||
PUBLIC
|
||||
${DAWN_SHARED_DEFINITIONS}
|
||||
DAWN_TOOL_INSTANCE=VNSceneTool
|
||||
DAWN_TOOL_HEADER="VNSceneTool.hpp"
|
||||
)
|
||||
|
||||
# Libraries
|
||||
target_link_libraries(vnscenetool
|
||||
PUBLIC
|
||||
${DAWN_BUILD_HOST_LIBS}
|
||||
)
|
||||
|
||||
# Tool Function
|
||||
function(tool_vnscene in)
|
||||
set(DEPS "")
|
||||
if(DAWN_BUILD_TOOLS)
|
||||
set(DEPS vnscenetool)
|
||||
endif()
|
||||
|
||||
STRING(REGEX REPLACE "[\.|\\|\/]" "-" prefab_name ${in})
|
||||
add_custom_target(prefab_${prefab_name}
|
||||
COMMAND vnscenetool --input="${DAWN_ASSETS_SOURCE_DIR}/${in}"
|
||||
COMMENT "Generating prefab from ${in}"
|
||||
DEPENDS ${DEPS}
|
||||
)
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DAWN_GENERATED_DIR}/generatedprefabs
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} prefab_${prefab_name})
|
||||
endfunction()
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSceneEventsParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNSceneEventsParser::getRequiredAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNSceneEventsParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNSceneEventsParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNSceneEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
int32_t ret;
|
||||
|
||||
auto itChildren = node->children.begin();
|
||||
while(itChildren != node->children.end()) {
|
||||
Xml *child = *itChildren;
|
||||
|
||||
// Parse event(s)
|
||||
if(child->node == "position") {
|
||||
struct VNPosition position;
|
||||
ret = (VNPositionParser()).parse(child, &position, error);
|
||||
if(ret != 0) return ret;
|
||||
out->position = position;
|
||||
}
|
||||
|
||||
itChildren++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// 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 "events/VNPositionParser.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct VNSceneEvent {
|
||||
int32_t bruh;
|
||||
};
|
||||
|
||||
class VNSceneEventsParser : public XmlParser<struct VNSceneEvent> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes() override;
|
||||
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNSceneEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSceneParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNSceneParser::getRequiredAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNSceneParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNSceneParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNScene *out,
|
||||
std::string *error
|
||||
) {
|
||||
//
|
||||
int32_t ret;
|
||||
|
||||
auto itChildren = node->children.begin();
|
||||
while(itChildren != node->children.end()) {
|
||||
Xml *child = *itChildren;
|
||||
|
||||
// Parse event(s)
|
||||
if(child->node == "events") {
|
||||
struct VNSceneEvent scene;
|
||||
ret = (VNSceneEventsParser()).parse(child, &scene, error);
|
||||
if(ret != 0) return ret;
|
||||
out->events.push_back(scene);
|
||||
}
|
||||
|
||||
|
||||
itChildren++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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 "VNSceneEventsParser.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct VNScene {
|
||||
std::vector<struct VNSceneEvent> events;
|
||||
};
|
||||
|
||||
class VNSceneParser : public XmlParser<struct VNScene> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes() override;
|
||||
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNScene *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSceneTool.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNSceneTool::getRequiredFlags() {
|
||||
return { "input" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNSceneTool::getOptionalFlags() {
|
||||
return std::map<std::string, std::string>();
|
||||
}
|
||||
|
||||
int32_t VNSceneTool::start() {
|
||||
File input = File(flags["input"]);
|
||||
if(!input.exists()) {
|
||||
std::cout << "Input file does not exist!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string data;
|
||||
if(!input.readString(&data)) {
|
||||
std::cout << "Failed to read input file!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto xml = Xml::load(data);
|
||||
std::string error;
|
||||
struct VNScene scene;
|
||||
auto result = ((VNSceneParser()).parse(&xml, &scene, &error));
|
||||
if(result != 0) {
|
||||
std::cout << "Failed to parse scene: " << error << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Generate output
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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 "VNSceneParser.hpp"
|
||||
#include "util/File.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VNSceneTool : public DawnTool {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredFlags() override;
|
||||
std::map<std::string, std::string> getOptionalFlags() override;
|
||||
|
||||
public:
|
||||
int32_t start();
|
||||
};
|
||||
}
|
||||
@@ -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(vnscenetool
|
||||
PRIVATE
|
||||
VNPositionParser.cpp
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNPositionParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNPositionParser::getRequiredAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNPositionParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNPositionParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNPosition *out,
|
||||
std::string *error
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
Reference in new issue
Block a user