X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fscripting%2Ffunctions.cpp;h=aa08d282cdbd536e59974de446f990861d670fb5;hb=5d1290054358cb4560f54bcd6840121a69360bf9;hp=fbff6d8a7dcd71bdf58cb60aa8339c1b05188bd3;hpb=864c93e01ec366f730b3ebad08d5c52d6a9363b6;p=supertux.git diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index fbff6d8a7..aa08d282c 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -1,13 +1,135 @@ +// $Id: main.cpp 3275 2006-04-09 00:32:34Z sommer $ +// +// SuperTux +// Copyright (C) 2005 Matthias Braun +// +// 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 2 +// 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, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +#include + +#include #include -#include "functions.h" -#include "script_interpreter.h" +#include +#include +#include +#include "textscroller.hpp" +#include "functions.hpp" +#include "game_session.hpp" +#include "tinygettext/tinygettext.hpp" +#include "physfs/physfs_stream.hpp" +#include "script_manager.hpp" +#include "resources.hpp" +#include "gettext.hpp" +#include "log.hpp" +#include "mainloop.hpp" +#include "worldmap.hpp" +#include "world.hpp" + +#include "squirrel_error.hpp" +#include "wrapper_util.hpp" namespace Scripting { -void wait(float seconds) +int display(HSQUIRRELVM vm) +{ + Console::output << squirrel2string(vm, -1) << std::endl; + return 0; +} + +void wait(HSQUIRRELVM vm, float seconds) +{ + SQUserPointer ptr = sq_getforeignptr(vm); + ScriptManager* script_manager = reinterpret_cast (ptr); + script_manager->set_wakeup_event(vm, ScriptManager::TIME, seconds); +} + +void wait_for_screenswitch(HSQUIRRELVM vm) +{ + SQUserPointer ptr = sq_getforeignptr(vm); + ScriptManager* script_manager = reinterpret_cast (ptr); + script_manager->set_wakeup_event(vm, ScriptManager::SCREEN_SWITCHED); +} + +void exit_screen() +{ + main_loop->exit_screen(); +} + +std::string translate(const std::string& text) +{ + return dictionary_manager.get_dictionary().translate(text); +} + +void display_text_file(const std::string& filename) +{ + main_loop->push_screen(new TextScroller(filename)); +} + +void load_worldmap(const std::string& filename) { - ScriptInterpreter::current()->suspend(seconds); + using namespace WorldMapNS; + + std::auto_ptr worldmap(new WorldMap()); + worldmap->loadmap(filename); + main_loop->push_screen(worldmap.release()); +} + +void load_level(const std::string& filename) +{ + main_loop->push_screen(new GameSession(filename, ST_GL_PLAY)); +} + +static SQInteger squirrel_read_char(SQUserPointer file) +{ + std::istream* in = reinterpret_cast (file); + char c = in->get(); + if(in->eof()) + return 0; + + return c; +} + + +void import(HSQUIRRELVM vm, const std::string& filename) +{ + IFileStream in(filename); + + if(SQ_FAILED(sq_compile(vm, squirrel_read_char, &in, + filename.c_str(), SQTrue))) + throw SquirrelError(vm, "Couldn't parse script"); + + sq_pushroottable(vm); + if(SQ_FAILED(sq_call(vm, 1, SQFalse))) { + sq_pop(vm, 1); + throw SquirrelError(vm, "Couldn't execute script"); + } + sq_pop(vm, 1); +} + +void add_key(int new_key) +{ + player_status->set_keys(new_key); +} + +void save_state() +{ + if(World::current() == NULL) + throw std::runtime_error("Can't save state without active World"); + + World::current()->save_state(); } }