@perplexdotgg/mecs 0.4.0 → 0.4.1

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/build/mecs.js +37 -15
  2. package/package.json +1 -1
package/build/mecs.js CHANGED
@@ -42,18 +42,8 @@ function getEntityClassCode(componentMap, queries, options) {
42
42
  `;
43
43
  componentFlags.push(componentFlagValue);
44
44
  componentFlagsCode += `${componentFlagValue}n, `;
45
- createFromDataCode += `
46
- if ('${componentKey}' in data) {
47
- this.addComponent('${componentKey}', data.${componentKey}, false);
48
- } else {
49
- this.${componentKey} = null;
50
- }
51
- `;
52
- createFromDataCodeAllNulls += `
53
- this.${componentKey} = null;
54
- `;
55
45
  destroyCode += `
56
- if ((thisComponentFlags & ${componentFlagValue}n) !== 0n) {
46
+ if ((this.componentFlags & ${componentFlagValue}n) !== 0n) {
57
47
  this.removeComponent('${componentKey}', updateQueryMemberships);
58
48
  }
59
49
  `;
@@ -229,9 +219,8 @@ function getEntityClassCode(componentMap, queries, options) {
229
219
  `;
230
220
  removeComponentFunctionsCode += `
231
221
  (instance, entity, componentKey, updateQueryMemberships) => {
232
- const newFlagValue = entity.componentFlags & ~${componentFlagValue}n;
233
222
  if (updateQueryMemberships) {
234
- entity.updateQueryMemberships(newFlagValue);
223
+ entity.updateQueryMemberships(entity.componentFlags & ~${componentFlagValue}n);
235
224
  }
236
225
 
237
226
  ${beforeComponentRemovedCode}
@@ -239,10 +228,28 @@ function getEntityClassCode(componentMap, queries, options) {
239
228
  ${componentKey}ComponentToEntity[instance.index] = null;
240
229
  instance.destroy();
241
230
 
242
- entity.componentFlags = newFlagValue;
231
+ ${""}
232
+ ${""}
233
+ entity.componentFlags = entity.componentFlags & ~${componentFlagValue}n;
243
234
  ${nullComponentCode};
244
235
  },
245
236
  `;
237
+ createFromDataCode += `
238
+ if ('${componentKey}' in data) {
239
+ if (this.hasComponent('${componentKey}')) {
240
+ this.${componentKey}.reset(data.${componentKey}, false);
241
+ } else {
242
+ this.addComponent('${componentKey}', data.${componentKey}, false);
243
+ }
244
+ } else if (!this.hasComponent('${componentKey}')) {
245
+ this.${componentKey} = null;
246
+ }
247
+ `;
248
+ createFromDataCodeAllNulls += `
249
+ if (!this.hasComponent('${componentKey}')) {
250
+ this.${componentKey} = null;
251
+ }
252
+ `;
246
253
  } else {
247
254
  addComponentFunctionsCode += `
248
255
  (data, entity, componentKey, updateQueryMemberships) => {
@@ -269,6 +276,22 @@ function getEntityClassCode(componentMap, queries, options) {
269
276
  ${nullComponentCode};
270
277
  },
271
278
  `;
279
+ createFromDataCode += `
280
+ if ('${componentKey}' in data) {
281
+ if (this.hasComponent('${componentKey}')) {
282
+ this.${componentKey} = data.${componentKey};
283
+ } else {
284
+ this.addComponent('${componentKey}', data.${componentKey}, false);
285
+ }
286
+ } else if (!this.hasComponent('${componentKey}')) {
287
+ this.${componentKey} = null;
288
+ }
289
+ `;
290
+ createFromDataCodeAllNulls += `
291
+ if (!this.hasComponent('${componentKey}')) {
292
+ this.${componentKey} = null;
293
+ }
294
+ `;
272
295
  }
273
296
  componentFlagValue <<= 1n;
274
297
  componentIndex++;
@@ -613,7 +636,6 @@ function getEntityClassCode(componentMap, queries, options) {
613
636
  }
614
637
 
615
638
  destroy(updateQueryMemberships = true) {
616
- const thisComponentFlags = this.componentFlags;
617
639
  ${destroyCode}
618
640
  if (this.version & 1 === 1) {
619
641
  ${""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perplexdotgg/mecs",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "MECS - Monomorph ECS - A high-performance Entity Component System for TypeScript and JavaScript projects, designed for games and simulations.",
5
5
  "repository": {
6
6
  "type": "git",