From: LMH Date: Tue, 24 Jan 2012 20:43:54 +0000 (-1000) Subject: Scripted Object: gravity can be turned on/off (patch by rgcjonas, bug 874) X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=13ea4b4d0b3be6e0c90be31f8a45578c68433fb1;p=supertux.git Scripted Object: gravity can be turned on/off (patch by rgcjonas, bug 874) --- diff --git a/src/object/scripted_object.cpp b/src/object/scripted_object.cpp index e64c62c09..e17de285a 100644 --- a/src/object/scripted_object.cpp +++ b/src/object/scripted_object.cpp @@ -143,6 +143,18 @@ ScriptedObject::is_solid() return solid; } +bool +ScriptedObject::gravity_enabled() const +{ + return physic.gravity_enabled(); +} + +void +ScriptedObject::enable_gravity(bool f) +{ + physic.enable_gravity(f); +} + void ScriptedObject::set_action(const std::string& animation) { diff --git a/src/object/scripted_object.hpp b/src/object/scripted_object.hpp index f3ae63238..69b82a0ea 100644 --- a/src/object/scripted_object.hpp +++ b/src/object/scripted_object.hpp @@ -54,6 +54,8 @@ public: bool is_visible(); void set_solid(bool solid); bool is_solid(); + void enable_gravity(bool gravity_enabled); + bool gravity_enabled() const; std::string get_name(); diff --git a/src/scripting/scripted_object.hpp b/src/scripting/scripted_object.hpp index 27da30b18..966dbc5e1 100644 --- a/src/scripting/scripted_object.hpp +++ b/src/scripting/scripted_object.hpp @@ -39,6 +39,9 @@ public: virtual float get_velocity_x() = 0; virtual float get_velocity_y() = 0; + virtual void enable_gravity(bool gravity_enabled) = 0; + virtual bool gravity_enabled() const = 0; + virtual void set_visible(bool visible) = 0; virtual bool is_visible() = 0; diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 0f4ae0650..4dccd3264 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -1883,6 +1883,60 @@ static SQInteger ScriptedObject_get_velocity_y_wrapper(HSQUIRRELVM vm) } +static SQInteger ScriptedObject_enable_gravity_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0)) || !data) { + sq_throwerror(vm, _SC("'enable_gravity' called without instance")); + return SQ_ERROR; + } + scripting::ScriptedObject* _this = reinterpret_cast (data); + SQBool arg0; + if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a bool")); + return SQ_ERROR; + } + + try { + _this->enable_gravity(arg0 == SQTrue); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'enable_gravity'")); + return SQ_ERROR; + } + +} + +static SQInteger ScriptedObject_gravity_enabled_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0)) || !data) { + sq_throwerror(vm, _SC("'gravity_enabled' called without instance")); + return SQ_ERROR; + } + scripting::ScriptedObject* _this = reinterpret_cast (data); + + try { + bool return_value = _this->gravity_enabled(); + + sq_pushbool(vm, return_value); + return 1; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'gravity_enabled'")); + return SQ_ERROR; + } + +} + static SQInteger ScriptedObject_set_visible_wrapper(HSQUIRRELVM vm) { SQUserPointer data; @@ -5145,6 +5199,20 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register function 'get_velocity_y'"); } + sq_pushstring(v, "enable_gravity", -1); + sq_newclosure(v, &ScriptedObject_enable_gravity_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tb"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'enable_gravity'"); + } + + sq_pushstring(v, "gravity_enabled", -1); + sq_newclosure(v, &ScriptedObject_gravity_enabled_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'gravity_enabled'"); + } + sq_pushstring(v, "set_visible", -1); sq_newclosure(v, &ScriptedObject_set_visible_wrapper, 0); sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tb");