From 3123643bb70ce4fb137ab2c2362fb7e634c6bc08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 4 Jul 2020 01:11:04 +0200 Subject: [PATCH] MAPG-44 modify game to use pov of place --- public/static/js/game.js | 11 +++++++---- src/Controller/GameFlowController.php | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/public/static/js/game.js b/public/static/js/game.js index 0f557ee..de9098b 100644 --- a/public/static/js/game.js +++ b/public/static/js/game.js @@ -8,6 +8,7 @@ rounds: [], scoreSum: 0, panoId: null, + pov: null, panorama: null, map: null, guessMarker: null, @@ -35,6 +36,7 @@ } Game.panoId = this.response.panoId; + Game.pov = this.response.pov; if (this.response.history) { for (var i = 0; i < this.response.history.length; ++i) { @@ -116,7 +118,7 @@ document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS); - Game.loadPano(Game.panoId); + Game.loadPano(Game.panoId, Game.pov); }, handleErrorResponse: function (error) { @@ -129,13 +131,13 @@ }); }, - loadPano: function (panoId) { + loadPano: function (panoId, pov) { if (Game.adaptGuess) { document.getElementById('guess').classList.add('adapt'); } - Game.panorama.setPov({ heading: 0, pitch: 0 }); - Game.panorama.setZoom(0); + Game.panorama.setPov({ heading: pov.heading, pitch: pov.pitch }); + Game.panorama.setZoom(pov.zoom); Game.panorama.setPano(panoId); }, @@ -199,6 +201,7 @@ } Game.panoId = this.response.panoId; + Game.pov = this.response.pov; }, data); }, diff --git a/src/Controller/GameFlowController.php b/src/Controller/GameFlowController.php index b15ffa7..e1b10fa 100644 --- a/src/Controller/GameFlowController.php +++ b/src/Controller/GameFlowController.php @@ -41,7 +41,10 @@ class GameFlowController $session->set('state', $state); - $data = ['panoId' => $place->getPanoIdCached()]; + $data = [ + 'panoId' => $place->getPanoIdCached(), + 'pov' => $place->getPov()->toArray() + ]; } else { $rounds = count($state['rounds']); $last = $state['rounds'][$rounds - 1]; @@ -59,7 +62,10 @@ class GameFlowController $data = [ 'history' => $history, - 'panoId' => $last['panoId'] + 'panoId' => $last['panoId'], + 'pov' => isset($last['pov']) ? // should be checked not to break with old sessions + $last['pov']->toArray() : + ['heading' => 0.0, 'pitch' => 0.0, 'zoom' => 0.0], ]; } @@ -103,10 +109,12 @@ class GameFlowController $this->addNewRoundToState($state, $place, $placesWithoutPano); $panoId = $place->getPanoIdCached(); + $pov = $place->getPov()->toArray(); } else { $state['rounds'] = []; $panoId = null; + $pov = null; } $session->set('state', $state); @@ -117,7 +125,8 @@ class GameFlowController 'distance' => $distance, 'score' => $score ], - 'panoId' => $panoId + 'panoId' => $panoId, + 'pov' => $pov ]; return new JsonContent($data); } @@ -128,7 +137,8 @@ class GameFlowController 'placesWithoutPano' => $placesWithoutPano, 'placeId' => $place->getId(), 'position' => $place->getPosition(), - 'panoId' => $place->getPanoIdCached() + 'panoId' => $place->getPanoIdCached(), + 'pov' => $place->getPov() ]; }