squishjs 0.7.2 → 0.7.3

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/Squisher.js +18 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squishjs",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "description": "squish & unsquish stuff",
5
5
  "scripts": {
6
6
  "test": "node testRunner.js"
package/src/Squisher.js CHANGED
@@ -19,7 +19,7 @@ class Squisher {
19
19
  this.listeners = new Set();
20
20
  this.scale = scale || {x: 1, y: 1};
21
21
  this.state = this.squish(this.game.getLayers());
22
- this.spectatorState = this.game.getSpectatorLayers ? this.squish(this.game.getSpectatorLayers()) : [];
22
+ // this.spectatorState = this.game.getSpectatorLayers ? this.squish(this.game.getSpectatorLayers()) : [];
23
23
  this.assets = {};
24
24
  if (this.game.tick) {
25
25
  const tickRate = this.gameMetadata && this.gameMetadata.tickRate ? this.gameMetadata.tickRate : DEFAULT_TICK_RATE;
@@ -80,7 +80,7 @@ class Squisher {
80
80
  }
81
81
 
82
82
 
83
- if (this.customTopLayer) {
83
+ if (this.customTopLayer) {
84
84
  const squishedLayer = [];
85
85
  this.squishHelper(this.customTopLayer.root, squishedLayer, this.customTopLayer.scale, playerMap);
86
86
  toSquish.push(squishedLayer);
@@ -95,7 +95,7 @@ class Squisher {
95
95
  return this.playerFrames[playerId];
96
96
  }
97
97
 
98
- squishHelper(node, squishedNodes, scale = {x: 1, y: 1}, playerMap = {}) {
98
+ squishHelper(node, squishedNodes, scale = {x: 1, y: 1}, playerMap = {}, playerIdFilter = new Set()) {
99
99
  if (!node.node.listeners.has(this)) {
100
100
  node.addListener(this);
101
101
  }
@@ -103,24 +103,29 @@ class Squisher {
103
103
  const squished = squish(node, scale);
104
104
  squishedNodes.push(squished);
105
105
 
106
- if (playerMap) {
107
- if (node.node.playerIds && node.node.playerIds.length) {
108
- node.node.playerIds.forEach(playerId => {
106
+ if (node.node.playerIds && node.node.playerIds.length > 0) {
107
+ node.node.playerIds.forEach(pId => playerIdFilter.add(pId));
108
+ }
109
+
110
+ if (playerIdFilter.size > 0) {
111
+ for (let playerId of playerIdFilter) {
109
112
  if (playerMap[playerId]) {
110
113
  playerMap[playerId].push(squished);
111
114
  } else {
112
115
  console.warn(`Node references unknown player ID: ${playerId}`);
113
116
  }
114
- });
115
- } else {
116
- Object.keys(playerMap).forEach(playerId => {
117
- playerMap[playerId].push(squished);
118
- })
119
- }
117
+ }
118
+ } else {
119
+ Object.keys(playerMap).forEach(playerId => {
120
+ playerMap[playerId].push(squished);
121
+ })
120
122
  }
121
123
 
122
124
  for (let i = 0; i < node.node.children.length; i++) {
123
- this.squishHelper(node.node.children[i], squishedNodes, scale, playerMap);
125
+ // make a new set so child calls within a single generation arent
126
+ // modifying the same filter set
127
+ const pathFilter = new Set(playerIdFilter);
128
+ this.squishHelper(node.node.children[i], squishedNodes, scale, playerMap, pathFilter);
124
129
  }
125
130
 
126
131
  }