@routevn/creator-model 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routevn/creator-model",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.js CHANGED
@@ -5,3 +5,9 @@ export {
5
5
  validatePayload,
6
6
  validateState,
7
7
  } from "./model.js";
8
+ export {
9
+ SYSTEM_VARIABLE_GROUPS,
10
+ SYSTEM_VARIABLE_IDS,
11
+ getSystemVariableDefinitions,
12
+ isSystemVariableId,
13
+ } from "./systemVariables.js";
package/src/model.js CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  isPlainObject,
16
16
  removeTreeNode,
17
17
  } from "./helpers.js";
18
+ import { isSystemVariableId } from "./systemVariables.js";
18
19
 
19
20
  const COLLECTION_KEYS = [
20
21
  "scenes",
@@ -109,6 +110,7 @@ const VARIABLE_SCOPE_KEYS = ["context", "global-device", "global-account"];
109
110
  const VARIABLE_TYPE_KEYS = ["string", "number", "boolean"];
110
111
  const LAYOUT_TYPE_KEYS = ["normal", "dialogue", "nvl", "choice"];
111
112
  const LAYOUT_ELEMENT_TEXT_STYLE_ALIGN_KEYS = ["left", "center", "right"];
113
+ const LAYOUT_TEXT_REVEAL_EFFECT_KEYS = ["typewriter", "softWipe", "none"];
112
114
  const LAYOUT_ELEMENT_BASE_TYPES = [
113
115
  "folder",
114
116
  "container",
@@ -219,6 +221,15 @@ const invalidInvariant = (message, details = {}) =>
219
221
  details,
220
222
  });
221
223
 
224
+ const isVariableReferenceTarget = (state, variableId) => {
225
+ if (isSystemVariableId(variableId)) {
226
+ return true;
227
+ }
228
+
229
+ const variable = state.variables.items[variableId];
230
+ return isPlainObject(variable) && variable.type !== "folder";
231
+ };
232
+
222
233
  const toDomainErrorDetails = (publicError) => {
223
234
  const details = isPlainObject(publicError?.details)
224
235
  ? { ...publicError.details }
@@ -2095,11 +2106,7 @@ const validateCharacterSpriteItems = ({ items, path, errorFactory }) => {
2095
2106
  }
2096
2107
  };
2097
2108
 
2098
- const validateLayoutElementTextStyle = ({
2099
- textStyle,
2100
- path,
2101
- errorFactory,
2102
- }) => {
2109
+ const validateLayoutElementTextStyle = ({ textStyle, path, errorFactory }) => {
2103
2110
  {
2104
2111
  const result = validateAllowedKeys({
2105
2112
  value: textStyle,
@@ -2202,6 +2209,7 @@ const validateLayoutElementData = ({
2202
2209
  "text",
2203
2210
  "textStyle",
2204
2211
  "displaySpeed",
2212
+ "revealEffect",
2205
2213
  "imageId",
2206
2214
  "hoverImageId",
2207
2215
  "clickImageId",
@@ -2314,6 +2322,7 @@ const validateLayoutElementData = ({
2314
2322
  "clickTextStyleId",
2315
2323
  "containerType",
2316
2324
  "variableId",
2325
+ "revealEffect",
2317
2326
  "thumbImageId",
2318
2327
  "barImageId",
2319
2328
  "hoverThumbImageId",
@@ -2335,6 +2344,16 @@ const validateLayoutElementData = ({
2335
2344
  );
2336
2345
  }
2337
2346
 
2347
+ if (
2348
+ data.revealEffect !== undefined &&
2349
+ !LAYOUT_TEXT_REVEAL_EFFECT_KEYS.includes(data.revealEffect)
2350
+ ) {
2351
+ return invalidFromErrorFactory(
2352
+ errorFactory,
2353
+ `${path}.revealEffect must be one of ${LAYOUT_TEXT_REVEAL_EFFECT_KEYS.join(", ")} when provided`,
2354
+ );
2355
+ }
2356
+
2338
2357
  if (
2339
2358
  data.direction !== undefined &&
2340
2359
  data.direction !== "horizontal" &&
@@ -2444,6 +2463,7 @@ const validateLayoutElementItems = ({ items, path, errorFactory }) => {
2444
2463
  "text",
2445
2464
  "textStyle",
2446
2465
  "displaySpeed",
2466
+ "revealEffect",
2447
2467
  "imageId",
2448
2468
  "hoverImageId",
2449
2469
  "clickImageId",
@@ -3889,8 +3909,7 @@ export const assertInvariants = ({ state }) => {
3889
3909
  elementId,
3890
3910
  targetId,
3891
3911
  }) => {
3892
- const variable = state.variables.items[targetId];
3893
- if (!isPlainObject(variable) || variable.type === "folder") {
3912
+ if (!isVariableReferenceTarget(state, targetId)) {
3894
3913
  return invalidInvariant(
3895
3914
  `${ownerLabel} element variableId must reference an existing non-folder variable`,
3896
3915
  {
@@ -6501,8 +6520,7 @@ const validateVisualElementReferenceTargets = ({
6501
6520
  }
6502
6521
 
6503
6522
  if (data.variableId !== undefined) {
6504
- const variable = state.variables.items[data.variableId];
6505
- if (!isPlainObject(variable) || variable.type === "folder") {
6523
+ if (!isVariableReferenceTarget(state, data.variableId)) {
6506
6524
  return invalidFromErrorFactory(
6507
6525
  errorFactory,
6508
6526
  `${ownerLabel} element variableId must reference an existing non-folder variable`,
@@ -0,0 +1,42 @@
1
+ export const SYSTEM_VARIABLE_GROUPS = Object.freeze([
2
+ {
3
+ id: "routeEngine",
4
+ name: "Route Engine",
5
+ variables: Object.freeze([
6
+ {
7
+ id: "_skipUnseenText",
8
+ name: "Skip Unseen Text",
9
+ scope: "global-device",
10
+ type: "boolean",
11
+ default: false,
12
+ description:
13
+ "When enabled, skip mode can continue through lines the player has not viewed yet.",
14
+ },
15
+ {
16
+ id: "_dialogueTextSpeed",
17
+ name: "Dialogue Text Speed",
18
+ scope: "global-device",
19
+ type: "number",
20
+ default: 50,
21
+ description:
22
+ "Controls the default dialogue text speed stored for this device.",
23
+ },
24
+ ]),
25
+ },
26
+ ]);
27
+
28
+ export const SYSTEM_VARIABLE_IDS = Object.freeze(
29
+ SYSTEM_VARIABLE_GROUPS.flatMap((group) =>
30
+ (group.variables || []).map((variable) => variable.id),
31
+ ),
32
+ );
33
+
34
+ const SYSTEM_VARIABLE_ID_SET = new Set(SYSTEM_VARIABLE_IDS);
35
+
36
+ export const isSystemVariableId = (value) => {
37
+ return typeof value === "string" && SYSTEM_VARIABLE_ID_SET.has(value);
38
+ };
39
+
40
+ export const getSystemVariableDefinitions = () => {
41
+ return SYSTEM_VARIABLE_GROUPS.flatMap((group) => group.variables || []);
42
+ };