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