3 #include <BLIB/Util/FileUtil.hpp>
26 bl::ecs::Entity entity = owner.
engine().ecs().createEntity(bl::ecs::Flags::WorldObject);
27 std::string animation;
28 BL_LOG_DEBUG <<
"Created character entity " << entity;
30 bl::ecs::Cleaner cleaner(owner.
engine().ecs(), entity);
33 bl::tmap::Position* pos =
34 owner.
engine().ecs().addComponent<bl::tmap::Position>(entity, spawn.
position);
45 BL_LOG_ERROR <<
"Failed to load NPC: " << spawn.
file;
46 return bl::ecs::InvalidEntity;
48 BL_LOG_INFO <<
"Spawning NPC " << data.
name() <<
" at ("
49 <<
static_cast<int>(spawn.
position.level) <<
", " << spawn.
position.position.x
50 <<
", " << spawn.
position.position.y <<
") id=" << entity;
53 BL_LOG_ERROR <<
"Failed to add behavior to spawned npc: " << entity;
54 return bl::ecs::InvalidEntity;
66 BL_LOG_ERROR <<
"Failed to load trainer: " << spawn.
file;
67 return bl::ecs::InvalidEntity;
69 BL_LOG_INFO <<
"Spawning trainer " << data.
name <<
" at ("
70 <<
static_cast<int>(spawn.
position.level) <<
", " << spawn.
position.position.x
71 <<
", " << spawn.
position.position.y <<
") id=" << entity;
74 BL_LOG_ERROR <<
"Failed to add behavior to spawned npc: " << entity;
75 return bl::ecs::InvalidEntity;
82 BL_LOG_ERROR <<
"Unknown character file type: " << spawn.
file;
83 return bl::ecs::InvalidEntity;
103 BL_LOG_ERROR <<
"Unknown item id: " << item.
id;
107 const bl::ecs::Entity entity = owner.
engine().ecs().createEntity(bl::ecs::Flags::WorldObject);
109 bl::tmap::Position* pos = owner.
engine().ecs().emplaceComponent<bl::tmap::Position>(
113 bl::tmap::Direction::Up);
120 owner.
engine().ecs().getComponent<bl::com::Transform2D>(entity)->setOrigin(0.f, 0.f);
128 const std::string& gfx,
map::Map& map) {
129 bl::ecs::Entity entity = owner.
engine().ecs().createEntity(bl::ecs::Flags::WorldObject);
130 bl::ecs::Cleaner cleaner(owner.
engine().ecs(), entity);
131 BL_LOG_DEBUG <<
"Created generic entity " << entity;
133 bl::tmap::Position* pos = owner.
engine().ecs().emplaceComponent<bl::tmap::Position>(
134 entity, level, tiles, bl::tmap::Direction::Up);
135 const bool isAnim = bl::util::FileUtil::getExtension(gfx) ==
"anim";
156 const std::string& gfx,
map::Map& map) {
157 bl::ecs::Entity entity = owner.
engine().ecs().createEntity(bl::ecs::Flags::WorldObject);
158 bl::ecs::Cleaner cleaner(owner.
engine().ecs(), entity);
159 BL_LOG_DEBUG <<
"Created animation entity " << entity;
Id
Represents an item in its simplist form.
Core classes and functionality for both the editor and game.
Empty component to indicate that an entity cannot be moved through.
Adding this component to an entity allows it to be controlled.
Add this component to an entity to make it give an item when interacted with. On interact the owning ...
Adding this component to an entity will allow it to move.
Adding this to an entity will allow it to be interacted with and talked to.
static Renderable & createFromAnimation(bl::engine::Engine &engine, bl::ecs::Entity entity, bl::rc::Scene *scene, const std::string &path)
Creates a renderable component from a single animation.
static Renderable & createFromSprite(bl::engine::Engine &engine, bl::ecs::Entity entity, bl::rc::Scene *scene, const std::string &path)
Creates a renderable component for a static sprite.
static Renderable & createFromMoveAnims(bl::engine::Engine &engine, bl::ecs::Entity entity, bl::rc::Scene *scene, const std::string &path)
Creates a renderable component for movement animations.
Adding this to an entity will make it a trainer that can battle.
Behavior & behavior()
The behavior of the NPC.
std::string & name()
The name of the NPC.
bool load(const std::string &file, bl::tmap::Direction spawnDir=bl::tmap::Direction::Up)
Loads the NPC data from the given file.
std::string & animation()
The directory of the movement animations.
Static data for trainers in the world.
bool load(const std::string &file, bl::tmap::Direction spawnDir=bl::tmap::Direction::Down)
Loads the trainer data from the given file.
static const std::string & getName(item::Id item)
Returns the name of the given item.
static Id cast(unsigned int id)
Helper function to cast a raw id to an item Id.
Represents a character to be spawned into a map on load.
bl::tmap::Position position
Basic struct representing a pickup-able item in Map.
The primary map class that represents a usable map in the game.
bl::rc::SceneRef getScene()
Returns the scene for this map.
void setupEntityPosition(bl::ecs::Entity entity)
Performs the final setup of the position components for the given entity. Must already have a bl::tma...
static const std::string & ItemSprite()
static const std::string & NpcFileExtension()
static const std::string & TrainerPath()
static float CharacterMoveSpeed()
static const std::string & NpcPath()
static const std::string & CharacterAnimationPath()
static const std::string & TrainerFileExtension()
static const std::string & ImagePath()
bool addBehavior(bl::ecs::Entity entity, const file::Behavior &behavior)
Helper function for adding the given behavior to the given entity.
Entity(Systems &owner)
Construct a new Entity system.
bool spawnItem(const map::Item &item, map::Map &map)
Spawns an item into the world.
bl::ecs::Entity spawnAnimation(std::uint8_t level, const glm::vec2 &position, const std::string &gfx, map::Map &map)
Spawns an animation-only entity at the given position. The animation is not played until manually tri...
bl::ecs::Entity spawnGeneric(std::uint8_t level, const glm::i32vec2 &tiles, bool collidable, const std::string &gfx, map::Map &map)
Spawns a generic entity with some basic components.
bl::ecs::Entity spawnCharacter(const map::CharacterSpawn &spawn, map::Map &map)
Spawns a trainer or an npc from the given spawn information.
Owns all primary systems and a reference to the engine.
const bl::engine::Engine & engine() const
Const accessor for the Engine.
AI & ai()
Returns the AI system.