@woosh/meep-engine 2.92.19 → 2.92.21

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
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.92.19",
8
+ "version": "2.92.21",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1 +1 @@
1
- {"version":3,"file":"DataViewStructAccessor.d.ts","sourceRoot":"","sources":["../../../../../src/core/binary/data_view/DataViewStructAccessor.js"],"names":[],"mappings":"AAOA;IAiBI;;;;OAIG;IACH,yCAFW,OAAO,EAiCjB;IApDD;;OAEG;IACH,OAFU,QAAQ,CAEZ;IAEN;;OAEG;IACH,SAFU,MAAM,CAEJ;IAEZ;;;OAGG;IACH,4BAFU,MAAM,CAEM;IAwCtB;;;OAGG;IACH,qCAEC;IAED;;;;OAIG;IACH,gBAHW,QAAQ,eACR,MAAM,QAKhB;IAED;;;;OAIG;IACH,yBAHW,QAAQ,SACR,MAAM,QAKhB;CACJ"}
1
+ {"version":3,"file":"DataViewStructAccessor.d.ts","sourceRoot":"","sources":["../../../../../src/core/binary/data_view/DataViewStructAccessor.js"],"names":[],"mappings":"AAGA;IAiBI;;;;OAIG;IACH,yCAFW,OAAO,EAYjB;IA/BD;;OAEG;IACH,OAFU,QAAQ,CAEZ;IAEN;;OAEG;IACH,SAFU,MAAM,CAEJ;IAEZ;;;OAGG;IACH,4BAFU,MAAM,CAEM;IAmBtB;;;OAGG;IACH,qCAEC;IAED;;;;OAIG;IACH,gBAHW,QAAQ,eACR,MAAM,QAKhB;IAED;;;;OAIG;IACH,yBAHW,QAAQ,SACR,MAAM,QAKhB;CACJ"}
@@ -1,9 +1,5 @@
1
- import { assert } from "../../assert.js";
2
- import { FunctionCompiler } from "../../function/FunctionCompiler.js";
3
1
  import { BinaryDataType } from "../type/BinaryDataType.js";
4
- import { DataTypeByteSizes } from "../type/DataTypeByteSizes.js";
5
- import { DataType2DataViewReaders } from "./DataType2DataViewReaders.js";
6
- import { DataType2DataViewWriters } from "./DataType2DataViewWriters.js";
2
+ import { buildAccessor } from "./buildAccessor.js";
7
3
 
