// // LUA_CleanupScene scene (object) // static int LUA_CleanupScene(lua_State *lua) { int count = lua_gettop(lua); if (count < 1) { CzScriptEngineLua::DisplayError(lua, "scene.cleanup() not enough parameters, expected scene (object)"); lua_pushboolean(lua, false); return 1; } // Get scene CzScene* scene = NULL; if (lua_isuserdata(lua, 1)) scene = (CzScene*)lua_touserdata(lua, 1); if (scene == NULL || scene->getClassTypeHash() != CzHashes::Scene_Hash) { CzScriptEngineLua::DisplayError(lua, "scene.cleanup() invalid scene (Param0), expected scene"); lua_pushboolean(lua, false); return 1; } scene->CleanupRemovedActors(); lua_pushboolean(lua, true); return 1; }
// // LUA_SetCurrentScene(scene-name (string)) - returns previous scene // static int LUA_SetCurrentScene(lua_State *lua) { int count = lua_gettop(lua); if (lua_gettop(lua) < 1) { CzScriptEngineLua::DisplayError(lua, "scene.setCurrent() not enough parameters, expected scene (object)"); lua_pushnil(lua); return 1; } // Get the main game object CzApp* game = (CzApp*)CZ_GLOBAL_RESOURCES->getResourceManager()->getParent(); // Get the scene CzScene* scene = NULL; if (lua_isuserdata(lua, 1)) scene = (CzScene*)lua_touserdata(lua, 1); if (scene == NULL || scene->getClassTypeHash() != CzHashes::Scene_Hash) { CzScriptEngineLua::DisplayError(lua, "scene.setCurrent() Invalid scene for Param0"); lua_pushnil(lua); return 1; } CzScene* prev_scene = game->getCurrentScene(); game->changeScene(scene); lua_pushlightuserdata(lua, prev_scene); return 1; }
// // LUA_SceneToScreen scene (object) x (number) y (number) - Returns vector // static int LUA_SceneToScreen(lua_State *lua) { if (lua_gettop(lua) < 3) { CzScriptEngineLua::DisplayError(lua, "scene.toScreen() not enough parameters, expected scene (object) x (number) y (number)"); lua_pushnil(lua); return 1; } // Get the scene object CzScene* scene = NULL; if (lua_isuserdata(lua, 1)) scene = (CzScene*)lua_touserdata(lua, 1); if (scene == NULL || scene->getClassTypeHash() != CzHashes::Scene_Hash) { CzScriptEngineLua::DisplayError(lua, "scene.toScreen() Invalid scene object"); lua_pushnil(lua); return 1; } // Get x coord float x = 0; if (lua_isnumber(lua, 2)) x = (float)lua_tonumber(lua, 2); else { CzScriptEngineLua::DisplayError(lua, "scene.toScreen() expected a number for Param1"); lua_pushnil(lua); return 1; } // Get y coord float y = 0; if (lua_isnumber(lua, 3)) y = (float)lua_tonumber(lua, 3); else { CzScriptEngineLua::DisplayError(lua, "scene.toScreen() expected a number for Param2"); lua_pushnil(lua); return 1; } CzVec2 screen = scene->VirtualToScreen(x, y); lua_pushvec(lua, screen.x, screen.y, 0, 0); return 1; }
// // LUA_UpdateScenePhysics scene (object), time (number) // static int LUA_UpdateScenePhysics(lua_State *lua) { int count = lua_gettop(lua); if (count < 2) { CzScriptEngineLua::DisplayError(lua, "scene.updatePhysics() not enough parameters, expected scene (object), time (number)"); lua_pushboolean(lua, false); return 1; } // Get scene CzScene* scene = NULL; if (lua_isuserdata(lua, 1)) scene = (CzScene*)lua_touserdata(lua, 1); if (scene == NULL || scene->getClassTypeHash() != CzHashes::Scene_Hash) { CzScriptEngineLua::DisplayError(lua, "scene.updatePhysics() invalid scene (Param0), expected scene"); lua_pushboolean(lua, false); return 1; } // Get time float time; if (lua_isnumber(lua, 2)) time = (float)lua_tonumber(lua, 2); else { CzScriptEngineLua::DisplayError(lua, "scene.updatePhysics() Invalid time expected number for Param1"); lua_pushboolean(lua, false); return 1; } scene->UpdatePhysics(time); lua_pushboolean(lua, true); return 1; }
// // LUA_ScreenToScene scene (object) x (number) y (number) include_camera (boolean) - Returns vector // static int LUA_ScreenToScene(lua_State *lua) { if (lua_gettop(lua) < 3) { CzScriptEngineLua::DisplayError(lua, "scene.toScene() not enough parameters, expected scene (object) x (number) y (number) include_camera (boolean)"); lua_pushnil(lua); return 1; } // Get the scene object CzScene* scene = NULL; if (lua_isuserdata(lua, 1)) scene = (CzScene*)lua_touserdata(lua, 1); if (scene == NULL || scene->getClassTypeHash() != CzHashes::Scene_Hash) { CzScriptEngineLua::DisplayError(lua, "scene.toScene() Invalid scene object"); lua_pushnil(lua); return 1; } // Get x coord float x = 0; if (lua_isnumber(lua, 2)) x = (float)lua_tonumber(lua, 2); else { CzScriptEngineLua::DisplayError(lua, "scene.toScene() expected a number for Param1"); lua_pushnil(lua); return 1; } // Get y coord float y = 0; if (lua_isnumber(lua, 3)) y = (float)lua_tonumber(lua, 3); else { CzScriptEngineLua::DisplayError(lua, "scene.toScene() expected a number for Param2"); lua_pushnil(lua); return 1; } // Get include camera parameter bool camera = false; if (lua_gettop(lua) > 3) { if (lua_isboolean(lua, 4)) camera = lua_toboolean(lua, 4) != 0; else { CzScriptEngineLua::DisplayError(lua, "scene.toScene() expected a boolean for Param3"); lua_pushnil(lua); return 1; } } CzVec2 s; if (camera) s = scene->ScreenToCamera(x, y); else s = scene->ScreenToVirtual(x, y); lua_pushvec(lua, s.x, s.y, 0, 0); return 1; }