Skip to content

Commit

Permalink
Remove level "edit mode", replace with cheat menu option
Browse files Browse the repository at this point in the history
Level "edit mode" used to be enabled via the scripting function `Level.edit(true)`, and made players unable to die, toggling them into ghost mode if about to. However, this is very obscure for such a potentially helpful playtesting feature.

`Level.edit(false)` used to serve the purpose of disabling "edit mode", however, it only restarted and freezed the level entirely.

This feature is now available under a different name, "Prevent Death", and can be toggled from the "Cheat Menu". It affects all players.

Additionally, `GameSession` no longer preserves the previous level after a restart, which seems to have been a bugfix to a bug, regarding `Level.edit(false)` (see a370586).
  • Loading branch information
Vankata453 committed Nov 17, 2023
1 parent d9f8785 commit 49e6ed1
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 120 deletions.
11 changes: 2 additions & 9 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player
m_airarrow(Surface::from_file("images/engine/hud/airarrow.png")),
m_floor_normal(0.0f, 0.0f),
m_ghost_mode(false),
m_edit_mode(false),
m_unduck_hurt_timer(),
m_idle_timer(),
m_idle_stage(0),
Expand Down Expand Up @@ -2317,8 +2316,8 @@ Player::kill(bool completely)
} else {
SoundManager::current()->play("sounds/kill.wav", get_pos());

// do not die when in edit mode
if (m_edit_mode) {
if (GameSession::current() && GameSession::current()->m_prevent_death)
{
set_ghost_mode(true);
return;
}
Expand Down Expand Up @@ -2502,12 +2501,6 @@ Player::set_ghost_mode(bool enable)
}
}

void
Player::set_edit_mode(bool enable)
{
m_edit_mode = enable;
}

void
Player::start_climbing(Climbable& climbable)
{
Expand Down
5 changes: 0 additions & 5 deletions src/object/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ class Player final : public MovingObject,
Lets Tux float around and through solid objects. */
void set_ghost_mode(bool enable);

/** Switches edit mode on/off.
In edit mode, Tux will enter ghost_mode instead of dying. */
void set_edit_mode(bool enable);

/** Returns whether ghost mode is currently enabled */
bool get_ghost_mode() const { return m_ghost_mode; }

Expand Down Expand Up @@ -386,7 +382,6 @@ class Player final : public MovingObject,
Vector m_floor_normal;

bool m_ghost_mode; /**< indicates if Tux should float around and through solid objects */
bool m_edit_mode; /**< indicates if Tux should switch to ghost mode rather than dying */

Timer m_unduck_hurt_timer; /**< if Tux wants to stand up again after ducking and cannot, this timer is started */

Expand Down
7 changes: 0 additions & 7 deletions src/scripting/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ Level_toggle_pause()
game_session.toggle_pause();
}

void
Level_edit(bool edit_mode)
{
SCRIPT_GUARD_GAMESESSION();
game_session.set_editmode(edit_mode);
}

void
Level_pause_target_timer()
{
Expand Down
6 changes: 0 additions & 6 deletions src/scripting/level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ void Level_flip_vertically();
*/
void Level_toggle_pause();

/**
* Switch to/from edit mode
* @param bool $edit_mode
*/
void Level_edit(bool edit_mode);

/**
* Pauses the target timer.
*/
Expand Down
30 changes: 0 additions & 30 deletions src/scripting/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12779,29 +12779,6 @@ static SQInteger Level_toggle_pause_wrapper(HSQUIRRELVM vm)

}

static SQInteger Level_edit_wrapper(HSQUIRRELVM vm)
{
SQBool arg0;
if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) {
sq_throwerror(vm, _SC("Argument 1 not a bool"));
return SQ_ERROR;
}

try {
scripting::Level_edit(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 'Level_edit'"));
return SQ_ERROR;
}

}

static SQInteger Level_pause_target_timer_wrapper(HSQUIRRELVM vm)
{
(void) vm;
Expand Down Expand Up @@ -14116,13 +14093,6 @@ void register_supertux_wrapper(HSQUIRRELVM v)
throw SquirrelError(v, "Couldn't register function 'Level_toggle_pause'");
}

sq_pushstring(v, "Level_edit", -1);
sq_newclosure(v, &Level_edit_wrapper, 0);
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".b|n");
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register function 'Level_edit'");
}

