Cleanup
This commit is contained in:
parent
2e5988f8f4
commit
3ba8a2f44b
@ -34,21 +34,11 @@ CutsceneAnchor CutsceneDatabase::parseCutsceneAnchor(const std::string& value) {
|
||||
|
||||
CutsceneLine CutsceneDatabase::parseCutsceneLine(const json& j) {
|
||||
CutsceneLine line;
|
||||
line.speaker = j.value("speaker", "");
|
||||
line.text = j.value("text", "");
|
||||
line.portrait = j.value("portrait", "");
|
||||
line.sfx = j.value("sfx", "");
|
||||
line.background = j.value("background", "");
|
||||
line.backgroundWidth = j.value("backgroundWidth", 0);
|
||||
line.backgroundHeight= j.value("backgroundHeight", 0);
|
||||
line.luaCallback = j.value("luaCallback", "");
|
||||
line.durationMs = j.value("durationMs", 0);
|
||||
line.waitForConfirm = j.value("waitForConfirm", false);
|
||||
line.questUnlock = j.value("questUnlock", "");
|
||||
line.questComplete = j.value("questComplete", "");
|
||||
line.questFail = j.value("questFail", "");
|
||||
line.objectiveComplete = j.value("objectiveComplete", "");
|
||||
line.objectiveVisible = j.value("objectiveVisible", "");
|
||||
line.speaker = j.value("speaker", "");
|
||||
line.text = j.value("text", "");
|
||||
line.luaCallback = j.value("luaCallback", "");
|
||||
line.durationMs = j.value("durationMs", 0);
|
||||
line.waitForConfirm = j.value("waitForConfirm", false);
|
||||
return line;
|
||||
}
|
||||
|
||||
@ -94,7 +84,6 @@ StaticCutsceneDefinition CutsceneDatabase::parseCutscene(const json& j) {
|
||||
cutscene.background = j.value("background", "");
|
||||
cutscene.backgroundWidth = j.value("backgroundWidth", 1280);
|
||||
cutscene.backgroundHeight= j.value("backgroundHeight", 720);
|
||||
cutscene.music = j.value("music", "");
|
||||
cutscene.skippable = j.value("skippable", true);
|
||||
cutscene.durationMs = j.value("durationMs", 0);
|
||||
cutscene.fadeOutMs = j.value("fadeOutMs", 0);
|
||||
|
||||
@ -6,20 +6,10 @@
|
||||
|
||||
namespace ZL::Cutscene {
|
||||
|
||||
static std::pair<std::string, std::string> splitDot(const std::string& s) {
|
||||
const auto dot = s.find('.');
|
||||
if (dot == std::string::npos) return {s, ""};
|
||||
return {s.substr(0, dot), s.substr(dot + 1)};
|
||||
}
|
||||
|
||||
void CutsceneRuntime::setDatabase(const CutsceneDatabase* value) {
|
||||
database = value;
|
||||
}
|
||||
|
||||
void CutsceneRuntime::setQuestJournal(Quest::QuestJournal* journal) {
|
||||
questJournal = journal;
|
||||
}
|
||||
|
||||
void CutsceneRuntime::setOnFinished(std::function<void(const std::string&)> cb) {
|
||||
onFinished = std::move(cb);
|
||||
}
|
||||
@ -47,7 +37,6 @@ bool CutsceneRuntime::start(const std::string& cutsceneId) {
|
||||
activeCutsceneId = cutsceneId;
|
||||
active = true;
|
||||
fadeInCallbackFired = false;
|
||||
currentCutsceneBackground = def->background;
|
||||
cutsceneElapsedMs = 0;
|
||||
cutsceneTimerMs = 0;
|
||||
currentCutsceneLine = def->lines.empty() ? -1 : 0;
|
||||
@ -77,8 +66,6 @@ bool CutsceneRuntime::start(const std::string& cutsceneId) {
|
||||
|
||||
if (!def->lines.empty()) {
|
||||
const CutsceneLine& firstLine = def->lines[0];
|
||||
applyQuestActions(firstLine.questUnlock, firstLine.questComplete,
|
||||
firstLine.questFail, firstLine.objectiveComplete, firstLine.objectiveVisible);
|
||||
if (onLineStarted && !firstLine.luaCallback.empty())
|
||||
onLineStarted(firstLine.luaCallback);
|
||||
}
|
||||
@ -100,7 +87,6 @@ void CutsceneRuntime::stop() {
|
||||
cutsceneElapsedMs = 0;
|
||||
cutsceneTotalDurationMs = 0;
|
||||
cutsceneContentDurationMs = 0;
|
||||
currentCutsceneBackground.clear();
|
||||
presentation = {};
|
||||
}
|
||||
|
||||
@ -191,25 +177,6 @@ void CutsceneRuntime::skip() {
|
||||
finish();
|
||||
}
|
||||
|
||||
void CutsceneRuntime::applyQuestActions(
|
||||
const std::string& questUnlock, const std::string& questComplete,
|
||||
const std::string& questFail, const std::string& objectiveComplete,
|
||||
const std::string& objectiveVisible)
|
||||
{
|
||||
if (!questJournal) return;
|
||||
if (!questUnlock.empty()) questJournal->unlockQuest(questUnlock);
|
||||
if (!questComplete.empty()) questJournal->completeQuest(questComplete);
|
||||
if (!questFail.empty()) questJournal->failQuest(questFail);
|
||||
if (!objectiveComplete.empty()) {
|
||||
auto [qId, oId] = splitDot(objectiveComplete);
|
||||
questJournal->setObjectiveCompleted(qId, oId);
|
||||
}
|
||||
if (!objectiveVisible.empty()) {
|
||||
auto [qId, oId] = splitDot(objectiveVisible);
|
||||
questJournal->setObjectiveVisible(qId, oId);
|
||||
}
|
||||
}
|
||||
|
||||
void CutsceneRuntime::finish() {
|
||||
std::cout << "[CUTSCENE] finish id=" << activeCutsceneId << std::endl;
|
||||
const std::string finishedId = activeCutsceneId;
|
||||
@ -270,8 +237,6 @@ void CutsceneRuntime::advanceLine() {
|
||||
}
|
||||
|
||||
const CutsceneLine& newLine = activeCutscene->lines[currentCutsceneLine];
|
||||
applyQuestActions(newLine.questUnlock, newLine.questComplete,
|
||||
newLine.questFail, newLine.objectiveComplete, newLine.objectiveVisible);
|
||||
if (onLineStarted && !newLine.luaCallback.empty())
|
||||
onLineStarted(newLine.luaCallback);
|
||||
|
||||
@ -316,9 +281,7 @@ std::vector<PresentedCutsceneImage> CutsceneRuntime::evaluateImages() const {
|
||||
std::vector<PresentedCutsceneImage> result;
|
||||
if (!activeCutscene) return result;
|
||||
|
||||
const std::string& fallbackPath = !currentCutsceneBackground.empty()
|
||||
? currentCutsceneBackground
|
||||
: activeCutscene->background;
|
||||
const std::string& fallbackPath = activeCutscene->background;
|
||||
|
||||
if (activeCutscene->images.empty()) {
|
||||
if (!fallbackPath.empty()) {
|
||||
@ -443,17 +406,9 @@ void CutsceneRuntime::refreshPresentation() {
|
||||
|
||||
const CutsceneLine& line = activeCutscene->lines[currentCutsceneLine];
|
||||
|
||||
if (!line.background.empty()) {
|
||||
currentCutsceneBackground = line.background;
|
||||
if (line.backgroundWidth > 0) presentation.backgroundWidth = line.backgroundWidth;
|
||||
if (line.backgroundHeight > 0) presentation.backgroundHeight = line.backgroundHeight;
|
||||
}
|
||||
|
||||
presentation.backgroundPath = currentCutsceneBackground;
|
||||
presentation.speaker = line.speaker;
|
||||
presentation.fullText = line.text;
|
||||
presentation.visibleText = line.text;
|
||||
presentation.portraitPath = line.portrait;
|
||||
presentation.selectedChoice = 0;
|
||||
|
||||
std::cout << "[CUTSCENE] lines=" << activeCutscene->lines.size()
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
#include "cutscene/CutsceneDatabase.h"
|
||||
#include "dialogue/DialogueTypes.h"
|
||||
#include "quest/QuestJournal.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
@ -11,7 +10,6 @@ namespace ZL::Cutscene {
|
||||
class CutsceneRuntime {
|
||||
public:
|
||||
void setDatabase(const CutsceneDatabase* value);
|
||||
void setQuestJournal(Quest::QuestJournal* journal);
|
||||
|
||||
void setOnFinished(std::function<void(const std::string&)> cb);
|
||||
void setOnLineStarted(std::function<void(const std::string&)> cb);
|
||||
@ -29,7 +27,6 @@ public:
|
||||
|
||||
private:
|
||||
const CutsceneDatabase* database = nullptr;
|
||||
Quest::QuestJournal* questJournal = nullptr;
|
||||
|
||||
const StaticCutsceneDefinition* activeCutscene = nullptr;
|
||||
std::string activeCutsceneId;
|
||||
@ -41,7 +38,6 @@ private:
|
||||
int cutsceneElapsedMs = 0;
|
||||
int cutsceneTotalDurationMs = 0;
|
||||
int cutsceneContentDurationMs = 0;
|
||||
std::string currentCutsceneBackground;
|
||||
|
||||
ZL::Dialogue::PresentationModel presentation;
|
||||
|
||||
@ -49,10 +45,6 @@ private:
|
||||
std::function<void(const std::string&)> onLineStarted;
|
||||
std::function<void(const std::string&)> onFadeInComplete;
|
||||
|
||||
void applyQuestActions(const std::string& questUnlock, const std::string& questComplete,
|
||||
const std::string& questFail, const std::string& objectiveComplete,
|
||||
const std::string& objectiveVisible);
|
||||
|
||||
void finish();
|
||||
void syncLineToElapsedTime();
|
||||
void advanceLine();
|
||||
|
||||
@ -30,20 +30,9 @@ enum class CutsceneAnchor {
|
||||
struct CutsceneLine {
|
||||
std::string speaker;
|
||||
std::string text;
|
||||
std::string portrait;
|
||||
std::string sfx;
|
||||
std::string background;
|
||||
std::string luaCallback;
|
||||
int backgroundWidth = 0;
|
||||
int backgroundHeight = 0;
|
||||
int durationMs = 0;
|
||||
bool waitForConfirm = false;
|
||||
|
||||
std::string questUnlock;
|
||||
std::string questComplete;
|
||||
std::string questFail;
|
||||
std::string objectiveComplete; // "quest_id.objective_id"
|
||||
std::string objectiveVisible; // "quest_id.objective_id"
|
||||
};
|
||||
|
||||
struct CutsceneCameraPose {
|
||||
@ -74,7 +63,6 @@ struct StaticCutsceneDefinition {
|
||||
std::string background;
|
||||
int backgroundWidth = 1280;
|
||||
int backgroundHeight = 720;
|
||||
std::string music;
|
||||
std::string onFadeInCallback;
|
||||
bool skippable = true;
|
||||
int durationMs = 0;
|
||||
|
||||
@ -52,7 +52,6 @@ public:
|
||||
}
|
||||
void setQuestJournal(Quest::QuestJournal* journal) {
|
||||
dialogueRuntime.setQuestJournal(journal);
|
||||
cutsceneRuntime.setQuestJournal(journal);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user