Refactoring cutscenes
This commit is contained in:
1 parent
7011bbb754
commit
2e5988f8f4
20 files changed
+1913
-1881
No files matched your search
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "dialogue/DialogueDatabase.h"
|
||||
#include "quest/QuestJournal.h"
|
||||
#include "external/nlohmann/json.hpp"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -13,70 +12,54 @@ namespace ZL::Dialogue {
|
||||
|
||||
class DialogueRuntime {
|
||||
public:
|
||||
using json = nlohmann::json;
|
||||
|
||||
void setDatabase(const DialogueDatabase* value);
|
||||
|
||||
bool startDialogue(const std::string& dialogueId);
|
||||
bool startStandaloneCutscene(const std::string& cutsceneId);
|
||||
void setOnCutsceneFinished(std::function<void(const std::string&)> cb);
|
||||
void setOnDialogueLineStarted(std::function<void(const std::string&)> cb);
|
||||
void setOnCutsceneLineStarted(std::function<void(const std::string&)> cb);
|
||||
void setOnCutsceneFadeInComplete(std::function<void(const std::string&)> cb);
|
||||
void setOnChatBubbleReady(std::function<void(const std::string&, bool)> cb);
|
||||
void stop();
|
||||
|
||||
// Called by DialogueSystem after the inline cutscene finishes.
|
||||
void resumeFromNode(const std::string& nodeId);
|
||||
|
||||
void setOnCutsceneStartNeeded(std::function<void(const std::string& cutsceneId, const std::string& nextNodeId)> cb);
|
||||
void setOnDialogueLineStarted(std::function<void(const std::string&)> cb);
|
||||
void setOnChatBubbleReady(std::function<void(const std::string&, bool)> cb);
|
||||
|
||||
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);
|
||||
bool canSkipCurrentCutscene() const;
|
||||
void skipCurrentCutscene();
|
||||
|
||||
const PresentationModel& getPresentation() const { return presentation; }
|
||||
|
||||
void setFlag(const std::string& name, int value);
|
||||
int getFlag(const std::string& name) const;
|
||||
|
||||
void setGlobalFlagStore(std::unordered_map<std::string, int>* store);
|
||||
|
||||
void setQuestJournal(Quest::QuestJournal* journal);
|
||||
|
||||
//json buildSaveState() const;
|
||||
//bool restoreSaveState(const json& state);
|
||||
|
||||
private:
|
||||
enum class Mode {
|
||||
Inactive,
|
||||
PresentingLine,
|
||||
WaitingForChoice,
|
||||
PlayingCutscene
|
||||
WaitingForCutscene // paused while an inline cutscene plays
|
||||
};
|
||||
|
||||
std::function<void(const std::string&)> onCutsceneFinished;
|
||||
std::function<void(const std::string&, const std::string&)> onCutsceneStartNeeded;
|
||||
std::function<void(const std::string&)> onDialogueLineStarted;
|
||||
std::function<void(const std::string&)> onCutsceneLineStarted;
|
||||
std::function<void(const std::string&)> onCutsceneFadeInComplete;
|
||||
std::function<void(const std::string&, bool)> onChatBubbleReady;
|
||||
std::string activeCutsceneId;
|
||||
bool fadeInCallbackFired = false;
|
||||
|
||||
const DialogueDatabase* database = nullptr;
|
||||
Quest::QuestJournal* questJournal = nullptr;
|
||||
const DialogueDefinition* activeDialogue = nullptr;
|
||||
const StaticCutsceneDefinition* activeCutscene = nullptr;
|
||||
|
||||
std::unordered_map<std::string, int>* flagStore = nullptr;
|
||||
std::unordered_set<std::string> consumedChoices;
|
||||
|
||||
std::string currentNodeId;
|
||||
std::string pendingNodeAfterCutscene;
|
||||
|
||||
std::vector<Choice> visibleChoices;
|
||||
PresentationModel presentation;
|
||||
Mode mode = Mode::Inactive;
|
||||
@@ -84,14 +67,6 @@ private:
|
||||
int selectedChoice = -1;
|
||||
float revealCharacters = 0.0f;
|
||||
float revealSpeedCharsPerSecond = 52.0f;
|
||||
|
||||
int currentCutsceneLine = -1;
|
||||
int cutsceneTimerMs = 0;
|
||||
int cutsceneElapsedMs = 0;
|
||||
int cutsceneTotalDurationMs = 0;
|
||||
int cutsceneContentDurationMs = 0;
|
||||
|
||||
std::string currentCutsceneBackground;
|
||||
|
||||
bool evaluateConditions(const std::vector<Condition>& conditions) const;
|
||||
void applyEffects(const std::vector<Effect>& effects);
|
||||
@@ -102,18 +77,6 @@ private:
|
||||
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 syncCutsceneLineToElapsedTime();
|
||||
|
||||
void advanceCutsceneLine();
|
||||
void refreshCutscenePresentation();
|
||||
CutsceneCameraBlendState evaluateCutsceneCameraBlend() const;
|
||||
std::vector<PresentedCutsceneImage> evaluateCutsceneImages() const;
|
||||
|
||||
static float applyEasing(EasingType easing, float t);
|
||||
static int computeFallbackCutsceneDurationMs(const std::string& text);
|
||||
static int computeCameraTrackDurationMs(const StaticCutsceneDefinition& cutscene);
|
||||
};
|
||||
|
||||
} // namespace ZL::Dialogue
|
||||
Reference in new issue
Block a user