refactored some supertux mainloops
[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 << "' ("
40       << file << ")");
41     return;
42   }
43
44   sq_push(v, -2);
45   if(sq_call(v, 1, false) < 0) {
46     msg_warning("Couldn't execute script '" << filename << "' ("
47       << file << ")");
48     return;
49   }
50 }
51
52 void add_key(int new_key)
53 {
54   player_status->set_keys(new_key);
55 }
56
57 }
58