Made SpawnerSystem utilize the new EntityFile for spawning instead

This commit is contained in:
2016-03-02 19:52:34 +01:00
parent 069583e09f
commit 5923d2d7a7
2 changed files with 9 additions and 8 deletions
+1 -2
View File
@@ -7,8 +7,7 @@
#include "Core/System.h"
#include "Events/ESpawnerSpawn.h"
#include "Core/Transform.h"
#include "Core/ResourceManager.h"
#include "Core/EntityXMLFileParser.h"
#include "Core/EntityFile.h"
class SpawnerSystem : public System
{
+7 -5
View File
@@ -17,14 +17,16 @@ EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent /
// Load the entity file and parse it
const std::string& entityFilePath = spawner["Spawner"]["EntityFile"];
auto entityFile = ResourceManager::Load<EntityXMLFile>(entityFilePath);
if (entityFile == nullptr) {
EntityWrapper spawnedEntity;
try {
auto entityFile = ResourceManager::Load<EntityFile>(entityFilePath);
spawnedEntity = entityFile->MergeInto(world);
world->SetParent(spawnedEntity.ID, parent.ID);
} catch (const Resource::FailedLoadingException& e) {
return EntityWrapper::Invalid;
}
EntityXMLFileParser parser(entityFile);
EntityWrapper spawnedEntity(world, parser.MergeEntities(world, parent.ID));
//If the spawned entity is collideable, then we must not spawn it where it collides with something that
// If the spawned entity is collidable, then we must not spawn it where it collides with something that
// has a dontCollideComponent attached.
bool spawnOnCollidable = dontCollideComponent.empty() || !spawnedEntity.HasComponent("Collidable");
if (!spawnOnCollidable) {