Skip to content

Commit

Permalink
#292 Map object group _fetchSuccess generalized
Browse files Browse the repository at this point in the history
  • Loading branch information
Wotuu committed May 22, 2020
1 parent 47bcdc7 commit 622e8c7
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 114 deletions.
Expand Up @@ -9,6 +9,7 @@
namespace App\Http\Controllers\Traits;

use App\Models\DungeonFloorSwitchMarker;
use Illuminate\Support\Collection;

trait ListsDungeonFloorSwitchMarkers
{
Expand All @@ -17,10 +18,10 @@ trait ListsDungeonFloorSwitchMarkers
* Lists all dungeon floor switch markers on a floor.
*
* @param $floorId
* @return DungeonFloorSwitchMarker[]
* @return Collection
*/
function listDungeonFloorSwitchMarkers($floorId)
{
return DungeonFloorSwitchMarker::all()->where('floor_id', $floorId);
return DungeonFloorSwitchMarker::where('floor_id', $floorId)->get();
}
}
14 changes: 13 additions & 1 deletion resources/assets/js/custom/mapobjectgroup.js
@@ -1,9 +1,10 @@
class MapObjectGroup extends Signalable {

constructor(manager, name, editable = false) {
constructor(manager, name, field, editable = false) {
super();
this.manager = manager;
this.name = name;
this.field = field;
this.editable = editable;

this.objects = [];
Expand Down Expand Up @@ -48,6 +49,17 @@ class MapObjectGroup extends Signalable {
*/
_fetchSuccess(response) {
console.assert(this instanceof MapObjectGroup, 'this is not a MapObjectGroup', this);

let mapObjects = response[this.field];

console.assert(typeof mapObjects === 'object', 'mapObjects is not an array', mapObjects);

// Now draw the map objects on the map
for (let i = 0; i < mapObjects.length; i++) {
if (mapObjects.hasOwnProperty(i)) {
this._restoreObject(mapObjects[i]);
}
}
}

/**
Expand Down
@@ -1,6 +1,6 @@
class BrushlineMapObjectGroup extends MapObjectGroup {
constructor(manager, editable) {
super(manager, MAP_OBJECT_GROUP_BRUSHLINE, editable);
super(manager, MAP_OBJECT_GROUP_BRUSHLINE, 'brushline', editable);

let self = this;

Expand Down Expand Up @@ -65,19 +65,4 @@ class BrushlineMapObjectGroup extends MapObjectGroup {
// Show echo notification or not
this._showReceivedFromEcho(brushline, username);
}

_fetchSuccess(response) {
super._fetchSuccess(response);
// no super call required
console.assert(this instanceof BrushlineMapObjectGroup, 'this is not a BrushlineMapObjectGroup', this);

let brushlines = response.brushline;

// Now draw the brushlines on the map
for (let index in brushlines) {
if (brushlines.hasOwnProperty(index)) {
this._restoreObject(brushlines[index]);
}
}
}
}
@@ -1,6 +1,6 @@
class DungeonFloorSwitchMarkerMapObjectGroup extends MapObjectGroup {
constructor(manager, editable) {
super(manager, MAP_OBJECT_GROUP_DUNGEON_FLOOR_SWITCH_MARKER, editable);
super(manager, MAP_OBJECT_GROUP_DUNGEON_FLOOR_SWITCH_MARKER, 'dungeonfloorswitchmarker', editable);

this.title = 'Hide/show floor switch markers';
this.fa_class = 'fa-door-open';
Expand Down Expand Up @@ -49,18 +49,4 @@ class DungeonFloorSwitchMarkerMapObjectGroup extends MapObjectGroup {
// We just downloaded the floor switch marker, it's synced alright!
dungeonFloorSwitchMarker.setSynced(true);
}

_fetchSuccess(response) {
// no super call required
console.assert(this instanceof DungeonFloorSwitchMarkerMapObjectGroup, 'this is not a DungeonFloorSwitchMarkerMapObjectGroup', this);

let floorSwitchMarkers = response.dungeonfloorswitchmarker;

// Now draw the enemies on the map
for (let index in floorSwitchMarkers) {
if (floorSwitchMarkers.hasOwnProperty(index)) {
this._restoreObject(floorSwitchMarkers[index]);
}
}
}
}
Expand Up @@ -70,7 +70,7 @@ class EnemyMapObjectGroup extends MapObjectGroup {
}

_fetchSuccess(response) {
// no super call required
// no super call, we're handling this by ourselves
console.assert(this instanceof EnemyMapObjectGroup, 'this is not a EnemyMapObjectGroup', this);

// The enemies are no longer returned from the response; get it from the getState() instead
Expand Down
@@ -1,6 +1,6 @@
class EnemyPackMapObjectGroup extends MapObjectGroup {
constructor(manager, editable) {
super(manager, MAP_OBJECT_GROUP_ENEMY_PACK, editable);
super(manager, MAP_OBJECT_GROUP_ENEMY_PACK, 'enemypack', editable);

this.title = 'Hide/show enemy packs';
this.fa_class = 'fa-draw-polygon';
Expand Down Expand Up @@ -73,18 +73,4 @@ class EnemyPackMapObjectGroup extends MapObjectGroup {
}
}
}

_fetchSuccess(response) {
super._fetchSuccess(response);

// no super call required
console.assert(this instanceof EnemyPackMapObjectGroup, 'this is not a EnemyPackMapObjectGroup', this);

let enemyPacks = response.enemypack;

// Now draw the packs on the map
for (let i = 0; i < enemyPacks.length; i++) {
this._restoreObject(enemyPacks[i]);
}
}
}
@@ -1,6 +1,6 @@
class EnemyPatrolMapObjectGroup extends MapObjectGroup {
constructor(manager, editable) {
super(manager, MAP_OBJECT_GROUP_ENEMY_PATROL, editable);
super(manager, MAP_OBJECT_GROUP_ENEMY_PATROL, 'enemypatrol', editable);

this.title = 'Hide/show enemy patrol routes';
this.fa_class = 'fa-exchange-alt';
Expand Down Expand Up @@ -44,18 +44,4 @@ class EnemyPatrolMapObjectGroup extends MapObjectGroup {
enemyPatrol.setSynced(true);
}
}

_fetchSuccess(response) {
// no super call required
console.assert(this instanceof EnemyPatrolMapObjectGroup, 'this is not a EnemyPatrolMapObjectGroup', this);

let enemyPatrols = response.enemypatrol;

// Now draw the patrols on the map
for (let index in enemyPatrols) {
if (enemyPatrols.hasOwnProperty(index)) {
this._restoreObject(enemyPatrols[index]);
}
}
}
}
@@ -1,6 +1,6 @@
class KillZoneMapObjectGroup extends MapObjectGroup {
constructor(manager, editable) {
super(manager, MAP_OBJECT_GROUP_KILLZONE, editable);
super(manager, MAP_OBJECT_GROUP_KILLZONE, 'killzone', editable);

let self = this;

Expand Down Expand Up @@ -84,21 +84,6 @@ class KillZoneMapObjectGroup extends MapObjectGroup {
return killzone;
}

_fetchSuccess(response) {
super._fetchSuccess(response);
// no super call required
console.assert(this instanceof KillZoneMapObjectGroup, 'this is not a KillZoneMapObjectGroup', this);

let killzones = response.killzone;

// Now draw the killzones on the map
for (let index in killzones) {
if (killzones.hasOwnProperty(index)) {
this._restoreObject(killzones[index]);
}
}
}

/**
* Creates a whole new pull.
* @param enemyIds array Any enemies that must be in the pull from the start
Expand Down
@@ -1,6 +1,6 @@
class MapIconMapObjectGroup extends MapObjectGroup {
constructor(manager, editable) {
super(manager, MAP_OBJECT_GROUP_MAPICON, editable);
super(manager, MAP_OBJECT_GROUP_MAPICON, 'mapicon', editable);

let self = this;

Expand Down Expand Up @@ -66,19 +66,4 @@ class MapIconMapObjectGroup extends MapObjectGroup {
// Show echo notification or not
this._showReceivedFromEcho(mapIcon, username);
}

_fetchSuccess(response) {
super._fetchSuccess(response);
// no super call required
console.assert(this instanceof MapIconMapObjectGroup, 'this is not a MapIconMapObjectGroup', this);

let mapIcons = response.mapicon;

// Now draw the map icons on the map
for (let index in mapIcons) {
if (mapIcons.hasOwnProperty(index)) {
this._restoreObject(mapIcons[index]);
}
}
}
}
18 changes: 1 addition & 17 deletions resources/assets/js/custom/mapobjectgroups/pathmapobjectgroup.js
@@ -1,6 +1,6 @@
class PathMapObjectGroup extends MapObjectGroup {
constructor(manager, editable) {
super(manager, MAP_OBJECT_GROUP_PATH, editable);
super(manager, MAP_OBJECT_GROUP_PATH, 'path', editable);

let self = this;

Expand Down Expand Up @@ -62,20 +62,4 @@ class PathMapObjectGroup extends MapObjectGroup {
// Show echo notification or not
this._showReceivedFromEcho(path, username);
}

_fetchSuccess(response) {
super._fetchSuccess(response);

console.assert(this instanceof PathMapObjectGroup, 'this is not a PathMapObjectGroup', this);

// Should always exist
let paths = response.path;

// Now draw the paths on the map
for (let index in paths) {
if (paths.hasOwnProperty(index)) {
this._restoreObject(paths[index]);
}
}
}
}

0 comments on commit 622e8c7

Please sign in to comment.