sq_pushstring(v, "Level_pause_target_timer", -1);
sq_newclosure(v, &Level_pause_target_timer_wrapper, 0);
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".");
Expand Down
53 changes: 1 addition & 52 deletions src/supertux/game_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ GameSession::GameSession(const std::string& levelfile_, Savegame& savegame, Stat
GameSessionRecorder(),
reset_button(false),
reset_checkpoint_button(false),
m_prevent_death(false),
m_level(),
m_old_level(),
m_statistics_backdrop(Surface::from_file("images/engine/menu/score-backdrop.png")),
m_scripts(),
m_currentsector(nullptr),
Expand All @@ -66,7 +66,6 @@ GameSession::GameSession(const std::string& levelfile_, Savegame& savegame, Stat
m_best_level_statistics(statistics),
m_savegame(savegame),
m_play_time(0),
m_edit_mode(false),
m_levelintro_shown(false),
m_coins_at_start(),
m_boni_at_start(),
Expand Down Expand Up @@ -138,12 +137,6 @@ GameSession::restart_level(bool after_death)
}
}


if (m_edit_mode) {
force_ghost_mode();
return (-1);
}

m_game_pause = false;
m_end_sequence = nullptr;
m_endsequence_timer.stop();
Expand All @@ -158,7 +151,6 @@ GameSession::restart_level(bool after_death)
}

try {
m_old_level = std::move(m_level);
m_level = LevelParser::from_file(m_levelfile, false, false);

/* Determine the spawnpoint to spawn/respawn Tux to. */
Expand Down Expand Up @@ -337,38 +329,6 @@ GameSession::is_active() const
return !m_game_pause && m_active && !(m_end_sequence && m_end_sequence->is_running());
}

void
GameSession::set_editmode(bool edit_mode_)
{
if (m_edit_mode == edit_mode_) return;
m_edit_mode = edit_mode_;

for (auto* p : m_currentsector->get_players())
{
p->set_edit_mode(edit_mode_);
}

if (edit_mode_) {

// Entering edit mode.

} else {

// Leaving edit mode.
restart_level();

}
}

void
GameSession::force_ghost_mode()
{
for (auto* p : m_currentsector->get_players())
{
p->set_ghost_mode(true);
}
}

void
GameSession::check_end_conditions()
{
Expand Down Expand Up @@ -618,11 +578,6 @@ GameSession::finish(bool win)

using namespace worldmap;

if (m_edit_mode) {
force_ghost_mode();
return;
}

if (win) {
if (WorldMapSector::current())
{
Expand Down Expand Up @@ -715,12 +670,6 @@ GameSession::has_active_sequence() const
void
GameSession::start_sequence(Player* caller, Sequence seq, const SequenceData* data)
{
// Do not play sequences when in edit mode.
if (m_edit_mode) {
force_ghost_mode();
return;
}

// Handle special "stoptux" sequence.
if (seq == SEQ_STOPTUX) {
if (!m_end_sequence) {
Expand Down
16 changes: 6 additions & 10 deletions src/supertux/game_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,11 @@ class GameSession final : public Screen,
std::string get_working_directory() const;
bool has_active_sequence() const;
int restart_level(bool after_death = false);
bool reset_button;
bool reset_checkpoint_button;

void toggle_pause();
void abort_level();
bool is_active() const;

/** Enters or leaves level editor mode */
void set_editmode(bool edit_mode = true);

/** Forces all Players to enter ghost mode */
void force_ghost_mode();

Savegame& get_savegame() const { return m_savegame; }

void set_scheduler(SquirrelScheduler& new_scheduler);
Expand All @@ -142,9 +134,14 @@ class GameSession final : public Screen,

void on_escape_press(bool force_quick_respawn);

public:
bool reset_button;
bool reset_checkpoint_button;

bool m_prevent_death; /**< true if players should enter ghost mode instead of dying */

private:
std::unique_ptr<Level> m_level;
std::unique_ptr<Level> m_old_level;
SurfacePtr m_statistics_backdrop;

// scripts
Expand Down Expand Up @@ -174,7 +171,6 @@ class GameSession final : public Screen,
// but NOT if Tux respawns at a checkpoint (for LevelTimes to work)
float m_play_time; /**< total time in seconds that this session ran interactively */

bool m_edit_mode; /**< true if GameSession runs in level editor mode */
bool m_levelintro_shown; /**< true if the LevelIntro screen was already shown */

int m_coins_at_start; /** How many coins does the player have at the start */
Expand Down
5 changes: 4 additions & 1 deletion src/supertux/menu/cheat_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ CheatMenu::CheatMenu()
add_entry(MNID_SHRINK, _("Shrink Tux"));
add_entry(MNID_KILL, _("Kill Tux"));
add_entry(MNID_FINISH, _("Finish Level"));

if (players.size() == 1)
{
add_entry(MNID_GHOST, players[0]->get_ghost_mode() ?
Expand All @@ -51,6 +50,10 @@ CheatMenu::CheatMenu()
add_entry(MNID_GHOST, _("Activate Ghost Mode"));
add_entry(MNID_UNGHOST, _("Leave Ghost Mode"));
}

if (GameSession::current())
add_toggle(-1, _("Prevent Death"), &GameSession::current()->m_prevent_death);

add_hl();
add_back(_("Back"));
}
Expand Down

0 comments on commit 49e6ed1

Please sign in to comment.