In "edit" mode, Tux will not die and sequences will not play, but Tux will become a ghost instead.
SVN-Revision: 5239
Level.finish(true);
}
+function edit()
+{
+ Level.edit(true);
+}
+
+function play()
+{
+ Level.edit(false);
+}
+
function worldmapfinish()
{
save_state();
end_sequence(0),
levelfile(levelfile_), best_level_statistics(statistics),
capture_demo_stream(0), playback_demo_stream(0), demo_controller(0),
- play_time(0)
+ play_time(0), edit_mode(false)
{
current_ = this;
currentsector = NULL;
void
GameSession::restart_level()
{
+
+ if (edit_mode) {
+ force_ghost_mode();
+ return;
+ }
+
game_pause = false;
end_sequence = 0;
}
}
+void
+GameSession::set_editmode(bool edit_mode)
+{
+ if (this->edit_mode == edit_mode) return;
+ this->edit_mode = edit_mode;
+
+ currentsector->get_players()[0]->set_edit_mode(edit_mode);
+
+ if (edit_mode) {
+
+ // entering edit mode
+
+ } else {
+
+ // leaving edit mode
+ restart_level();
+
+ }
+}
+
+void
+GameSession::force_ghost_mode()
+{
+ currentsector->get_players()[0]->set_ghost_mode(true);
+}
+
HSQUIRRELVM
GameSession::run_script(std::istream& in, const std::string& sourcename)
{
{
using namespace WorldMapNS;
+ if (edit_mode) {
+ force_ghost_mode();
+ return;
+ }
+
if(win) {
if(WorldMap::current())
WorldMap::current()->finished_level(level.get());
void
GameSession::start_sequence(const std::string& sequencename)
{
+ // do not play sequences when in edit mode
+ if (edit_mode) {
+ force_ghost_mode();
+ return;
+ }
+
// handle special "stoptux" sequence
if (sequencename == "stoptux") {
if (!end_sequence) {
void toggle_pause();
+ /**
+ * Enters or leaves level editor mode
+ */
+ void set_editmode(bool edit_mode = true);
+
+ /**
+ * Forces all Players to enter ghost mode
+ */
+ void force_ghost_mode();
+
private:
void check_end_conditions();
void process_events();
std::auto_ptr<Menu> game_menu;
float play_time; /**< total time in seconds that this session ran interactively */
+
+ bool edit_mode; /**< true if GameSession runs in level editor mode */
};
#endif /*SUPERTUX_GAMELOOP_H*/
: scripting_controller(0),
player_status(_player_status),
scripting_controller_old(0),
- grabbed_object(NULL), ghost_mode(false), climbing(0)
+ grabbed_object(NULL), ghost_mode(false), edit_mode(false), climbing(0)
{
this->name = name;
controller = main_controller;
return;
sound_manager->play("sounds/hurt.wav");
+
if (climbing) stop_climbing(*climbing);
physic.set_velocity_x(0);
duck = false;
}
} else {
+
+ // do not die when in edit mode
+ if (edit_mode) {
+ set_ghost_mode(true);
+ return;
+ }
+
if (player_status->coins >= 25 && !GameSession::current()->get_reset_point_sectorname().empty())
{
for (int i = 0; i < 5; i++)
}
/* fallen out of the level? */
- if (get_pos().y > Sector::current()->get_height()) {
+ if ((get_pos().y > Sector::current()->get_height()) && (!ghost_mode)) {
kill(true);
return;
}
}
+void
+Player::set_edit_mode(bool enable)
+{
+ edit_mode = enable;
+}
+
void
Player::start_climbing(Climbable& climbable)
{
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() { return ghost_mode; }
void try_grab();
bool ghost_mode; /**< indicates if Tux should float around and through solid objects */
+ bool edit_mode; /**< indicates if Tux should switch to ghost mode rather than dying */
Timer unduck_hurt_timer; /**< if Tux wants to stand up again after ducking and cannot, this timer is started */
return;
GameSession::current()->toggle_pause();
}
+
+ void
+ Level::edit(bool edit_mode)
+ {
+ if(GameSession::current() == NULL) return;
+ GameSession::current()->set_editmode(edit_mode);
+ }
+
}
void flip_vertically();
/** toggle pause */
void toggle_pause();
+
+ /** Switch to and from edit mode */
+ void edit(bool edit_mode);
};
}
}
+static SQInteger Level_edit_wrapper(HSQUIRRELVM vm)
+{
+ SQUserPointer data;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0))) {
+ sq_throwerror(vm, _SC("'edit' called without instance"));
+ return SQ_ERROR;
+ }
+ Scripting::Level* _this = reinterpret_cast<Scripting::Level*> (data);
+ SQBool arg0;
+ if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) {
+ sq_throwerror(vm, _SC("Argument 1 not a bool"));
+ return SQ_ERROR;
+ }
+
+ try {
+ _this->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 'edit'"));
+ return SQ_ERROR;
+ }
+
+}
+
static SQInteger ScriptedObject_release_hook(SQUserPointer ptr, SQInteger )
{
Scripting::ScriptedObject* _this = reinterpret_cast<Scripting::ScriptedObject*> (ptr);
throw SquirrelError(v, "Couldn't register function 'toggle_pause'");
}
+ sq_pushstring(v, "edit", -1);
+ sq_newclosure(v, &Level_edit_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'edit'");
+ }
+
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register class 'Level'");
}