@dcl/ecs 7.0.6-4124638014.commit-0cffdf7 → 7.0.6-4138167187.commit-c9d306a
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/engine/entity.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createVersionGSet } from '@dcl/crdt/dist/gset';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
@@ -64,7 +64,7 @@ export function EntityContainer() {
|
|
|
64
64
|
let entityCounter = RESERVED_STATIC_ENTITIES;
|
|
65
65
|
const usedEntities = new Set();
|
|
66
66
|
let toRemoveEntities = [];
|
|
67
|
-
const removedEntities =
|
|
67
|
+
const removedEntities = createVersionGSet();
|
|
68
68
|
function generateNewEntity() {
|
|
69
69
|
if (entityCounter > MAX_ENTITY_NUMBER - 1) {
|
|
70
70
|
throw new Error(`It fails trying to generate an entity out of range ${MAX_ENTITY_NUMBER}.`);
|
|
@@ -1,16 +1,69 @@
|
|
|
1
|
+
import { Int32 } from './Integer';
|
|
2
|
+
import { FlatString } from './String';
|
|
3
|
+
/**
|
|
4
|
+
* Validates the enum to ensure all member values are numbers and within the range of Int32.
|
|
5
|
+
* @param enumValue The enum to be checked.
|
|
6
|
+
* @throws If any member value is not a number or is outside the range of Int32.
|
|
7
|
+
*/
|
|
8
|
+
function validateMemberValuesAreNumbersAndInRangeInt32(enumValue) {
|
|
9
|
+
const MIN_VALUE = -(2 ** 31), MAX_VALUE = 2 ** 31 - 1;
|
|
10
|
+
let valueCount = 0, totalCount = 0;
|
|
11
|
+
for (const key in enumValue) {
|
|
12
|
+
if (typeof enumValue[key] === 'number') {
|
|
13
|
+
if (enumValue[key] > MAX_VALUE || enumValue[key] < MIN_VALUE) {
|
|
14
|
+
throw new Error(`Enum member values must be numbers within the range of ${MIN_VALUE} to ${MAX_VALUE}.`);
|
|
15
|
+
}
|
|
16
|
+
valueCount++;
|
|
17
|
+
}
|
|
18
|
+
totalCount++;
|
|
19
|
+
}
|
|
20
|
+
if (totalCount !== valueCount * 2) {
|
|
21
|
+
throw new Error('All enum member values must be of numeric type.');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validates the enum to ensure all member values are of string type.
|
|
26
|
+
* @param enumValue The enum to be checked.
|
|
27
|
+
* @throws If any member value is not of string type.
|
|
28
|
+
*/
|
|
29
|
+
function validateMemberValuesAreStrings(enumValue) {
|
|
30
|
+
for (const key in enumValue) {
|
|
31
|
+
if (typeof enumValue[key] !== 'string') {
|
|
32
|
+
throw new Error('All enum member values must be of string type.');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export const IntEnum = (enumObject, defaultValue) => {
|
|
40
|
+
validateMemberValuesAreNumbersAndInRangeInt32(enumObject);
|
|
41
|
+
return {
|
|
42
|
+
serialize(value, builder) {
|
|
43
|
+
Int32.serialize(value, builder);
|
|
44
|
+
},
|
|
45
|
+
deserialize(reader) {
|
|
46
|
+
return Int32.deserialize(reader);
|
|
47
|
+
},
|
|
48
|
+
create() {
|
|
49
|
+
return defaultValue;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
1
53
|
/**
|
|
2
54
|
* @internal
|
|
3
55
|
*/
|
|
4
|
-
export const
|
|
56
|
+
export const StringEnum = (enumObject, defaultValue) => {
|
|
57
|
+
validateMemberValuesAreStrings(enumObject);
|
|
5
58
|
return {
|
|
6
59
|
serialize(value, builder) {
|
|
7
|
-
|
|
60
|
+
FlatString.serialize(value, builder);
|
|
8
61
|
},
|
|
9
62
|
deserialize(reader) {
|
|
10
|
-
return
|
|
63
|
+
return FlatString.deserialize(reader);
|
|
11
64
|
},
|
|
12
65
|
create() {
|
|
13
|
-
return
|
|
66
|
+
return defaultValue;
|
|
14
67
|
}
|
|
15
68
|
};
|
|
16
69
|
};
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -40,7 +40,9 @@ export declare namespace Schemas {
|
|
|
40
40
|
/** @public */
|
|
41
41
|
const Entity: ISchema<Entity>;
|
|
42
42
|
/** @public */
|
|
43
|
-
const
|
|
43
|
+
const EnumNumber: <T>(enumObject: Record<any, any>, defaultValue: T) => ISchema<T>;
|
|
44
|
+
/** @public */
|
|
45
|
+
const EnumString: <T>(enumObject: Record<any, any>, defaultValue: T) => ISchema<T>;
|
|
44
46
|
/** @public */
|
|
45
47
|
const Array: <T>(type: ISchema<T>) => ISchema<T[]>;
|
|
46
48
|
/** @public */
|
package/dist/schemas/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IArray } from './Array';
|
|
2
2
|
import { Bool } from './basic/Boolean';
|
|
3
|
-
import {
|
|
3
|
+
import { IntEnum as IntEnumSchema, StringEnum as StringEnumSchema } from './basic/Enum';
|
|
4
4
|
import { Float32, Float64 } from './basic/Float';
|
|
5
5
|
import { Int16, Int32, Int8, Int64 as iInt64 } from './basic/Integer';
|
|
6
6
|
import { EcsString } from './basic/String';
|
|
@@ -45,7 +45,9 @@ export var Schemas;
|
|
|
45
45
|
/** @public */
|
|
46
46
|
Schemas.Entity = EntitySchema;
|
|
47
47
|
/** @public */
|
|
48
|
-
Schemas.
|
|
48
|
+
Schemas.EnumNumber = IntEnumSchema;
|
|
49
|
+
/** @public */
|
|
50
|
+
Schemas.EnumString = StringEnumSchema;
|
|
49
51
|
/** @public */
|
|
50
52
|
Schemas.Array = IArray;
|
|
51
53
|
/** @public */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/ecs",
|
|
3
|
-
"version": "7.0.6-
|
|
3
|
+
"version": "7.0.6-4138167187.commit-c9d306a",
|
|
4
4
|
"description": "Decentraland ECS",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"ts-proto": "^1.112.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@dcl/crdt": "7.0.6-
|
|
30
|
+
"@dcl/crdt": "7.0.6-4138167187.commit-c9d306a",
|
|
31
31
|
"@dcl/js-runtime": "file:../js-runtime",
|
|
32
32
|
"@dcl/protocol": "1.0.0-4114477251.commit-ccb88d6"
|
|
33
33
|
},
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"displayName": "ECS",
|
|
42
42
|
"tsconfig": "./tsconfig.json"
|
|
43
43
|
},
|
|
44
|
-
"commit": "
|
|
44
|
+
"commit": "c9d306af4a8af8d3cf0f7da983300be92d6b3bc8"
|
|
45
45
|
}
|