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) 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..c9122fa8f16 100644 --- a/src/scripting/game_object.cpp +++ b/src/scripting/game_object.cpp @@ -21,14 +21,14 @@ namespace scripting { -GameObjectManager& get_game_object_manager() +::GameObjectManager& get_game_object_manager() { using namespace worldmap; 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/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..9745cfd817d --- /dev/null +++ b/src/scripting/game_object_manager.cpp @@ -0,0 +1,76 @@ +// 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 +// 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..0115e64a9cf --- /dev/null +++ b/src/scripting/game_object_manager.hpp @@ -0,0 +1,56 @@ +// 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 +// 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..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 @@ -25,58 +26,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..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 @@ -19,12 +20,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 +41,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 new file mode 100644 index 00000000000..49aaafab966 --- /dev/null +++ b/src/scripting/worldmap.cpp @@ -0,0 +1,43 @@ +// 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 +// 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 "worldmap/worldmap.hpp" + +namespace scripting { + +WorldMap::WorldMap(::worldmap::WorldMap* parent) : + GameObjectManager(parent), + m_parent(parent) +{ +} + +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 + +/* EOF */ diff --git a/src/scripting/worldmap.hpp b/src/scripting/worldmap.hpp new file mode 100644 index 00000000000..5eeb3f70f4f --- /dev/null +++ b/src/scripting/worldmap.hpp @@ -0,0 +1,54 @@ +// 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 +// 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 +#include "scripting/game_object_manager.hpp" +namespace worldmap { +class WorldMap; +} +#endif + +namespace scripting { + +class WorldMap final : public GameObjectManager +{ +#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: + float get_tux_x(); + float get_tux_y(); +}; + +} // namespace scripting + +#endif + +/* EOF */ diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 8f800e60119..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); @@ -8217,239 +8441,14 @@ static SQInteger ScriptedObject_set_visible_wrapper(HSQUIRRELVM vm) return SQ_ERROR; } - SQBool arg0; - if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) { - sq_throwerror(vm, _SC("Argument 1 not a bool")); - return SQ_ERROR; - } - - try { - _this->set_visible(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 'set_visible'")); - return SQ_ERROR; - } - -} - -static SQInteger ScriptedObject_is_visible_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'is_visible' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - - try { - bool return_value = _this->is_visible(); - - 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 'is_visible'")); - return SQ_ERROR; - } - -} - -static SQInteger ScriptedObject_set_solid_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'set_solid' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - SQBool arg0; - if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) { - sq_throwerror(vm, _SC("Argument 1 not a bool")); - return SQ_ERROR; - } - - try { - _this->set_solid(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 'set_solid'")); - return SQ_ERROR; - } - -} - -static SQInteger ScriptedObject_is_solid_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'is_solid' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - - try { - bool return_value = _this->is_solid(); - - 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 'is_solid'")); - return SQ_ERROR; - } - -} - -static SQInteger ScriptedObject_get_name_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'get_name' called without instance")); - return SQ_ERROR; - } - auto _this = reinterpret_cast (data); - - if (_this == nullptr) { - return SQ_ERROR; - } - - - try { - std::string return_value = _this->get_name(); - - assert(return_value.size() < static_cast(std::numeric_limits::max())); - sq_pushstring(vm, return_value.c_str(), static_cast(return_value.size())); - 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_name'")); - return SQ_ERROR; - } - -} - -static SQInteger Sector_release_hook(SQUserPointer ptr, SQInteger ) -{ - auto _this = reinterpret_cast (ptr); - delete _this; - return 0; -} - -static SQInteger Sector_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 Sector_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")); + SQBool arg0; + if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a bool")); return SQ_ERROR; } try { - _this->fade_to_ambient_light(static_cast (arg0), static_cast (arg1), static_cast (arg2), static_cast (arg3)); + _this->set_visible(arg0 == SQTrue); return 0; @@ -8457,20 +8456,20 @@ static SQInteger Sector_fade_to_ambient_light_wrapper(HSQUIRRELVM vm) sq_throwerror(vm, e.what()); return SQ_ERROR; } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'fade_to_ambient_light'")); + sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_visible'")); return SQ_ERROR; } } -static SQInteger Sector_get_ambient_red_wrapper(HSQUIRRELVM vm) +static SQInteger ScriptedObject_is_visible_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("'is_visible' called without instance")); return SQ_ERROR; } - auto _this = reinterpret_cast (data); + auto _this = reinterpret_cast (data); if (_this == nullptr) { return SQ_ERROR; @@ -8478,59 +8477,63 @@ static SQInteger Sector_get_ambient_red_wrapper(HSQUIRRELVM vm) try { - float return_value = _this->get_ambient_red(); + bool return_value = _this->is_visible(); - sq_pushfloat(vm, return_value); + 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 'get_ambient_red'")); + sq_throwerror(vm, _SC("Unexpected exception while executing function 'is_visible'")); return SQ_ERROR; } } -static SQInteger Sector_get_ambient_green_wrapper(HSQUIRRELVM vm) +static SQInteger ScriptedObject_set_solid_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("'set_solid' called without instance")); return SQ_ERROR; } - auto _this = reinterpret_cast (data); + auto _this = reinterpret_cast (data); if (_this == nullptr) { return SQ_ERROR; } + SQBool arg0; + if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a bool")); + return SQ_ERROR; + } try { - float return_value = _this->get_ambient_green(); + _this->set_solid(arg0 == SQTrue); - 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 'set_solid'")); return SQ_ERROR; } } -static SQInteger Sector_get_ambient_blue_wrapper(HSQUIRRELVM vm) +static SQInteger ScriptedObject_is_solid_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("'is_solid' called without instance")); return SQ_ERROR; } - auto _this = reinterpret_cast (data); + auto _this = reinterpret_cast (data); if (_this == nullptr) { return SQ_ERROR; @@ -8538,60 +8541,64 @@ static SQInteger Sector_get_ambient_blue_wrapper(HSQUIRRELVM vm) try { - float return_value = _this->get_ambient_blue(); + bool return_value = _this->is_solid(); - sq_pushfloat(vm, return_value); + 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 'get_ambient_blue'")); + sq_throwerror(vm, _SC("Unexpected exception while executing function 'is_solid'")); return SQ_ERROR; } } -static SQInteger Sector_set_gravity_wrapper(HSQUIRRELVM vm) +static SQInteger ScriptedObject_get_name_wrapper(HSQUIRRELVM vm) { SQUserPointer data; if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) { - sq_throwerror(vm, _SC("'set_gravity' called without instance")); + sq_throwerror(vm, _SC("'get_name' 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")); - return SQ_ERROR; - } try { - _this->set_gravity(static_cast (arg0)); + std::string return_value = _this->get_name(); - return 0; + assert(return_value.size() < static_cast(std::numeric_limits::max())); + sq_pushstring(vm, return_value.c_str(), static_cast(return_value.size())); + return 1; } catch(std::exception& e) { sq_throwerror(vm, e.what()); return SQ_ERROR; } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_gravity'")); + sq_throwerror(vm, _SC("Unexpected exception while executing function 'get_name'")); return SQ_ERROR; } } -static SQInteger Sector_set_music_wrapper(HSQUIRRELVM vm) +static SQInteger Sector_release_hook(SQUserPointer ptr, SQInteger ) +{ + auto _this = reinterpret_cast (ptr); + delete _this; + return 0; +} + +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_music' called without instance")); + sq_throwerror(vm, _SC("'set_gravity' called without instance")); return SQ_ERROR; } auto _this = reinterpret_cast (data); @@ -8600,14 +8607,14 @@ static SQInteger Sector_set_music_wrapper(HSQUIRRELVM vm) return SQ_ERROR; } - const SQChar* arg0; - if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) { - sq_throwerror(vm, _SC("Argument 1 not a string")); + 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_music(arg0); + _this->set_gravity(static_cast (arg0)); return 0; @@ -8615,7 +8622,7 @@ static SQInteger Sector_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 'set_gravity'")); return SQ_ERROR; } @@ -11078,6 +11085,13 @@ 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 display_wrapper(HSQUIRRELVM vm) { return scripting::display(vm); @@ -12468,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; @@ -12910,6 +12950,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; @@ -14644,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) { @@ -15215,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) { diff --git a/src/scripting/wrapper.hpp b/src/scripting/wrapper.hpp index d1cbb0da557..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; @@ -68,6 +70,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..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" @@ -30,5 +31,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..7b17b36b76b 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"); @@ -712,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;