Skip to content

Commit

Permalink
#345 Started work adding a npc created event so people don't have to …
Browse files Browse the repository at this point in the history
…refresh their page all the time to fetch the latest npcs.
  • Loading branch information
Wotuu committed Aug 4, 2020
1 parent fcd2ab3 commit 1cafd58
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
21 changes: 21 additions & 0 deletions app/Events/NpcAddedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Events;

class NpcAddedEvent extends ContextEvent
{
public function broadcastAs()
{
return 'npc-added';
}

public function broadcastWith()
{
return array_merge(
parent::broadcastWith(),
[
'color' => $this->_user->echo_color
]
);
}
}
4 changes: 2 additions & 2 deletions resources/assets/js/custom/models/enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ class Enemy extends MapObject {

let self = this;
let selectNpcs = [];
let npcs = this.map.options.npcs;
let npcs = getState().getRawNpcs();
for (let index in npcs) {
if (npcs.hasOwnProperty(index)) {
let npc = npcs[index];
selectNpcs.push({
id: npc.id,
name: npc.name + ' (' + npc.id + ')'
name: `${npc.name} (${npc.id})`
});
}
}
Expand Down
18 changes: 18 additions & 0 deletions resources/assets/js/custom/statemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class StateManager extends Signalable {
this.mapIconTypes = [];
this.classColors = [];
this.enemies = [];
this.rawNpcs = [];
this.rawEnemies = [];
this.mdtEnemies = [];
this.factions = [];
Expand Down Expand Up @@ -179,6 +180,14 @@ class StateManager extends Signalable {
this.enemies = enemies;
}

/**
* Sets the raw NPCs for the state.
* @param rawNpcs {Object[]}
*/
setRawNpcs(rawNpcs) {
this.rawNpcs = rawNpcs;
}

/**
* Sets the raw enemies (not converted to Enemy classes yet; pure objects)
* @param rawEnemies
Expand Down Expand Up @@ -477,6 +486,15 @@ class StateManager extends Signalable {
return enemy;
}

/**
* Get all the raw npcs of this dungeon.
* @returns {[]}
*/
getRawNpcs() {
console.assert(this instanceof StateManager, 'this is not a StateManager', this);
return this.rawNpcs;
}

/**
* Get all the raw enemies of this dungeon.
* @returns {[]}
Expand Down
1 change: 1 addition & 0 deletions resources/views/common/general/statemanager.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
_stateManager.setDungeonData({!! $dungeonData !!});
_stateManager.setMapIconTypes({!! $mapIconTypes !!});
_stateManager.setClassColors({!! $classColors !!});
_stateManager.setRawNpcs({!! $npcs !!});
_stateManager.setRawEnemies({!! $enemies !!});
_stateManager.setRaidMarkers({!! $raidMarkers !!});
_stateManager.setFactions({!! $factions !!});
Expand Down
16 changes: 7 additions & 9 deletions resources/views/common/maps/map.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@
$floorId = isset($floorId) ? $floorId : $dungeon->floors->first()->id;
// Show the attribution
$showAttribution = isset($showAttribution) && !$showAttribution ? false : true;
// Build options for displayed NPCs
$npcOptions = new \Illuminate\Support\Collection();
foreach ($npcs as $npc) {
$npcOptions->push(['id' => $npc->id, 'name' => $npc->name, 'dungeon_id' => $npc->dungeon_id]);
}
// Additional options to pass to the map when we're in an admin environment
$adminOptions = [];
if ($isAdmin) {
// Build options for displayed NPCs
$npcOptions = [];
foreach ($npcs as $npc) {
$npcOptions[] = ['id' => $npc->id, 'name' => $npc->name, 'dungeon_id' => $npc->dungeon_id];
}
$adminOptions = [
// Display options for changing Teeming status for map objects
'teemingOptions' => [
Expand All @@ -64,9 +63,7 @@
['key' => 'any', 'description' => __('Any')],
['key' => 'alliance', 'description' => __('Alliance')],
['key' => 'horde', 'description' => __('Horde')],
],
// Display options for changing the NPC of an enemy
'npcs' => $npcOptions
]
];
}
?>
Expand Down Expand Up @@ -103,6 +100,7 @@
'dungeonData' => $dungeon,
'paidTiers' => Auth::check() ? $user->getPaidTiers() : collect(),
'userData' => $user,
'npcs' => $npcOptions,
'dungeonroute' => [
'publicKey' => $routePublicKey,
'faction' => $routeFaction,
Expand Down

0 comments on commit 1cafd58

Please sign in to comment.