Messaging subsystem rewrite, step I
[supertux.git] / src / scripting / functions.cpp
1 #include <stdio.h>
2 #include <string>
3 #include <squirrel.h>
4 #include <sqstdio.h>
5 #include "textscroller.hpp"
6 #include "functions.hpp"
7 #include "script_interpreter.hpp"
8 #include "tinygettext/tinygettext.hpp"
9 #include "resources.hpp"
10 #include "gettext.hpp"
11 #include "msg.hpp"
12 #include "mainloop.hpp"
13
14 namespace Scripting
15 {
16
17 void wait(float seconds)
18 {
19   ScriptInterpreter::current()->set_wakeup_time(seconds);
20 }
21
22 std::string translate(const std::string& text)
23 {
24   return dictionary_manager.get_dictionary().translate(text);
25 }
26
27 void display_text_file(const std::string& filename)
28 {
29   std::string file 
30       = ScriptInterpreter::current()->get_working_directory() + filename;
31   main_loop->push_screen(new TextScroller(file));
32 }
33
34 void import(HSQUIRRELVM v, const std::string& filename)
35 {
36   std::string file 
37     = ScriptInterpreter::current()->get_working_directory() + filename;
38   if(sqstd_loadfile(v, file.c_str(), true) < 0) {
39     msg_warning << "couldn't load script '" << filename << "' (" << file << ")" << std::endl;
40     return;
41   }
42
43   sq_push(v, -2);
44   if(sq_call(v, 1, false) < 0) {
45     msg_warning << "Couldn't execute script '" << filename << "' (" << file << ")" << std::endl;
46     return;
47   }
48 }
49
50 void add_key(int new_key)
51 {
52   player_status->set_keys(new_key);
53 }
54
55 }
56