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.1 to 0.5.2

2

package.json
{
"name": "squishjs",
"version": "0.5.1",
"version": "0.5.2",
"description": "squish & unsquish stuff",

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

@@ -5,4 +5,4 @@ const listenable = require("./util/listenable");

const gameNode = (color, onClick, coordinates2d, border, fill, text, asset, playerId, effects, input) => {
const node = new InternalGameNode(color, onClick, coordinates2d, border, fill, text, asset, playerId, effects, input);
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);
return listenable(node, node.onStateChange.bind(node));

@@ -12,4 +12,4 @@ };

class Shape {
constructor(color, shapeType, shapeInfo, playerId, onClick, effects, input) {
this.node = gameNode(color, onClick, shapeInfo.coordinates2d, shapeInfo.border, shapeInfo.fill, null, null, playerId, effects, input);
constructor(color, shapeType, shapeInfo, playerIds, onClick, effects, input) {
this.node = gameNode(color, onClick, shapeInfo.coordinates2d, shapeInfo.border, shapeInfo.fill, null, null, playerIds, effects, input);
this.id = this.node.id;

@@ -42,4 +42,4 @@ }

class Text {
constructor(textInfo, playerId, input) {
this.node = gameNode(null, null, null, null, null, textInfo, null, playerId, null, input);
constructor(textInfo, playerIds, input) {
this.node = gameNode(null, null, null, null, null, textInfo, null, playerIds, null, input);
this.id = this.node.id;

@@ -72,4 +72,4 @@ }

class Asset {
constructor(onClick, coordinates2d, assetInfo, playerId) {
this.node = gameNode(null, onClick, coordinates2d, null, null, null, assetInfo, playerId);
constructor(onClick, coordinates2d, assetInfo, playerIds) {
this.node = gameNode(null, onClick, coordinates2d, null, null, null, assetInfo, playerIds);
this.id = this.node.id;

@@ -76,0 +76,0 @@ }

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

@@ -17,3 +17,6 @@ this.children = new Array();

this.listeners = new Set();
this.playerId = Number(playerId);
if (playerIds && !(playerIds instanceof Array)) {
playerIds = [playerIds];
}
this.playerIds = playerIds || [];
}

@@ -20,0 +23,0 @@

@@ -41,10 +41,6 @@ const InternalGameNode = require("./InternalGameNode");

},
playerId: {
playerIds: {
type: PLAYER_ID_SUBTYPE,
squish: (i) => {
return [i];
},
unsquish: (squished) => {
return squished[0];
}
squish: (i) => i,
unsquish: (squished) => squished
},

@@ -291,3 +287,3 @@ pos: {

'color',
'playerId',
'playerIds',
'coordinates2d',

@@ -294,0 +290,0 @@ 'fill',

@@ -76,2 +76,40 @@ const { squish, unsquish } = require('../src/squish');

test("Simple shape visible to 2 players", () => {
const gameNode = new GameNode.Shape(
COLORS.RED,
Shapes.POLYGON,
{
coordinates2d: ShapeUtils.rectangle(10, 10, 50, 50),
fill: COLORS.RED
},
[1, 2]
);
const squishedGameNode = squish(gameNode.node);
const unsquishedGameNode = unsquish(squishedGameNode);
compareSquished(gameNode.node, unsquishedGameNode);
assert(unsquishedGameNode.playerIds.length == 2);
assert(unsquishedGameNode.playerIds[0] == 1);
assert(unsquishedGameNode.playerIds[1] == 2);
});
test("Simple text visible to 255 players", () => {
const playerIds = Array.from({length: 255}, (_, i) => i + 1);
const gameNode = new GameNode.Text({
text: 'Hello, world!',
x: 4,
y: 20,
size: 5,
align: 'center',
color: COLORS.RED
}, playerIds);
const squishedGameNode = squish(gameNode.node);
const unsquishedGameNode = unsquish(squishedGameNode);
compareSquished(gameNode.node, unsquishedGameNode);
assert(unsquishedGameNode.playerIds.length == 255);
for (let i = 0; i < playerIds.length; i++) {
assert(unsquishedGameNode.playerIds[i] == playerIds[i]);
}
});
test("Text node", () => {

@@ -122,3 +160,3 @@ const gameNode = new GameNode.Text({

},
42,
[42],
null,

@@ -125,0 +163,0 @@ {

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