diff options
Diffstat (limited to 'src/systems/scripting.cpp')
| -rw-r--r-- | src/systems/scripting.cpp | 45 |
1 files changed, 16 insertions, 29 deletions
| diff --git a/src/systems/scripting.cpp b/src/systems/scripting.cpp index dc1fff5..57c3fd5 100644 --- a/src/systems/scripting.cpp +++ b/src/systems/scripting.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | #include "game.h" | 2 | #include "game.h" |
| 3 | #include "components/runnable.h" | 3 | #include "components/runnable.h" |
| 4 | #include "components/ponderable.h" | 4 | #include "components/ponderable.h" |
| 5 | #include "components/realizable.h" | ||
| 6 | #include "components/transformable.h" | 5 | #include "components/transformable.h" |
| 7 | #include "components/playable.h" | 6 | #include "components/playable.h" |
| 8 | #include "components/mappable.h" | 7 | #include "components/mappable.h" |
| @@ -24,9 +23,9 @@ ScriptingSystem::ScriptingSystem(Game& game) : System(game) | |||
| 24 | { | 23 | { |
| 25 | id_type entity = game_.getEntityManager().emplaceEntity(); | 24 | id_type entity = game_.getEntityManager().emplaceEntity(); |
| 26 | 25 | ||
| 27 | engine.open_libraries(sol::lib::base, sol::lib::coroutine); | 26 | engine_.open_libraries(sol::lib::base, sol::lib::coroutine); |
| 28 | 27 | ||
| 29 | engine.new_usertype<vec2d>( | 28 | engine_.new_usertype<vec2d>( |
| 30 | "vec2d", | 29 | "vec2d", |
| 31 | sol::constructors<vec2d(), vec2d(double, double)>(), | 30 | sol::constructors<vec2d(), vec2d(double, double)>(), |
| 32 | "x", sol::property( | 31 | "x", sol::property( |
| @@ -36,13 +35,13 @@ ScriptingSystem::ScriptingSystem(Game& game) : System(game) | |||
| 36 | [] (vec2d& v) -> double { return v.y(); }, | 35 | [] (vec2d& v) -> double { return v.y(); }, |
| 37 | [] (vec2d& v, double y) { v.y() = y; })); | 36 | [] (vec2d& v, double y) { v.y() = y; })); |
| 38 | 37 | ||
| 39 | engine.new_usertype<vec2i>( | 38 | engine_.new_usertype<vec2i>( |
| 40 | "vec2i", | 39 | "vec2i", |
| 41 | sol::constructors<vec2i(), vec2i(int, int)>(), | 40 | sol::constructors<vec2i(), vec2i(int, int)>(), |
| 42 | "x", [] (vec2i& v) -> int& { return v.x(); }, | 41 | "x", [] (vec2i& v) -> int& { return v.x(); }, |
| 43 | "y", [] (vec2i& v) -> int& { return v.y(); }); | 42 | "y", [] (vec2i& v) -> int& { return v.y(); }); |
| 44 | 43 | ||
| 45 | engine.new_usertype<script_entity>( | 44 | engine_.new_usertype<script_entity>( |
| 46 | "entity", | 45 | "entity", |
| 47 | sol::constructors<script_entity(id_type)>(), | 46 | sol::constructors<script_entity(id_type)>(), |
| 48 | "id", &script_entity::id, | 47 | "id", &script_entity::id, |
| @@ -66,62 +65,50 @@ ScriptingSystem::ScriptingSystem(Game& game) : System(game) | |||
| 66 | return game_.getEntityManager(). | 65 | return game_.getEntityManager(). |
| 67 | getComponent<PlayableComponent>(entity.id); | 66 | getComponent<PlayableComponent>(entity.id); |
| 68 | }, | 67 | }, |
| 69 | "realizable", | ||
| 70 | [&] (script_entity& entity) -> RealizableComponent& { | ||
| 71 | return game_.getEntityManager(). | ||
| 72 | getComponent<RealizableComponent>(entity.id); | ||
| 73 | }, | ||
| 74 | "prototypable", | 68 | "prototypable", |
| 75 | [&] (script_entity& entity) -> PrototypableComponent& { | 69 | [&] (script_entity& entity) -> PrototypableComponent& { |
| 76 | return game_.getEntityManager(). | 70 | return game_.getEntityManager(). |
| 77 | getComponent<PrototypableComponent>(entity.id); | 71 | getComponent<PrototypableComponent>(entity.id); |
| 78 | }); | 72 | }); |
| 79 | 73 | ||
| 80 | engine.new_usertype<TransformableComponent>( | 74 | engine_.new_usertype<TransformableComponent>( |
| 81 | "transformable", | 75 | "transformable", |
| 82 | "pos", &TransformableComponent::pos); | 76 | "pos", &TransformableComponent::pos); |
| 83 | 77 | ||
| 84 | engine.new_usertype<PonderableComponent>( | 78 | engine_.new_usertype<PonderableComponent>( |
| 85 | "ponderable", | 79 | "ponderable", |
| 86 | "vel", &PonderableComponent::vel, | 80 | "vel", &PonderableComponent::vel, |
| 87 | "accel", &PonderableComponent::accel); | 81 | "accel", &PonderableComponent::accel); |
| 88 | 82 | ||
| 89 | engine.new_usertype<MappableComponent>( | 83 | engine_.new_usertype<MappableComponent>( |
| 90 | "mappable", | 84 | "mappable", |
| 91 | "mapId", &MappableComponent::mapId); | 85 | "mapId", &MappableComponent::mapId); |
| 92 | 86 | ||
| 93 | engine.new_usertype<PlayableComponent>( | 87 | engine_.new_usertype<PlayableComponent>( |
| 94 | "playable", | 88 | "playable", |
| 95 | "checkpointPos", &PlayableComponent::checkpointPos, | 89 | "checkpointPos", &PlayableComponent::checkpointPos, |
| 96 | "checkpointMapId", &PlayableComponent::checkpointMapId, | 90 | "checkpointMapId", &PlayableComponent::checkpointMapId, |
| 97 | "checkpointMapObject", &PlayableComponent::checkpointMapObject, | 91 | "checkpointMapObject", &PlayableComponent::checkpointMapObject, |
| 98 | "checkpointMapObjectIndex", &PlayableComponent::checkpointMapObjectIndex); | 92 | "checkpointMapObjectIndex", &PlayableComponent::checkpointMapObjectIndex); |
| 99 | 93 | ||
| 100 | engine.new_usertype<RealizableComponent>( | 94 | engine_.new_usertype<PrototypableComponent>( |
| 101 | "realizable", | ||
| 102 | "activeMap", &RealizableComponent::activeMap); | ||
| 103 | |||
| 104 | engine.new_usertype<PrototypableComponent>( | ||
| 105 | "prototypable", | 95 | "prototypable", |
| 106 | "mapObjectIndex", &PrototypableComponent::mapObjectIndex, | 96 | "mapObjectIndex", &PrototypableComponent::mapObjectIndex, |
| 107 | "prototypeId", &PrototypableComponent::prototypeId); | 97 | "prototypeId", &PrototypableComponent::prototypeId); |
| 108 | 98 | ||
| 109 | engine.new_usertype<RealizingSystem>( | 99 | engine_.new_usertype<RealizingSystem>( |
| 110 | "realizing", | 100 | "realizing", |
| 111 | "singleton", | 101 | "activeMap", sol::property(&RealizingSystem::getActiveMap)); |
| 112 | [&] (RealizingSystem& realizing) -> script_entity { | ||
| 113 | return realizing.getSingleton(); | ||
| 114 | }); | ||
| 115 | 102 | ||
| 116 | engine.set_function( | 103 | engine_.set_function( |
| 117 | "realizing", | 104 | "realizing", |
| 118 | [&] () { | 105 | [&] () { |
| 119 | return game_.getSystemManager().getSystem<RealizingSystem>(); | 106 | return game_.getSystemManager().getSystem<RealizingSystem>(); |
| 120 | }); | 107 | }); |
| 121 | 108 | ||
| 122 | engine.script_file("scripts/common.lua"); | 109 | engine_.script_file("scripts/common.lua"); |
| 123 | engine.script_file("scripts/movplat.lua"); | 110 | engine_.script_file("scripts/movplat.lua"); |
| 124 | engine.script_file("scripts/checkpoint.lua"); | 111 | engine_.script_file("scripts/checkpoint.lua"); |
| 125 | } | 112 | } |
| 126 | 113 | ||
| 127 | void ScriptingSystem::tick(double dt) | 114 | void ScriptingSystem::tick(double dt) |
| @@ -177,7 +164,7 @@ EntityManager::id_type ScriptingSystem::runScript( | |||
| 177 | std::unique_ptr<sol::thread>( | 164 | std::unique_ptr<sol::thread>( |
| 178 | new sol::thread( | 165 | new sol::thread( |
| 179 | sol::thread::create( | 166 | sol::thread::create( |
| 180 | engine.lua_state()))); | 167 | engine_.lua_state()))); |
| 181 | 168 | ||
| 182 | runnable.callable = | 169 | runnable.callable = |
| 183 | std::unique_ptr<sol::coroutine>( | 170 | std::unique_ptr<sol::coroutine>( |
