Skip to content

Commit

Permalink
wat
Browse files Browse the repository at this point in the history
  • Loading branch information
prosif committed Jan 27, 2024
1 parent 10e0d04 commit 07803aa
Show file tree
Hide file tree
Showing 20 changed files with 545 additions and 95 deletions.
387 changes: 384 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"squish-1000": "npm:[email protected]",
"squish-1004": "npm:[email protected]",
"squish-1005": "npm:[email protected]",
"unzipper": "^0.10.11",
"squish-1006": "npm:[email protected]",
"decompress": "^4.2.1",
"ws": "7.4.6"
}
}
56 changes: 21 additions & 35 deletions src/dashboard/HomegamesDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const http = require('http');
const https = require('https');
const path = require('path');

const { Asset, Game, ViewableGame, GameNode, Colors, ShapeUtils, Shapes, squish, unsquish, ViewUtils } = require('squish-0767');
const { Asset, Game, ViewableGame, GameNode, Colors, ShapeUtils, Shapes, squish, unsquish, ViewUtils } = require('squish-1006');

const squishMap = require('../common/squish-map');

const unzipper = require('unzipper');
const decompress = require('decompress');
const fs = require('fs');
const gameModal = require('./game-modal');

Expand Down Expand Up @@ -322,7 +322,7 @@ class HomegamesDashboard extends ViewableGame {
return {
aspectRatio: {x: 16, y: 9},
author: 'Joseph Garcia',
squishVersion: '0767'
squishVersion: '1006'
};
}

Expand Down Expand Up @@ -410,14 +410,14 @@ class HomegamesDashboard extends ViewableGame {
const referencedGame = this.localGames[gameKey];
const versionId = versionKey || Object.keys(referencedGame.versions)[Object.keys(referencedGame.versions).length - 1];

const squishVersion = referencedGame.versions[versionId].metadata.squishVersion || '0767';
const squishVersion = referencedGame.versions[versionId].metadata.squishVersion || '1006';

const func = fork;
const tingEnv = process.env;

// referenced game file needs to use our dependencies
tingEnv.NODE_PATH = `${process.cwd()}${path.sep}node_modules`;

const childSession = func(childGameServerPath, [], { env: { SQUISH_PATH: squishMap[squishVersion], ...tingEnv}});

sessions[port] = childSession;
Expand Down Expand Up @@ -445,12 +445,15 @@ class HomegamesDashboard extends ViewableGame {
});

childSession.on('error', (err) => {
console.log('error!');
console.log(err);
this.sessions[sessionId] = {};
childSession.kill();
log.error('child session error', err);
});

childSession.on('close', (err) => {
console.log(err);
log.error('Child session closed');
log.error(err);
this.sessions[sessionId] = {};
Expand Down Expand Up @@ -544,7 +547,6 @@ class HomegamesDashboard extends ViewableGame {
},
onClose: () => {
playerRoot.removeChild(modal.node.id);
this.clearAllChildren(modal);
}
});

Expand Down Expand Up @@ -1028,20 +1030,19 @@ class HomegamesDashboard extends ViewableGame {
}
return new Promise((resolve, reject) => {
const gamePath = `${DOWNLOADED_GAME_DIRECTORY}${path.sep}${gameId}${path.sep}${versionId}`;
const zipPath = `${DOWNLOADED_GAME_DIRECTORY}${path.sep}${gameId}${path.sep}${versionId}.zip`;

if (!fs.existsSync(`${DOWNLOADED_GAME_DIRECTORY}${path.sep}${gameId}`)) {
fs.mkdirSync(`${DOWNLOADED_GAME_DIRECTORY}${path.sep}${gameId}`);
}

https.get(location, (res) => {
const stream = res.pipe(unzipper.Extract({
path: gamePath
}));

stream.on('close', () => {
fs.readdir(gamePath, (err, files) => {
const zipWriteStream = fs.createWriteStream(zipPath);

zipWriteStream.on('close', () => {
decompress(zipPath, gamePath).then((files) => {
const currentMetadata = getGameMetadataMap();
const indexPath = `${gamePath}${path.sep}index.js`;
const foundIndex = files.filter(f => f.type === 'file' && f.path.endsWith('index.js'))[0];
const indexPath = path.join(gamePath, foundIndex.path);//`${gamePath}${path.sep}index.js`;

currentMetadata[indexPath] = metadataToStore;
updateGameMetadataMap(currentMetadata);
Expand All @@ -1054,9 +1055,14 @@ class HomegamesDashboard extends ViewableGame {
});
});
resolve(indexPath);
});
});
});

https.get(location, (res) => {
res.pipe(zipWriteStream);
zipWriteStream.on('finish', () => {
zipWriteStream.close();
});
});
});
}
Expand All @@ -1067,29 +1073,9 @@ class HomegamesDashboard extends ViewableGame {
const node = playerViewRoot.node;
this.playerRootNode.removeChild(node.id);
delete this.playerRoots[playerId];
this.clearAllChildren(node);
}
}

