Skip to content

Commit

Permalink
Icy island timeshift (#1692)
Browse files Browse the repository at this point in the history
* Added settings Squirrel proprety to worldmaps (allows dynamic changes to ambient light and music)

* Refactored Secter/Worldmap scripting to use inheritance

* Marked scripting::WorlMap's internal variable as unused

* Fixed copyright headers

* Fixed build error

* Fixed MSVC not recognising the 'unused' attribute

* Removed needless attribute

* Added timeshift to worldmap

Co-authored-by: Semphris <semphris@protonmail.com>
  • Loading branch information
Semphriss and Semphris authored May 17, 2021
1 parent 6b8583e commit 221e10b
Show file tree
Hide file tree
Showing 15 changed files with 732 additions and 404 deletions.
77 changes: 56 additions & 21 deletions data/levels/world1/worldmap.stwm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/scripting/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorldMapScreen>(
std::make_unique<WorldMap>(filename, WorldMap::current()->get_savegame())));
std::make_unique<::worldmap::WorldMap>(filename, ::worldmap::WorldMap::current()->get_savegame())));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/scripting/game_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/game_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class GameObjectManager;

namespace scripting {

GameObjectManager& get_game_object_manager();
::GameObjectManager& get_game_object_manager();

template<class T>
class GameObject
Expand Down
76 changes: 76 additions & 0 deletions src/scripting/game_object_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SuperTux
// Copyright (C) 2015 Ingo Ruhnke <grumbel@gmail.com>
// 2021 A. Semphris <semphris@protonmail.com>
//
// 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 <http://www.gnu.org/licenses/>.

#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<AmbientLight>();
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<AmbientLight>();
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<AmbientLight>();
return ambient_light.get_ambient_light().red;
}

float
GameObjectManager::get_ambient_green() const
{
auto& ambient_light = m_gom_parent->get_singleton_by_type<AmbientLight>();
return ambient_light.get_ambient_light().green;
}

float
GameObjectManager::get_ambient_blue() const
{
auto& ambient_light = m_gom_parent->get_singleton_by_type<AmbientLight>();
return ambient_light.get_ambient_light().blue;
}

void
GameObjectManager::set_music(const std::string& filename)
{
auto& music = m_gom_parent->get_singleton_by_type<MusicObject>();
music.set_music(filename);
}

} // namespace scripting

/* EOF */
56 changes: 56 additions & 0 deletions src/scripting/game_object_manager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SuperTux
// Copyright (C) 2021 A. Semphris <semphris@protonmail.com>
//
// 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 <http://www.gnu.org/licenses/>.

#ifndef HEADER_SUPERTUX_SCRIPTING_GAME_OBJECT_MANAGER_HPP
#define HEADER_SUPERTUX_SCRIPTING_GAME_OBJECT_MANAGER_HPP

#ifndef SCRIPTING_API
#include <string>
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 */
44 changes: 2 additions & 42 deletions src/scripting/sector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SuperTux
// Copyright (C) 2015 Ingo Ruhnke <grumbel@gmail.com>
// 2021 A. Semphris <semphris@protonmail.com>
//
// 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
Expand All @@ -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<AmbientLight>();
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<AmbientLight>();
ambient_light.set_ambient_light(Color(red, green, blue));
}

float
Sector::get_ambient_red() const
{
auto& ambient_light = m_parent->get_singleton_by_type<AmbientLight>();
return ambient_light.get_ambient_light().red;
}

float
Sector::get_ambient_green() const
{
auto& ambient_light = m_parent->get_singleton_by_type<AmbientLight>();
return ambient_light.get_ambient_light().green;
}

float
Sector::get_ambient_blue() const
{
auto& ambient_light = m_parent->get_singleton_by_type<AmbientLight>();
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<MusicObject>();
music.set_music(filename);
}

} // namespace scripting

/* EOF */
11 changes: 3 additions & 8 deletions src/scripting/sector.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SuperTux - Sector scripting
// Copyright (C) 2006 Wolfgang Becker <uafr@gmx.de>
// 2021 A. Semphris <semphris@protonmail.com>
//
// 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
Expand All @@ -19,12 +20,13 @@

#ifndef SCRIPTING_API
#include <string>
#include "scripting/game_object_manager.hpp"
class Sector;
#endif

namespace scripting {

class Sector final
class Sector final : public GameObjectManager
{
#ifndef SCRIPTING_API
private:
Expand All @@ -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
Expand Down
Loading

0 comments on commit 221e10b

Please sign in to comment.