Unified Messaging Subsystem
[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
13 namespace Scripting
14 {
15
16 void wait(float seconds)
17 {
18   ScriptInterpreter::current()->set_wakeup_time(seconds);
19 }
20
21 std::string translate(const std::string& text)
22 {
23   return dictionary_manager.get_dictionary().translate(text);
24 }
25
26 void display_text_file(const std::string& filename)
27 {
28   std::string file 
29     = ScriptInterpreter::current()->get_working_directory() + filename;
30   ::display_text_file(file);
31 }
32
33 void import(HSQUIRRELVM v, const std::string& filename)
34 {
35   std::string file 
36     = ScriptInterpreter::current()->get_working_directory() + filename;
37   if(sqstd_loadfile(v, file.c_str(), true) < 0) {
38     msg_warning("couldn't load script '" << filename << "' ("
39       << file << ")");
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 << "' ("
46       << file << ")");
47     return;
48   }
49 }
50
51 void add_key(int new_key)
52 {
53   player_status->set_keys(new_key);
54 }
55
56 }
57