fighting git conflicts
This commit is contained in:
parent
53a2c06d43
commit
e36d41a7c4
10 changed files with 692 additions and 0 deletions
|
|
@ -15,6 +15,7 @@
|
|||
"license": "ISC",
|
||||
"packageManager": "pnpm@10.24.0",
|
||||
"dependencies": {
|
||||
<<<<<<< HEAD
|
||||
"@fastify/autoload": "^6.3.1",
|
||||
"@fastify/formbody": "^8.0.2",
|
||||
"@fastify/multipart": "^9.3.0",
|
||||
|
|
@ -31,5 +32,9 @@
|
|||
"rollup-plugin-node-externals": "^8.1.2",
|
||||
"vite": "^7.3.0",
|
||||
"vite-tsconfig-paths": "^5.1.4"
|
||||
=======
|
||||
"fastify-socket.io": "^5.1.0",
|
||||
"socket.io": "^4.8.1"
|
||||
>>>>>>> 16e6ae0 ((schism): started separating backend from frontend)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
<<<<<<< HEAD
|
||||
import { TTC } from './game';
|
||||
import { FastifyInstance, FastifyPluginAsync } from 'fastify';
|
||||
import fastifyFormBody from '@fastify/formbody';
|
||||
|
|
@ -96,6 +97,61 @@ async function onReady(fastify: FastifyInstance, game: TTC) {
|
|||
});
|
||||
});
|
||||
}
|
||||
=======
|
||||
import { FastifyInstance, FastifyPluginAsync } from 'fastify';
|
||||
import fastifySocketIO from 'fastify-socket.io';
|
||||
import { TTC } from './game';
|
||||
|
||||
const app: FastifyPluginAsync = async (fastify: FastifyInstance, opts): Promise<void> => {
|
||||
void opts;
|
||||
await fastify.register(fastifySocketIO, {
|
||||
cors: {
|
||||
origin: '*',
|
||||
methods: ['GET', 'POST'],
|
||||
},
|
||||
});
|
||||
|
||||
const game = new TTC();
|
||||
|
||||
fastify.ready().then(() => {
|
||||
fastify.io.on('connection', (socket) => {
|
||||
fastify.log.info(`Client connected: ${socket.id}`);
|
||||
|
||||
socket.emit('gameState', {
|
||||
board: game.board,
|
||||
turn: game.currentPlayer,
|
||||
gameOver: game.isGameOver,
|
||||
});
|
||||
|
||||
socket.on('makeMove', (idx: number) => {
|
||||
const result = game.makeMove(idx);
|
||||
|
||||
if (result === 'invalidMove') {
|
||||
socket.emit('error', 'Invalid Move');
|
||||
}
|
||||
else {
|
||||
fastify.io.emit('gameState', {
|
||||
board: game.board,
|
||||
turn: game.currentPlayer,
|
||||
lastResult: result,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('resetGame', () => {
|
||||
game.reset();
|
||||
fastify.io.emit('gameState', {
|
||||
board: game.board,
|
||||
turn: game.currentPlayer,
|
||||
reset: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default app;
|
||||
>>>>>>> 16e6ae0 ((schism): started separating backend from frontend)
|
||||
|
||||
// // TODO: Import the plugins defined for this microservice
|
||||
// // TODO: Import the routes defined for this microservice
|
||||
|
|
|
|||
|
|
@ -78,4 +78,8 @@ export class TTC {
|
|||
|
||||
return result;
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
=======
|
||||
}
|
||||
>>>>>>> 16e6ae0 ((schism): started separating backend from frontend)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue