From 028d8a22a2ef7b91f48f13b4291721e05a2b7b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 4 Jul 2020 01:06:37 +0200 Subject: [PATCH 1/4] MAPG-44 modify DB structure to store pov data --- .../migrations/structure/20200704_0005_pov_for_places.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 database/migrations/structure/20200704_0005_pov_for_places.sql diff --git a/database/migrations/structure/20200704_0005_pov_for_places.sql b/database/migrations/structure/20200704_0005_pov_for_places.sql new file mode 100644 index 0000000..93da617 --- /dev/null +++ b/database/migrations/structure/20200704_0005_pov_for_places.sql @@ -0,0 +1,8 @@ +ALTER TABLE + `places` +ADD + `pov_heading` decimal(6, 3) NOT NULL DEFAULT 0.0, +ADD + `pov_pitch` decimal(5, 3) NOT NULL DEFAULT 0.0, +ADD + `pov_zoom` decimal(5, 4) NOT NULL DEFAULT 0.0; From 4e48e6ae7319735bf315d9e4826c75915df2e6f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 4 Jul 2020 01:09:00 +0200 Subject: [PATCH 2/4] MAPG-44 add Pov class and adjust Place model to store pov --- src/PersistentData/Model/Place.php | 46 +++++++++++++++++++++++- src/Util/Panorama/Pov.php | 56 ++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/Util/Panorama/Pov.php diff --git a/src/PersistentData/Model/Place.php b/src/PersistentData/Model/Place.php index d8d26b1..033f05e 100644 --- a/src/PersistentData/Model/Place.php +++ b/src/PersistentData/Model/Place.php @@ -5,12 +5,13 @@ use DateTime; use MapGuesser\Http\Request; use MapGuesser\PersistentData\PersistentDataManager; use MapGuesser\Util\Geo\Position; +use MapGuesser\Util\Panorama\Pov; class Place extends Model { protected static string $table = 'places'; - protected static array $fields = ['map_id', 'lat', 'lng', 'pano_id_cached', 'pano_id_cached_timestamp']; + protected static array $fields = ['map_id', 'lat', 'lng', 'pano_id_cached', 'pano_id_cached_timestamp', 'pov_heading', 'pov_pitch', 'pov_zoom']; protected static array $relations = ['map' => Map::class]; @@ -24,9 +25,12 @@ class Place extends Model private ?DateTime $panoIdCachedTimestamp = null; + private Pov $pov; + public function __construct() { $this->position = new Position(0.0, 0.0); + $this->pov = new Pov(0.0, 0.0, 0.0); } public function setMap(Map $map): void @@ -54,6 +58,26 @@ class Place extends Model $this->position->setLng($lng); } + public function setPov(Pov $pov): void + { + $this->pov = $pov; + } + + public function setPovHeading(float $heading): void + { + $this->pov->setHeading($heading); + } + + public function setPovPitch(float $pitch): void + { + $this->pov->setPitch($pitch); + } + + public function setPovZoom(float $zoom): void + { + $this->pov->setZoom($zoom); + } + public function setPanoIdCached(?string $panoIdCached): void { $this->panoIdCached = $panoIdCached; @@ -96,6 +120,26 @@ class Place extends Model return $this->position->getLng(); } + public function getPov(): Pov + { + return $this->pov; + } + + public function getPovHeading(): float + { + return $this->pov->getHeading(); + } + + public function getPovPitch(): float + { + return $this->pov->getPitch(); + } + + public function getPovZoom(): float + { + return $this->pov->getZoom(); + } + public function getFreshPanoId(bool $canBeIndoor = false): ?string { if ( diff --git a/src/Util/Panorama/Pov.php b/src/Util/Panorama/Pov.php new file mode 100644 index 0000000..8aaaf8f --- /dev/null +++ b/src/Util/Panorama/Pov.php @@ -0,0 +1,56 @@ +heading = $heading; + $this->pitch = $pitch; + $this->zoom = $zoom; + } + + public function setHeading(float $heading): void + { + $this->heading = $heading; + } + + public function setPitch(float $pitch): void + { + $this->pitch = $pitch; + } + + public function setZoom(float $zoom): void + { + $this->zoom = $zoom; + } + + public function getHeading(): float + { + return $this->heading; + } + + public function getPitch(): float + { + return $this->pitch; + } + + public function getZoom(): float + { + return $this->zoom; + } + + public function toArray(): array + { + return [ + 'heading' => $this->heading, + 'pitch' => $this->pitch, + 'zoom' => $this->zoom + ]; + } +} From b736ce89700fff58e98d3734e31faba40429378a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 4 Jul 2020 01:10:03 +0200 Subject: [PATCH 3/4] MAPG-44 modify MapAdminController to get/save place pov data --- src/Controller/MapAdminController.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Controller/MapAdminController.php b/src/Controller/MapAdminController.php index d12ccbf..0d7ad02 100644 --- a/src/Controller/MapAdminController.php +++ b/src/Controller/MapAdminController.php @@ -16,6 +16,7 @@ use MapGuesser\Response\HtmlContent; use MapGuesser\Response\JsonContent; use MapGuesser\Util\Geo\Bounds; use MapGuesser\Util\Geo\Position; +use MapGuesser\Util\Panorama\Pov; class MapAdminController implements ISecured { @@ -94,6 +95,11 @@ class MapAdminController implements ISecured $place->setMap($map); $place->setLat((float) $placeRaw['lat']); $place->setLng((float) $placeRaw['lng']); + $place->setPov(new Pov( + (float) $placeRaw['pov']['heading'], + (float) $placeRaw['pov']['pitch'], + (float) $placeRaw['pov']['zoom'] + )); if ($placeRaw['panoId'] === -1) { $place->setPanoIdCachedTimestampDate(new DateTime('-1 day')); @@ -114,6 +120,11 @@ class MapAdminController implements ISecured $place = $this->placeRepository->getById((int) $placeRaw['id']); $place->setLat((float) $placeRaw['lat']); $place->setLng((float) $placeRaw['lng']); + $place->setPov(new Pov( + (float) $placeRaw['pov']['heading'], + (float) $placeRaw['pov']['pitch'], + (float) $placeRaw['pov']['zoom'] + )); $place->setPanoIdCachedTimestampDate(new DateTime('-1 day')); $this->pdm->saveToDb($place); @@ -150,7 +161,8 @@ class MapAdminController implements ISecured return new JsonContent($data); } - public function deleteMap() { + public function deleteMap() + { $mapId = (int) $this->request->query('mapId'); $map = $this->mapRepository->getById($mapId); @@ -206,7 +218,7 @@ class MapAdminController implements ISecured { //TODO: from repository or relations $select = new Select(\Container::$dbConnection, 'places'); - $select->columns(['id', 'lat', 'lng', 'pano_id_cached', 'pano_id_cached_timestamp']); + $select->columns(['id', 'lat', 'lng', 'pano_id_cached', 'pano_id_cached_timestamp', 'pov_heading', 'pov_pitch', 'pov_zoom']); $select->where('map_id', '=', $map->getId()); $result = $select->execute(); @@ -214,8 +226,6 @@ class MapAdminController implements ISecured $places = []; while ($place = $result->fetch(IResultSet::FETCH_ASSOC)) { - //$panoId = ??? - //$pov = ??? $noPano = $place['pano_id_cached_timestamp'] && $place['pano_id_cached'] === null; $places[$place['id']] = [ @@ -223,7 +233,11 @@ class MapAdminController implements ISecured 'lat' => $place['lat'], 'lng' => $place['lng'], 'panoId' => null, - 'pov' => ['heading' => 0.0, 'pitch' => 0.0, 'zoom' => 0.0], + 'pov' => [ + 'heading' => (float) $place['pov_heading'], + 'pitch' => (float) $place['pov_pitch'], + 'zoom' => (float) $place['pov_zoom'] + ], 'noPano' => $noPano ]; } 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 4/4] 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() ]; }