From cf5313c5378f50f62911962222b0e871f19602e6 Mon Sep 17 00:00:00 2001 From: Tobias Markus Date: Sun, 23 Jul 2023 22:31:35 +0200 Subject: [PATCH] Add set_action to Decal scripting Fixes #2557 --- src/scripting/decal.cpp | 7 +++++++ src/scripting/decal.hpp | 5 +++++ src/scripting/wrapper.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/src/scripting/decal.cpp b/src/scripting/decal.cpp index 55cd5859bd3..472ea2221d2 100644 --- a/src/scripting/decal.cpp +++ b/src/scripting/decal.cpp @@ -47,6 +47,13 @@ Decal::fade_out(float time) object.fade_out(time); } +void +Decal::set_action(const std::string& action) +{ + SCRIPT_GUARD_VOID; + object.set_action(action); +} + } // namespace scripting /* EOF */ diff --git a/src/scripting/decal.hpp b/src/scripting/decal.hpp index cf65af140bc..3e5cf0a1d0c 100644 --- a/src/scripting/decal.hpp +++ b/src/scripting/decal.hpp @@ -65,6 +65,11 @@ class Decal final * @param float $time */ void fade_out(float time); + /** + * Sets the action for this decal + * @param float $time + */ + void set_action(const std::string& action); }; } // namespace scripting diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 7d316bc8251..e61e5653580 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -4920,6 +4920,36 @@ static SQInteger Decal_fade_out_wrapper(HSQUIRRELVM vm) } +static SQInteger Decal_set_action_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr, SQTrue)) || !data) { + sq_throwerror(vm, _SC("'set_action' called without instance")); + return SQ_ERROR; + } + scripting::Decal* _this = reinterpret_cast (data); + + const SQChar* arg0; + if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a string")); + return SQ_ERROR; + } + + try { + _this->set_action(arg0); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_action'")); + return SQ_ERROR; + } + +} + static SQInteger Dispenser_release_hook(SQUserPointer ptr, SQInteger ) { scripting::Dispenser* _this = reinterpret_cast (ptr); @@ -14951,6 +14981,13 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register function 'fade_out'"); } + sq_pushstring(v, "set_action", -1); + sq_newclosure(v, &Decal_set_action_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".s"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'set_action'"); + } + if(SQ_FAILED(sq_createslot(v, -3))) { throw SquirrelError(v, "Couldn't register class 'Decal'"); }