clearAllChildren(node) {
const proxiesToRevoke = this.clearAllChildrenHelper(node);

proxiesToRevoke.forEach(p => {
p.free();
});
}

clearAllChildrenHelper(_node, proxiesToRevoke = []) {
const node = _node.node || _node;
proxiesToRevoke.push(node);

for (let i = 0; i < node.children.length; i++) {
this.clearAllChildrenHelper(node.children[i], proxiesToRevoke);
}

return proxiesToRevoke;
}

}

module.exports = HomegamesDashboard;
3 changes: 1 addition & 2 deletions src/dashboard/game-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ const { fork } = require('child_process');
const http = require('http');
const https = require('https');
const path = require('path');
const { Game, ViewableGame, GameNode, Colors, ShapeUtils, Shapes, squish, unsquish, ViewUtils } = require('squish-0767');
const { Game, ViewableGame, GameNode, Colors, ShapeUtils, Shapes, squish, unsquish, ViewUtils } = require('squish-1006');

const unzipper = require('unzipper');
const fs = require('fs');

const COLORS = Colors.COLORS;
Expand Down
5 changes: 2 additions & 3 deletions src/dashboard/game-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ const { fork } = require('child_process');
const http = require('http');
const https = require('https');
const path = require('path');
const { Asset, Game, ViewableGame, GameNode, Colors, ShapeUtils, Shapes, squish, unsquish, ViewUtils } = require('squish-0767');
const { Asset, Game, ViewableGame, GameNode, Colors, ShapeUtils, Shapes, squish, unsquish, ViewUtils } = require('squish-1006');

const unzipper = require('unzipper');
const fs = require('fs');
const gameModal = require('./game-modal');

Expand Down Expand Up @@ -71,4 +70,4 @@ const gameOption = ({ x, y, width, height, assetKey, gameName, onClick }) => {
return node;
};

module.exports = gameOption;
module.exports = gameOption;
4 changes: 2 additions & 2 deletions src/games/draw/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { Asset, Colors, Game, GameNode, Shapes, ShapeUtils } = require('squish-0767');
const { Asset, Colors, Game, GameNode, Shapes, ShapeUtils } = require('squish-1006');

const COLORS = Colors.COLORS;

