diff options
Diffstat (limited to 'src/script_system.cpp')
-rw-r--r-- | src/script_system.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/script_system.cpp b/src/script_system.cpp index 3f89290..08d66d4 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp | |||
@@ -4,6 +4,8 @@ | |||
4 | #include "message_system.h" | 4 | #include "message_system.h" |
5 | #include "animation_system.h" | 5 | #include "animation_system.h" |
6 | #include "character_system.h" | 6 | #include "character_system.h" |
7 | #include "transform_system.h" | ||
8 | #include "vector.h" | ||
7 | 9 | ||
8 | ScriptSystem::ScriptSystem(Game& game) : game_(game) { | 10 | ScriptSystem::ScriptSystem(Game& game) : game_(game) { |
9 | engine_.open_libraries( | 11 | engine_.open_libraries( |
@@ -11,8 +13,14 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
11 | sol::lib::coroutine, | 13 | sol::lib::coroutine, |
12 | sol::lib::math); | 14 | sol::lib::math); |
13 | 15 | ||
16 | engine_.new_usertype<vec2i>( | ||
17 | "vec2i", | ||
18 | "x", [] (const vec2i& v) { return v.x(); }, | ||
19 | "y", [] (const vec2i& v) { return v.y(); }); | ||
20 | |||
14 | engine_.new_usertype<Sprite>( | 21 | engine_.new_usertype<Sprite>( |
15 | "sprite", | 22 | "sprite", |
23 | "loc", &Sprite::loc, | ||
16 | "dir", &Sprite::dir, | 24 | "dir", &Sprite::dir, |
17 | "followers", &Sprite::followers, | 25 | "followers", &Sprite::followers, |
18 | "characterState", &Sprite::characterState, | 26 | "characterState", &Sprite::characterState, |
@@ -29,6 +37,7 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
29 | 37 | ||
30 | engine_.new_usertype<AnimationSystem>( | 38 | engine_.new_usertype<AnimationSystem>( |
31 | "animation", | 39 | "animation", |
40 | "initSprite", &AnimationSystem::initSprite, | ||
32 | "setSpriteAnimation", &AnimationSystem::setSpriteAnimation, | 41 | "setSpriteAnimation", &AnimationSystem::setSpriteAnimation, |
33 | "setSpriteDirection", &AnimationSystem::setSpriteDirection); | 42 | "setSpriteDirection", &AnimationSystem::setSpriteDirection); |
34 | 43 | ||
@@ -37,6 +46,12 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
37 | "startRunning", &CharacterSystem::startRunning, | 46 | "startRunning", &CharacterSystem::startRunning, |
38 | "halt", &CharacterSystem::halt); | 47 | "halt", &CharacterSystem::halt); |
39 | 48 | ||
49 | engine_.new_usertype<TransformSystem>( | ||
50 | "transform", | ||
51 | "initSprite", [] (TransformSystem& transform, int spriteId, int x, int y, SpriteLayer layer) { | ||
52 | transform.initSprite(spriteId, vec2i{x, y}, layer); | ||
53 | }); | ||
54 | |||
40 | engine_.new_usertype<Mixer>( | 55 | engine_.new_usertype<Mixer>( |
41 | "mixer", | 56 | "mixer", |
42 | "playSound", &Mixer::playSound, | 57 | "playSound", &Mixer::playSound, |
@@ -62,12 +77,30 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
62 | }); | 77 | }); |
63 | 78 | ||
64 | engine_.set_function( | 79 | engine_.set_function( |
80 | "transform", | ||
81 | [&] () -> TransformSystem& { | ||
82 | return game_.getSystem<TransformSystem>(); | ||
83 | }); | ||
84 | |||
85 | engine_.set_function( | ||
65 | "mixer", | 86 | "mixer", |
66 | [&] () -> Mixer& { | 87 | [&] () -> Mixer& { |
67 | return game_.getMixer(); | 88 | return game_.getMixer(); |
68 | }); | 89 | }); |
69 | 90 | ||
70 | engine_.set_function( | 91 | engine_.set_function( |
92 | "emplaceSprite", | ||
93 | [&] (std::string alias) -> int { | ||
94 | return game_.emplaceSprite(alias); | ||
95 | }); | ||
96 | |||
97 | engine_.set_function( | ||
98 | "destroySprite", | ||
99 | [&] (int spriteId) { | ||
100 | game_.destroySprite(spriteId); | ||
101 | }); | ||
102 | |||
103 | engine_.set_function( | ||
71 | "getSpriteByAlias", | 104 | "getSpriteByAlias", |
72 | [&] (std::string alias) -> int { | 105 | [&] (std::string alias) -> int { |
73 | return game_.getSpriteByAlias(alias); | 106 | return game_.getSpriteByAlias(alias); |