First real pass at VN Event Parsing
This commit is contained in:
45
src/dawn/games/vn/events/VNChoiceEvent.hpp
Normal file
45
src/dawn/games/vn/events/VNChoiceEvent.hpp
Normal 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);
|
||||
}
|
||||
};
|
||||
}
|
21
src/dawn/games/vn/events/VNChoiceSetEvent.hpp
Normal file
21
src/dawn/games/vn/events/VNChoiceSetEvent.hpp
Normal 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();
|
||||
}
|
||||
};
|
||||
}
|
@@ -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();
|
||||
}
|
||||
};
|
||||
|
28
src/dawn/games/vn/events/VNIfEvent.hpp
Normal file
28
src/dawn/games/vn/events/VNIfEvent.hpp
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user