class Draw extends Game {
static metadata() {
return {
aspectRatio: {x: 16, y: 9},
squishVersion: '0767',
squishVersion: '1006',
author: 'Joseph Garcia',
thumbnail: '1e844026921f7662a62ce72da869da63'
};
Expand Down
11 changes: 8 additions & 3 deletions src/games/image-test/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
const { Asset, Game, GameNode, Colors, Shapes } = require('squish-0767');
const { Asset, Game, GameNode, Colors, Shapes } = require('squish-1006');
const COLORS = Colors.COLORS;

class ImageTest extends Game {
static metadata() {
return {
aspectRatio: {x: 16, y: 9},
squishVersion: '0767',
squishVersion: '1006',
author: 'Joseph Garcia',
thumbnail: '2a0cf606567326c6c40df592ee1358ca',
isTest: true
isTest: true,
tickRate: 60
};
}

tick() {
this.base.node.onStateChange();
}

constructor() {
super();
const aspectRatio = this.constructor.metadata().aspectRatio;
Expand Down
11 changes: 8 additions & 3 deletions src/games/layer-test/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const { Game, GameNode, Colors, Shapes } = require('squish-0767');
const { Game, GameNode, Colors, Shapes } = require('squish-1006');

class LayerTest extends Game {
static metadata() {
return {
aspectRatio: {x: 16, y: 9},
author: 'Joseph Garcia',
thumbnail: 'f103961541614b68c503a9ae2fd4cc47',
squishVersion: '0767',
isTest: true
squishVersion: '1006',
isTest: true,
tickRate: 60
};
}

Expand Down Expand Up @@ -70,6 +71,10 @@ class LayerTest extends Game {
getLayers() {
return this.layers;
}

tick() {
this.base.node.onStateChange();
}
}

module.exports = LayerTest;
6 changes: 3 additions & 3 deletions src/games/mem-test/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Game, ViewableGame, GameNode, Colors, ShapeUtils, Shapes, squish, unsquish, ViewUtils } = require('squish-0767');
const { Game, ViewableGame, GameNode, Colors, ShapeUtils, Shapes, squish, unsquish, ViewUtils } = require('squish-1006');
const { ExpiringSet, animations } = require('../../common/util');

const COLORS = Colors.COLORS;
Expand All @@ -8,7 +8,7 @@ class MemTest extends Game {
return {
aspectRatio: {x: 16, y: 9},
author: 'Joseph Garcia',
squishVersion: '0767',
squishVersion: '1006',
isTest: true
};
}
Expand All @@ -35,12 +35,12 @@ class MemTest extends Game {

if (this.lastNode) {
this.whiteBase.removeChild(this.lastNode.id);
this.lastNode.free();
}

this.lastNode = newNode;

this.whiteBase.addChild(newNode);
this.whiteBase.node.onStateChange();
}

handleLayerClick() {
Expand Down
6 changes: 3 additions & 3 deletions src/games/perf-test/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { Game, GameNode, Colors, Shapes, ShapeUtils } = require('squish-0767');
const { Game, GameNode, Colors, Shapes, ShapeUtils } = require('squish-1006');

class PerfTest extends Game {
static metadata() {
return {
aspectRatio: {x: 16, y: 9},
squishVersion: '0767',
squishVersion: '1006',
author: 'Joseph Garcia',
thumbnail: '14966f35c53029f6e219369038fe1ebf',
isTest: true
// isTest: true
};
}

Expand Down
11 changes: 8 additions & 3 deletions src/games/sponge/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dictionary = require('../../common/util/dictionary');

const { Asset, Game, GameNode, Colors, Shapes, ShapeUtils, Physics, GeometryUtils, subtypes } = require('squish-1005');
const { Asset, Game, GameNode, Colors, Shapes, ShapeUtils, Physics, GeometryUtils, subtypes } = require('squish-1006');

const COLORS = Colors.COLORS;

Expand All @@ -13,11 +13,16 @@ class Sponge extends Game {
description: 'sponge',
author: 'Joseph Garcia',
thumbnail: '8727eec293b562692fa6c7e3901a2274',
squishVersion: '1005',
maxPlayers: 2
squishVersion: '1006',
maxPlayers: 2,
tickRate: 60
};
}

tick() {
this.base.node.onStateChange();
}

constructor() {
super();

Expand Down
10 changes: 6 additions & 4 deletions src/games/squarer/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const { Colors, Game, GameNode, Shapes, ShapeUtils } = require('squish-0767');
const { Colors, Game, GameNode, Shapes, ShapeUtils } = require('squish-1006');
const { BLACK, GRAY, GOLD, GREEN } = Colors.COLORS;

class Squarer extends Game {
static metadata() {
return {
aspectRatio: {x: 16, y: 9},
squishVersion: '0767',
squishVersion: '1006',
author: 'Yazeed Loonat',
thumbnail: 'b11960b455550b0c38ae7f5544af74ae'
thumbnail: 'b11960b455550b0c38ae7f5544af74ae',
tickRate: 60
};
}

Expand Down Expand Up @@ -58,7 +59,6 @@ class Squarer extends Game {
this.npc.forEach(npc => {
clearInterval(npc.interval);
this.base.removeChild(npc.id);
npc.free();
});
this.npc = [];
if (this.level > 9) {
Expand Down Expand Up @@ -221,6 +221,8 @@ class Squarer extends Game {
}
}
}

this.base.node.onStateChange();
}

checkForCollisions(node, toCheck = [], bounceFound = false) {
Expand Down
Loading

0 comments on commit 07803aa

Please sign in to comment.