add dialogue and cutscene system
This commit is contained in:
1 parent
178f69967b
commit
7125674308
23 files changed
+1619
-2
No files matched your search
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include "dialogue/DialogueDatabase.h"
|
||||
#include "external/nlohmann/json.hpp"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace ZL::Dialogue {
|
||||
|
||||
class DialogueRuntime {
|
||||
public:
|
||||
using json = nlohmann::json;
|
||||
|
||||
void setDatabase(const DialogueDatabase* value);
|
||||
|
||||
bool startDialogue(const std::string& dialogueId);
|
||||
void stop();
|
||||
|
||||
void update(int deltaMs);
|
||||
|
||||
bool isActive() const { return mode != Mode::Inactive; }
|
||||
bool isInChoice() const { return mode == Mode::WaitingForChoice; }
|
||||
bool isPlayingCutscene() const { return mode == Mode::PlayingCutscene; }
|
||||
|
||||
void confirmAdvance();
|
||||
void moveSelection(int delta);
|
||||
|
||||
const PresentationModel& getPresentation() const { return presentation; }
|
||||
|
||||
void setFlag(const std::string& name, int value);
|
||||
int getFlag(const std::string& name) const;
|
||||
|
||||
json buildSaveState() const;
|
||||
bool restoreSaveState(const json& state);
|
||||
|
||||
private:
|
||||
enum class Mode {
|
||||
Inactive,
|
||||
PresentingLine,
|
||||
WaitingForChoice,
|
||||
PlayingCutscene
|
||||
};
|
||||
|
||||
const DialogueDatabase* database = nullptr;
|
||||
const DialogueDefinition* activeDialogue = nullptr;
|
||||
const StaticCutsceneDefinition* activeCutscene = nullptr;
|
||||
|
||||
std::unordered_map<std::string, int> flags;
|
||||
std::unordered_set<std::string> consumedChoices;
|
||||
|
||||
std::string currentNodeId;
|
||||
std::string pendingNodeAfterCutscene;
|
||||
|
||||
std::vector<Choice> visibleChoices;
|
||||
PresentationModel presentation;
|
||||
Mode mode = Mode::Inactive;
|
||||
|
||||
int selectedChoice = 0;
|
||||
float revealCharacters = 0.0f;
|
||||
float revealSpeedCharsPerSecond = 52.0f;
|
||||
|
||||
int currentCutsceneLine = -1;
|
||||
int cutsceneTimerMs = 0;
|
||||
|
||||
bool evaluateConditions(const std::vector<Condition>& conditions) const;
|
||||
void applyEffects(const std::vector<Effect>& effects);
|
||||
|
||||
bool enterNode(const std::string& nodeId);
|
||||
void presentLine(const Node& node);
|
||||
void presentChoices(const Node& node);
|
||||
void startCutscene(const std::string& cutsceneId, const std::string& nextNodeAfterCutscene);
|
||||
|
||||
void advanceCutsceneLine();
|
||||
void refreshCutscenePresentation();
|
||||
|
||||
static int computeFallbackCutsceneDurationMs(const std::string& text);
|
||||
};
|
||||
|
||||
} // namespace ZL::Dialogue
|
||||
Reference in new issue
Block a user