60 bool registerCharacter(
const std::string &
id,
const std::string &displayName);
62 bool hasCharacter(
const std::string &
id)
const;
64 std::string getDisplayName(
const std::string &
id)
const;
70 int getCharacterCount()
const;
72 std::string getCharacterId(
int index)
const;
75 bool show(
const std::string &
id,
const std::string &
slot);
77 bool hide(
const std::string &
id);
79 bool isShown(
const std::string &
id)
const;
81 std::string getSlot(
const std::string &
id)
const;
83 void setSlotX(
const std::string &
slot,
float xNorm);
85 float getSlotX(
const std::string &
slot)
const;
87 bool setExpression(
const std::string &
id,
const std::string &expression);
89 bool setMotion(
const std::string &
id,
const std::string &motion);
92 void syncStage(
float stageWidth,
float stageHeight);
95 void say(
const std::string &speakerId,
const std::string &
text);
97 void narrate(
const std::string &
text);
99 void setTypeSpeed(
float charsPerSecond);
105 bool isTyping()
const;
107 bool isWaitingAdvance()
const;
116 std::string getSpeakerName()
const;
120 std::string getVisibleText()
const;
122 std::string getPhase()
const;
125 void setLipSyncEnabled(
bool enabled);
129 void setLipSyncParameter(
const std::string &
name);
133 void setLipSyncAmplitude(
float amplitude);
142 bool addChoice(
const std::string &
id,
const std::string &
label);
144 void presentChoices();
146 bool isWaitingChoice()
const;
148 int getChoiceCount()
const;
150 std::string getChoiceId(
int index)
const;
152 std::string getChoiceLabel(
int index)
const;
154 bool selectChoice(
int index);
161 bool setVar(
const std::string &
name, ssq::Object
value,
const std::string &
scope);
168 std::string getVarType(
const std::string &
name,
const std::string &
scope)
const;
176 std::string getVarString(
const std::string &
name,
const std::string &
defaultValue,
177 const std::string &
scope)
const;
179 bool hasVar(
const std::string &
name,
const std::string &
scope)
const;
181 bool clearVar(
const std::string &
name,
const std::string &
scope);
183 void clearVars(
const std::string &
scope);
188 bool registerCondition(
const std::string &
name, ssq::Object
fn);
190 bool unregisterCondition(
const std::string &
name);
192 bool evalCondition(ssq::Object table);
194 bool evalConditionData(
const DataValue &cond);
198 int loadPoolsFromTable(ssq::Object table);
206 int getPoolCount()
const;
208 std::string getPoolId(
int index)
const;
210 bool hasPool(
const std::string &
id)
const;
217 void setRandomSeed(
int seed);
223 std::string pickLine(
const std::string &poolId, ssq::Object
params);
225 std::string pickLineWithParams(
const std::string &poolId,
226 const std::unordered_map<std::string, VarValue> &
params);
228 bool playLine(
const std::string &lineId, ssq::Object
params);
230 bool playLineWithParams(
const std::string &lineId,
231 const std::unordered_map<std::string, VarValue> &
params);
233 bool playPool(
const std::string &poolId, ssq::Object
params);
235 bool playPoolWithParams(
const std::string &poolId,
236 const std::unordered_map<std::string, VarValue> &
params);
240 std::string getCurrentLineMeta(
const std::string &field)
const;
242 std::vector<std::string> getCurrentLineTags()
const;
245 void update(
float dt);
258 bool restoreState(
const StateValue& in, std::string* err =
nullptr);
261 bool resetToDefaults();
267 std::string displayName;
269 std::optional<size_t> avatarHook;
279 enum class Phase { Idle, Typing, WaitingAdvance, WaitingChoice };
281 Character *findCharacter(
const std::string &
id);
282 const Character *findCharacter(
const std::string &
id)
const;
283 void beginLine(
const std::string &speakerId,
const std::string &
text);
285 std::vector<Character> characters_;
286 std::unordered_map<std::string, float> slotX_;
288 Phase phase_ = Phase::Idle;
289 std::string speakerId_;
290 std::string fullText_;
291 float typeSpeed_ = 40.f;
294 std::vector<Choice> choices_;
295 std::string selectedChoiceId_;
297 bool lipSyncEnabled_ =
true;
298 std::string lipSyncParameter_ =
"mouthOpen";
299 float lipSyncAmplitude_ = 0.85f;
300 float lipSyncValue_ = 0.f;
301 float lipSyncTime_ = 0.f;
303 void updateLipSync(
float dt);
304 void applyLipSyncToSpeaker();
311 Kind
kind = Kind::Always;
326 std::unordered_map<std::string, std::string> meta;
327 std::vector<std::string>
tags;
333 std::vector<Line>
lines;
334 std::vector<size_t> recent;
337 std::unordered_map<std::string, VarValue> *varsForScope(
const std::string &
scope);
338 const std::unordered_map<std::string, VarValue> *varsForScope(
const std::string &
scope)
const;
339 std::unordered_map<std::string, VarValue> mergedVars(
340 const std::unordered_map<std::string, VarValue> &
params)
const;
341 std::unordered_map<std::string, std::string> stringParams(
342 const std::unordered_map<std::string, VarValue> &vars)
const;
343 bool parseCondition(
const DataValue &
v, Condition &
out, std::string &
error);
344 bool parseLineData(
const std::string &poolId,
const DataValue &
v,
int index, Line &
line,
346 bool evalConditionInternal(
const Condition &
c,
347 const std::unordered_map<std::string, VarValue> &merged,
348 const std::unordered_map<std::string, VarValue> &
params,
349 const std::string &lineId)
const;
350 bool evalScriptPredicate(
const std::string &
name,
351 const std::unordered_map<std::string, VarValue> &merged,
352 const std::unordered_map<std::string, VarValue> &
params,
353 const std::string &lineId)
const;
354 bool compareEq(
const VarValue &
a,
const VarValue &
b)
const;
355 bool compareOrder(
const std::string &op,
const VarValue &
a,
const VarValue &
b)
const;
357 const std::unordered_map<std::string, VarValue> &vars)
const;
358 Pool *findPool(
const std::string &
id);
359 const Pool *findPool(
const std::string &
id)
const;
360 Line *findLine(
const std::string &
id);
361 const Line *findLine(
const std::string &
id)
const;
362 void applyLineMeta(
const Line &
line);
363 void pollSceneChange();
364 uint32_t nextRandom();
367 std::unordered_map<std::string, VarValue> globalVars_;
368 std::unordered_map<std::string, VarValue> sceneVars_;
369 std::unordered_map<std::string, HSQOBJECT> predicates_;
370 std::vector<Pool> pools_;
371 std::string lastPoolsError_;
372 uint32_t rngState_ = 0x9E3779B9u;
373 std::string lastSceneName_;
374 std::string currentLineId_;
375 std::unordered_map<std::string, std::string> currentLineMeta_;
376 std::vector<std::string> currentLineTags_;