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 "Systems/SpawnerSystem.h"
|
||||
#include "Events/ESpawnerSpawn.h"
|
||||
#include "Events/EPlayerSpawned.h"
|
||||
|
||||
class PlayerSpawnSystem : public ImpureSystem
|
||||
{
|
||||
@@ -11,8 +12,14 @@ public:
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
struct SpawnRequest
|
||||
{
|
||||
int PlayerID;
|
||||
ComponentInfo::EnumType Team;
|
||||
};
|
||||
|
||||
EventRelay<PlayerSpawnSystem, Events::InputCommand> m_OnInputCommand;
|
||||
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;
|
||||
}
|
||||
|
||||
for (auto& team : m_SpawnRequests) {
|
||||
for (auto& req : m_SpawnRequests) {
|
||||
for (auto& cPlayerSpawn : *playerSpawns) {
|
||||
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
|
||||
if (!spawner.HasComponent("Spawner")) {
|
||||
@@ -22,7 +22,7 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
|
||||
// If the spawner has a team affiliation, check it
|
||||
if (spawner.HasComponent("Team")) {
|
||||
if ((int)spawner["Team"]["Team"] != team) {
|
||||
if ((int)spawner["Team"]["Team"] != req.Team) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,14 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
// Spawn the player!
|
||||
EntityWrapper player = SpawnerSystem::Spawn(spawner);
|
||||
// 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();
|
||||
@@ -43,7 +50,10 @@ bool PlayerSpawnSystem::OnInputCommand(const Events::InputCommand& e)
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user