Created EPlayerSpawned that gets published when a player spawns
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef EPlayerSpawned_h__
|
||||||
|
#define EPlayerSpawned_h__
|
||||||
|
|
||||||
|
#include "Core/Event.h"
|
||||||
|
#include "Core/EntityWrapper.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct PlayerSpawned : Event
|
||||||
|
{
|
||||||
|
int PlayerID;
|
||||||
|
EntityWrapper Player;
|
||||||
|
EntityWrapper Spawner;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "Input/EInputCommand.h"
|
#include "Input/EInputCommand.h"
|
||||||
#include "Systems/SpawnerSystem.h"
|
#include "Systems/SpawnerSystem.h"
|
||||||
#include "Events/ESpawnerSpawn.h"
|
#include "Events/ESpawnerSpawn.h"
|
||||||
|
#include "Events/EPlayerSpawned.h"
|
||||||
|
|
||||||
class PlayerSpawnSystem : public ImpureSystem
|
class PlayerSpawnSystem : public ImpureSystem
|
||||||
{
|
{
|
||||||
@@ -11,8 +12,14 @@ public:
|
|||||||
virtual void Update(double dt) override;
|
virtual void Update(double dt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct SpawnRequest
|
||||||
|
{
|
||||||
|
int PlayerID;
|
||||||
|
ComponentInfo::EnumType Team;
|
||||||
|
};
|
||||||
|
|
||||||
EventRelay<PlayerSpawnSystem, Events::InputCommand> m_OnInputCommand;
|
EventRelay<PlayerSpawnSystem, Events::InputCommand> m_OnInputCommand;
|
||||||
bool OnInputCommand(const Events::InputCommand& e);
|
bool OnInputCommand(const Events::InputCommand& e);
|
||||||
|
|
||||||
std::vector<int> m_SpawnRequests;
|
std::vector<SpawnRequest> m_SpawnRequests;
|
||||||
};
|
};
|
||||||
@@ -13,7 +13,7 @@ void PlayerSpawnSystem::Update(double dt)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& team : m_SpawnRequests) {
|
for (auto& req : m_SpawnRequests) {
|
||||||
for (auto& cPlayerSpawn : *playerSpawns) {
|
for (auto& cPlayerSpawn : *playerSpawns) {
|
||||||
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
|
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
|
||||||
if (!spawner.HasComponent("Spawner")) {
|
if (!spawner.HasComponent("Spawner")) {
|
||||||
@@ -22,7 +22,7 @@ void PlayerSpawnSystem::Update(double dt)
|
|||||||
|
|
||||||
// If the spawner has a team affiliation, check it
|
// If the spawner has a team affiliation, check it
|
||||||
if (spawner.HasComponent("Team")) {
|
if (spawner.HasComponent("Team")) {
|
||||||
if ((int)spawner["Team"]["Team"] != team) {
|
if ((int)spawner["Team"]["Team"] != req.Team) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,14 @@ void PlayerSpawnSystem::Update(double dt)
|
|||||||
// Spawn the player!
|
// Spawn the player!
|
||||||
EntityWrapper player = SpawnerSystem::Spawn(spawner);
|
EntityWrapper player = SpawnerSystem::Spawn(spawner);
|
||||||
// Set the player team affiliation
|
// Set the player team affiliation
|
||||||
player["Team"]["Team"] = team;
|
player["Team"]["Team"] = req.Team;
|
||||||
|
|
||||||
|
// Publish a PlayerSpawned event
|
||||||
|
Events::PlayerSpawned e;
|
||||||
|
e.PlayerID = req.PlayerID;
|
||||||
|
e.Player = player;
|
||||||
|
e.Spawner = spawner;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_SpawnRequests.clear();
|
m_SpawnRequests.clear();
|
||||||
@@ -43,7 +50,10 @@ bool PlayerSpawnSystem::OnInputCommand(const Events::InputCommand& e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e.Value != 0) {
|
if (e.Value != 0) {
|
||||||
m_SpawnRequests.push_back((int)e.Value);
|
SpawnRequest req;
|
||||||
|
req.PlayerID = e.PlayerID;
|
||||||
|
req.Team = (ComponentInfo::EnumType)e.Value;
|
||||||
|
m_SpawnRequests.push_back(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user