summary refs log tree commit diff stats
path: root/src/prototype.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/prototype.cpp')
-rw-r--r--src/prototype.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/prototype.cpp b/src/prototype.cpp new file mode 100644 index 0000000..a4a0e80 --- /dev/null +++ b/src/prototype.cpp
@@ -0,0 +1,55 @@
1#include "prototype.h"
2#include "game.h"
3#include "animation.h"
4#include "components/animatable.h"
5#include "components/transformable.h"
6#include "components/ponderable.h"
7#include "systems/pondering.h"
8#include "systems/playing.h"
9
10id_type Prototype::instantiate(
11 Game& game,
12 const Map::Object& object) const
13{
14 id_type entity = game.getEntityManager().emplaceEntity();
15
16 AnimationSet entityGraphics(spritePath_.c_str(), w_, h_, 1);
17 entityGraphics.emplaceAnimation("default", 0, 1, 1);
18
19 game.getEntityManager().emplaceComponent<AnimatableComponent>(
20 entity,
21 std::move(entityGraphics),
22 "default");
23
24 game.getEntityManager().emplaceComponent<TransformableComponent>(
25 entity,
26 object.getX(),
27 object.getY(),
28 w_,
29 h_);
30
31 game.getSystemManager().getSystem<PonderingSystem>().initializeBody(
32 entity,
33 PonderableComponent::BodyType::vacuumed,
34 PonderableComponent::ColliderType::event);
35
36 auto& ponderable = game.getEntityManager().
37 getComponent<PonderableComponent>(entity);
38
39 switch (action_)
40 {
41 case Action::save:
42 {
43 ponderable.setEventCallback(PonderableComponent::ColliderType::player,
44 [] (Game& game) {
45 auto& playing = game.getSystemManager().getSystem<PlayingSystem>();
46
47 playing.save();
48 });
49
50 break;
51 }
52 }
53
54 return entity;
55}