From a3ff5364c90053c8b2acd068c0090383f87cd2f6 Mon Sep 17 00:00:00 2001 From: Tobias Markus Date: Sun, 16 Jul 2023 21:45:19 +0200 Subject: [PATCH] Fix stuff --- src/scripting/functions.cpp | 24 --------- src/scripting/functions.hpp | 11 ---- src/scripting/level.cpp | 14 +++++ src/scripting/level.hpp | 10 ++++ src/scripting/wrapper.cpp | 104 ++++++++++++++++++------------------ 5 files changed, 76 insertions(+), 87 deletions(-) diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index a61739e66b7..3a8d78835a0 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -136,30 +136,6 @@ bool check_cutscene() return session->get_current_level().m_is_in_cutscene; } -void pause_target_timer() -{ - auto session = GameSession::current(); - if (session == nullptr) - { - log_info << "No game session" << std::endl; - return; - } - - return session->set_target_timer_paused(true); -} - -void resume_target_timer() -{ - auto session = GameSession::current(); - if (session == nullptr) - { - log_info << "No game session" << std::endl; - return; - } - - return session->set_target_timer_paused(false); -} - void wait(HSQUIRRELVM vm, float seconds) { if(GameSession::current()->get_current_level().m_skip_cutscene) diff --git a/src/scripting/functions.hpp b/src/scripting/functions.hpp index 66394d3d8a8..08c2295f27a 100644 --- a/src/scripting/functions.hpp +++ b/src/scripting/functions.hpp @@ -95,17 +95,6 @@ void end_cutscene(); */ bool check_cutscene(); -/** - * Pauses the target timer - */ -void pause_target_timer(); - -/** - * Resumes the target timer - */ -void resume_target_timer(); - - /** * Suspends the script execution for a specified number of seconds. * @param float $seconds diff --git a/src/scripting/level.cpp b/src/scripting/level.cpp index 184fe5532c2..f513ccc07f8 100644 --- a/src/scripting/level.cpp +++ b/src/scripting/level.cpp @@ -86,6 +86,20 @@ Level_edit(bool edit_mode) game_session.set_editmode(edit_mode); } +void +Level_pause_target_timer() +{ + SCRIPT_GUARD_GAMESESSION; + game_session.set_target_timer_paused(true); +} + +void +Level_resume_target_timer() +{ + SCRIPT_GUARD_GAMESESSION; + game_session.set_target_timer_paused(false); +} + } // namespace scripting /* EOF */ diff --git a/src/scripting/level.hpp b/src/scripting/level.hpp index 970631c8f59..a35e1dafc15 100644 --- a/src/scripting/level.hpp +++ b/src/scripting/level.hpp @@ -109,6 +109,16 @@ void Level_toggle_pause(); */ void Level_edit(bool edit_mode); +/** + * Pauses the target timer. + */ +void Level_pause_target_timer(); + +/** + * Resumes the target timer. + */ +void Level_resume_target_timer(); + #ifdef DOXYGEN_SCRIPTING } #endif diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 51decfc73b6..6a6c74dffe7 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -11319,44 +11319,6 @@ static SQInteger check_cutscene_wrapper(HSQUIRRELVM vm) } -static SQInteger pause_target_timer_wrapper(HSQUIRRELVM vm) -{ - (void) vm; - - try { - scripting::pause_target_timer(); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'pause_target_timer'")); - return SQ_ERROR; - } - -} - -static SQInteger resume_target_timer_wrapper(HSQUIRRELVM vm) -{ - (void) vm; - - try { - scripting::resume_target_timer(); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'resume_target_timer'")); - return SQ_ERROR; - } - -} - static SQInteger wait_wrapper(HSQUIRRELVM vm) { HSQUIRRELVM arg0 = vm; @@ -12384,6 +12346,44 @@ static SQInteger Level_edit_wrapper(HSQUIRRELVM vm) } +static SQInteger Level_pause_target_timer_wrapper(HSQUIRRELVM vm) +{ + (void) vm; + + try { + scripting::Level_pause_target_timer(); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'Level_pause_target_timer'")); + return SQ_ERROR; + } + +} + +static SQInteger Level_resume_target_timer_wrapper(HSQUIRRELVM vm) +{ + (void) vm; + + try { + scripting::Level_resume_target_timer(); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'Level_resume_target_timer'")); + return SQ_ERROR; + } + +} + } // namespace wrapper void create_squirrel_instance(HSQUIRRELVM v, scripting::AmbientSound* object, bool setup_releasehook) { @@ -13352,20 +13352,6 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register function 'check_cutscene'"); } - sq_pushstring(v, "pause_target_timer", -1); - sq_newclosure(v, &pause_target_timer_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "."); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'pause_target_timer'"); - } - - sq_pushstring(v, "resume_target_timer", -1); - sq_newclosure(v, &resume_target_timer_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "."); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'resume_target_timer'"); - } - sq_pushstring(v, "wait", -1); sq_newclosure(v, &wait_wrapper, 0); sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".b|n"); @@ -13674,6 +13660,20 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register function 'Level_edit'"); } + sq_pushstring(v, "Level_pause_target_timer", -1); + sq_newclosure(v, &Level_pause_target_timer_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "."); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'Level_pause_target_timer'"); + } + + sq_pushstring(v, "Level_resume_target_timer", -1); + sq_newclosure(v, &Level_resume_target_timer_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "."); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'Level_resume_target_timer'"); + } + // Register class AmbientSound sq_pushstring(v, "AmbientSound", -1); if(sq_newclass(v, SQFalse) < 0) {