msgstr ""
"-Penny ist verschwunden!\n"
"\n"
-"#Tux und Penny sassen gemtlich beim Picknick\n"
+"#Tux und Penny sassen gemütlich beim Picknick\n"
"#in den eisigen Ebenen der Antarktis.\n"
"#Plötzlich sprang eine dunkle Kreatur hinter\n"
"#einem Felsen hervor. Tux sah einen grellen\n"
"#hatte lag jetzt ein Zettel:\n"
"\n"
"#\"Tux, mein Erzfeind!\n"
-"#Ich habe deine Freundinn Penny entfhrt und\n"
+"#Ich habe deine Freundinn Penny entführt und\n"
"#halte sie in meiner Festung gefangen. Den Weg\n"
"#dorthin bewachen meine finsteren Kreaturen!\n"
"#Versuche gar nicht erst sie zu retten, du\n"
(supertux-worldmap
(properties
(name (_ "Icyisland"))
- (intro-filename "intro.txt")
(music "salcon.mod")
)
+ (intro-script "
+display_text_file(\"intro.txt\")
+")
(spawnpoint
(name "main")
(x 4)
(level
(x 7)
(y 20)
- (extro-filename "extro.txt")
+ (extro-script "
+display_text_file(\"extro.txt\")
+")
(name "level26.stl")
(quit-worldmap #t))
)
#include "object/camera.h"
#include "yeti_stalactite.h"
#include "bouncing_snowball.h"
+#include "game_session.h"
#include "scripting/script_interpreter.h"
static const float JUMP_VEL1 = 250;
if(dead_script != "") {
try {
ScriptInterpreter* interpreter
- = new ScriptInterpreter(Sector::current());
+ = new ScriptInterpreter(GameSession::current()->get_working_directory());
+ interpreter->register_sector(Sector::current());
std::istringstream in(dead_script);
interpreter->load_script(in, "Yeti - dead-script");
interpreter->start_script();
#include "control/codecontroller.h"
#include "control/joystickkeyboardcontroller.h"
#include "main.h"
+#include "file_system.h"
#include "gameconfig.h"
#include "gettext.h"
reset_pos = pos;
}
+std::string
+GameSession::get_working_directory()
+{
+ return FileSystem::dirname(levelfile);
+}
+
void
GameSession::display_info_box(const std::string& text)
{
void start_sequence(const std::string& sequencename);
/// called by JoystickKeyboardController after an ascii key has been pressed
void try_cheats();
+
+ /** returns the "working directory" usually this is the directory where the
+ * currently played level resides. This is used when locating additional
+ * resources for the current level/world
+ */
+ std::string get_working_directory();
private:
void restart_level();
#include <stdio.h>
#include <string>
#include <squirrel.h>
+#include "textscroller.h"
#include "functions.h"
#include "script_interpreter.h"
#include "tinygettext/tinygettext.h"
+#include "resources.h"
#include "gettext.h"
namespace Scripting
return dictionary_manager.get_dictionary().translate(text);
}
+void display_text_file(const std::string& filename)
+{
+ std::string file
+ = ScriptInterpreter::current()->get_working_directory() + filename;
+ ::display_text_file(file);
+}
+
}
namespace Scripting
{
+/** displays a text file and scrolls it over the screen */
+void display_text_file(const std::string& filename);
/** Suspends the script execution for the specified number of seconds */
void set_wakeup_time(float seconds);
/** translates a give text into the users language (by looking it up in the .po
#include "wrapper.h"
#include "wrapper_util.h"
#include "sector.h"
+#include "file_system.h"
+#include "game_session.h"
#include "object/text_object.h"
#include "object/scripted_object.h"
#include "object/display_effect.h"
ScriptInterpreter* ScriptInterpreter::_current = 0;
-ScriptInterpreter::ScriptInterpreter(Sector* sector)
- : sound(0), level(0)
+ScriptInterpreter::ScriptInterpreter(const std::string& new_working_directory)
+ : working_directory(new_working_directory), sound(0), level(0)
{
v = sq_open(1024);
if(v == 0)
// register supertux API
register_functions(v, supertux_global_functions);
- register_classes(v, supertux_classes);
+ register_classes(v, supertux_classes);
+ // expose some "global" objects
+ sound = new Scripting::Sound();
+ expose_object(sound, "Sound", "Sound");
+
+ level = new Scripting::Level();
+ expose_object(level, "Level", "Level");
+}
+
+void
+ScriptInterpreter::register_sector(Sector* sector)
+{
// expose ScriptedObjects to the script
for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
i != sector->gameobjects.end(); ++i) {
expose_object(scripted_object, scripted_object->get_name(),
"ScriptedObject");
}
- // expose some "global" objects
- sound = new Scripting::Sound();
- expose_object(sound, "Sound", "Sound");
-
- level = new Scripting::Level();
- expose_object(level, "Level", "Level");
TextObject* text_object = new TextObject();
sector->add_object(text_object);
class ScriptInterpreter : public GameObject
{
public:
- ScriptInterpreter(Sector* sector);
+ ScriptInterpreter(const std::string& working_dir);
~ScriptInterpreter();
+ void register_sector(Sector* sector);
+
void draw(DrawingContext& );
void update(float );
return _current;
}
+ const std::string& get_working_directory() const
+ {
+ return working_directory;
+ }
+
private:
HSQUIRRELVM v;
static ScriptInterpreter* _current;
Timer wakeup_timer;
+ /// this directory is used as base for all filenames used in scripts
+ std::string working_directory;
Scripting::Sound* sound;
Scripting::Level* level;
};
return 0;
}
+static int display_text_file_wrapper(HSQUIRRELVM v)
+{
+ const char* arg0;
+ sq_getstring(v, 2, &arg0);
+
+ Scripting::display_text_file(arg0);
+
+ return 0;
+}
+
static int set_wakeup_time_wrapper(HSQUIRRELVM v)
{
float arg0;
}
WrappedFunction supertux_global_functions[] = {
+ { "display_text_file", &display_text_file_wrapper },
{ "set_wakeup_time", &set_wakeup_time_wrapper },
{ "translate", &translate_wrapper },
{ 0, 0 }
// Run init script
if(init_script != "") {
try {
- ScriptInterpreter* interpreter = new ScriptInterpreter(this);
+ ScriptInterpreter* interpreter
+ = new ScriptInterpreter(GameSession::current()->get_working_directory());
+ interpreter->register_sector(this);
std::string sourcename = std::string("Sector(") + name + ") - init";
std::istringstream in(init_script);
interpreter->load_script(in, sourcename);
{\r
try\r
{\r
- ScriptInterpreter* interpreter = new ScriptInterpreter(Sector::current());\r
+ ScriptInterpreter* interpreter \r
+ = new ScriptInterpreter(GameSession::current()->get_working_directory());\r
+ interpreter->register_sector(Sector::current());\r
std::istringstream in(script);\r
interpreter->load_script(in, "trigger-script");\r
interpreter->start_script();\r
#include "control/joystickkeyboardcontroller.h"
#include "object/background.h"
#include "object/tilemap.h"
+#include "scripting/script_interpreter.h"
Menu* worldmap_menu = 0;
const lisp::Lisp* props = iter.lisp();
props->get("name", name);
props->get("music", music);
- props->get("intro-filename", intro_filename);
+ } else if(iter.item() == "intro-script") {
+ iter.value()->get(intro_script);
} else if(iter.item() == "spawnpoint") {
SpawnPoint* sp = new SpawnPoint(iter.lisp());
spawn_points.push_back(sp);
level.south = true;
level.west = true;
- level_lisp->get("extro-filename", level.extro_filename);
+ level_lisp->get("extro-script", level.extro_script);
level_lisp->get("next-worldmap", level.next_worldmap);
level.quit_worldmap = false;
/* The porpose of the next checking is that if the player lost
the level (in case there is one), don't show anything */
if(level_finished) {
- if (!level->extro_filename.empty()) {
- // Display a text file
- std::string filename = levels_path + level->extro_filename;
- display_text_file(filename);
+ if (level->extro_script != "") {
+ ScriptInterpreter* interpreter = new ScriptInterpreter(levels_path);
+ std::istringstream in(level->extro_script);
+ interpreter->load_script(in, "level-extro-script");
+ interpreter->start_script();
+ add_object(interpreter);
}
if (!level->next_worldmap.empty())
song = sound_manager->load_music(datadir + "/music/" + music);
sound_manager->play_music(song);
- if(!intro_displayed && intro_filename != "") {
- std::string filename = levels_path + intro_filename;
- display_text_file(filename);
+ if(!intro_displayed && intro_script != "") {
+ ScriptInterpreter* interpreter = new ScriptInterpreter(levels_path);
+ std::istringstream in(intro_script);
+ interpreter->load_script(in, "worldmap-intro-script");
+ interpreter->start_script();
+ add_object(interpreter);
+
intro_displayed = true;
}
/** Check if this level should be vertically flipped */
bool vertical_flip;
- /** Filename of the extro text to show once the level is
- successfully completed */
- std::string extro_filename;
+ /** Script that is run when the level is successfully finished */
+ std::string extro_script;
/** Go to this world */
std::string next_worldmap;
Vector offset;
std::string savegame_file;
- std::string intro_filename;
+ std::string intro_script;
bool intro_displayed;
void get_level_title(Level& level);