Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
prosif committed Sep 30, 2023
1 parent 9614407 commit 240529b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 19 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"electron-log": "^4.4.8",
"homegames-common": "1.0.1",
"process-stats": "^3.5.5",
"squish-0756": "npm:[email protected]",
"squish-0762": "npm:[email protected]",
"squish-0765": "npm:[email protected]",
"squish-0766": "npm:[email protected]",
Expand Down
2 changes: 2 additions & 0 deletions src/child_game_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const startServer = (sessionInfo) => {
}
gameSession = new GameSession(gameInstance, sessionInfo.port, sessionInfo.username);
} catch (err) {
console.log("EYAYSDYFYDSF");
console.log(err);
log.error('Error instantiating game session', err);
if (ERROR_REPORTING_ENABLED) {
reportBug(`Exception: ${err.message} Stack: ${err.stack}`);
Expand Down
1 change: 1 addition & 0 deletions src/common/squish-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ try {
const electronOverrideVersion = require.resolve('squish-1004');

module.exports = {
'0756': isMain ? require.resolve('squish-0756') : electronOverrideVersion,
'0762': isMain ? require.resolve('squish-0762') : electronOverrideVersion,
'0765': isMain ? require.resolve('squish-0765') : electronOverrideVersion,
'0766': isMain ? require.resolve('squish-0766') : electronOverrideVersion,
Expand Down
65 changes: 48 additions & 17 deletions src/dashboard/HomegamesDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ const optionHeight = (gameContainerHeight - ((rowsPerPage - 1) * gameTopYMargin)

const CHILD_SESSION_HEARTBEAT_INTERVAL = getConfigValue('CHILD_SESSION_HEARTBEAT_INTERVAL', 500);

const GAME_DIRECTORY = path.join(baseDir, 'hg-games');
const SOURCE_GAME_DIRECTORY = path.resolve(`${baseDir}${path.sep}src${path.sep}games`);
const DOWNLOADED_GAME_DIRECTORY = path.join(getAppDataPath(), 'hg-games');

const updateGameMetadataMap = (newMetadata) => {
fs.writeFileSync(GAME_DIRECTORY + path.sep + '.metadata', JSON.stringify(newMetadata));
fs.writeFileSync(DOWNLOADED_GAME_DIRECTORY + path.sep + '.metadata', JSON.stringify(newMetadata));
}

const getGameMetadataMap = () => {
if (fs.existsSync(GAME_DIRECTORY + path.sep + '.metadata')) {
const bytes = fs.readFileSync(GAME_DIRECTORY + path.sep + '.metadata');
if (fs.existsSync(DOWNLOADED_GAME_DIRECTORY + path.sep + '.metadata')) {
const bytes = fs.readFileSync(DOWNLOADED_GAME_DIRECTORY + path.sep + '.metadata');
return JSON.parse(bytes);
}

Expand Down Expand Up @@ -113,10 +114,6 @@ const getUrl = (url, headers = {}) => new Promise((resolve, reject) => {

});

const SOURCE_GAME_DIRECTORY = path.resolve(`${baseDir}${path.sep}src${path.sep}games`);

const DOWNLOADED_GAME_DIRECTORY = path.join(getAppDataPath(), 'hg-games');

if (!fs.existsSync(DOWNLOADED_GAME_DIRECTORY)) {
try {
fs.mkdirSync(DOWNLOADED_GAME_DIRECTORY);
Expand Down Expand Up @@ -167,9 +164,9 @@ const networkHelper = {
})
};

if (!fs.existsSync(GAME_DIRECTORY)) {
if (!fs.existsSync(DOWNLOADED_GAME_DIRECTORY)) {
try {
fs.mkdirSync(GAME_DIRECTORY);
fs.mkdirSync(DOWNLOADED_GAME_DIRECTORY);
} catch (err) {
console.error('Unable to create game directory');
console.error(err);
Expand All @@ -189,6 +186,10 @@ const getGamePathsHelper = (dir) => {

entries.forEach(entry => {
const entryPath = path.resolve(`${dir}${path.sep}${entry}`);

console.log("THIS IS ENTRY PATRH");
console.log(entry);
console.log(entryPath);

const metadata = fs.statSync(entryPath);
if (metadata.isFile()) {
Expand All @@ -197,13 +198,18 @@ const getGamePathsHelper = (dir) => {
const regex = new RegExp(/games\\[a-zA-Z0-9-_]+\\index.js/);
isMatch = !!regex.exec(entryPath);
} else {
isMatch = entryPath.match(`games${path.sep}[a-zA-Z0-9\\-_]+${path.sep}index.js`);
isMatch = entryPath.match(`${path.sep}[a-zA-Z0-9\\-_]+${path.sep}index.js`);
}

if (isMatch) {
if (entryPath.endsWith('index.js')) {
console.log("RESULTTLTLTLTL! ");
results.add(entryPath);
} else {
console.log("nooeoeoeoeoe 3");
}
} else {
console.log("nooeoeoeoeoe 2");
}
} else if (metadata.isDirectory()) {
const nestedPaths = getGamePathsHelper(entryPath);
Expand All @@ -219,6 +225,9 @@ const getGameMap = () => {
const sourceGames = getGamePathsHelper(SOURCE_GAME_DIRECTORY);
const downloadedGames = getGamePathsHelper(DOWNLOADED_GAME_DIRECTORY);

console.log("DOWNLOADED GAMES IN DIR " + DOWNLOADED_GAME_DIRECTORY);
console.log(downloadedGames);

const gamePaths = Array.from(new Set([...sourceGames, ...downloadedGames])).sort();

const games = {};
Expand Down Expand Up @@ -410,6 +419,8 @@ class HomegamesDashboard extends ViewableGame {
const port = getServerPort();

const childGameServerPath = path.join(path.resolve(__dirname, '..'), 'child_game_server.js');
console.log("DAMGSSE KEY " + gameKey);
console.log(this.localGames);

if (this.localGames[gameKey]) {
const referencedGame = this.localGames[gameKey];
Expand All @@ -419,6 +430,12 @@ class HomegamesDashboard extends ViewableGame {

const func = electron ? electron.utilityProcess.fork : fork;
const tingEnv = process.env;

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

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

sessions[port] = childSession;
Expand All @@ -445,14 +462,17 @@ class HomegamesDashboard extends ViewableGame {
}
});

childSession.on('error', (err) => {

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

childSession.on('close', (err) => {
console.log('LCOSDSRED!');
console.log(err);
this.sessions[sessionId] = {};
});

Expand Down Expand Up @@ -530,13 +550,23 @@ class HomegamesDashboard extends ViewableGame {
this.joinSession(playerId, session);
},
onCreateSession: () => {
console.log('jdsfkdsf');
console.log(game);
console.log(gameVersion);
if (this.localGames[gameId]?.versions[gameVersion.versionId]) {
this.startSession(playerId, gameId, gameVersion.versionId);
} else {
console.log('dskufdsfdsf');
this.downloadGame({ gameDetails: game, version: gameVersion }).then(() => {
console.log("dsf;dsfdsf");
this.renderGamePlane();
console.log("dsf;dsfdsf 2");
this.startSession(playerId, gameId, gameVersion.versionId);
})
console.log("dsf;dsfdsf 3");
}).catch(err => {
console.log('eroeororor');
console.log(err);
});
}
},
onClose: () => {
Expand Down Expand Up @@ -1024,10 +1054,10 @@ class HomegamesDashboard extends ViewableGame {
}
}
return new Promise((resolve, reject) => {
const gamePath = `${GAME_DIRECTORY}${path.sep}${gameId}${path.sep}${versionId}`;
const gamePath = `${DOWNLOADED_GAME_DIRECTORY}${path.sep}${gameId}${path.sep}${versionId}`;

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

https.get(location, (res) => {
Expand All @@ -1053,6 +1083,7 @@ class HomegamesDashboard extends ViewableGame {
resolve(indexPath);
});
});
});

});
});
Expand Down
5 changes: 3 additions & 2 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-0762');
const { Asset, Game, GameNode, Colors, Shapes, ShapeUtils, Physics, GeometryUtils, subtypes } = require('squish-1005');

const COLORS = Colors.COLORS;

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

constructor() {
console.log("SDKJFHKDSJFHDSF");
super();

this.playerSides = {};
Expand Down

0 comments on commit 240529b

Please sign in to comment.