@routevn/creator-model 1.7.1 → 1.7.3
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 +1 -1
- package/src/model.js +119 -4
package/package.json
CHANGED
package/src/model.js
CHANGED
|
@@ -496,6 +496,15 @@ const isVariableReferenceTarget = (state, variableId) => {
|
|
|
496
496
|
return isPlainObject(variable) && variable.type !== "folder";
|
|
497
497
|
};
|
|
498
498
|
|
|
499
|
+
const isStringVariableReferenceTarget = (state, variableId) => {
|
|
500
|
+
const variable = state.variables.items[variableId];
|
|
501
|
+
return (
|
|
502
|
+
isPlainObject(variable) &&
|
|
503
|
+
variable.type === "variable" &&
|
|
504
|
+
variable.variableType === "string"
|
|
505
|
+
);
|
|
506
|
+
};
|
|
507
|
+
|
|
499
508
|
const LAYOUT_ITEM_TARGET_SET = new Set(["item.savedAt"]);
|
|
500
509
|
const LAYOUT_DIALOGUE_TARGET_SET = new Set(["dialogue.characterId"]);
|
|
501
510
|
const RUNTIME_TARGET_DOT_PATTERN = /^runtime\.([A-Za-z_$][A-Za-z0-9_$]*)$/;
|
|
@@ -4254,6 +4263,7 @@ const validateCharacterItems = ({ items, path, errorFactory }) => {
|
|
|
4254
4263
|
"tagIds",
|
|
4255
4264
|
"spriteGroups",
|
|
4256
4265
|
"shortcut",
|
|
4266
|
+
"nameVariableId",
|
|
4257
4267
|
"fileId",
|
|
4258
4268
|
"sprites",
|
|
4259
4269
|
],
|
|
@@ -4326,6 +4336,16 @@ const validateCharacterItems = ({ items, path, errorFactory }) => {
|
|
|
4326
4336
|
);
|
|
4327
4337
|
}
|
|
4328
4338
|
|
|
4339
|
+
if (
|
|
4340
|
+
item.nameVariableId !== undefined &&
|
|
4341
|
+
!isNonEmptyString(item.nameVariableId)
|
|
4342
|
+
) {
|
|
4343
|
+
return invalidFromErrorFactory(
|
|
4344
|
+
errorFactory,
|
|
4345
|
+
`${itemPath}.nameVariableId must be a non-empty string when provided`,
|
|
4346
|
+
);
|
|
4347
|
+
}
|
|
4348
|
+
|
|
4329
4349
|
if (item.fileId !== undefined && !isNonEmptyString(item.fileId)) {
|
|
4330
4350
|
return invalidFromErrorFactory(
|
|
4331
4351
|
errorFactory,
|
|
@@ -4781,6 +4801,13 @@ const applyCharacterUpdate = ({ currentItem, data }) => {
|
|
|
4781
4801
|
}
|
|
4782
4802
|
}
|
|
4783
4803
|
|
|
4804
|
+
if (
|
|
4805
|
+
Object.hasOwn(data, "nameVariableId") &&
|
|
4806
|
+
(data.nameVariableId === undefined || data.nameVariableId === "")
|
|
4807
|
+
) {
|
|
4808
|
+
delete nextItem.nameVariableId;
|
|
4809
|
+
}
|
|
4810
|
+
|
|
4784
4811
|
return nextItem;
|
|
4785
4812
|
};
|
|
4786
4813
|
|
|
@@ -6495,6 +6522,28 @@ const validateTransformPreviewImageReferences = ({
|
|
|
6495
6522
|
return VALID_RESULT;
|
|
6496
6523
|
};
|
|
6497
6524
|
|
|
6525
|
+
const validateStringVariableReference = ({
|
|
6526
|
+
state,
|
|
6527
|
+
variableId,
|
|
6528
|
+
path,
|
|
6529
|
+
details = {},
|
|
6530
|
+
errorFactory = createPreconditionValidationError,
|
|
6531
|
+
}) => {
|
|
6532
|
+
if (variableId === undefined || variableId === null || variableId === "") {
|
|
6533
|
+
return VALID_RESULT;
|
|
6534
|
+
}
|
|
6535
|
+
|
|
6536
|
+
if (!isStringVariableReferenceTarget(state, variableId)) {
|
|
6537
|
+
return invalidFromErrorFactory(
|
|
6538
|
+
errorFactory,
|
|
6539
|
+
`${path} must reference an existing string variable`,
|
|
6540
|
+
details,
|
|
6541
|
+
);
|
|
6542
|
+
}
|
|
6543
|
+
|
|
6544
|
+
return VALID_RESULT;
|
|
6545
|
+
};
|
|
6546
|
+
|
|
6498
6547
|
export const assertInvariants = ({ state }) => {
|
|
6499
6548
|
if (!isPlainObject(state)) {
|
|
6500
6549
|
return invalidInvariant("state must be an object");
|
|
@@ -6909,6 +6958,19 @@ export const assertInvariants = ({ state }) => {
|
|
|
6909
6958
|
}
|
|
6910
6959
|
}
|
|
6911
6960
|
|
|
6961
|
+
if (character.nameVariableId !== undefined) {
|
|
6962
|
+
const result = validateStringVariableReference({
|
|
6963
|
+
state,
|
|
6964
|
+
variableId: character.nameVariableId,
|
|
6965
|
+
path: "character.nameVariableId",
|
|
6966
|
+
details: { characterId, variableId: character.nameVariableId },
|
|
6967
|
+
errorFactory: createInvariantValidationError,
|
|
6968
|
+
});
|
|
6969
|
+
if (!result.valid) {
|
|
6970
|
+
return result;
|
|
6971
|
+
}
|
|
6972
|
+
}
|
|
6973
|
+
|
|
6912
6974
|
{
|
|
6913
6975
|
const result = validateTagIdsAgainstScope({
|
|
6914
6976
|
state,
|
|
@@ -10083,7 +10145,6 @@ const validateVariableCreateData = ({ data, errorFactory }) => {
|
|
|
10083
10145
|
value: data.tagIds,
|
|
10084
10146
|
path: "payload.data.tagIds",
|
|
10085
10147
|
errorFactory,
|
|
10086
|
-
allowEmpty: false,
|
|
10087
10148
|
});
|
|
10088
10149
|
if (result?.valid === false) {
|
|
10089
10150
|
return result;
|
|
@@ -10207,7 +10268,6 @@ const validateVariableUpdateData = ({ data, errorFactory }) => {
|
|
|
10207
10268
|
value: data.tagIds,
|
|
10208
10269
|
path: "payload.data.tagIds",
|
|
10209
10270
|
errorFactory,
|
|
10210
|
-
allowEmpty: false,
|
|
10211
10271
|
});
|
|
10212
10272
|
if (result?.valid === false) {
|
|
10213
10273
|
return result;
|
|
@@ -10641,6 +10701,7 @@ const validateCharacterCreateData = ({ data, errorFactory }) => {
|
|
|
10641
10701
|
"tagIds",
|
|
10642
10702
|
"spriteGroups",
|
|
10643
10703
|
"shortcut",
|
|
10704
|
+
"nameVariableId",
|
|
10644
10705
|
"fileId",
|
|
10645
10706
|
"sprites",
|
|
10646
10707
|
],
|
|
@@ -10696,6 +10757,16 @@ const validateCharacterCreateData = ({ data, errorFactory }) => {
|
|
|
10696
10757
|
);
|
|
10697
10758
|
}
|
|
10698
10759
|
|
|
10760
|
+
if (
|
|
10761
|
+
data.nameVariableId !== undefined &&
|
|
10762
|
+
!isNonEmptyString(data.nameVariableId)
|
|
10763
|
+
) {
|
|
10764
|
+
return invalidFromErrorFactory(
|
|
10765
|
+
errorFactory,
|
|
10766
|
+
"payload.data.nameVariableId must be a non-empty string when provided",
|
|
10767
|
+
);
|
|
10768
|
+
}
|
|
10769
|
+
|
|
10699
10770
|
if (data.fileId !== undefined && !isNonEmptyString(data.fileId)) {
|
|
10700
10771
|
return invalidFromErrorFactory(
|
|
10701
10772
|
errorFactory,
|
|
@@ -10737,6 +10808,7 @@ const validateCharacterUpdateData = ({ data, errorFactory }) => {
|
|
|
10737
10808
|
"tagIds",
|
|
10738
10809
|
"spriteGroups",
|
|
10739
10810
|
"shortcut",
|
|
10811
|
+
"nameVariableId",
|
|
10740
10812
|
"fileId",
|
|
10741
10813
|
],
|
|
10742
10814
|
path: "payload.data",
|
|
@@ -10775,6 +10847,17 @@ const validateCharacterUpdateData = ({ data, errorFactory }) => {
|
|
|
10775
10847
|
);
|
|
10776
10848
|
}
|
|
10777
10849
|
|
|
10850
|
+
if (
|
|
10851
|
+
data.nameVariableId !== undefined &&
|
|
10852
|
+
data.nameVariableId !== "" &&
|
|
10853
|
+
!isNonEmptyString(data.nameVariableId)
|
|
10854
|
+
) {
|
|
10855
|
+
return invalidFromErrorFactory(
|
|
10856
|
+
errorFactory,
|
|
10857
|
+
"payload.data.nameVariableId must be a non-empty string when provided",
|
|
10858
|
+
);
|
|
10859
|
+
}
|
|
10860
|
+
|
|
10778
10861
|
{
|
|
10779
10862
|
const result = validateOptionalUniqueIdArray({
|
|
10780
10863
|
value: data.tagIds,
|
|
@@ -11105,7 +11188,6 @@ const validateControlCreateData = ({ data, errorFactory }) => {
|
|
|
11105
11188
|
value: data.tagIds,
|
|
11106
11189
|
path: "payload.data.tagIds",
|
|
11107
11190
|
errorFactory,
|
|
11108
|
-
allowEmpty: false,
|
|
11109
11191
|
});
|
|
11110
11192
|
if (result?.valid === false) {
|
|
11111
11193
|
return result;
|
|
@@ -11239,7 +11321,6 @@ const validateControlUpdateData = ({ data, errorFactory }) => {
|
|
|
11239
11321
|
value: data.tagIds,
|
|
11240
11322
|
path: "payload.data.tagIds",
|
|
11241
11323
|
errorFactory,
|
|
11242
|
-
allowEmpty: false,
|
|
11243
11324
|
});
|
|
11244
11325
|
if (result?.valid === false) {
|
|
11245
11326
|
return result;
|
|
@@ -17076,6 +17157,10 @@ const COMMAND_DEFINITIONS = [
|
|
|
17076
17157
|
item.fileId = payload.data.fileId;
|
|
17077
17158
|
}
|
|
17078
17159
|
|
|
17160
|
+
if (payload.data.nameVariableId !== undefined) {
|
|
17161
|
+
item.nameVariableId = payload.data.nameVariableId;
|
|
17162
|
+
}
|
|
17163
|
+
|
|
17079
17164
|
assignOptionalTagIds({
|
|
17080
17165
|
target: item,
|
|
17081
17166
|
tagIds: payload.data.tagIds,
|
|
@@ -17116,6 +17201,21 @@ const COMMAND_DEFINITIONS = [
|
|
|
17116
17201
|
}
|
|
17117
17202
|
}
|
|
17118
17203
|
|
|
17204
|
+
{
|
|
17205
|
+
const result = validateStringVariableReference({
|
|
17206
|
+
state,
|
|
17207
|
+
variableId: payload.data.nameVariableId,
|
|
17208
|
+
path: "payload.data.nameVariableId",
|
|
17209
|
+
details: {
|
|
17210
|
+
characterId: payload.characterId,
|
|
17211
|
+
variableId: payload.data.nameVariableId,
|
|
17212
|
+
},
|
|
17213
|
+
});
|
|
17214
|
+
if (!result.valid) {
|
|
17215
|
+
return result;
|
|
17216
|
+
}
|
|
17217
|
+
}
|
|
17218
|
+
|
|
17119
17219
|
{
|
|
17120
17220
|
const result = validateTagIdsAgainstScope({
|
|
17121
17221
|
state,
|
|
@@ -17221,6 +17321,21 @@ const COMMAND_DEFINITIONS = [
|
|
|
17221
17321
|
return result;
|
|
17222
17322
|
}
|
|
17223
17323
|
|
|
17324
|
+
if (Object.hasOwn(payload.data, "nameVariableId")) {
|
|
17325
|
+
const variableResult = validateStringVariableReference({
|
|
17326
|
+
state,
|
|
17327
|
+
variableId: payload.data.nameVariableId,
|
|
17328
|
+
path: "payload.data.nameVariableId",
|
|
17329
|
+
details: {
|
|
17330
|
+
characterId: payload.characterId,
|
|
17331
|
+
variableId: payload.data.nameVariableId,
|
|
17332
|
+
},
|
|
17333
|
+
});
|
|
17334
|
+
if (!variableResult.valid) {
|
|
17335
|
+
return variableResult;
|
|
17336
|
+
}
|
|
17337
|
+
}
|
|
17338
|
+
|
|
17224
17339
|
{
|
|
17225
17340
|
const tagResult = validateTagIdsAgainstScope({
|
|
17226
17341
|
state,
|