summary refs log tree commit diff stats
path: root/src/prototype.cpp
blob: a4a0e807d0f83166b70893b73e07d22ede275031 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "prototype.h"
#include "game.h"
#include "animation.h"
#include "components/animatable.h"
#include "components/transformable.h"
#include "components/ponderable.h"
#include "systems/pondering.h"
#include "systems/playing.h"

id_type Prototype::instantiate(
  Game& game,
  const Map::Object& object) const
{
  id_type entity = game.getEntityManager().emplaceEntity();

  AnimationSet entityGraphics(spritePath_.c_str(), w_, h_, 1);
  entityGraphics.emplaceAnimation("default", 0, 1, 1);

  game.getEntityManager().emplaceComponent<AnimatableComponent>(
    entity,
    std::move(entityGraphics),
    "default");

  game.getEntityManager().emplaceComponent<TransformableComponent>(
    entity,
    object.getX(),
    object.getY(),
    w_,
    h_);

  game.getSystemManager().getSystem<PonderingSystem>().initializeBody(
    entity,
    PonderableComponent::BodyType::vacuumed,
    PonderableComponent::ColliderType::event);

  auto& ponderable = game.getEntityManager().
    getComponent<PonderableComponent>(entity);

  switch (action_)
  {
    case Action::save:
    {
      ponderable.setEventCallback(PonderableComponent::ColliderType::player,
        [] (Game& game) {
          auto& playing = game.getSystemManager().getSystem<PlayingSystem>();

          playing.save();
        });

      break;
    }
  }

  return entity;
}