Camera API, improved cutscene API

This commit is contained in:
Jan Racek
2026-03-28 20:13:12 +01:00
parent 68cf8a7460
commit 561ee9dd64
6 changed files with 160 additions and 29 deletions

View File

@@ -284,7 +284,20 @@ void LuaAPI::RegisterAll(psyqo::Lua& L, SceneManager* scene, CutscenePlayer* cut
L.setField(-2, "IsPlaying");
L.setGlobal("Cutscene");
// ========================================================================
// CONTROLS API
// ========================================================================
L.newTable();
L.push(Controls_SetEnabled);
L.setField(-2, "SetEnabled");
L.push(Controls_IsEnabled);
L.setField(-2, "IsEnabled");
L.setGlobal("Controls");
// ========================================================================
// UI API
// ========================================================================
@@ -1473,13 +1486,38 @@ void LuaAPI::PersistClear() {
int LuaAPI::Cutscene_Play(lua_State* L) {
psyqo::Lua lua(L);
if (!s_cutscenePlayer || !lua.isString(1)) {
return 0;
}
const char* name = lua.toString(1);
s_cutscenePlayer->play(name);
bool loop = false;
int onCompleteRef = LUA_NOREF;
// Optional second argument: options table {loop=bool, onComplete=function}
if (lua.isTable(2)) {
lua.getField(2, "loop");
if (lua.isBoolean(-1)) loop = lua.toBoolean(-1);
lua.pop();
lua.getField(2, "onComplete");
if (lua.isFunction(-1)) {
onCompleteRef = lua.ref(); // pops and stores in registry
} else {
lua.pop();
}
}
// Clear any previous callback before starting a new cutscene
int oldRef = s_cutscenePlayer->getOnCompleteRef();
if (oldRef != LUA_NOREF) {
luaL_unref(L, LUA_REGISTRYINDEX, oldRef);
}
s_cutscenePlayer->setLuaState(L);
s_cutscenePlayer->setOnCompleteRef(onCompleteRef);
s_cutscenePlayer->play(name, loop);
return 0;
}
@@ -1503,6 +1541,28 @@ int LuaAPI::Cutscene_IsPlaying(lua_State* L) {
return 1;
}
// ============================================================================
// CONTROLS API IMPLEMENTATION
// ============================================================================
int LuaAPI::Controls_SetEnabled(lua_State* L) {
psyqo::Lua lua(L);
if (s_sceneManager && lua.isBoolean(1)) {
s_sceneManager->setControlsEnabled(lua.toBoolean(1));
}
return 0;
}
int LuaAPI::Controls_IsEnabled(lua_State* L) {
psyqo::Lua lua(L);
if (s_sceneManager) {
lua.push(s_sceneManager->isControlsEnabled());
} else {
lua.push(false);
}
return 1;
}
// ============================================================================
// UI API IMPLEMENTATION
// ============================================================================