@routevn/creator-model 1.3.2 → 1.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/model.js +100 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routevn/creator-model",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/model.js CHANGED
@@ -40,6 +40,7 @@ const LINE_UPDATE_ACTIONS_PRESERVE_PATHS = ["dialogue.content"];
40
40
  const LINE_UPDATE_ACTIONS_PRESERVE_PATHS_SET = new Set(
41
41
  LINE_UPDATE_ACTIONS_PRESERVE_PATHS,
42
42
  );
43
+ const isPositiveFiniteNumber = (value) => isFiniteNumber(value) && value > 0;
43
44
  const createEmptyCollectionState = () => ({
44
45
  items: {},
45
46
  tree: [],
@@ -973,7 +974,7 @@ const validateSpritesheetAnimationMap = ({
973
974
  {
974
975
  const result = validateAllowedKeys({
975
976
  value: animation,
976
- allowedKeys: ["frames", "animationSpeed", "loop"],
977
+ allowedKeys: ["frames", "animationSpeed", "fps", "loop"],
977
978
  path: animationPath,
978
979
  errorFactory,
979
980
  });
@@ -1009,6 +1010,16 @@ const validateSpritesheetAnimationMap = ({
1009
1010
  );
1010
1011
  }
1011
1012
 
1013
+ if (
1014
+ animation.fps !== undefined &&
1015
+ !isPositiveFiniteNumber(animation.fps)
1016
+ ) {
1017
+ return invalidFromErrorFactory(
1018
+ errorFactory,
1019
+ `${animationPath}.fps must be a positive finite number when provided`,
1020
+ );
1021
+ }
1022
+
1012
1023
  if (animation.loop !== undefined && typeof animation.loop !== "boolean") {
1013
1024
  return invalidFromErrorFactory(
1014
1025
  errorFactory,
@@ -2395,6 +2406,7 @@ const validateParticleItems = ({ items, path, errorFactory }) => {
2395
2406
  "height",
2396
2407
  "seed",
2397
2408
  "modules",
2409
+ "thumbnailFileId",
2398
2410
  ],
2399
2411
  path: itemPath,
2400
2412
  errorFactory,
@@ -2469,6 +2481,16 @@ const validateParticleItems = ({ items, path, errorFactory }) => {
2469
2481
  );
2470
2482
  }
2471
2483
 
2484
+ if (
2485
+ item.thumbnailFileId !== undefined &&
2486
+ !isNonEmptyString(item.thumbnailFileId)
2487
+ ) {
2488
+ return invalidFromErrorFactory(
2489
+ errorFactory,
2490
+ `${itemPath}.thumbnailFileId must be a non-empty string when provided`,
2491
+ );
2492
+ }
2493
+
2472
2494
  {
2473
2495
  const result = validateParticleModules({
2474
2496
  modules: item.modules,
@@ -6200,6 +6222,19 @@ export const assertInvariants = ({ state }) => {
6200
6222
  continue;
6201
6223
  }
6202
6224
 
6225
+ if (particle.thumbnailFileId !== undefined) {
6226
+ const result = validateFileReference({
6227
+ state,
6228
+ fileId: particle.thumbnailFileId,
6229
+ path: "particle.thumbnailFileId",
6230
+ details: { particleId, thumbnailFileId: particle.thumbnailFileId },
6231
+ errorFactory: createInvariantValidationError,
6232
+ });
6233
+ if (!result.valid) {
6234
+ return result;
6235
+ }
6236
+ }
6237
+
6203
6238
  {
6204
6239
  const result = validateTagIdsAgainstScope({
6205
6240
  state,
@@ -8764,6 +8799,7 @@ const validateParticleCreateData = ({ data, errorFactory }) => {
8764
8799
  "height",
8765
8800
  "seed",
8766
8801
  "modules",
8802
+ "thumbnailFileId",
8767
8803
  ],
8768
8804
  path: "payload.data",
8769
8805
  errorFactory,
@@ -8791,6 +8827,16 @@ const validateParticleCreateData = ({ data, errorFactory }) => {
8791
8827
  return;
8792
8828
  }
8793
8829
 
8830
+ if (
8831
+ data.thumbnailFileId !== undefined &&
8832
+ !isNonEmptyString(data.thumbnailFileId)
8833
+ ) {
8834
+ return invalidFromErrorFactory(
8835
+ errorFactory,
8836
+ "payload.data.thumbnailFileId must be a non-empty string when provided",
8837
+ );
8838
+ }
8839
+
8794
8840
  {
8795
8841
  const result = validateOptionalUniqueIdArray({
8796
8842
  value: data.tagIds,
@@ -8851,6 +8897,7 @@ const validateParticleUpdateData = ({ data, errorFactory }) => {
8851
8897
  "height",
8852
8898
  "seed",
8853
8899
  "modules",
8900
+ "thumbnailFileId",
8854
8901
  ],
8855
8902
  path: "payload.data",
8856
8903
  errorFactory,
@@ -8881,6 +8928,16 @@ const validateParticleUpdateData = ({ data, errorFactory }) => {
8881
8928
  );
8882
8929
  }
8883
8930
 
8931
+ if (
8932
+ data.thumbnailFileId !== undefined &&
8933
+ !isNonEmptyString(data.thumbnailFileId)
8934
+ ) {
8935
+ return invalidFromErrorFactory(
8936
+ errorFactory,
8937
+ "payload.data.thumbnailFileId must be a non-empty string when provided",
8938
+ );
8939
+ }
8940
+
8884
8941
  {
8885
8942
  const result = validateOptionalUniqueIdArray({
8886
8943
  value: data.tagIds,
@@ -11263,6 +11320,20 @@ const findReferencedFileUsage = ({ state, fileId }) => {
11263
11320
  }
11264
11321
  }
11265
11322
 
11323
+ for (const [particleId, particle] of Object.entries(state.particles.items)) {
11324
+ if (particle.type !== "particle") {
11325
+ continue;
11326
+ }
11327
+
11328
+ if (particle.thumbnailFileId === fileId) {
11329
+ return {
11330
+ kind: "particle",
11331
+ field: "thumbnailFileId",
11332
+ ownerId: particleId,
11333
+ };
11334
+ }
11335
+ }
11336
+
11266
11337
  return null;
11267
11338
  };
11268
11339
 
@@ -15366,6 +15437,10 @@ const COMMAND_DEFINITIONS = [
15366
15437
  item.seed = payload.data.seed;
15367
15438
  }
15368
15439
 
15440
+ if (payload.data.thumbnailFileId !== undefined) {
15441
+ item.thumbnailFileId = payload.data.thumbnailFileId;
15442
+ }
15443
+
15369
15444
  return item;
15370
15445
  },
15371
15446
  updateItem: ({ currentItem, payload }) => {
@@ -15393,6 +15468,18 @@ const COMMAND_DEFINITIONS = [
15393
15468
  }
15394
15469
 
15395
15470
  if (currentItem.type === "particle") {
15471
+ const fileResult = validateReferencedFilesInData({
15472
+ state,
15473
+ data: payload.data,
15474
+ fields: ["thumbnailFileId"],
15475
+ details: {
15476
+ particleId: payload.particleId,
15477
+ },
15478
+ });
15479
+ if (!fileResult.valid) {
15480
+ return fileResult;
15481
+ }
15482
+
15396
15483
  return validateTagIdsAgainstScope({
15397
15484
  state,
15398
15485
  tagIds: payload.data.tagIds,
@@ -15409,6 +15496,18 @@ const COMMAND_DEFINITIONS = [
15409
15496
  return;
15410
15497
  }
15411
15498
 
15499
+ const fileResult = validateReferencedFilesInData({
15500
+ state,
15501
+ data: payload.data,
15502
+ fields: ["thumbnailFileId"],
15503
+ details: {
15504
+ particleId: payload.particleId,
15505
+ },
15506
+ });
15507
+ if (!fileResult.valid) {
15508
+ return fileResult;
15509
+ }
15510
+
15412
15511
  return validateTagIdsAgainstScope({
15413
15512
  state,
15414
15513
  tagIds: payload.data.tagIds,