Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worldmap scripting #1691

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
43 changes: 43 additions & 0 deletions src/scripting/worldmap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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/>.

#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() const
{
return m_parent->get_tux_pos().x;
}

float
WorldMap::get_tux_y() const
{
return m_parent->get_tux_pos().y;
}

} // namespace scripting

/* EOF */
54 changes: 54 additions & 0 deletions src/scripting/worldmap.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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_WORLDMAP_HPP
#define HEADER_SUPERTUX_SCRIPTING_WORLDMAP_HPP


#ifndef SCRIPTING_API
#include <string>
#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() const;
float get_tux_y() const;
};

} // namespace scripting

#endif

/* EOF */
Loading