59 bool registerCharacter(
const std::string &
id,
const std::string &displayName);
61 bool hasCharacter(
const std::string &
id)
const;
63 std::string getDisplayName(
const std::string &
id)
const;
69 int getCharacterCount()
const;
71 std::string getCharacterId(
int index)
const;
74 bool show(
const std::string &
id,
const std::string &slot);
76 bool hide(
const std::string &
id);
78 bool isShown(
const std::string &
id)
const;
80 std::string getSlot(
const std::string &
id)
const;
82 void setSlotX(
const std::string &slot,
float xNorm);
84 float getSlotX(
const std::string &slot)
const;
86 bool setExpression(
const std::string &
id,
const std::string &expression);
88 bool setMotion(
const std::string &
id,
const std::string &motion);
91 void syncStage(
float stageWidth,
float stageHeight);
94 void say(
const std::string &speakerId,
const std::string &
text);
96 void narrate(
const std::string &
text);
98 void setTypeSpeed(
float charsPerSecond);
104 bool isTyping()
const;
106 bool isWaitingAdvance()
const;
115 std::string getSpeakerName()
const;
119 std::string getVisibleText()
const;
121 std::string getPhase()
const;
124 void setLipSyncEnabled(
bool enabled);
128 void setLipSyncParameter(
const std::string &
name);
132 void setLipSyncAmplitude(
float amplitude);
141 bool addChoice(
const std::string &
id,
const std::string &
label);
143 void presentChoices();
145 bool isWaitingChoice()
const;
147 int getChoiceCount()
const;
149 std::string getChoiceId(
int index)
const;
151 std::string getChoiceLabel(
int index)
const;
153 bool selectChoice(
int index);
160 bool setVar(
const std::string &
name, ssq::Object
value,
const std::string &
scope);
167 std::string getVarType(
const std::string &
name,
const std::string &
scope)
const;
175 std::string getVarString(
const std::string &
name,
const std::string &
defaultValue,
176 const std::string &
scope)
const;
178 bool hasVar(
const std::string &
name,
const std::string &
scope)
const;
180 bool clearVar(
const std::string &
name,
const std::string &
scope);
182 void clearVars(
const std::string &
scope);
187 bool registerCondition(
const std::string &
name, ssq::Object
fn);
189 bool unregisterCondition(
const std::string &
name);
191 bool evalCondition(ssq::Object table);
193 bool evalConditionData(
const DataValue &cond);
197 int loadPoolsFromTable(ssq::Object table);
205 int getPoolCount()
const;
207 std::string getPoolId(
int index)
const;
209 bool hasPool(
const std::string &
id)
const;
216 void setRandomSeed(
int seed);
222 std::string pickLine(
const std::string &poolId, ssq::Object
params);
224 std::string pickLineWithParams(
const std::string &poolId,
225 const std::unordered_map<std::string, VarValue> &
params);
227 bool playLine(
const std::string &lineId, ssq::Object
params);
229 bool playLineWithParams(
const std::string &lineId,
230 const std::unordered_map<std::string, VarValue> &
params);
232 bool playPool(
const std::string &poolId, ssq::Object
params);
234 bool playPoolWithParams(
const std::string &poolId,
235 const std::unordered_map<std::string, VarValue> &
params);
239 std::string getCurrentLineMeta(
const std::string &field)
const;
241 std::vector<std::string> getCurrentLineTags()
const;
244 void update(
float dt);
257 bool restoreState(
const StateValue& in, std::string* err =
nullptr);
260 bool resetToDefaults();
266 std::string displayName;
268 std::optional<size_t> avatarHook;
278 enum class Phase { Idle, Typing, WaitingAdvance, WaitingChoice };
280 Character *findCharacter(
const std::string &
id);
281 const Character *findCharacter(
const std::string &
id)
const;
282 void beginLine(
const std::string &speakerId,
const std::string &
text);
284 std::vector<Character> characters_;
285 std::unordered_map<std::string, float> slotX_;
287 Phase phase_ = Phase::Idle;
288 std::string speakerId_;
289 std::string fullText_;
290 float typeSpeed_ = 40.f;
293 std::vector<Choice> choices_;
294 std::string selectedChoiceId_;
296 bool lipSyncEnabled_ =
true;
297 std::string lipSyncParameter_ =
"mouthOpen";
298 float lipSyncAmplitude_ = 0.85f;
299 float lipSyncValue_ = 0.f;
300 float lipSyncTime_ = 0.f;
302 void updateLipSync(
float dt);
303 void applyLipSyncToSpeaker();
310 Kind
kind = Kind::Always;
325 std::unordered_map<std::string, std::string> meta;
326 std::vector<std::string> tags;
332 std::vector<Line>
lines;
333 std::vector<size_t> recent;
336 std::unordered_map<std::string, VarValue> *varsForScope(
const std::string &
scope);
337 const std::unordered_map<std::string, VarValue> *varsForScope(
const std::string &
scope)
const;
338 std::unordered_map<std::string, VarValue> mergedVars(
339 const std::unordered_map<std::string, VarValue> &
params)
const;
340 std::unordered_map<std::string, std::string> stringParams(
341 const std::unordered_map<std::string, VarValue> &vars)
const;
342 bool parseCondition(
const DataValue &
v, Condition &out, std::string &
error);
343 bool parseLineData(
const std::string &poolId,
const DataValue &
v,
int index, Line &
line,
345 bool evalConditionInternal(
const Condition &
c,
346 const std::unordered_map<std::string, VarValue> &merged,
347 const std::unordered_map<std::string, VarValue> &
params,
348 const std::string &lineId)
const;
349 bool evalScriptPredicate(
const std::string &
name,
350 const std::unordered_map<std::string, VarValue> &merged,
351 const std::unordered_map<std::string, VarValue> &
params,
352 const std::string &lineId)
const;
353 bool compareEq(
const VarValue &
a,
const VarValue &
b)
const;
354 bool compareOrder(
const std::string &op,
const VarValue &
a,
const VarValue &
b)
const;
356 const std::unordered_map<std::string, VarValue> &vars)
const;
357 Pool *findPool(
const std::string &
id);
358 const Pool *findPool(
const std::string &
id)
const;
359 Line *findLine(
const std::string &
id);
360 const Line *findLine(
const std::string &
id)
const;
361 void applyLineMeta(
const Line &
line);
362 void pollSceneChange();
363 uint32_t nextRandom();
366 std::unordered_map<std::string, VarValue> globalVars_;
367 std::unordered_map<std::string, VarValue> sceneVars_;
368 std::unordered_map<std::string, HSQOBJECT> predicates_;
369 std::vector<Pool> pools_;
370 std::string lastPoolsError_;
371 uint32_t rngState_ = 0x9E3779B9u;
372 std::string lastSceneName_;
373 std::string currentLineId_;
374 std::unordered_map<std::string, std::string> currentLineMeta_;
375 std::vector<std::string> currentLineTags_;