Better boat handling

This commit is contained in:
2025-11-30 18:28:26 +03:00
parent cd82fb0eed
commit 5b014dcb65
21 changed files with 938 additions and 230 deletions

View File

@@ -415,6 +415,15 @@ LuaData::LuaData()
return 1;
});
lua_setglobal(L, "ecs_character_trigger");
lua_pushcfunction(L, [](lua_State *L) -> int {
luaL_checktype(L, 1, LUA_TNUMBER); // object
int object = lua_tointeger(L, 1);
flecs::entity object_e = idmap.get_entity(object);
flecs::entity parent_e = object_e.parent();
lua_pushinteger(L, idmap.add_entity(parent_e));
return 1;
});
lua_setglobal(L, "ecs_parent");
lua_pushcfunction(L, [](lua_State *L) -> int {
OgreAssert(lua_gettop(L) == 7, "bad parameters");
luaL_checktype(L, 1, LUA_TNUMBER); // parent
@@ -551,10 +560,9 @@ LuaData::LuaData()
int object = lua_tointeger(L, 2);
flecs::entity object_e = idmap.get_entity(object);
bool enable = lua_toboolean(L, 3);
if (enable)
object_e.remove<CharacterDisablePhysics>();
else
object_e.add<CharacterDisablePhysics>();
OgreAssert(object_e.has<CharacterBase>(),
"Not a character");
PhysicsModule::controlPhysics(object_e, enable);
object_e.add<CharacterUpdatePhysicsState>();
return 0;
} else if (command == "is-player") {
@@ -659,8 +667,7 @@ LuaData::LuaData()
Ogre::String slot = lua_tostring(L, 3);
flecs::entity parent_e = idmap.get_entity(parent);
flecs::entity object_e = idmap.get_entity(object);
if (!object_e.has<CharacterDisablePhysics>())
object_e.add<CharacterDisablePhysics>();
PhysicsModule::controlPhysics(object_e, false);
object_e.set<ParentSlot>({ parent_e, slot });
return 0;
});
@@ -840,7 +847,11 @@ LuaModule::LuaModule(flecs::world &ecs)
lua.startup_called = false;
})
.add(flecs::Singleton);
ecs.add<LuaBase>();
ecs.component<LuaEvent>().add(flecs::Singleton);
if (!ecs.has<LuaBase>())
ecs.add<LuaBase>();
if (!ecs.has<LuaEvent>())
ecs.set<LuaEvent>({});
ecs.system<const EngineData, LuaBase>("LuaUpdate")
.kind(flecs::OnUpdate)
@@ -888,5 +899,14 @@ LuaModule::LuaModule(flecs::world &ecs)
trigger.parent = parentNode;
e.modified<EventTrigger>();
});
ecs.system<LuaBase, LuaEvent>("HandleLuaEvents")
.kind(flecs::OnUpdate)
.each([](LuaBase &base, LuaEvent &evt) {
while (!evt.events.empty()) {
LuaEvent::Event &ev = evt.events.front();
base.mLua->call_handler(ev.event, ev.e1, ev.e2);
evt.events.pop_front();
}
});
}
}