Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

squishjs

Package Overview
Dependencies
Maintainers
2
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

squishjs - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

src/util/state-codes.js

8

index.js

@@ -1,2 +0,2 @@

const { squish, unsquish } = require('./src/squish');
const { unsquishSize, squishSize, squish, unsquish } = require('./src/squish');
const { gameNode, GameNode } = require('./src/GameNode');

@@ -8,2 +8,3 @@ const InternalGameNode = require('./src/InternalGameNode');

const shapeUtils = require('./src/util/shapes');
const StateSignals = require('./src/util/state-codes');

@@ -13,2 +14,4 @@ module.exports = {

unsquish,
squishSize,
unsquishSize,
gameNode,

@@ -19,3 +22,4 @@ Game,

Shapes,
ShapeUtils: shapeUtils
ShapeUtils: shapeUtils,
StateSignals
};
{
"name": "squishjs",
"version": "0.5.2",
"version": "0.5.3",
"description": "squish & unsquish stuff",

@@ -5,0 +5,0 @@ "scripts": {

const listenable = require("./util/listenable");
const InternalGameNode = require('./InternalGameNode');
const Shapes = require('./Shapes');
const StateSignals = require('./util/state-codes');
const gameNode = (color, onClick, coordinates2d, border, fill, text, asset, playerIds, effects, input) => {
const node = new InternalGameNode(color, onClick, coordinates2d, border, fill, text, asset, playerIds, effects, input);
const gameNode = (color, onClick, coordinates2d, border, fill, text, asset, playerIds, effects, input, buf, stateSignal, holdHandlers) => {
const node = new InternalGameNode(color, onClick, coordinates2d, border, fill, text, asset, playerIds, effects, input, buf, stateSignal, holdHandlers);
return listenable(node, node.onStateChange.bind(node));
};
class State {
constructor(stateSignal, playerIds) {
this.node = gameNode(null, null, null, null, null, null, null, playerIds, null, null, null, stateSignal);
this.id = this.node.id;
}
addChild(child) {
this.node.addChild(child);
}
addChildren(...nodes) {
for (let nodeIndex = 0; nodeIndex < nodes.length; nodeIndex++) {
this.addChild(nodes[nodeIndex]);
}
}
removeChild(nodeId) {
this.node.removeChild(nodeId);
}
addListener(listener) {
this.node.addListener(listener);
}
clearChildren(excludedNodeIds) {
this.node.clearChildren(excludedNodeIds);
}
}
class Audio {
constructor(playerIds, buf) {
this.node = gameNode(null, null, null, null, null, null, null, playerIds, null, null, buf);
this.id = this.node.id;
}
addChild(child) {
this.node.addChild(child);
}
addChildren(...nodes) {
for (let nodeIndex = 0; nodeIndex < nodes.length; nodeIndex++) {
this.addChild(nodes[nodeIndex]);
}
}
removeChild(nodeId) {
this.node.removeChild(nodeId);
}
addListener(listener) {
this.node.addListener(listener);
}
clearChildren(excludedNodeIds) {
this.node.clearChildren(excludedNodeIds);
}
}
class Shape {
constructor(color, shapeType, shapeInfo, playerIds, onClick, effects, input) {
this.node = gameNode(color, onClick, shapeInfo.coordinates2d, shapeInfo.border, shapeInfo.fill, null, null, playerIds, effects, input);
constructor(color, shapeType, shapeInfo, playerIds, onClick, effects, input, holdHandlers) {
this.node = gameNode(color, onClick, shapeInfo.coordinates2d, shapeInfo.border, shapeInfo.fill, null, null, playerIds, effects, input, null, null, holdHandlers);
this.id = this.node.id;

@@ -102,3 +162,5 @@ }

Shape,
Text
Text,
Audio,
State
};

@@ -105,0 +167,0 @@

let id = 0;
class InternalGameNode {
constructor(color, onClick, coordinates2d, border, fill, text, asset, playerIds = [], effects = null, input = null) {
constructor(color, onClick, coordinates2d, border, fill, text, asset, playerIds = [], effects = null, input = null, buf = null, stateSignal = null, holdHandlers = {}) {
this.id = id++;

@@ -21,2 +21,5 @@ this.children = new Array();

this.playerIds = playerIds || [];
this.buf = buf;
this.stateSignal = stateSignal;
this.holdHandlers = holdHandlers;
}

@@ -23,0 +26,0 @@

@@ -21,4 +21,20 @@ const InternalGameNode = require("./InternalGameNode");

const BORDER_SUBTYPE = 54;
const BUF_SUBTYPE = 55;
const STATE_SUBTYPE = 56;
const squishSpec = {
stateSignal: {
type: STATE_SUBTYPE,
squish: (i) => [i],
unsquish: (arr) => arr[0]
},
buf: {
type: BUF_SUBTYPE,
squish: (i) => {
return i
},
unsquish: (arr) => {
return arr;
}
},
id: {

@@ -297,3 +313,5 @@ type: ID_SUBTYPE,

'handleClick',
'input'
'input',
'buf',
'stateSignal'
];

@@ -308,31 +326,74 @@

const unsquish = (squished) => {
assert(squished[0] == 3);
assert(squished.length === squished[1]);
assert(squished[0] == 3);
let squishedIndex = 2;
const unsquishedLength = unsquishSize([
squished[1],
squished[2],
squished[3],
squished[4],
squished[5],
squished[6],
squished[7],
squished[8]
]);
let constructedGameNode = new InternalGameNode();
assert(squished.length === unsquishedLength);//squished[1]);
while(squishedIndex < squished.length) {
let squishedIndex = 9;
const subFrameType = squished[squishedIndex];
const subFrameLength = squished[squishedIndex + 1];
const subFrame = squished.slice(squishedIndex + 2, squishedIndex + subFrameLength);
let constructedGameNode = new InternalGameNode();
if (!typeToSquishMap[subFrameType]) {
console.warn("Unknown sub frame type " + subFrameType);
break;
} else {
const objField = typeToSquishMap[subFrameType];
const unsquishFun = squishSpec[objField]['unsquish'];
const unsquishedVal = unsquishFun(subFrame);
constructedGameNode[objField] = unsquishedVal;
}
squishedIndex += subFrameLength;
while(squishedIndex < squished.length) {
const subFrameType = squished[squishedIndex];
const subFrameLength = unsquishSize([
squished[squishedIndex + 1],
squished[squishedIndex + 2],
squished[squishedIndex + 3],
squished[squishedIndex + 4],
squished[squishedIndex + 5],
squished[squishedIndex + 6],
squished[squishedIndex + 7],
squished[squishedIndex + 8]
]);
const subFrame = squished.slice(squishedIndex + 9, squishedIndex + subFrameLength);
if (!typeToSquishMap[subFrameType]) {
console.warn("Unknown sub frame type " + subFrameType);
break;
} else {
const objField = typeToSquishMap[subFrameType];
const unsquishFun = squishSpec[objField]['unsquish'];
const unsquishedVal = unsquishFun(subFrame);
constructedGameNode[objField] = unsquishedVal;
}
return constructedGameNode;
squishedIndex += subFrameLength;
}
return constructedGameNode;
}
const squishSize = (size) => {
const a = Math.floor((size / Math.pow(255, 7)) % 255);
const b = Math.floor((size / Math.pow(255, 6)) % 255);
const c = Math.floor((size / Math.pow(255, 5)) % 255);
const d = Math.floor((size / Math.pow(255, 4)) % 255);
const e = Math.floor((size / Math.pow(255, 3)) % 255);
const f = Math.floor((size / Math.pow(255, 2)) % 255);
const g = Math.floor((size / Math.pow(255, 1)) % 255);
const h = Math.floor((size / Math.pow(255, 0)) % 255);
return [a, b, c, d, e, f, g, h];
};
const unsquishSize = (squishedSize) => {
return squishedSize[0] * Math.pow(255, 7) +
squishedSize[1] * Math.pow(255, 6) +
squishedSize[2] * Math.pow(255, 5) +
squishedSize[3] * Math.pow(255, 4) +
squishedSize[4] * Math.pow(255, 3) +
squishedSize[5] * Math.pow(255, 2) +
squishedSize[6] * Math.pow(255, 1) +
squishedSize[7];
};
const squish = (entity) => {

@@ -347,3 +408,4 @@ let squishedPieces = [];

const squished = squishSpec[key].squish(attr);
squishedPieces.push([squishSpec[key]['type'], squished.length + 2, ...squished]);
const squishedLength = squishSize(squished.length + 9);
squishedPieces.push([squishSpec[key]['type'], ...squishedLength, ...squished]);
}

@@ -354,3 +416,4 @@ }

const squished = squishedPieces.flat();
return [3, squished.length + 2, ...squished];
const squishedLength = squishSize(squished.length + 9);
return [3, ...squishedLength, ...squished];

@@ -361,3 +424,5 @@ }

squish,
unsquish
unsquish,
squishSize,
unsquishSize
};

@@ -217,1 +217,12 @@ const { squish, unsquish } = require('../src/squish');

test("Text with text input", () => {
const gameNode = new GameNode.Audio(
null,
[1, 2, 3]
);
const squishedNode = squish(gameNode.node);
const unsquishedNode = unsquish(squishedNode);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc