@dcl/playground-assets 7.0.6-4116376172.commit-af09ca7 → 7.0.6-4137912823.commit-aa69b28

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/dist/alpha.d.ts CHANGED
@@ -4330,7 +4330,9 @@ export declare namespace Schemas {
4330
4330
  /** @public */
4331
4331
  const Entity: ISchema<Entity>;
4332
4332
  /** @public */
4333
- const Enum: <T>(type: ISchema<any>) => ISchema<T>;
4333
+ const EnumNumber: <T>(enumObject: Record<any, any>, defaultValue: T) => ISchema<T>;
4334
+ /** @public */
4335
+ const EnumString: <T>(enumObject: Record<any, any>, defaultValue: T) => ISchema<T>;
4334
4336
  /** @public */
4335
4337
  const Array: <T>(type: ISchema<T>) => ISchema<T[]>;
4336
4338
  /** @public */
package/dist/beta.d.ts CHANGED
@@ -4326,7 +4326,9 @@ export declare namespace Schemas {
4326
4326
  /** @public */
4327
4327
  const Entity: ISchema<Entity>;
4328
4328
  /** @public */
4329
- const Enum: <T>(type: ISchema<any>) => ISchema<T>;
4329
+ const EnumNumber: <T>(enumObject: Record<any, any>, defaultValue: T) => ISchema<T>;
4330
+ /** @public */
4331
+ const EnumString: <T>(enumObject: Record<any, any>, defaultValue: T) => ISchema<T>;
4330
4332
  /** @public */
4331
4333
  const Array: <T>(type: ISchema<T>) => ISchema<T[]>;
4332
4334
  /** @public */
@@ -4326,7 +4326,9 @@ export declare namespace Schemas {
4326
4326
  /** @public */
4327
4327
  const Entity: ISchema<Entity>;
4328
4328
  /** @public */
4329
- const Enum: <T>(type: ISchema<any>) => ISchema<T>;
4329
+ const EnumNumber: <T>(enumObject: Record<any, any>, defaultValue: T) => ISchema<T>;
4330
+ /** @public */
4331
+ const EnumString: <T>(enumObject: Record<any, any>, defaultValue: T) => ISchema<T>;
4330
4332
  /** @public */
4331
4333
  const Array: <T>(type: ISchema<T>) => ISchema<T[]>;
4332
4334
  /** @public */
package/dist/index.js CHANGED
@@ -13286,52 +13286,6 @@
13286
13286
  }
13287
13287
  };
13288
13288
 
13289
- /**
13290
- * @internal
13291
- */
13292
- const IEnum = (type) => {
13293
- return {
13294
- serialize(value, builder) {
13295
- type.serialize(value, builder);
13296
- },
13297
- deserialize(reader) {
13298
- return type.deserialize(reader);
13299
- },
13300
- create() {
13301
- return type.create();
13302
- }
13303
- };
13304
- };
13305
-
13306
- /**
13307
- * @internal
13308
- */
13309
- const Float32 = {
13310
- serialize(value, builder) {
13311
- builder.writeFloat32(value);
13312
- },
13313
- deserialize(reader) {
13314
- return reader.readFloat32();
13315
- },
13316
- create() {
13317
- return 0.0;
13318
- }
13319
- };
13320
- /**
13321
- * @internal
13322
- */
13323
- const Float64 = {
13324
- serialize(value, builder) {
13325
- builder.writeFloat64(value);
13326
- },
13327
- deserialize(reader) {
13328
- return reader.readFloat64();
13329
- },
13330
- create() {
13331
- return 0.0;
13332
- }
13333
- };
13334
-
13335
13289
  /**
13336
13290
  * @internal
13337
13291
  */
@@ -13408,6 +13362,103 @@
13408
13362
  */
13409
13363
  const EcsString = FlatString;
13410
13364
 
13365
+ /**
13366
+ * Validates the enum to ensure all member values are numbers and within the range of Int32.
13367
+ * @param enumValue The enum to be checked.
13368
+ * @throws If any member value is not a number or is outside the range of Int32.
13369
+ */
13370
+ function validateMemberValuesAreNumbersAndInRangeInt32(enumValue) {
13371
+ const MIN_VALUE = -(2 ** 31), MAX_VALUE = 2 ** 31 - 1;
13372
+ let valueCount = 0, totalCount = 0;
13373
+ for (const key in enumValue) {
13374
+ if (typeof enumValue[key] === 'number') {
13375
+ if (enumValue[key] > MAX_VALUE || enumValue[key] < MIN_VALUE) {
13376
+ throw new Error(`Enum member values must be numbers within the range of ${MIN_VALUE} to ${MAX_VALUE}.`);
13377
+ }
13378
+ valueCount++;
13379
+ }
13380
+ totalCount++;
13381
+ }
13382
+ if (totalCount !== valueCount * 2) {
13383
+ throw new Error('All enum member values must be of numeric type.');
13384
+ }
13385
+ }
13386
+ /**
13387
+ * Validates the enum to ensure all member values are of string type.
13388
+ * @param enumValue The enum to be checked.
13389
+ * @throws If any member value is not of string type.
13390
+ */
13391
+ function validateMemberValuesAreStrings(enumValue) {
13392
+ for (const key in enumValue) {
13393
+ if (typeof enumValue[key] !== 'string') {
13394
+ throw new Error('All enum member values must be of string type.');
13395
+ }
13396
+ }
13397
+ }
13398
+ /**
13399
+ * @internal
13400
+ */
13401
+ const IntEnum = (enumObject, defaultValue) => {
13402
+ validateMemberValuesAreNumbersAndInRangeInt32(enumObject);
13403
+ return {
13404
+ serialize(value, builder) {
13405
+ Int32.serialize(value, builder);
13406
+ },
13407
+ deserialize(reader) {
13408
+ return Int32.deserialize(reader);
13409
+ },
13410
+ create() {
13411
+ return defaultValue;
13412
+ }
13413
+ };
13414
+ };
13415
+ /**
13416
+ * @internal
13417
+ */
13418
+ const StringEnum = (enumObject, defaultValue) => {
13419
+ validateMemberValuesAreStrings(enumObject);
13420
+ return {
13421
+ serialize(value, builder) {
13422
+ FlatString.serialize(value, builder);
13423
+ },
13424
+ deserialize(reader) {
13425
+ return FlatString.deserialize(reader);
13426
+ },
13427
+ create() {
13428
+ return defaultValue;
13429
+ }
13430
+ };
13431
+ };
13432
+
13433
+ /**
13434
+ * @internal
13435
+ */
13436
+ const Float32 = {
13437
+ serialize(value, builder) {
13438
+ builder.writeFloat32(value);
13439
+ },
13440
+ deserialize(reader) {
13441
+ return reader.readFloat32();
13442
+ },
13443
+ create() {
13444
+ return 0.0;
13445
+ }
13446
+ };
13447
+ /**
13448
+ * @internal
13449
+ */
13450
+ const Float64 = {
13451
+ serialize(value, builder) {
13452
+ builder.writeFloat64(value);
13453
+ },
13454
+ deserialize(reader) {
13455
+ return reader.readFloat64();
13456
+ },
13457
+ create() {
13458
+ return 0.0;
13459
+ }
13460
+ };
13461
+
13411
13462
  /**
13412
13463
  * @internal
13413
13464
  */
@@ -13605,7 +13656,9 @@
13605
13656
  /** @public */
13606
13657
  Schemas.Entity = EntitySchema;
13607
13658
  /** @public */
13608
- Schemas.Enum = IEnum;
13659
+ Schemas.EnumNumber = IntEnum;
13660
+ /** @public */
13661
+ Schemas.EnumString = StringEnum;
13609
13662
  /** @public */
13610
13663
  Schemas.Array = IArray;
13611
13664
  /** @public */