8
4
  export class DataViewStructAccessor {
9
5
  /**
@@ -28,36 +24,15 @@ export class DataViewStructAccessor {
28
24
  * @param {boolean} [little_endian]
29
25
  */
30
26
  constructor(schema, little_endian = false) {
31
- assert.defined(schema, 'schema');
32
- assert.isBoolean(little_endian, 'little_endian');
33
27
 
34
- const props = Object.keys(schema);
35
- const property_count = props.length;
28
+ this.$record_byte_size = buildAccessor({
29
+ schema,
30
+ target: this,
31
+ data_variable_name: "this.$data",
32
+ offset_variable_name: "this.$offset",
33
+ little_endian
34
+ });
36
35
 
37
- let offset = 0;
38
- for (let i = 0; i < property_count; i++) {
39
- const property = props[i];
40
- const type = schema[property];
41
-
42
- assert.enum(type, BinaryDataType, "type");
43
-
44
- assert.arrayHasNo(["bind", "$data", "$offset", "this", "constructor", "get", "set"], property, `Illegal property name ${property}`);
45
-
46
- //
47
- Object.defineProperty(this, property, {
48
- get: FunctionCompiler.INSTANCE.compile({
49
- code: `return this.$data.${DataType2DataViewReaders[type]}(this.$offset + ${offset}, ${little_endian})`
50
- }),
51
- set: FunctionCompiler.INSTANCE.compile({
52
- args: ["value"],
53
- code: `this.$data.${DataType2DataViewWriters[type]}(this.$offset + ${offset}, value, ${little_endian})`
54
- })
55
- })
56
-
57
- offset += DataTypeByteSizes[type];
58
- }
59
-
60
- this.$record_byte_size = offset;
61
36
  }
62
37
 
63
38
  /**
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @param {Object} param
3
+ * @param {Object<BinaryDataType>} param.schema
4
+ * @param {Object} param.target
5
+ * @param {string} [param.data_variable_name]
6
+ * @param {string} [param.offset_variable_name]
7
+ * @param {boolean} [param.little_endian]
8
+ * @return {number}
9
+ */
10
+ export function buildAccessor({ schema, target, data_variable_name, offset_variable_name, little_endian }: {
11
+ schema: any;
12
+ target: any;
13
+ data_variable_name?: string;
14
+ offset_variable_name?: string;
15
+ little_endian?: boolean;
16
+ }): number;
17
+ //# sourceMappingURL=buildAccessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildAccessor.d.ts","sourceRoot":"","sources":["../../../../../src/core/binary/data_view/buildAccessor.js"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH;IAPyC,MAAM;IACtB,MAAM;IACL,kBAAkB,GAAjC,MAAM;IACS,oBAAoB,GAAnC,MAAM;IACU,aAAa,GAA7B,OAAO;IACN,MAAM,CA8CjB"}
@@ -0,0 +1,61 @@
1
+ import { assert } from "../../assert.js";
2
+ import { FunctionCompiler } from "../../function/FunctionCompiler.js";
3
+ import { BinaryDataType } from "../type/BinaryDataType.js";
4
+ import { DataTypeByteSizes } from "../type/DataTypeByteSizes.js";
5
+ import { DataType2DataViewReaders } from "./DataType2DataViewReaders.js";
6
+ import { DataType2DataViewWriters } from "./DataType2DataViewWriters.js";
7
+
8
+ /**
9
+ * @param {Object} param
10
+ * @param {Object<BinaryDataType>} param.schema
11
+ * @param {Object} param.target
12
+ * @param {string} [param.data_variable_name]
13
+ * @param {string} [param.offset_variable_name]
14
+ * @param {boolean} [param.little_endian]
15
+ * @return {number}
16
+ */
17
+ export function buildAccessor({
18
+ schema,
19
+ target,
20
+ data_variable_name = "this.$data",
21
+ offset_variable_name = "this.$offset",
22
+ little_endian = false
23
+ }) {
24
+
25
+ assert.defined(schema, 'schema');
26
+ assert.isBoolean(little_endian, 'little_endian');
27
+
28
+ assert.isString(data_variable_name, 'data_variable_name')
29
+ assert.isString(offset_variable_name, 'offset_variable_name')
30
+
31
+ assert.defined(target, 'target');
32
+ assert.notNull(target, 'target');
33
+
34
+ const props = Object.keys(schema);
35
+ const property_count = props.length;
36
+
37
+ let offset = 0;
38
+ for (let i = 0; i < property_count; i++) {
39
+ const property = props[i];
40
+ const type = schema[property];
41
+
42
+ assert.enum(type, BinaryDataType, "type");
43
+
44
+ assert.arrayHasNo(["bind", "$data", "$offset", "this", "constructor", "get", "set"], property, `Illegal property name ${property}`);
45
+
46
+ //
47
+ Object.defineProperty(target, property, {
48
+ get: FunctionCompiler.INSTANCE.compile({
49
+ code: `return ${data_variable_name}.${DataType2DataViewReaders[type]}(${offset_variable_name} + ${offset}, ${little_endian})`
50
+ }),
51
+ set: FunctionCompiler.INSTANCE.compile({
52
+ args: ["value"],
53
+ code: `${data_variable_name}.${DataType2DataViewWriters[type]}(${offset_variable_name} + ${offset}, value, ${little_endian})`
54
+ })
55
+ })
56
+
57
+ offset += DataTypeByteSizes[type];
58
+ }
59
+
60
+ return offset;
61
+ }