@@ -51,12 +51,12 @@ import {
51
51
SpinRadiansCommand ,
52
52
} from "../command/move-command" ;
53
53
import { GridIndices } from "../robot/grid-indices" ;
54
- import { puzzles , type PuzzleComponents } from "./puzzles" ;
55
54
import {
56
55
moveAllRobotsHomeToDefaultOptimized ,
57
56
moveAllRobotsToDefaultPositions ,
58
- moveAllRobotsFromBoardToHome ,
59
57
} from "../robot/path-materializer" ;
58
+ import type { PuzzleComponents } from "./puzzles" ;
59
+ import { puzzles } from "./puzzles" ;
60
60
import { tcpServer } from "./tcp-interface" ;
61
61
import { robotManager } from "../robot/robot-manager" ;
62
62
import { executor } from "../command/executor" ;
@@ -76,7 +76,7 @@ async function setupDefaultRobotPositions(
76
76
moveAllRobotsToDefaultPositions ( defaultPositionsMap ) ;
77
77
await executor . execute ( command ) ;
78
78
} else {
79
- setAllRobotsToDefaultPositions ( defaultPositionsMap ) ;
79
+ moveAllRobotsToDefaultPositions ( defaultPositionsMap ) ;
80
80
}
81
81
} else {
82
82
if ( isMoving ) {
@@ -186,6 +186,17 @@ apiRouter.get("/client-information", async (req, res) => {
186
186
) ,
187
187
) ;
188
188
}
189
+ const robotPos = new Map (
190
+ oldSave ! . robotPos ?. map < [ string , GridIndices ] > ( ( obj ) => [
191
+ obj [ 1 ] ,
192
+ new GridIndices (
193
+ parseInt ( obj [ 0 ] . split ( ", " ) [ 0 ] ) ,
194
+ parseInt ( obj [ 0 ] . split ( ", " ) [ 1 ] ) ,
195
+ ) ,
196
+ ] ) ,
197
+ ) ;
198
+ console . log ( robotPos ) ;
199
+ setAllRobotsToDefaultPositions ( robotPos ) ;
189
200
}
190
201
/**
191
202
* Note the client currently redirects to home from the game over screen
@@ -285,7 +296,6 @@ apiRouter.post("/start-puzzle-game", async (req, res) => {
285
296
const fen = puzzle . fen ;
286
297
const moves = puzzle . moves ;
287
298
const difficulty = puzzle . rating ;
288
- const tooltip = puzzle . tooltip ;
289
299
290
300
if ( puzzle . robotDefaultPositions ) {
291
301
// Convert puzzle.robotDefaultPositions from Record<string, string> to Map<string, GridIndices>
@@ -322,7 +332,7 @@ apiRouter.post("/start-puzzle-game", async (req, res) => {
322
332
new ChessEngine ( ) ,
323
333
socketManager ,
324
334
fen ,
325
- tooltip ,
335
+ "" ,
326
336
moves ,
327
337
difficulty ,
328
338
) ,
@@ -331,15 +341,6 @@ apiRouter.post("/start-puzzle-game", async (req, res) => {
331
341
return res . send ( { message : "success" } ) ;
332
342
} ) ;
333
343
334
- /**
335
- * Returns robots to home after a game ends.
336
- */
337
- apiRouter . post ( "/return-home" , async ( _req , res ) => {
338
- const command = moveAllRobotsFromBoardToHome ( ) ;
339
- await executor . execute ( command ) ;
340
- return res . send ( { message : "success" } ) ;
341
- } ) ;
342
-
343
344
/**
344
345
* Returns all registered robot ids
345
346
*/
@@ -575,6 +576,23 @@ apiRouter.get("/pause-game", (_, res) => {
575
576
*/
576
577
apiRouter . get ( "/unpause-game" , async ( _ , res ) => {
577
578
gamePaused . flag = false ;
579
+ const ids = clientManager . getIds ( ) ;
580
+ if ( ids ) {
581
+ const oldSave = SaveManager . loadGame ( ids [ 0 ] ) ;
582
+ gameManager ?. chess . loadFen ( oldSave ! . oldPos ) ;
583
+ setAllRobotsToDefaultPositions (
584
+ new Map (
585
+ oldSave ! . oldRobotPos ?. map < [ string , GridIndices ] > ( ( obj ) => [
586
+ obj [ 1 ] ,
587
+ new GridIndices (
588
+ parseInt ( obj [ 0 ] . split ( ", " ) [ 0 ] ) ,
589
+ parseInt ( obj [ 0 ] . split ( ", " ) [ 1 ] ) ,
590
+ ) ,
591
+ ] ) ,
592
+ ) ,
593
+ ) ;
594
+ socketManager . sendToAll ( new SetChessMessage ( oldSave ! . oldPos ) ) ;
595
+ }
578
596
socketManager . sendToAll ( new GameHoldMessage ( GameHoldReason . GAME_UNPAUSED ) ) ;
579
597
return res . send ( { message : "success" } ) ;
580
598
} ) ;
0 commit comments