Comparing version 0.7.3 to 0.7.4
{ | ||
"name": "squishjs", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "squish & unsquish stuff", | ||
@@ -5,0 +5,0 @@ "scripts": { |
class Game { | ||
constructor() { | ||
this.players = {}; | ||
this.spectators = {}; | ||
this.listeners = new Set(); | ||
this.intervals = []; | ||
this.timeouts = []; | ||
this.playerInfoMap = {}; | ||
} | ||
_hgAddPlayer(player) { | ||
this.players[player.id] = player; | ||
} | ||
_hgRemovePlayer(playerId) { | ||
delete this.players[playerId]; | ||
} | ||
addStateListener(listener) { | ||
@@ -19,0 +10,0 @@ this.listeners.add(listener); |
@@ -76,3 +76,9 @@ const assert = require('assert'); | ||
const constructor = TYPE_TO_CONSTRUCTOR[squished[2]]; | ||
return new constructor({ node: constructedInternalNode }); | ||
if (constructor) { | ||
return new constructor({ node: constructedInternalNode }); | ||
} | ||
return { | ||
node: constructedInternalNode | ||
} | ||
} | ||
@@ -79,0 +85,0 @@ |
@@ -48,3 +48,3 @@ const ASSET_TYPE = 1; | ||
squish(layers, scale = null) { | ||
if (!layers) { | ||
@@ -60,6 +60,2 @@ return []; | ||
Object.keys(this.game.players).forEach(playerId => { | ||
playerMap[Number(playerId)] = []; | ||
}); | ||
if (this.customBottomLayer) { | ||
@@ -114,10 +110,13 @@ const squishedLayer = []; | ||
for (let playerId of playerIdFilter) { | ||
if (playerMap[playerId]) { | ||
playerMap[playerId].push(squished); | ||
} else { | ||
console.warn(`Node references unknown player ID: ${playerId}`); | ||
} | ||
} | ||
if (!playerMap[playerId]) { | ||
playerMap[Number(playerId)] = []; | ||
} | ||
playerMap[playerId].push(squished); | ||
} | ||
} else { | ||
Object.keys(playerMap).forEach(playerId => { | ||
if (!playerMap[playerId]) { | ||
playerMap[Number(playerId)] = []; | ||
} | ||
playerMap[playerId].push(squished); | ||
@@ -124,0 +123,0 @@ }) |
@@ -1,2 +0,2 @@ | ||
const { getFractional } = require('../util') | ||
const { getFractional } = require('../util'); | ||
@@ -9,3 +9,3 @@ const ASSET_SUBTYPE = 48; | ||
const assetKey = Object.keys(a)[0]; | ||
const squishedAssets = new Array(8 + assetKey.length); | ||
const squishedAssets = new Array(10 + assetKey.length); | ||
@@ -20,2 +20,4 @@ const asset = a[assetKey]; | ||
const startTimeSecond = asset.startTime || 0; | ||
squishedAssets[0] = Math.floor(posX); | ||
@@ -33,4 +35,7 @@ squishedAssets[1] = getFractional(posX); | ||
squishedAssets[8] = Math.floor(startTimeSecond); | ||
squishedAssets[9] = getFractional(startTimeSecond); | ||
for (let i = 0; i < assetKey.length; i++) { | ||
squishedAssets[8 + i] = assetKey.codePointAt(i); | ||
squishedAssets[10 + i] = assetKey.codePointAt(i); | ||
} | ||
@@ -47,3 +52,6 @@ | ||
const assetKey = String.fromCodePoint.apply(null, squished.slice(8)); | ||
const startTime = squished[8] + squished[9] / 100; | ||
const assetKey = String.fromCodePoint.apply(null, squished.slice(10)); | ||
return { | ||
@@ -58,3 +66,4 @@ [assetKey]: { | ||
y: assetSizeY | ||
} | ||
}, | ||
startTime | ||
} | ||
@@ -61,0 +70,0 @@ } |
@@ -6,6 +6,39 @@ const ID_SUBTYPE = 43; | ||
squish: (i) => { | ||
return [i]; | ||
// max val: 10 000 000 000 000 000 (ten quadrillion) | ||
const idStr = i.toString(); | ||
let strChunks = []; | ||
if (idStr.length > 2) { | ||
let j; | ||
for (j = 0; j + 2 <= idStr.length; j += 2) { | ||
strChunks.push(idStr.substring(j, j + 2)); | ||
} | ||
if (j == idStr.length - 1) { | ||
strChunks.push(idStr.substring(j, j + 2)); | ||
} | ||
} else { | ||
if (idStr.length === 1) { | ||
strChunks.push('0' + idStr); | ||
} else { | ||
strChunks.push(idStr); | ||
} | ||
} | ||
if (strChunks.length < 8) { | ||
while (strChunks.length < 8) { | ||
strChunks = ["00", ...strChunks]; | ||
} | ||
} | ||
return strChunks.map(c => new Number(c)); | ||
}, | ||
unsquish: (arr) => { | ||
return arr[0]; | ||
// build up from right to left then parse | ||
let str = ''; | ||
for (let i = arr.length - 1; i >= 0; i--) { | ||
const val = arr[i]; | ||
str = val + str | ||
} | ||
return new Number(str); | ||
} | ||
@@ -12,0 +45,0 @@ } |
160187
3868