squishjs 0.7.3 → 0.7.4

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squishjs",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "squish & unsquish stuff",
5
5
  "scripts": {
6
6
  "test": "node testRunner.js"
package/src/Game.js CHANGED
@@ -1,18 +1,9 @@
1
1
  class Game {
2
2
  constructor() {
3
- this.players = {};
4
- this.spectators = {};
5
3
  this.listeners = new Set();
6
4
  this.intervals = [];
7
5
  this.timeouts = [];
8
- }
9
-
10
- _hgAddPlayer(player) {
11
- this.players[player.id] = player;
12
- }
13
-
14
- _hgRemovePlayer(playerId) {
15
- delete this.players[playerId];
6
+ this.playerInfoMap = {};
16
7
  }
17
8
 
18
9
  addStateListener(listener) {
package/src/Squisher.js CHANGED
@@ -45,7 +45,7 @@ class Squisher {
45
45
  }
46
46
 
47
47
  squish(layers, scale = null) {
48
-
48
+
49
49
  if (!layers) {
50
50
  return [];
51
51
  }
@@ -56,10 +56,6 @@ class Squisher {
56
56
 
57
57
  const playerMap = {};
58
58
 
59
- Object.keys(this.game.players).forEach(playerId => {
60
- playerMap[Number(playerId)] = [];
61
- });
62
-
63
59
  if (this.customBottomLayer) {
64
60
  const squishedLayer = [];
65
61
  this.squishHelper(this.customBottomLayer.root, squishedLayer, this.customBottomLayer.scale, playerMap);
@@ -109,14 +105,17 @@ class Squisher {
109
105
 
110
106
  if (playerIdFilter.size > 0) {
111
107
  for (let playerId of playerIdFilter) {
112
- if (playerMap[playerId]) {
113
- playerMap[playerId].push(squished);
114
- } else {
115
- console.warn(`Node references unknown player ID: ${playerId}`);
116
- }
117
- }
108
+ if (!playerMap[playerId]) {
109
+ playerMap[Number(playerId)] = [];
110
+ }
111
+
112
+ playerMap[playerId].push(squished);
113
+ }
118
114
  } else {
119
115
  Object.keys(playerMap).forEach(playerId => {
116
+ if (!playerMap[playerId]) {
117
+ playerMap[Number(playerId)] = [];
118
+ }
120
119
  playerMap[playerId].push(squished);
121
120
  })
122
121
  }
package/src/squish.js CHANGED
@@ -73,7 +73,13 @@ const unsquish = (squished) => {
73
73
  }
74
74
 
75
75
  const constructor = TYPE_TO_CONSTRUCTOR[squished[2]];
76
- return new constructor({ node: constructedInternalNode });
76
+ if (constructor) {
77
+ return new constructor({ node: constructedInternalNode });
78
+ }
79
+
80
+ return {
81
+ node: constructedInternalNode
82
+ }
77
83
  }
78
84
 
79
85
  // When squishing, we need to make sure that properties that other properties depend on are inserted first.
@@ -1,4 +1,4 @@
1
- const { getFractional } = require('../util')
1
+ const { getFractional } = require('../util');
2
2
 
3
3
  const ASSET_SUBTYPE = 48;
4
4
 
@@ -6,7 +6,7 @@ const squishAsset = {
6
6
  type: ASSET_SUBTYPE,
7
7
  squish: (a, scale) => {
8
8
  const assetKey = Object.keys(a)[0];
9
- const squishedAssets = new Array(8 + assetKey.length);
9
+ const squishedAssets = new Array(10 + assetKey.length);
10
10
 
11
11
  const asset = a[assetKey];
12
12
 
@@ -16,6 +16,8 @@ const squishAsset = {
16
16
  const sizeX = scale ? scale.x * asset.size.x : asset.size.x;
17
17
  const sizeY = scale ? scale.y * asset.size.y : asset.size.y;
18
18
 
19
+ const startTimeSecond = asset.startTime || 0;
20
+
19
21
  squishedAssets[0] = Math.floor(posX);
20
22
  squishedAssets[1] = getFractional(posX);
21
23
 
@@ -28,8 +30,11 @@ const squishAsset = {
28
30
  squishedAssets[6] = Math.floor(sizeY);
29
31
  squishedAssets[7] = getFractional(sizeY);
30
32
 
33
+ squishedAssets[8] = Math.floor(startTimeSecond);
34
+ squishedAssets[9] = getFractional(startTimeSecond);
35
+
31
36
  for (let i = 0; i < assetKey.length; i++) {
32
- squishedAssets[8 + i] = assetKey.codePointAt(i);
37
+ squishedAssets[10 + i] = assetKey.codePointAt(i);
33
38
  }
34
39
 
35
40
  return squishedAssets;
@@ -41,7 +46,10 @@ const squishAsset = {
41
46
  const assetSizeX = squished[4] + squished[5] / 100;
42
47
  const assetSizeY = squished[6] + squished[7] / 100;
43
48
 
44
- const assetKey = String.fromCodePoint.apply(null, squished.slice(8));
49
+ const startTime = squished[8] + squished[9] / 100;
50
+
51
+ const assetKey = String.fromCodePoint.apply(null, squished.slice(10));
52
+
45
53
  return {
46
54
  [assetKey]: {
47
55
  pos: {
@@ -51,7 +59,8 @@ const squishAsset = {
51
59
  size: {
52
60
  x: assetSizeX,
53
61
  y: assetSizeY
54
- }
62
+ },
63
+ startTime
55
64
  }
56
65
  }
57
66
  }
@@ -3,10 +3,43 @@ const ID_SUBTYPE = 43;
3
3
  const squishId = {
4
4
  type: ID_SUBTYPE,
5
5
  squish: (i) => {
6
- return [i];
6
+ // max val: 10 000 000 000 000 000 (ten quadrillion)
7
+ const idStr = i.toString();
8
+ let strChunks = [];
9
+ if (idStr.length > 2) {
10
+ let j;
11
+ for (j = 0; j + 2 <= idStr.length; j += 2) {
12
+ strChunks.push(idStr.substring(j, j + 2));
13
+ }
14
+
15
+ if (j == idStr.length - 1) {
16
+ strChunks.push(idStr.substring(j, j + 2));
17
+ }
18
+ } else {
19
+ if (idStr.length === 1) {
20
+ strChunks.push('0' + idStr);
21
+ } else {
22
+ strChunks.push(idStr);
23
+ }
24
+ }
25
+
26
+ if (strChunks.length < 8) {
27
+ while (strChunks.length < 8) {
28
+ strChunks = ["00", ...strChunks];
29
+ }
30
+ }
31
+
32
+ return strChunks.map(c => new Number(c));
7
33
  },
8
34
  unsquish: (arr) => {
9
- return arr[0];
35
+ // build up from right to left then parse
36
+ let str = '';
37
+ for (let i = arr.length - 1; i >= 0; i--) {
38
+ const val = arr[i];
39
+ str = val + str
40
+ }
41
+
42
+ return new Number(str);
10
43
  }
11
44
  }
12
45