From fc00a499c5b05c76b231259f3ad5deda4fc290a8 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Thu, 14 Oct 2021 22:23:29 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(viewer)=20Enable=20loading=20game?= =?UTF-8?q?=20directly=20from=20json=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- viewer/.gitignore | 2 ++ viewer/src/self-contained.ts | 10 ++++++++-- viewer/tsconfig.json | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/viewer/.gitignore b/viewer/.gitignore index 3614cbb..a22e349 100644 --- a/viewer/.gitignore +++ b/viewer/.gitignore @@ -19,3 +19,5 @@ pnpm-debug.log* *.njsproj *.sln *.sw? + +.env \ No newline at end of file diff --git a/viewer/src/self-contained.ts b/viewer/src/self-contained.ts index e3a4dee..a0fd886 100644 --- a/viewer/src/self-contained.ts +++ b/viewer/src/self-contained.ts @@ -1,6 +1,7 @@ -import { move as execMove, Move, setup, stripSecret } from 'container-engine'; +import { GameState, move as execMove, Move, setup, stripSecret } from 'container-engine'; import { moveAI } from 'container-engine/src/engine'; import { cloneDeep } from 'lodash'; +import AbstractJudge from '../../engine/src/fixtures/Abstract-judge-7215.json'; import launch from './launch'; function launchSelfContained(selector = '#app') { @@ -14,12 +15,17 @@ function launchSelfContained(selector = '#app') { gameState.players[i].name = `Player ${i + 1}`; } - const playerIndex = 1; + let playerIndex = 1; for (const player of gameState.players) { if (player.id != playerIndex) player.isAI = true; } + if (process.env.VUE_APP_loadGame) { + gameState = AbstractJudge as GameState; + playerIndex = AbstractJudge.currentPlayers[0]; + } + emitter.on('move', async (move: Move) => { console.log('move received', move); gameState = execMove(gameState, move, playerIndex); diff --git a/viewer/tsconfig.json b/viewer/tsconfig.json index cdd674a..dac3e6e 100644 --- a/viewer/tsconfig.json +++ b/viewer/tsconfig.json @@ -11,6 +11,7 @@ "allowSyntheticDefaultImports": true, "noImplicitAny": false, "sourceMap": true, + "resolveJsonModule": true, "baseUrl": ".", "types": ["webpack-env", "mocha", "chai"], "paths": {