First real pass at VN Event Parsing

This commit is contained in:
2023-04-22 22:50:20 -07:00
parent 72a0bb9192
commit c269841236
27 changed files with 476 additions and 60 deletions

View File

@ -23,6 +23,15 @@ void VNManager::setEvent(VNEvent *event) {
this->currentEvent = event;
}
void VNManager::setFlag(std::string key, std::string value) {
this->flags[key] = value;
}
std::string VNManager::getFlag(std::string key) {
if(this->flags.find(key) == this->flags.end()) return "";
return this->flags[key];
}
void VNManager::nextEvent() {
if(this->currentEvent == nullptr) return;
auto old = this->currentEvent;

View File

@ -13,6 +13,7 @@ namespace Dawn {
protected:
std::vector<VNEvent*> events;
VNEvent *currentEvent = nullptr;
std::map<std::string, std::string> flags;
public:
/**
@ -46,6 +47,22 @@ namespace Dawn {
*/
void nextEvent();
/**
* Sets a flag for the visual novel.
*
* @param key Key of the flag.
* @param value Value of the flag.
*/
void setFlag(std::string key, std::string value);
/**
* Gets a flag for the visual novel.
*
* @param key Key of the flag.
* @return Value of the flag, or an empty string if it doesn't exist.
*/
std::string getFlag(std::string key);
void onStart() override;
void onDispose() override;

View File

@ -0,0 +1,45 @@
// 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 VNChoiceEvent : public VNEvent {
public:
std::string text;
std::string key;
std::map<std::string, std::string> choices;
int32_t choice = 0;
protected:
void onStart() override {
choice = 0;
std::cout << "CHOICE: " << text << std::endl;
for(auto& choice : choices) {
std::cout << " " << choice.first << ": " << choice.second << std::endl;
}
useEvent([&](float_t delta) {
auto im = &getScene()->game->inputManager;
if(im->isPressed(INPUT_BIND_ACCEPT)) {
auto it = choices.begin();
std::advance(it, choice);
std::string choiceMade = it->first;
std::cout << "Choice made " << choiceMade << std::endl;
this->manager->setFlag(this->key, choiceMade);
this->next();
} else if(im->isPressed(INPUT_BIND_NEGATIVE_Y)) {
choice = mathClamp<int32_t>((choice - 1), 0, choices.size() - 1);
std::cout << "Current choice: state" << choice << std::endl;
} else if(im->isPressed(INPUT_BIND_POSITIVE_Y)) {
choice = mathClamp<int32_t>((choice + 1), 0, choices.size() - 1);
std::cout << "Current choice: state" << choice << std::endl;
}
}, getScene()->eventSceneUpdate);
}
};
}

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 "VNEvent.hpp"
namespace Dawn {
class VNChoiceSetEvent : public VNEvent {
public:
std::string key;
std::string value;
protected:
void onStart() override {
this->manager->setFlag(this->key, this->value);
this->next();
}
};
}

View File

@ -10,7 +10,7 @@ namespace Dawn {
class VNDummyEvent : public VNEvent {
protected:
void onStart() override {
std::cout << "Test" << std::endl;
std::cout << "Dummy VN Event" << std::endl;
this->next();
}
};

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 "VNEvent.hpp"
namespace Dawn {
class VNIfEvent : public VNEvent {
public:
std::string key;
std::string value;
VNEvent *ifTrue = nullptr;
VNEvent * getNextEvent() override {
if(this->manager.getFlag(key) == value) {
return ifTrue;
}
return VNEvent::getNextEvent();
}
protected:
void onStart() override {
this->next();
}
}
}

View File

@ -14,7 +14,13 @@ namespace Dawn {
protected:
void onStart() override {
std::cout << "TEXT: " << text << std::endl;
this->next();
useEvent([&](float_t delta) {
if(getScene()->game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
std::cout << "Text Advance" << std::endl;
this->next();
}
}, getScene()->eventSceneUpdate);
}
};
}