From 1cb676a766c21f3cde0cd30d7cd3af137bb35030 Mon Sep 17 00:00:00 2001 From: Semphris Date: Sun, 7 Mar 2021 10:24:28 -0500 Subject: [PATCH 1/8] Added settings Squirrel proprety to worldmaps (allows dynamic changes to ambient light and music) --- src/scripting/functions.cpp | 4 +- src/scripting/game_object.cpp | 4 +- src/scripting/worldmap.cpp | 76 +++++++ src/scripting/worldmap.hpp | 57 ++++++ src/scripting/wrapper.cpp | 303 ++++++++++++++++++++++++++++ src/scripting/wrapper.hpp | 2 + src/scripting/wrapper.interface.hpp | 1 + src/worldmap/worldmap.cpp | 3 + 8 files changed, 446 insertions(+), 4 deletions(-) create mode 100644 src/scripting/worldmap.cpp create mode 100644 src/scripting/worldmap.hpp diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index 82297ee260c..8c633a6dec0 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -222,14 +222,14 @@ void load_worldmap(const std::string& filename) { using namespace worldmap; - if (!WorldMap::current()) + if (!::worldmap::WorldMap::current()) { throw std::runtime_error("Can't start Worldmap without active WorldMap"); } else { ScreenManager::current()->push_screen(std::make_unique( - std::make_unique(filename, WorldMap::current()->get_savegame()))); + std::make_unique<::worldmap::WorldMap>(filename, ::worldmap::WorldMap::current()->get_savegame()))); } } diff --git a/src/scripting/game_object.cpp b/src/scripting/game_object.cpp index e5df7538047..6b3c8e79f18 100644 --- a/src/scripting/game_object.cpp +++ b/src/scripting/game_object.cpp @@ -27,8 +27,8 @@ GameObjectManager& get_game_object_manager() if (::Sector::current() != nullptr) { return ::Sector::get(); - } else if (WorldMap::current() != nullptr) { - return *WorldMap::current(); + } else if (::worldmap::WorldMap::current() != nullptr) { + return *::worldmap::WorldMap::current(); } else { throw std::runtime_error("Neither sector nor worldmap active"); } diff --git a/src/scripting/worldmap.cpp b/src/scripting/worldmap.cpp new file mode 100644 index 00000000000..b0f4a67cb7b --- /dev/null +++ b/src/scripting/worldmap.cpp @@ -0,0 +1,76 @@ +// SuperTux +// Copyright (C) 2015 Ingo Ruhnke +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "scripting/worldmap.hpp" + +#include "math/easing.hpp" +#include "object/ambient_light.hpp" +#include "object/music_object.hpp" +#include "video/color.hpp" +#include "worldmap/worldmap.hpp" + +namespace scripting { + +WorldMap::WorldMap(::worldmap::WorldMap* parent) : + m_parent(parent) +{ +} + +void +WorldMap::fade_to_ambient_light(float red, float green, float blue, float fadetime) +{ + auto& ambient_light = m_parent->get_singleton_by_type(); + ambient_light.fade_to_ambient_light(red, green, blue, fadetime); +} + +void +WorldMap::set_ambient_light(float red, float green, float blue) +{ + auto& ambient_light = m_parent->get_singleton_by_type(); + ambient_light.set_ambient_light(Color(red, green, blue)); +} + +float +WorldMap::get_ambient_red() const +{ + auto& ambient_light = m_parent->get_singleton_by_type(); + return ambient_light.get_ambient_light().red; +} + +float +WorldMap::get_ambient_green() const +{ + auto& ambient_light = m_parent->get_singleton_by_type(); + return ambient_light.get_ambient_light().green; +} + +float +WorldMap::get_ambient_blue() const +{ + auto& ambient_light = m_parent->get_singleton_by_type(); + return ambient_light.get_ambient_light().blue; +} + +void +WorldMap::set_music(const std::string& filename) +{ + auto& music = m_parent->get_singleton_by_type(); + music.set_music(filename); +} + +} // namespace scripting + +/* EOF */ diff --git a/src/scripting/worldmap.hpp b/src/scripting/worldmap.hpp new file mode 100644 index 00000000000..aa4e2304e92 --- /dev/null +++ b/src/scripting/worldmap.hpp @@ -0,0 +1,57 @@ +// SuperTux - Sector scripting +// Copyright (C) 2006 Wolfgang Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_SCRIPTING_WORLDMAP_HPP +#define HEADER_SUPERTUX_SCRIPTING_WORLDMAP_HPP + +#ifndef SCRIPTING_API +#include +namespace worldmap { +class WorldMap; +} +#endif + +namespace scripting { + +class WorldMap final +{ +#ifndef SCRIPTING_API +private: + ::worldmap::WorldMap* m_parent; + +public: + WorldMap(::worldmap::WorldMap* parent); + +private: + WorldMap(const WorldMap&) = delete; + WorldMap& operator=(const WorldMap&) = delete; +#endif + +public: + void set_ambient_light(float red, float green, float blue); + void fade_to_ambient_light(float red, float green, float blue, float fadetime); + float get_ambient_red() const; + float get_ambient_green() const; + float get_ambient_blue() const; + + void set_music(const std::string& music); +}; + +} // namespace scripting + +#endif + +/* EOF */ diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 8f800e60119..eabc46af657 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -11078,6 +11078,230 @@ static SQInteger Wind_stop_wrapper(HSQUIRRELVM vm) } +static SQInteger WorldMap_release_hook(SQUserPointer ptr, SQInteger ) +{ + auto _this = reinterpret_cast (ptr); + delete _this; + return 0; +} + +static SQInteger WorldMap_set_ambient_light_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'set_ambient_light' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + SQFloat arg0; + if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a float")); + return SQ_ERROR; + } + SQFloat arg1; + if(SQ_FAILED(sq_getfloat(vm, 3, &arg1))) { + sq_throwerror(vm, _SC("Argument 2 not a float")); + return SQ_ERROR; + } + SQFloat arg2; + if(SQ_FAILED(sq_getfloat(vm, 4, &arg2))) { + sq_throwerror(vm, _SC("Argument 3 not a float")); + return SQ_ERROR; + } + + try { + _this->set_ambient_light(static_cast (arg0), static_cast (arg1), static_cast (arg2)); + + 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_ambient_light'")); + return SQ_ERROR; + } + +} + +static SQInteger WorldMap_fade_to_ambient_light_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'fade_to_ambient_light' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + SQFloat arg0; + if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a float")); + return SQ_ERROR; + } + SQFloat arg1; + if(SQ_FAILED(sq_getfloat(vm, 3, &arg1))) { + sq_throwerror(vm, _SC("Argument 2 not a float")); + return SQ_ERROR; + } + SQFloat arg2; + if(SQ_FAILED(sq_getfloat(vm, 4, &arg2))) { + sq_throwerror(vm, _SC("Argument 3 not a float")); + return SQ_ERROR; + } + SQFloat arg3; + if(SQ_FAILED(sq_getfloat(vm, 5, &arg3))) { + sq_throwerror(vm, _SC("Argument 4 not a float")); + return SQ_ERROR; + } + + try { + _this->fade_to_ambient_light(static_cast (arg0), static_cast (arg1), static_cast (arg2), static_cast (arg3)); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'fade_to_ambient_light'")); + return SQ_ERROR; + } + +} + +static SQInteger WorldMap_get_ambient_red_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'get_ambient_red' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + + try { + float return_value = _this->get_ambient_red(); + + sq_pushfloat(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 'get_ambient_red'")); + return SQ_ERROR; + } + +} + +static SQInteger WorldMap_get_ambient_green_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'get_ambient_green' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + + try { + float return_value = _this->get_ambient_green(); + + sq_pushfloat(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 'get_ambient_green'")); + return SQ_ERROR; + } + +} + +static SQInteger WorldMap_get_ambient_blue_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'get_ambient_blue' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + + try { + float return_value = _this->get_ambient_blue(); + + sq_pushfloat(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 'get_ambient_blue'")); + return SQ_ERROR; + } + +} + +static SQInteger WorldMap_set_music_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'set_music' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + 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_music(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_music'")); + return SQ_ERROR; + } + +} + static SQInteger display_wrapper(HSQUIRRELVM vm) { return scripting::display(vm); @@ -12910,6 +13134,32 @@ void create_squirrel_instance(HSQUIRRELVM v, scripting::Wind* object, bool setup sq_remove(v, -2); // remove root table } +void create_squirrel_instance(HSQUIRRELVM v, scripting::WorldMap* object, bool setup_releasehook) +{ + using namespace wrapper; + + sq_pushroottable(v); + sq_pushstring(v, "WorldMap", -1); + if(SQ_FAILED(sq_get(v, -2))) { + std::ostringstream msg; + msg << "Couldn't resolved squirrel type 'WorldMap'"; + throw SquirrelError(v, msg.str()); + } + + if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) { + std::ostringstream msg; + msg << "Couldn't setup squirrel instance for object of type 'WorldMap'"; + throw SquirrelError(v, msg.str()); + } + sq_remove(v, -2); // remove object name + + if(setup_releasehook) { + sq_setreleasehook(v, -1, WorldMap_release_hook); + } + + sq_remove(v, -2); // remove root table +} + void register_supertux_wrapper(HSQUIRRELVM v) { using namespace wrapper; @@ -15807,6 +16057,59 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register class 'Wind'"); } + // Register class WorldMap + sq_pushstring(v, "WorldMap", -1); + if(sq_newclass(v, SQFalse) < 0) { + std::ostringstream msg; + msg << "Couldn't create new class 'WorldMap'"; + throw SquirrelError(v, msg.str()); + } + sq_pushstring(v, "set_ambient_light", -1); + sq_newclosure(v, &WorldMap_set_ambient_light_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tnnn"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'set_ambient_light'"); + } + + sq_pushstring(v, "fade_to_ambient_light", -1); + sq_newclosure(v, &WorldMap_fade_to_ambient_light_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tnnnn"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'fade_to_ambient_light'"); + } + + sq_pushstring(v, "get_ambient_red", -1); + sq_newclosure(v, &WorldMap_get_ambient_red_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'get_ambient_red'"); + } + + sq_pushstring(v, "get_ambient_green", -1); + sq_newclosure(v, &WorldMap_get_ambient_green_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'get_ambient_green'"); + } + + sq_pushstring(v, "get_ambient_blue", -1); + sq_newclosure(v, &WorldMap_get_ambient_blue_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'get_ambient_blue'"); + } + + sq_pushstring(v, "set_music", -1); + sq_newclosure(v, &WorldMap_set_music_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|ts"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'set_music'"); + } + + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register class 'WorldMap'"); + } + } } // namespace scripting diff --git a/src/scripting/wrapper.hpp b/src/scripting/wrapper.hpp index d1cbb0da557..990fd26185a 100644 --- a/src/scripting/wrapper.hpp +++ b/src/scripting/wrapper.hpp @@ -68,6 +68,8 @@ class WillOWisp; void create_squirrel_instance(HSQUIRRELVM v, scripting::WillOWisp* object, bool setup_releasehook = false); class Wind; void create_squirrel_instance(HSQUIRRELVM v, scripting::Wind* object, bool setup_releasehook = false); +class WorldMap; +void create_squirrel_instance(HSQUIRRELVM v, scripting::WorldMap* object, bool setup_releasehook = false); } diff --git a/src/scripting/wrapper.interface.hpp b/src/scripting/wrapper.interface.hpp index 723e6b41f84..32f55592b92 100644 --- a/src/scripting/wrapper.interface.hpp +++ b/src/scripting/wrapper.interface.hpp @@ -30,5 +30,6 @@ #include "scripting/torch.hpp" #include "scripting/willowisp.hpp" #include "scripting/wind.hpp" +#include "scripting/worldmap.hpp" /* EOF */ diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index 27abd1daa29..041d49f0ffd 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -29,6 +29,7 @@ #include "object/tilemap.hpp" #include "physfs/ifile_stream.hpp" #include "physfs/physfs_file_system.hpp" +#include "scripting/worldmap.hpp" #include "sprite/sprite.hpp" #include "squirrel/squirrel_environment.hpp" #include "supertux/d_scope.hpp" @@ -630,6 +631,8 @@ WorldMap::setup() // register worldmap_table as worldmap in scripting m_squirrel_environment->expose_self(); + m_squirrel_environment->expose("settings", std::make_unique(this)); + //Run default.nut just before init script try { IFileStream in(m_levels_path + "default.nut"); From 6440abde1f5f5b2d71659e13c133380f8290899e Mon Sep 17 00:00:00 2001 From: Semphris Date: Sun, 7 Mar 2021 10:45:01 -0500 Subject: [PATCH 2/8] Refactored Secter/Worldmap scripting to use inheritance --- src/scripting/game_object.cpp | 2 +- src/scripting/game_object.hpp | 2 +- src/scripting/game_object_manager.cpp | 75 ++ src/scripting/game_object_manager.hpp | 56 ++ src/scripting/sector.cpp | 43 +- src/scripting/sector.hpp | 10 +- src/scripting/worldmap.cpp | 47 +- src/scripting/worldmap.hpp | 12 +- src/scripting/wrapper.cpp | 1007 ++++++++++--------------- src/scripting/wrapper.hpp | 2 + src/scripting/wrapper.interface.hpp | 1 + 11 files changed, 543 insertions(+), 714 deletions(-) create mode 100644 src/scripting/game_object_manager.cpp create mode 100644 src/scripting/game_object_manager.hpp diff --git a/src/scripting/game_object.cpp b/src/scripting/game_object.cpp index 6b3c8e79f18..c9122fa8f16 100644 --- a/src/scripting/game_object.cpp +++ b/src/scripting/game_object.cpp @@ -21,7 +21,7 @@ namespace scripting { -GameObjectManager& get_game_object_manager() +::GameObjectManager& get_game_object_manager() { using namespace worldmap; diff --git a/src/scripting/game_object.hpp b/src/scripting/game_object.hpp index ffbcfa2dcd9..cc30763f12a 100644 --- a/src/scripting/game_object.hpp +++ b/src/scripting/game_object.hpp @@ -81,7 +81,7 @@ class GameObjectManager; namespace scripting { -GameObjectManager& get_game_object_manager(); +::GameObjectManager& get_game_object_manager(); template class GameObject diff --git a/src/scripting/game_object_manager.cpp b/src/scripting/game_object_manager.cpp new file mode 100644 index 00000000000..c9015eb6acc --- /dev/null +++ b/src/scripting/game_object_manager.cpp @@ -0,0 +1,75 @@ +// SuperTux +// Copyright (C) 2015 Ingo Ruhnke +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "scripting/game_object_manager.hpp" + +#include "object/ambient_light.hpp" +#include "object/music_object.hpp" +#include "supertux/game_object_manager.hpp" +#include "video/color.hpp" + +namespace scripting { + +GameObjectManager::GameObjectManager(::GameObjectManager* parent) : + m_gom_parent(parent) +{ +} + +void +GameObjectManager::fade_to_ambient_light(float red, float green, float blue, float fadetime) +{ + auto& ambient_light = m_gom_parent->get_singleton_by_type(); + ambient_light.fade_to_ambient_light(red, green, blue, fadetime); +} + +void +GameObjectManager::set_ambient_light(float red, float green, float blue) +{ + auto& ambient_light = m_gom_parent->get_singleton_by_type(); + ambient_light.set_ambient_light(Color(red, green, blue)); +} + +float +GameObjectManager::get_ambient_red() const +{ + auto& ambient_light = m_gom_parent->get_singleton_by_type(); + return ambient_light.get_ambient_light().red; +} + +float +GameObjectManager::get_ambient_green() const +{ + auto& ambient_light = m_gom_parent->get_singleton_by_type(); + return ambient_light.get_ambient_light().green; +} + +float +GameObjectManager::get_ambient_blue() const +{ + auto& ambient_light = m_gom_parent->get_singleton_by_type(); + return ambient_light.get_ambient_light().blue; +} + +void +GameObjectManager::set_music(const std::string& filename) +{ + auto& music = m_gom_parent->get_singleton_by_type(); + music.set_music(filename); +} + +} // namespace scripting + +/* EOF */ diff --git a/src/scripting/game_object_manager.hpp b/src/scripting/game_object_manager.hpp new file mode 100644 index 00000000000..b095fdb9555 --- /dev/null +++ b/src/scripting/game_object_manager.hpp @@ -0,0 +1,56 @@ +// SuperTux - Sector scripting +// Copyright (C) 2006 Wolfgang Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_SCRIPTING_GAME_OBJECT_MANAGER_HPP +#define HEADER_SUPERTUX_SCRIPTING_GAME_OBJECT_MANAGER_HPP + +#ifndef SCRIPTING_API +#include +class GameObjectManager; +#endif + +namespace scripting { + +/** Superclass for sectors and worldmaps */ +class GameObjectManager +{ +#ifndef SCRIPTING_API +private: + ::GameObjectManager* m_gom_parent; + +public: + GameObjectManager(::GameObjectManager* parent); + +private: + GameObjectManager(const GameObjectManager&) = delete; + GameObjectManager& operator=(const GameObjectManager&) = delete; +#endif + +public: + void set_ambient_light(float red, float green, float blue); + void fade_to_ambient_light(float red, float green, float blue, float fadetime); + float get_ambient_red() const; + float get_ambient_green() const; + float get_ambient_blue() const; + + void set_music(const std::string& music); +}; + +} // namespace scripting + +#endif + +/* EOF */ diff --git a/src/scripting/sector.cpp b/src/scripting/sector.cpp index e1a00d7cb52..82c43326b41 100644 --- a/src/scripting/sector.cpp +++ b/src/scripting/sector.cpp @@ -25,58 +25,17 @@ namespace scripting { Sector::Sector(::Sector* parent) : + GameObjectManager(parent), m_parent(parent) { } -void -Sector::fade_to_ambient_light(float red, float green, float blue, float fadetime) -{ - auto& ambient_light = m_parent->get_singleton_by_type(); - ambient_light.fade_to_ambient_light(red, green, blue, fadetime); -} - -void -Sector::set_ambient_light(float red, float green, float blue) -{ - auto& ambient_light = m_parent->get_singleton_by_type(); - ambient_light.set_ambient_light(Color(red, green, blue)); -} - -float -Sector::get_ambient_red() const -{ - auto& ambient_light = m_parent->get_singleton_by_type(); - return ambient_light.get_ambient_light().red; -} - -float -Sector::get_ambient_green() const -{ - auto& ambient_light = m_parent->get_singleton_by_type(); - return ambient_light.get_ambient_light().green; -} - -float -Sector::get_ambient_blue() const -{ - auto& ambient_light = m_parent->get_singleton_by_type(); - return ambient_light.get_ambient_light().blue; -} - void Sector::set_gravity(float gravity) { m_parent->set_gravity(gravity); } -void -Sector::set_music(const std::string& filename) -{ - auto& music = m_parent->get_singleton_by_type(); - music.set_music(filename); -} - } // namespace scripting /* EOF */ diff --git a/src/scripting/sector.hpp b/src/scripting/sector.hpp index ffc80d10161..df90779fa10 100644 --- a/src/scripting/sector.hpp +++ b/src/scripting/sector.hpp @@ -19,12 +19,13 @@ #ifndef SCRIPTING_API #include +#include "scripting/game_object_manager.hpp" class Sector; #endif namespace scripting { -class Sector final +class Sector final : public GameObjectManager { #ifndef SCRIPTING_API private: @@ -39,14 +40,7 @@ class Sector final #endif public: - void set_ambient_light(float red, float green, float blue); - void fade_to_ambient_light(float red, float green, float blue, float fadetime); - float get_ambient_red() const; - float get_ambient_green() const; - float get_ambient_blue() const; - void set_gravity(float gravity); - void set_music(const std::string& music); }; } // namespace scripting diff --git a/src/scripting/worldmap.cpp b/src/scripting/worldmap.cpp index b0f4a67cb7b..c5a65c574fd 100644 --- a/src/scripting/worldmap.cpp +++ b/src/scripting/worldmap.cpp @@ -16,60 +16,17 @@ #include "scripting/worldmap.hpp" -#include "math/easing.hpp" -#include "object/ambient_light.hpp" -#include "object/music_object.hpp" -#include "video/color.hpp" #include "worldmap/worldmap.hpp" namespace scripting { WorldMap::WorldMap(::worldmap::WorldMap* parent) : + GameObjectManager(parent), m_parent(parent) { } -void -WorldMap::fade_to_ambient_light(float red, float green, float blue, float fadetime) -{ - auto& ambient_light = m_parent->get_singleton_by_type(); - ambient_light.fade_to_ambient_light(red, green, blue, fadetime); -} - -void -WorldMap::set_ambient_light(float red, float green, float blue) -{ - auto& ambient_light = m_parent->get_singleton_by_type(); - ambient_light.set_ambient_light(Color(red, green, blue)); -} - -float -WorldMap::get_ambient_red() const -{ - auto& ambient_light = m_parent->get_singleton_by_type(); - return ambient_light.get_ambient_light().red; -} - -float -WorldMap::get_ambient_green() const -{ - auto& ambient_light = m_parent->get_singleton_by_type(); - return ambient_light.get_ambient_light().green; -} - -float -WorldMap::get_ambient_blue() const -{ - auto& ambient_light = m_parent->get_singleton_by_type(); - return ambient_light.get_ambient_light().blue; -} - -void -WorldMap::set_music(const std::string& filename) -{ - auto& music = m_parent->get_singleton_by_type(); - music.set_music(filename); -} +// Add functions here } // namespace scripting diff --git a/src/scripting/worldmap.hpp b/src/scripting/worldmap.hpp index aa4e2304e92..aab44556470 100644 --- a/src/scripting/worldmap.hpp +++ b/src/scripting/worldmap.hpp @@ -17,8 +17,10 @@ #ifndef HEADER_SUPERTUX_SCRIPTING_WORLDMAP_HPP #define HEADER_SUPERTUX_SCRIPTING_WORLDMAP_HPP + #ifndef SCRIPTING_API #include +#include "scripting/game_object_manager.hpp" namespace worldmap { class WorldMap; } @@ -26,7 +28,7 @@ class WorldMap; namespace scripting { -class WorldMap final +class WorldMap final : public GameObjectManager { #ifndef SCRIPTING_API private: @@ -41,13 +43,7 @@ class WorldMap final #endif public: - void set_ambient_light(float red, float green, float blue); - void fade_to_ambient_light(float red, float green, float blue, float fadetime); - float get_ambient_red() const; - float get_ambient_green() const; - float get_ambient_blue() const; - - void set_music(const std::string& music); + // Add functions here }; } // namespace scripting diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index eabc46af657..4c3c34f3b4c 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -5945,6 +5945,230 @@ static SQInteger FloatingImage_fade_out_wrapper(HSQUIRRELVM vm) } +static SQInteger GameObjectManager_release_hook(SQUserPointer ptr, SQInteger ) +{ + auto _this = reinterpret_cast (ptr); + delete _this; + return 0; +} + +static SQInteger GameObjectManager_set_ambient_light_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'set_ambient_light' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + SQFloat arg0; + if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a float")); + return SQ_ERROR; + } + SQFloat arg1; + if(SQ_FAILED(sq_getfloat(vm, 3, &arg1))) { + sq_throwerror(vm, _SC("Argument 2 not a float")); + return SQ_ERROR; + } + SQFloat arg2; + if(SQ_FAILED(sq_getfloat(vm, 4, &arg2))) { + sq_throwerror(vm, _SC("Argument 3 not a float")); + return SQ_ERROR; + } + + try { + _this->set_ambient_light(static_cast (arg0), static_cast (arg1), static_cast (arg2)); + + 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_ambient_light'")); + return SQ_ERROR; + } + +} + +static SQInteger GameObjectManager_fade_to_ambient_light_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'fade_to_ambient_light' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + SQFloat arg0; + if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a float")); + return SQ_ERROR; + } + SQFloat arg1; + if(SQ_FAILED(sq_getfloat(vm, 3, &arg1))) { + sq_throwerror(vm, _SC("Argument 2 not a float")); + return SQ_ERROR; + } + SQFloat arg2; + if(SQ_FAILED(sq_getfloat(vm, 4, &arg2))) { + sq_throwerror(vm, _SC("Argument 3 not a float")); + return SQ_ERROR; + } + SQFloat arg3; + if(SQ_FAILED(sq_getfloat(vm, 5, &arg3))) { + sq_throwerror(vm, _SC("Argument 4 not a float")); + return SQ_ERROR; + } + + try { + _this->fade_to_ambient_light(static_cast (arg0), static_cast (arg1), static_cast (arg2), static_cast (arg3)); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'fade_to_ambient_light'")); + return SQ_ERROR; + } + +} + +static SQInteger GameObjectManager_get_ambient_red_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'get_ambient_red' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + + try { + float return_value = _this->get_ambient_red(); + + sq_pushfloat(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 'get_ambient_red'")); + return SQ_ERROR; + } + +} + +static SQInteger GameObjectManager_get_ambient_green_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'get_ambient_green' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + + try { + float return_value = _this->get_ambient_green(); + + sq_pushfloat(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 'get_ambient_green'")); + return SQ_ERROR; + } + +} + +static SQInteger GameObjectManager_get_ambient_blue_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'get_ambient_blue' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + + try { + float return_value = _this->get_ambient_blue(); + + sq_pushfloat(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 'get_ambient_blue'")); + return SQ_ERROR; + } + +} + +static SQInteger GameObjectManager_set_music_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { + sq_throwerror(vm, _SC("'set_music' called without instance")); + return SQ_ERROR; + } + auto _this = reinterpret_cast (data); + + if (_this == nullptr) { + return SQ_ERROR; + } + + 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_music(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_music'")); + return SQ_ERROR; + } + +} + static SQInteger Gradient_release_hook(SQUserPointer ptr, SQInteger ) { auto _this = reinterpret_cast (ptr); @@ -8370,11 +8594,11 @@ static SQInteger Sector_release_hook(SQUserPointer ptr, SQInteger ) return 0; } -static SQInteger Sector_set_ambient_light_wrapper(HSQUIRRELVM vm) +static SQInteger Sector_set_gravity_wrapper(HSQUIRRELVM vm) { SQUserPointer data; if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'set_ambient_light' called without instance")); + sq_throwerror(vm, _SC("'set_gravity' called without instance")); return SQ_ERROR; } auto _this = reinterpret_cast (data); @@ -8388,19 +8612,9 @@ static SQInteger Sector_set_ambient_light_wrapper(HSQUIRRELVM vm) sq_throwerror(vm, _SC("Argument 1 not a float")); return SQ_ERROR; } - SQFloat arg1; - if(SQ_FAILED(sq_getfloat(vm, 3, &arg1))) { - sq_throwerror(vm, _SC("Argument 2 not a float")); - return SQ_ERROR; - } - SQFloat arg2; - if(SQ_FAILED(sq_getfloat(vm, 4, &arg2))) { - sq_throwerror(vm, _SC("Argument 3 not a float")); - return SQ_ERROR; - } try { - _this->set_ambient_light(static_cast (arg0), static_cast (arg1), static_cast (arg2)); + _this->set_gravity(static_cast (arg0)); return 0; @@ -8408,252 +8622,45 @@ static SQInteger Sector_set_ambient_light_wrapper(HSQUIRRELVM vm) sq_throwerror(vm, e.what()); return SQ_ERROR; } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_ambient_light'")); + sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_gravity'")); return SQ_ERROR; } } -static SQInteger Sector_fade_to_ambient_light_wrapper(HSQUIRRELVM vm) +static SQInteger Spotlight_release_hook(SQUserPointer ptr, SQInteger ) +{ + auto _this = reinterpret_cast (ptr); + delete _this; + return 0; +} + +static SQInteger Spotlight_set_direction_wrapper(HSQUIRRELVM vm) { SQUserPointer data; if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'fade_to_ambient_light' called without instance")); + sq_throwerror(vm, _SC("'set_direction' called without instance")); return SQ_ERROR; } - auto _this = reinterpret_cast (data); + auto _this = reinterpret_cast (data); if (_this == nullptr) { return SQ_ERROR; } - SQFloat arg0; - if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { - sq_throwerror(vm, _SC("Argument 1 not a float")); + const SQChar* arg0; + if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a string")); return SQ_ERROR; } - SQFloat arg1; - if(SQ_FAILED(sq_getfloat(vm, 3, &arg1))) { - sq_throwerror(vm, _SC("Argument 2 not a float")); - return SQ_ERROR; - } - SQFloat arg2; - if(SQ_FAILED(sq_getfloat(vm, 4, &arg2))) { - sq_throwerror(vm, _SC("Argument 3 not a float")); - return SQ_ERROR; - } - SQFloat arg3; - if(SQ_FAILED(sq_getfloat(vm, 5, &arg3))) { - sq_throwerror(vm, _SC("Argument 4 not a float")); - return SQ_ERROR; - } - - try { - _this->fade_to_ambient_light(static_cast (arg0), static_cast (arg1), static_cast (arg2), static_cast (arg3)); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'fade_to_ambient_light'")); - return SQ_ERROR; - } - -} - -static SQInteger Sector_get_ambient_red_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'get_ambient_red' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - - try { - float return_value = _this->get_ambient_red(); - - sq_pushfloat(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 'get_ambient_red'")); - return SQ_ERROR; - } - -} - -static SQInteger Sector_get_ambient_green_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'get_ambient_green' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - - try { - float return_value = _this->get_ambient_green(); - - sq_pushfloat(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 'get_ambient_green'")); - return SQ_ERROR; - } - -} - -static SQInteger Sector_get_ambient_blue_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'get_ambient_blue' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - - try { - float return_value = _this->get_ambient_blue(); - - sq_pushfloat(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 'get_ambient_blue'")); - return SQ_ERROR; - } - -} - -static SQInteger Sector_set_gravity_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'set_gravity' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - SQFloat arg0; - if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { - sq_throwerror(vm, _SC("Argument 1 not a float")); - return SQ_ERROR; - } - - try { - _this->set_gravity(static_cast (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_gravity'")); - return SQ_ERROR; - } - -} - -static SQInteger Sector_set_music_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'set_music' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - 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_music(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_music'")); - return SQ_ERROR; - } - -} - -static SQInteger Spotlight_release_hook(SQUserPointer ptr, SQInteger ) -{ - auto _this = reinterpret_cast (ptr); - delete _this; - return 0; -} - -static SQInteger Spotlight_set_direction_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'set_direction' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - 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_direction(arg0); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); + + try { + _this->set_direction(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_direction'")); @@ -10955,237 +10962,14 @@ static SQInteger WillOWisp_set_state_wrapper(HSQUIRRELVM vm) } -static SQInteger WillOWisp_start_moving_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'start_moving' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - - try { - _this->start_moving(); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'start_moving'")); - return SQ_ERROR; - } - -} - -static SQInteger WillOWisp_stop_moving_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'stop_moving' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - - try { - _this->stop_moving(); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'stop_moving'")); - return SQ_ERROR; - } - -} - -static SQInteger Wind_release_hook(SQUserPointer ptr, SQInteger ) -{ - auto _this = reinterpret_cast (ptr); - delete _this; - return 0; -} - -static SQInteger Wind_start_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'start' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - - try { - _this->start(); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'start'")); - return SQ_ERROR; - } - -} - -static SQInteger Wind_stop_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'stop' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - - try { - _this->stop(); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'stop'")); - return SQ_ERROR; - } - -} - -static SQInteger WorldMap_release_hook(SQUserPointer ptr, SQInteger ) -{ - auto _this = reinterpret_cast (ptr); - delete _this; - return 0; -} - -static SQInteger WorldMap_set_ambient_light_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'set_ambient_light' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - SQFloat arg0; - if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { - sq_throwerror(vm, _SC("Argument 1 not a float")); - return SQ_ERROR; - } - SQFloat arg1; - if(SQ_FAILED(sq_getfloat(vm, 3, &arg1))) { - sq_throwerror(vm, _SC("Argument 2 not a float")); - return SQ_ERROR; - } - SQFloat arg2; - if(SQ_FAILED(sq_getfloat(vm, 4, &arg2))) { - sq_throwerror(vm, _SC("Argument 3 not a float")); - return SQ_ERROR; - } - - try { - _this->set_ambient_light(static_cast (arg0), static_cast (arg1), static_cast (arg2)); - - 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_ambient_light'")); - return SQ_ERROR; - } - -} - -static SQInteger WorldMap_fade_to_ambient_light_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'fade_to_ambient_light' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - SQFloat arg0; - if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { - sq_throwerror(vm, _SC("Argument 1 not a float")); - return SQ_ERROR; - } - SQFloat arg1; - if(SQ_FAILED(sq_getfloat(vm, 3, &arg1))) { - sq_throwerror(vm, _SC("Argument 2 not a float")); - return SQ_ERROR; - } - SQFloat arg2; - if(SQ_FAILED(sq_getfloat(vm, 4, &arg2))) { - sq_throwerror(vm, _SC("Argument 3 not a float")); - return SQ_ERROR; - } - SQFloat arg3; - if(SQ_FAILED(sq_getfloat(vm, 5, &arg3))) { - sq_throwerror(vm, _SC("Argument 4 not a float")); - return SQ_ERROR; - } - - try { - _this->fade_to_ambient_light(static_cast (arg0), static_cast (arg1), static_cast (arg2), static_cast (arg3)); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'fade_to_ambient_light'")); - return SQ_ERROR; - } - -} - -static SQInteger WorldMap_get_ambient_red_wrapper(HSQUIRRELVM vm) +static SQInteger WillOWisp_start_moving_wrapper(HSQUIRRELVM vm) { SQUserPointer data; if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'get_ambient_red' called without instance")); + sq_throwerror(vm, _SC("'start_moving' called without instance")); return SQ_ERROR; } - auto _this = reinterpret_cast (data); + auto _this = reinterpret_cast (data); if (_this == nullptr) { return SQ_ERROR; @@ -11193,29 +10977,28 @@ static SQInteger WorldMap_get_ambient_red_wrapper(HSQUIRRELVM vm) try { - float return_value = _this->get_ambient_red(); + _this->start_moving(); - sq_pushfloat(vm, return_value); - return 1; + return 0; } catch(std::exception& e) { sq_throwerror(vm, e.what()); return SQ_ERROR; } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'get_ambient_red'")); + sq_throwerror(vm, _SC("Unexpected exception while executing function 'start_moving'")); return SQ_ERROR; } } -static SQInteger WorldMap_get_ambient_green_wrapper(HSQUIRRELVM vm) +static SQInteger WillOWisp_stop_moving_wrapper(HSQUIRRELVM vm) { SQUserPointer data; if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'get_ambient_green' called without instance")); + sq_throwerror(vm, _SC("'stop_moving' called without instance")); return SQ_ERROR; } - auto _this = reinterpret_cast (data); + auto _this = reinterpret_cast (data); if (_this == nullptr) { return SQ_ERROR; @@ -11223,29 +11006,35 @@ static SQInteger WorldMap_get_ambient_green_wrapper(HSQUIRRELVM vm) try { - float return_value = _this->get_ambient_green(); + _this->stop_moving(); - sq_pushfloat(vm, return_value); - return 1; + return 0; } catch(std::exception& e) { sq_throwerror(vm, e.what()); return SQ_ERROR; } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'get_ambient_green'")); + sq_throwerror(vm, _SC("Unexpected exception while executing function 'stop_moving'")); return SQ_ERROR; } } -static SQInteger WorldMap_get_ambient_blue_wrapper(HSQUIRRELVM vm) +static SQInteger Wind_release_hook(SQUserPointer ptr, SQInteger ) +{ + auto _this = reinterpret_cast (ptr); + delete _this; + return 0; +} + +static SQInteger Wind_start_wrapper(HSQUIRRELVM vm) { SQUserPointer data; if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'get_ambient_blue' called without instance")); + sq_throwerror(vm, _SC("'start' called without instance")); return SQ_ERROR; } - auto _this = reinterpret_cast (data); + auto _this = reinterpret_cast (data); if (_this == nullptr) { return SQ_ERROR; @@ -11253,42 +11042,36 @@ static SQInteger WorldMap_get_ambient_blue_wrapper(HSQUIRRELVM vm) try { - float return_value = _this->get_ambient_blue(); + _this->start(); - sq_pushfloat(vm, return_value); - return 1; + return 0; } catch(std::exception& e) { sq_throwerror(vm, e.what()); return SQ_ERROR; } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'get_ambient_blue'")); + sq_throwerror(vm, _SC("Unexpected exception while executing function 'start'")); return SQ_ERROR; } } -static SQInteger WorldMap_set_music_wrapper(HSQUIRRELVM vm) +static SQInteger Wind_stop_wrapper(HSQUIRRELVM vm) { SQUserPointer data; if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'set_music' called without instance")); + sq_throwerror(vm, _SC("'stop' called without instance")); return SQ_ERROR; } - auto _this = reinterpret_cast (data); + auto _this = reinterpret_cast (data); if (_this == nullptr) { return SQ_ERROR; } - 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_music(arg0); + _this->stop(); return 0; @@ -11296,12 +11079,19 @@ static SQInteger WorldMap_set_music_wrapper(HSQUIRRELVM vm) sq_throwerror(vm, e.what()); return SQ_ERROR; } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_music'")); + sq_throwerror(vm, _SC("Unexpected exception while executing function 'stop'")); return SQ_ERROR; } } +static SQInteger WorldMap_release_hook(SQUserPointer ptr, SQInteger ) +{ + auto _this = reinterpret_cast (ptr); + delete _this; + return 0; +} + static SQInteger display_wrapper(HSQUIRRELVM vm) { return scripting::display(vm); @@ -12692,6 +12482,32 @@ void create_squirrel_instance(HSQUIRRELVM v, scripting::FloatingImage* object, b sq_remove(v, -2); // remove root table } +void create_squirrel_instance(HSQUIRRELVM v, scripting::GameObjectManager* object, bool setup_releasehook) +{ + using namespace wrapper; + + sq_pushroottable(v); + sq_pushstring(v, "GameObjectManager", -1); + if(SQ_FAILED(sq_get(v, -2))) { + std::ostringstream msg; + msg << "Couldn't resolved squirrel type 'GameObjectManager'"; + throw SquirrelError(v, msg.str()); + } + + if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) { + std::ostringstream msg; + msg << "Couldn't setup squirrel instance for object of type 'GameObjectManager'"; + throw SquirrelError(v, msg.str()); + } + sq_remove(v, -2); // remove object name + + if(setup_releasehook) { + sq_setreleasehook(v, -1, GameObjectManager_release_hook); + } + + sq_remove(v, -2); // remove root table +} + void create_squirrel_instance(HSQUIRRELVM v, scripting::Gradient* object, bool setup_releasehook) { using namespace wrapper; @@ -14894,6 +14710,92 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register class 'FloatingImage'"); } + // Register class GameObjectManager + sq_pushstring(v, "GameObjectManager", -1); + if(sq_newclass(v, SQFalse) < 0) { + std::ostringstream msg; + msg << "Couldn't create new class 'GameObjectManager'"; + throw SquirrelError(v, msg.str()); + } + sq_pushstring(v, "set_ambient_light", -1); + sq_newclosure(v, &GameObjectManager_set_ambient_light_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tnnn"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'set_ambient_light'"); + } + + sq_pushstring(v, "fade_to_ambient_light", -1); + sq_newclosure(v, &GameObjectManager_fade_to_ambient_light_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tnnnn"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'fade_to_ambient_light'"); + } + + sq_pushstring(v, "get_ambient_red", -1); + sq_newclosure(v, &GameObjectManager_get_ambient_red_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'get_ambient_red'"); + } + + sq_pushstring(v, "get_ambient_green", -1); + sq_newclosure(v, &GameObjectManager_get_ambient_green_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'get_ambient_green'"); + } + + sq_pushstring(v, "get_ambient_blue", -1); + sq_newclosure(v, &GameObjectManager_get_ambient_blue_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'get_ambient_blue'"); + } + + sq_pushstring(v, "set_music", -1); + sq_newclosure(v, &GameObjectManager_set_music_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|ts"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'set_music'"); + } + + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register class 'GameObjectManager'"); + } + + // Register class Sector + sq_pushstring(v, "Sector", -1); + sq_pushstring(v, "GameObjectManager", -1); + sq_get(v, -3); + if(sq_newclass(v, SQTrue) < 0) { + std::ostringstream msg; + msg << "Couldn't create new class 'Sector'"; + throw SquirrelError(v, msg.str()); + } + sq_pushstring(v, "set_gravity", -1); + sq_newclosure(v, &Sector_set_gravity_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tn"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'set_gravity'"); + } + + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register class 'Sector'"); + } + + // Register class WorldMap + sq_pushstring(v, "WorldMap", -1); + sq_pushstring(v, "GameObjectManager", -1); + sq_get(v, -3); + if(sq_newclass(v, SQTrue) < 0) { + std::ostringstream msg; + msg << "Couldn't create new class 'WorldMap'"; + throw SquirrelError(v, msg.str()); + } + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register class 'WorldMap'"); + } + // Register class Gradient sq_pushstring(v, "Gradient", -1); if(sq_newclass(v, SQFalse) < 0) { @@ -15465,66 +15367,6 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register class 'ScriptedObject'"); } - // Register class Sector - sq_pushstring(v, "Sector", -1); - if(sq_newclass(v, SQFalse) < 0) { - std::ostringstream msg; - msg << "Couldn't create new class 'Sector'"; - throw SquirrelError(v, msg.str()); - } - sq_pushstring(v, "set_ambient_light", -1); - sq_newclosure(v, &Sector_set_ambient_light_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tnnn"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'set_ambient_light'"); - } - - sq_pushstring(v, "fade_to_ambient_light", -1); - sq_newclosure(v, &Sector_fade_to_ambient_light_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tnnnn"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'fade_to_ambient_light'"); - } - - sq_pushstring(v, "get_ambient_red", -1); - sq_newclosure(v, &Sector_get_ambient_red_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'get_ambient_red'"); - } - - sq_pushstring(v, "get_ambient_green", -1); - sq_newclosure(v, &Sector_get_ambient_green_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'get_ambient_green'"); - } - - sq_pushstring(v, "get_ambient_blue", -1); - sq_newclosure(v, &Sector_get_ambient_blue_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'get_ambient_blue'"); - } - - sq_pushstring(v, "set_gravity", -1); - sq_newclosure(v, &Sector_set_gravity_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tn"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'set_gravity'"); - } - - sq_pushstring(v, "set_music", -1); - sq_newclosure(v, &Sector_set_music_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|ts"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'set_music'"); - } - - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register class 'Sector'"); - } - // Register class Spotlight sq_pushstring(v, "Spotlight", -1); if(sq_newclass(v, SQFalse) < 0) { @@ -16057,59 +15899,6 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register class 'Wind'"); } - // Register class WorldMap - sq_pushstring(v, "WorldMap", -1); - if(sq_newclass(v, SQFalse) < 0) { - std::ostringstream msg; - msg << "Couldn't create new class 'WorldMap'"; - throw SquirrelError(v, msg.str()); - } - sq_pushstring(v, "set_ambient_light", -1); - sq_newclosure(v, &WorldMap_set_ambient_light_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tnnn"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'set_ambient_light'"); - } - - sq_pushstring(v, "fade_to_ambient_light", -1); - sq_newclosure(v, &WorldMap_fade_to_ambient_light_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tnnnn"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'fade_to_ambient_light'"); - } - - sq_pushstring(v, "get_ambient_red", -1); - sq_newclosure(v, &WorldMap_get_ambient_red_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'get_ambient_red'"); - } - - sq_pushstring(v, "get_ambient_green", -1); - sq_newclosure(v, &WorldMap_get_ambient_green_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'get_ambient_green'"); - } - - sq_pushstring(v, "get_ambient_blue", -1); - sq_newclosure(v, &WorldMap_get_ambient_blue_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'get_ambient_blue'"); - } - - sq_pushstring(v, "set_music", -1); - sq_newclosure(v, &WorldMap_set_music_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|ts"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'set_music'"); - } - - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register class 'WorldMap'"); - } - } } // namespace scripting diff --git a/src/scripting/wrapper.hpp b/src/scripting/wrapper.hpp index 990fd26185a..652fe9f676f 100644 --- a/src/scripting/wrapper.hpp +++ b/src/scripting/wrapper.hpp @@ -34,6 +34,8 @@ class DisplayEffect; void create_squirrel_instance(HSQUIRRELVM v, scripting::DisplayEffect* object, bool setup_releasehook = false); class FloatingImage; void create_squirrel_instance(HSQUIRRELVM v, scripting::FloatingImage* object, bool setup_releasehook = false); +class GameObjectManager; +void create_squirrel_instance(HSQUIRRELVM v, scripting::GameObjectManager* object, bool setup_releasehook = false); class Gradient; void create_squirrel_instance(HSQUIRRELVM v, scripting::Gradient* object, bool setup_releasehook = false); class LevelTime; diff --git a/src/scripting/wrapper.interface.hpp b/src/scripting/wrapper.interface.hpp index 32f55592b92..ee73d68dd2e 100644 --- a/src/scripting/wrapper.interface.hpp +++ b/src/scripting/wrapper.interface.hpp @@ -12,6 +12,7 @@ #include "scripting/display_effect.hpp" #include "scripting/floating_image.hpp" #include "scripting/functions.hpp" +#include "scripting/game_object_manager.hpp" #include "scripting/gradient.hpp" #include "scripting/level.hpp" #include "scripting/level_time.hpp" From 04b18c7e72a8cc98f624618fe2a7ea25152aba6c Mon Sep 17 00:00:00 2001 From: Semphris Date: Sun, 7 Mar 2021 10:56:34 -0500 Subject: [PATCH 3/8] Marked scripting::WorlMap's internal variable as unused --- src/scripting/worldmap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripting/worldmap.hpp b/src/scripting/worldmap.hpp index aab44556470..f771eb7b6a1 100644 --- a/src/scripting/worldmap.hpp +++ b/src/scripting/worldmap.hpp @@ -32,7 +32,7 @@ class WorldMap final : public GameObjectManager { #ifndef SCRIPTING_API private: - ::worldmap::WorldMap* m_parent; + ::worldmap::WorldMap* m_parent __attribute__((unused)); public: WorldMap(::worldmap::WorldMap* parent); From 83ab68c7b466a1e930f4da861f0b5b8dc1116200 Mon Sep 17 00:00:00 2001 From: Semphris Date: Sun, 7 Mar 2021 11:03:07 -0500 Subject: [PATCH 4/8] Fixed copyright headers --- src/scripting/game_object_manager.cpp | 1 + src/scripting/game_object_manager.hpp | 4 ++-- src/scripting/sector.cpp | 1 + src/scripting/sector.hpp | 1 + src/scripting/worldmap.cpp | 2 +- src/scripting/worldmap.hpp | 4 ++-- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/scripting/game_object_manager.cpp b/src/scripting/game_object_manager.cpp index c9015eb6acc..9745cfd817d 100644 --- a/src/scripting/game_object_manager.cpp +++ b/src/scripting/game_object_manager.cpp @@ -1,5 +1,6 @@ // SuperTux // Copyright (C) 2015 Ingo Ruhnke +// 2021 A. Semphris // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/src/scripting/game_object_manager.hpp b/src/scripting/game_object_manager.hpp index b095fdb9555..0115e64a9cf 100644 --- a/src/scripting/game_object_manager.hpp +++ b/src/scripting/game_object_manager.hpp @@ -1,5 +1,5 @@ -// SuperTux - Sector scripting -// Copyright (C) 2006 Wolfgang Becker +// SuperTux +// Copyright (C) 2021 A. Semphris // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/src/scripting/sector.cpp b/src/scripting/sector.cpp index 82c43326b41..7c9dc3ab2ed 100644 --- a/src/scripting/sector.cpp +++ b/src/scripting/sector.cpp @@ -1,5 +1,6 @@ // SuperTux // Copyright (C) 2015 Ingo Ruhnke +// 2021 A. Semphris // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/src/scripting/sector.hpp b/src/scripting/sector.hpp index df90779fa10..1d47fe514f3 100644 --- a/src/scripting/sector.hpp +++ b/src/scripting/sector.hpp @@ -1,5 +1,6 @@ // SuperTux - Sector scripting // Copyright (C) 2006 Wolfgang Becker +// 2021 A. Semphris // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/src/scripting/worldmap.cpp b/src/scripting/worldmap.cpp index c5a65c574fd..0fc460402d3 100644 --- a/src/scripting/worldmap.cpp +++ b/src/scripting/worldmap.cpp @@ -1,5 +1,5 @@ // SuperTux -// Copyright (C) 2015 Ingo Ruhnke +// Copyright (C) 2021 A. Semphris // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/src/scripting/worldmap.hpp b/src/scripting/worldmap.hpp index f771eb7b6a1..63e4155596f 100644 --- a/src/scripting/worldmap.hpp +++ b/src/scripting/worldmap.hpp @@ -1,5 +1,5 @@ -// SuperTux - Sector scripting -// Copyright (C) 2006 Wolfgang Becker +// SuperTux +// Copyright (C) 2021 A. Semphris // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by From 565908af7eb879ef085f4768a7774dbfca80b681 Mon Sep 17 00:00:00 2001 From: Semphris Date: Sun, 7 Mar 2021 11:57:09 -0500 Subject: [PATCH 5/8] Fixed build error --- src/scripting/worldmap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripting/worldmap.hpp b/src/scripting/worldmap.hpp index 63e4155596f..b2ca7c6efc2 100644 --- a/src/scripting/worldmap.hpp +++ b/src/scripting/worldmap.hpp @@ -32,7 +32,7 @@ class WorldMap final : public GameObjectManager { #ifndef SCRIPTING_API private: - ::worldmap::WorldMap* m_parent __attribute__((unused)); + ::worldmap::WorldMap* __attribute__((unused)) m_parent; public: WorldMap(::worldmap::WorldMap* parent); From b2ec8a951d9549b7082fa45acf1cb3453b373d75 Mon Sep 17 00:00:00 2001 From: Semphris Date: Sun, 7 Mar 2021 15:34:15 -0500 Subject: [PATCH 6/8] Fixed MSVC not recognising the 'unused' attribute --- src/scripting/worldmap.cpp | 12 +++++++++++- src/scripting/worldmap.hpp | 3 ++- src/worldmap/worldmap.cpp | 6 ++++++ src/worldmap/worldmap.hpp | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/scripting/worldmap.cpp b/src/scripting/worldmap.cpp index 0fc460402d3..49aaafab966 100644 --- a/src/scripting/worldmap.cpp +++ b/src/scripting/worldmap.cpp @@ -26,7 +26,17 @@ WorldMap::WorldMap(::worldmap::WorldMap* parent) : { } -// Add functions here +float +WorldMap::get_tux_x() +{ + return m_parent->get_tux_pos().x; +} + +float +WorldMap::get_tux_y() +{ + return m_parent->get_tux_pos().y; +} } // namespace scripting diff --git a/src/scripting/worldmap.hpp b/src/scripting/worldmap.hpp index b2ca7c6efc2..511560be2de 100644 --- a/src/scripting/worldmap.hpp +++ b/src/scripting/worldmap.hpp @@ -43,7 +43,8 @@ class WorldMap final : public GameObjectManager #endif public: - // Add functions here + float get_tux_x(); + float get_tux_y(); }; } // namespace scripting diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index 041d49f0ffd..7b17b36b76b 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -715,6 +715,12 @@ WorldMap::set_passive_message(const std::string& message, float time) m_passive_message_timer.start(time); } +Vector +WorldMap::get_tux_pos() +{ + return m_tux->get_pos(); +} + } // namespace worldmap /* EOF */ diff --git a/src/worldmap/worldmap.hpp b/src/worldmap/worldmap.hpp index 081ceb9a903..08f8634705c 100644 --- a/src/worldmap/worldmap.hpp +++ b/src/worldmap/worldmap.hpp @@ -158,6 +158,8 @@ class WorldMap final : public GameObjectManager, Camera& get_camera() const { return *m_camera; } + Vector get_tux_pos(); + protected: virtual bool before_object_add(GameObject& object) override; virtual void before_object_remove(GameObject& object) override; From 884b015ea186e98dd2c7c389adfbd2a86381efe1 Mon Sep 17 00:00:00 2001 From: Semphris Date: Sun, 7 Mar 2021 16:21:58 -0500 Subject: [PATCH 7/8] Removed needless attribute --- src/scripting/worldmap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripting/worldmap.hpp b/src/scripting/worldmap.hpp index 511560be2de..5eeb3f70f4f 100644 --- a/src/scripting/worldmap.hpp +++ b/src/scripting/worldmap.hpp @@ -32,7 +32,7 @@ class WorldMap final : public GameObjectManager { #ifndef SCRIPTING_API private: - ::worldmap::WorldMap* __attribute__((unused)) m_parent; + ::worldmap::WorldMap* m_parent; public: WorldMap(::worldmap::WorldMap* parent); From fb029ea3ba605359a02a60293b35fd5b89547878 Mon Sep 17 00:00:00 2001 From: Semphris Date: Sun, 7 Mar 2021 16:24:36 -0500 Subject: [PATCH 8/8] Added timeshift to worldmap --- data/levels/world1/worldmap.stwm | 77 +++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/data/levels/world1/worldmap.stwm b/data/levels/world1/worldmap.stwm index 8724f097121..c14c0f325df 100644 --- a/data/levels/world1/worldmap.stwm +++ b/data/levels/world1/worldmap.stwm @@ -114,11 +114,6 @@ (x 61) (y 80) ) - (level - (level "end_of_tunnel.stl") - (x 67) - (y 82) - ) (level (level "path_in_the_clouds.stl") (x 68) @@ -170,32 +165,20 @@ ) (special-tile (invisible-tile #t) - (script "go_underground(true);") + (script "go_underground(true); +worldmap.settings.fade_to_ambient_light(0.5, 0.5, 0.5, 0.5);") (apply-to-direction "north") (x 70) (y 74) ) (special-tile (invisible-tile #t) - (script "go_underground(false);") + (script "go_underground(false); +worldmap.settings.fade_to_ambient_light(0.8, 0.6, 0.7, 0.5);") (apply-to-direction "south") (x 70) (y 73) ) - (special-tile - (invisible-tile #t) - (script "go_underground(false);") - (apply-to-direction "north") - (x 67) - (y 84) - ) - (special-tile - (invisible-tile #t) - (script "go_underground(true);") - (apply-to-direction "south") - (x 67) - (y 83) - ) (special-tile (map-message (_ "You found a secret area!")) (invisible-tile #t) @@ -211,6 +194,58 @@ (x 28) (y 30) ) + (special-tile + (invisible-tile #t) + (script "worldmap.settings.fade_to_ambient_light(0.8, 0.7, 0.6, 2);") + (x 66) + (y 66) + ) + (special-tile + (invisible-tile #t) + (script "worldmap.settings.fade_to_ambient_light(1, 1, 1, 2);") + (x 65) + (y 66) + ) + (special-tile + (invisible-tile #t) + (script "worldmap.settings.fade_to_ambient_light(0.8, 0.7, 0.6, 2);") + (x 69) + (y 66) + ) + (special-tile + (invisible-tile #t) + (script "worldmap.settings.fade_to_ambient_light(0.3, 0.4, 0.6, 2);") + (x 69) + (y 65) + ) + (special-tile + (invisible-tile #t) + (script "worldmap.settings.fade_to_ambient_light(0.3, 0.4, 0.6, 2);") + (x 72) + (y 70) + ) + (special-tile + (invisible-tile #t) + (script "worldmap.settings.fade_to_ambient_light(0.8, 0.6, 0.7, 2);") + (x 72) + (y 71) + ) + (special-tile + (invisible-tile #t) + (script "go_underground(false); +worldmap.settings.fade_to_ambient_light(1, 1, 1, 0.5);") + (apply-to-direction "north") + (x 67) + (y 84) + ) + (special-tile + (invisible-tile #t) + (script "go_underground(true); +worldmap.settings.fade_to_ambient_light(0.5, 0.5, 0.5, 0.5);") + (apply-to-direction "south") + (x 67) + (y 83) + ) (sprite-change (stay-action "boat") (change-on-touch #t)