94 lines
2.5 KiB
C++
94 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "dialogue/DialogueDatabase.h"
|
|
#include "external/nlohmann/json.hpp"
|
|
#include <functional>
|
|
#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, std::function<void()> onFinished = nullptr);
|
|
void stop();
|
|
void clearState();
|
|
|
|
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);
|
|
void selectChoice(int index);
|
|
|
|
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::function<void()> onFinishedCallback;
|
|
|
|
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;
|
|
int cutsceneElapsedMs = 0;
|
|
int cutsceneTotalDurationMs = 0;
|
|
|
|
std::string currentCutsceneBackground;
|
|
|
|
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 finishCutscene();
|
|
|
|
void advanceCutsceneLine();
|
|
void refreshCutscenePresentation();
|
|
CutsceneCameraBlendState evaluateCutsceneCameraBlend() const;
|
|
|
|
static float applyEasing(EasingType easing, float t);
|
|
static int computeFallbackCutsceneDurationMs(const std::string& text);
|
|
static int computeCameraTrackDurationMs(const StaticCutsceneDefinition& cutscene);
|
|
};
|
|
|
|
} // namespace ZL::Dialogue
|