10 #include <game_manager/lua_backend/lua_backend.hpp>
13 #ifndef TESTING_LUA_BACKEND
15 #include <game_manager/game_manager.hpp>
17 #elif defined(TESTING_LUA_BACKEND)
18 #include <test/game_manager/lua_backend/game_manager_mock.hpp>
21 #include <ST_util/string_util.hpp>
22 #include <game_manager/level/light.hpp>
24 #include <SDL_timer.h>
31 static bool singleton_initialized =
false;
42 if (singleton_initialized) {
43 throw std::runtime_error(
"The lua backend cannot be initialized more than once!");
45 singleton_initialized =
true;
49 gLua_backendLua =
this;
50 gGame_managerLua = game_mngr;
51 gMessage_busLua = msg_bus;
52 gMessage_bus = msg_bus;
57 fprintf(stderr,
"ERROR: Could not initialize a Lua context");
64 lua_register(L,
"logLua", logLua);
65 lua_register(L,
"showCollisions", showCollisionsLua);
66 lua_register(L,
"showFps", showFpsLua);
67 lua_register(L,
"showMetrics", showMetricsLua);
68 lua_register(L,
"consoleClear", consoleClearLua);
71 lua_register(L,
"saveGame", saveGameLua);
72 lua_register(L,
"setFullscreenLua", setFullscreenLua);
73 lua_register(L,
"getFullscreenStatus", getFullscreenStatusLua);
74 lua_register(L,
"hashString", hashStringLua);
75 lua_register(L,
"delay", delayLua);
76 lua_register(L,
"use", useLua);
77 lua_register(L,
"setVsyncLua", setVsyncLua);
78 lua_register(L,
"getVsyncState", getVsyncStateLua);
79 lua_register(L,
"setBrightness", setBrightnessLua);
80 lua_register(L,
"startLevelLua", startLevelLua);
81 lua_register(L,
"reloadLevelLua", reloadLevelLua);
82 lua_register(L,
"showMouseCursor", showMouseCursorLua);
83 lua_register(L,
"hideMouseCursor", hideMouseCursorLua);
84 lua_register(L,
"endGame", endGameLua);
85 lua_register(L,
"centerCamera", centerCameraLua);
86 lua_register(L,
"centreCamera", centerCameraLua);
87 lua_register(L,
"setLevelSize", setLevelSizeLua);
88 lua_register(L,
"setLevelFloor", setLevelFloorLua);
89 lua_register(L,
"loadLevel", load_levelLua);
90 lua_register(L,
"unloadLevel", unload_levelLua);
91 lua_register(L,
"loadAsset", loadAssetLua);
92 lua_register(L,
"unloadAsset", unloadAssetLua);
93 lua_register(L,
"setInternalResolution", setInternalResolutionLua);
94 lua_register(L,
"getInternalResolution", getInternalResolutionLua);
95 lua_register(L,
"setWindowResolution", setWindowResolutionLua);
96 lua_register(L,
"getWindowResolution", getWindowResolutionLua);
99 lua_register(L,
"setGravity", setGravityLua);
100 lua_register(L,
"getGravity", getGravityLua);
101 lua_register(L,
"pausePhysics", pausePhysicsLua);
102 lua_register(L,
"unpausePhysics", unpausePhysicsLua);
105 lua_register(L,
"setBackground", setBackgroundLua);
106 lua_register(L,
"setBackgroundColor", setBackgroundColorLua);
107 lua_register(L,
"setOverlay", setOverlayLua);
110 lua_register(L,
"getMouseX", getMouseXLua);
111 lua_register(L,
"getMouseY", getMouseYLua);
112 lua_register(L,
"keyHeld", keyHeldLua);
113 lua_register(L,
"keyPressed", keyPressedLua);
114 lua_register(L,
"keyReleased", keyReleasedLua);
115 lua_register(L,
"leftTrigger", leftTriggerLua);
116 lua_register(L,
"rightTrigger", rightTriggerLua);
117 lua_register(L,
"rightStickHorizontal", rightStickHorizontalLua);
118 lua_register(L,
"rightStickVertical", rightStickVerticalLua);
119 lua_register(L,
"leftStickHorizontal", leftStickHorizontalLua);
120 lua_register(L,
"leftStickVertical", leftStickVerticalLua);
121 lua_register(L,
"controllerRumble", controllerRumbleLua);
122 lua_register(L,
"setLeftStickHorizontalThreshold", setLeftStickHorizontalThresholdLua);
123 lua_register(L,
"setLeftStickVerticalThreshold", setLeftStickVerticalThresholdLua);
124 lua_register(L,
"setRightStickHorizontalThreshold", setRightStickHorizontalThresholdLua);
125 lua_register(L,
"setRightStickVerticalThreshold", setRightStickVerticalThresholdLua);
126 lua_register(L,
"setLeftTriggerThreshold", setLeftTriggerThresholdLua);
127 lua_register(L,
"setRightTriggerThreshold", setRightTriggerThresholdLua);
130 lua_register(L,
"playSound", playSoundLua);
131 lua_register(L,
"playMusic", playMusicLua);
132 lua_register(L,
"stopMusic", stopMusicLua);
133 lua_register(L,
"pauseMusic", pauseMusicLua);
134 lua_register(L,
"setAudioEnabledLua", setAudioEnabledLua);
135 lua_register(L,
"isAudioEnabled", isAudioEnabledLua);
136 lua_register(L,
"getSoundsVolume", getSoundsVolumeLua);
137 lua_register(L,
"getMusicVolume", getMusicVolumeLua);
138 lua_register(L,
"setSoundsVolume", setSoundsVolumeLua);
139 lua_register(L,
"setMusicVolume", setMusicVolumeLua);
140 lua_register(L,
"stopAllSounds", stopAllSoundsLua);
143 lua_register(L,
"setDarkness", setDarknessLua);
144 lua_register(L,
"enableLighting", enableLightingLua);
145 lua_register(L,
"createLight", createLightLua);
146 lua_register(L,
"setLightOriginX", setLightOriginXLua);
147 lua_register(L,
"getLightOriginX", getLightOriginXLua);
148 lua_register(L,
"setLightOriginY", setLightOriginYLua);
149 lua_register(L,
"getLightOriginY", getLightOriginYLua);
150 lua_register(L,
"setLightIntensity", setLightIntensityLua);
151 lua_register(L,
"getLightIntensity", getLightIntensityLua);
152 lua_register(L,
"setLightBrightness", setLightBrightnessLua);
153 lua_register(L,
"getLightBrightness", getLightBrightnessLua);
154 lua_register(L,
"setLightRadius", setLightRadiusLua);
155 lua_register(L,
"getLightRadius", getLightRadiusLua);
156 lua_register(L,
"setLightStatic", setLightStaticLua);
157 lua_register(L,
"isLightStatic", isLightStaticLua);
160 lua_register(L,
"createTextObject", createTextObjectLua);
161 lua_register(L,
"setTextObjectColor", setTextObjectColorLua);
162 lua_register(L,
"setTextObjectText", setTextObjectTextLua);
163 lua_register(L,
"setTextObjectFont", setTextObjectFontLua);
164 lua_register(L,
"setTextObjectX", setTextObjectXLua);
165 lua_register(L,
"setTextObjectY", setTextObjectYLua);
166 lua_register(L,
"setTextObjectVisible", setTextObjectVisibleLua);
171 lua_register(L,
"createEntity", createEntityLua);
172 lua_register(L,
"setEntityActive", setEntityActiveLua);
173 lua_register(L,
"setEntityX", setEntityXLua);
174 lua_register(L,
"setEntityY", setEntityYLua);
175 lua_register(L,
"getEntityX", getEntityXLua);
176 lua_register(L,
"getEntityY", getEntityYLua);
177 lua_register(L,
"setEntityStatic", setEntityStaticLua);
178 lua_register(L,
"setEntityVelocityX", setEntityVelocityXLua);
179 lua_register(L,
"setEntityVelocityY", setEntityVelocityYLua);
180 lua_register(L,
"getEntityVelocityX", getEntityVelocityXLua);
181 lua_register(L,
"getEntityVelocityY", getEntityVelocityYLua);
184 lua_register(L,
"setEntityTexture", setEntityTextureLua);
185 lua_register(L,
"getEntityTexW", getEntityTexWLua);
186 lua_register(L,
"getEntityTexH", getEntityTexHLua);
187 lua_register(L,
"setEntityTexW", setEntityTexWLua);
188 lua_register(L,
"setEntityTexH", setEntityTexHLua);
189 lua_register(L,
"setEntityVisible", setEntityVisibleLua);
190 lua_register(L,
"setEntityTextureScale", setEntityTextureScaleLua);
193 lua_register(L,
"setEntityCollisionBox", setEntityCollisionBoxLua);
194 lua_register(L,
"entityCollides", entityCollidesLua);
195 lua_register(L,
"setEntityAffectedByPhysics", setEntityAffectedByPhysicsLua);
196 lua_register(L,
"getEntityColX", getEntityColXLua);
197 lua_register(L,
"getEntityColY", getEntityColYLua);
198 lua_register(L,
"getEntityColXOffset", getEntityColXOffsetLua);
199 lua_register(L,
"getEntityColYOffset", getEntityColYOffsetLua);
202 lua_register(L,
"setEntityAnimation", setEntityAnimationLua);
203 lua_register(L,
"setEntityAnimationNum", setEntityAnimationNumLua);
204 lua_register(L,
"setEntitySpriteNum", setEntitySpriteNumLua);
207 lua_register(L,
"mouseOverLua", mouseOverLua);
208 lua_register(L,
"mouseOverTextureLua", mouseOverTextureLua);
210 luaL_dofile(L,
"lua/global_properties.lua");
211 luaL_dofile(L,
"lua/general.lua");
212 luaL_dofile(L,
"lua/debug.lua");
213 luaL_dofile(L,
"lua/objects/entity.lua");
214 luaL_dofile(L,
"lua/objects/text.lua");
215 luaL_dofile(L,
"lua/objects/light.lua");
216 luaL_dofile(L,
"lua/ui/button.lua");
217 luaL_dofile(L,
"lua/ui/label.lua");
218 luaL_dofile(L,
"lua/ui/checkbox.lua");
221 luaL_dofile(L,
"lua/main.lua");
232 std::string temp = hash_file(file);
233 int status = luaL_loadbuffer(L, temp.c_str(), temp.size(), file.c_str());
234 if (status == LUA_ERRSYNTAX || status == LUA_ERRFILE || lua_pcall(L, 0, 0, 0)) {
235 fprintf(stderr,
"cannot compile script\n");
249 std::string temp = hash_file(file);
250 int status = luaL_loadbuffer(L, temp.c_str(), temp.size(), file.c_str());
251 if (status == LUA_ERRSYNTAX || status == LUA_ERRFILE) {
252 fprintf(stderr,
"cannot compile script\n");
266 std::string temp = hash_string(script);
267 if (luaL_dostring(L, temp.c_str())) {
268 gMessage_bus->
send_msg(
new message(LOG_ERROR, make_data<std::string>(
"Cannot run script")));
280 lua_setglobal(L, arg.c_str());
288 lua_getglobal(L, arg.c_str());
289 lua_pcall(L, 0, 0, 0);
297 singleton_initialized =
false;
306 std::string lua_backend::hash_file(
const std::string &path) {
308 file.open(path.c_str());
310 if (file.is_open()) {
312 while (!file.eof()) {
315 temp.erase(temp.begin(), std::find_if(temp.begin(), temp.end(),
316 std::bind(std::not_equal_to<>(),
' ', std::placeholders::_1)));
317 while (temp.find(
"playSound(\"") != std::string::npos) {
318 std::string to_find =
"playSound(\"";
319 std::string temp_buf;
320 for (uint64_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
321 temp_buf.push_back((temp.at(i)));
323 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
324 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
325 ST::replace_string(temp, temp_buf_2, string_hash);
327 while (temp.find(
"playMusic(\"") != std::string::npos) {
328 std::string to_find =
"playMusic(\"";
329 std::string temp_buf;
330 for (uint64_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
331 temp_buf.push_back((temp.at(i)));
333 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
334 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
335 ST::replace_string(temp, temp_buf_2, string_hash);
337 while (temp.find(
"keyHeld(\"") != std::string::npos) {
338 std::string to_find =
"keyHeld(\"";
339 std::string temp_buf;
340 for (uint64_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
341 temp_buf.push_back((temp.at(i)));
343 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
344 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
345 ST::replace_string(temp, temp_buf_2, string_hash);
347 while (temp.find(
"keyPressed(\"") != std::string::npos) {
348 std::string to_find =
"keyPressed(\"";
349 std::string temp_buf;
350 for (uint64_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
351 temp_buf.push_back((temp.at(i)));
353 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
354 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
355 ST::replace_string(temp, temp_buf_2, string_hash);
357 while (temp.find(
"keyReleased(\"") != std::string::npos) {
358 std::string to_find =
"keyReleased(\"";
359 std::string temp_buf;
360 for (uint64_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
361 temp_buf.push_back((temp.at(i)));
363 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
364 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
365 ST::replace_string(temp, temp_buf_2, string_hash);
367 while (temp.find(
"setClickKey(\"") != std::string::npos) {
368 std::string to_find =
"setClickKey(\"";
369 std::string temp_buf;
370 for (uint64_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
371 temp_buf.push_back((temp.at(i)));
373 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
374 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
375 ST::replace_string(temp, temp_buf_2, string_hash);
378 while (temp.find(
"----@Key") != std::string::npos) {
379 std::string to_find =
"\"";
380 std::string temp_buf;
381 std::string next_line;
382 getline(file, next_line);
383 for (uint64_t i = next_line.find(to_find) + to_find.size(); next_line.at(i) !=
'\"'; i++) {
384 temp_buf.push_back((next_line.at(i)));
386 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
387 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
388 ST::replace_string(next_line, temp_buf_2, string_hash);
391 while (temp.find(
"----@Audio") != std::string::npos) {
392 std::string to_find =
"\"";
393 std::string temp_buf;
394 std::string next_line;
395 getline(file, next_line);
396 for (uint64_t i = next_line.find(to_find) + to_find.size(); next_line.at(i) !=
'\"'; i++) {
397 temp_buf.push_back((next_line.at(i)));
399 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
400 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
401 ST::replace_string(next_line, temp_buf_2, string_hash);
404 result += temp +
"\n";
410 gMessage_bus->
send_msg(
new message(LOG_ERROR, make_data<std::string>(
"File " + path +
" not found")));
421 std::string lua_backend::hash_string(
const std::string &arg) {
423 std::string temp = arg;
425 temp.erase(temp.begin(), std::find_if(temp.begin(), temp.end(),
426 std::bind(std::not_equal_to<>(),
' ', std::placeholders::_1)));
427 while (temp.find(
"playSound(\"") != std::string::npos) {
428 std::string to_find =
"playSound(\"";
429 std::string temp_buf;
430 for (uint64_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
431 temp_buf.push_back((temp.at(i)));
433 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
434 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
435 ST::replace_string(temp, temp_buf_2, string_hash);
437 while (temp.find(
"playMusic(\"") != std::string::npos) {
438 std::string to_find =
"playMusic(\"";
439 std::string temp_buf;
440 for (
size_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
441 temp_buf.push_back((temp.at(i)));
443 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
444 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
445 ST::replace_string(temp, temp_buf_2, string_hash);
447 while (temp.find(
"keyHeld(\"") != std::string::npos) {
448 std::string to_find =
"keyHeld(\"";
449 std::string temp_buf;
450 for (
size_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
451 temp_buf.push_back((temp.at(i)));
453 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
454 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
455 ST::replace_string(temp, temp_buf_2, string_hash);
457 while (temp.find(
"keyPressed(\"") != std::string::npos) {
458 std::string to_find =
"keyPressed(\"";
459 std::string temp_buf;
460 for (
size_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
461 temp_buf.push_back((temp.at(i)));
463 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
464 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
465 ST::replace_string(temp, temp_buf_2, string_hash);
467 while (temp.find(
"keyReleased(\"") != std::string::npos) {
468 std::string to_find =
"keyReleased(\"";
469 std::string temp_buf;
470 for (
size_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
471 temp_buf.push_back((temp.at(i)));
473 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
474 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
475 ST::replace_string(temp, temp_buf_2, string_hash);
477 while (temp.find(
"setClickKey(\"") != std::string::npos) {
478 std::string to_find =
"setClickKey(\"";
479 std::string temp_buf;
480 for (
size_t i = temp.find(to_find) + to_find.size(); temp.at(i) !=
'\"'; i++) {
481 temp_buf.push_back((temp.at(i)));
483 std::string string_hash = std::to_string(ST::hash_string(temp_buf));
484 std::string temp_buf_2 =
"\"" + temp_buf +
"\"";
485 ST::replace_string(temp, temp_buf_2, string_hash);
497 extern "C" int saveGameLua(lua_State *L) {
498 auto arg = std::string(lua_tostring(L, 1));
499 gGame_managerLua->save_state(arg);
509 extern "C" int setDarknessLua(lua_State *L) {
510 auto arg =
static_cast<uint8_t
>(lua_tointeger(L, 1));
515 extern "C" int enableLightingLua(lua_State *L) {
516 auto arg =
static_cast<bool>(lua_toboolean(L, 1));
527 extern "C" int createLightLua(lua_State *L) {
528 auto origin_x =
static_cast<int32_t
>(lua_tointeger(L, 1));
529 auto origin_y =
static_cast<int32_t
>(lua_tointeger(L, 2));
530 auto radius =
static_cast<uint16_t
>(lua_tointeger(L, 3));
531 auto intensity =
static_cast<uint16_t
>(lua_tointeger(L, 4));
532 auto brightness =
static_cast<uint16_t
>(lua_tointeger(L, 5));
533 gGame_managerLua->
get_level()->lights.emplace_back(origin_x, origin_y, radius, intensity, brightness);
543 extern "C" int setLightOriginXLua(lua_State *L) {
544 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
545 auto origin_x =
static_cast<int32_t
>(lua_tointeger(L, 2));
546 gGame_managerLua->
get_level()->lights[id].origin_x = origin_x;
556 extern "C" int getLightOriginXLua(lua_State *L) {
557 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
558 lua_pushinteger(L, gGame_managerLua->
get_level()->lights[
id].origin_x);
568 extern "C" int setLightOriginYLua(lua_State *L) {
569 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
570 auto origin_y =
static_cast<int32_t
>(lua_tointeger(L, 2));
571 gGame_managerLua->
get_level()->lights[id].origin_y = origin_y;
581 extern "C" int getLightOriginYLua(lua_State *L) {
582 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
583 lua_pushinteger(L, gGame_managerLua->
get_level()->lights[
id].origin_y);
593 extern "C" int getLightRadiusLua(lua_State *L) {
594 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
595 lua_pushinteger(L, gGame_managerLua->
get_level()->lights[
id].radius);
605 extern "C" int setLightRadiusLua(lua_State *L) {
606 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
607 auto radius =
static_cast<uint16_t
>(lua_tointeger(L, 2));
608 gGame_managerLua->
get_level()->lights[id].radius = radius;
618 extern "C" int getLightIntensityLua(lua_State *L) {
619 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
620 lua_pushinteger(L, gGame_managerLua->
get_level()->lights[
id].intensity);
630 extern "C" int setLightIntensityLua(lua_State *L) {
631 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
632 auto intensity =
static_cast<uint16_t
>(lua_tointeger(L, 2));
633 gGame_managerLua->
get_level()->lights[id].intensity = intensity;
643 extern "C" int getLightBrightnessLua(lua_State *L) {
644 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
645 lua_pushinteger(L, gGame_managerLua->
get_level()->lights[
id].brightness);
655 extern "C" int setLightBrightnessLua(lua_State *L) {
656 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
657 auto brightness =
static_cast<uint16_t
>(lua_tointeger(L, 2));
658 gGame_managerLua->
get_level()->lights[id].brightness = brightness;
668 extern "C" int setLightStaticLua(lua_State *L) {
669 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
670 auto is_static =
static_cast<bool>(lua_toboolean(L, 2));
671 gGame_managerLua->
get_level()->lights[id].is_static = is_static;
681 extern "C" int isLightStaticLua(lua_State *L) {
682 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
683 lua_pushboolean(L, gGame_managerLua->
get_level()->lights[
id].is_static);
693 extern "C" int hashStringLua(lua_State *L) {
694 auto str =
static_cast<std::string
>(lua_tostring(L, 1));
695 lua_pushinteger(L, (lua_Integer) ST::hash_string(str));
705 extern "C" int setFullscreenLua(lua_State *L) {
706 auto arg =
static_cast<bool>(lua_toboolean(L, 1));
717 extern "C" int getFullscreenStatusLua(lua_State *L) {
718 lua_pushboolean(L, gGame_managerLua->fullscreen_status);
731 extern "C" int createTextObjectLua(lua_State *L) {
732 auto x =
static_cast<int>(lua_tointeger(L, 1));
733 auto y =
static_cast<int>(lua_tointeger(L, 2));
734 auto text_string =
static_cast<std::string
>(lua_tostring(L, 3));
735 auto font =
static_cast<std::string
>(lua_tostring(L, 4));
736 auto size =
static_cast<uint8_t
>(lua_tointeger(L, 5));
737 SDL_Color temp_color = {255, 255, 255, 255};
738 gGame_managerLua->
get_level()->text_objects.emplace_back(x, y, temp_color, text_string,
739 ST::hash_string(font +
" " + std::to_string(size)));
749 extern "C" int setTextObjectColorLua(lua_State *L) {
750 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
751 auto r =
static_cast<uint8_t
>(lua_tointeger(L, 2));
752 auto g =
static_cast<uint8_t
>(lua_tointeger(L, 3));
753 auto b =
static_cast<uint8_t
>(lua_tointeger(L, 4));
754 auto a =
static_cast<uint8_t
>(lua_tointeger(L, 5));
755 gGame_managerLua->
get_level()->text_objects[id].color = {r, g, b, a};
765 extern "C" int setTextObjectTextLua(lua_State *L) {
766 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
767 auto text =
static_cast<std::string
>(lua_tostring(L, 2));
768 gGame_managerLua->
get_level()->text_objects[id].text_string = text;
778 extern "C" int setTextObjectFontLua(lua_State *L) {
779 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
780 auto font =
static_cast<std::string
>(lua_tostring(L, 2));
781 gGame_managerLua->
get_level()->text_objects[id].font = ST::hash_string(font);
791 extern "C" int setTextObjectXLua(lua_State *L) {
792 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
793 auto x =
static_cast<int>(lua_tointeger(L, 2));
794 gGame_managerLua->
get_level()->text_objects[id].x = x;
804 extern "C" int setTextObjectYLua(lua_State *L) {
805 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
806 auto y =
static_cast<int>(lua_tointeger(L, 2));
807 gGame_managerLua->
get_level()->text_objects[id].y = y;
817 extern "C" int setTextObjectVisibleLua(lua_State *L) {
818 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
819 auto arg =
static_cast<bool>(lua_toboolean(L, 2));
820 gGame_managerLua->
get_level()->text_objects[id].is_visible = arg;
833 extern "C" int createEntityLua(lua_State *) {
834 gGame_managerLua->
get_level()->entities.emplace_back();
844 extern "C" int setEntityXLua(lua_State *L) {
845 auto id =
static_cast<unsigned long>(lua_tointeger(L, 1));
846 auto x =
static_cast<int>(lua_tointeger(L, 2));
847 gGame_managerLua->
get_level()->entities[id].x = x;
857 extern "C" int setEntityActiveLua(lua_State *L) {
858 auto id =
static_cast<unsigned long>(lua_tointeger(L, 1));
859 auto arg =
static_cast<bool>(lua_toboolean(L, 2));
860 gGame_managerLua->
get_level()->entities[id].set_active(arg);
870 extern "C" int setEntityYLua(lua_State *L) {
871 auto id =
static_cast<unsigned long>(lua_tointeger(L, 1));
872 auto y =
static_cast<int>(lua_tointeger(L, 2));
873 gGame_managerLua->
get_level()->entities[id].y = y;
883 extern "C" int setEntityVelocityXLua(lua_State *L) {
884 auto id =
static_cast<unsigned long>(lua_tointeger(L, 1));
885 auto arg =
static_cast<int8_t
>(lua_tointeger(L, 2));
886 gGame_managerLua->
get_level()->entities[id].velocity_x = arg;
896 extern "C" int setEntityVelocityYLua(lua_State *L) {
897 auto id =
static_cast<unsigned long>(lua_tointeger(L, 1));
898 auto arg =
static_cast<int8_t
>(lua_tointeger(L, 2));
899 gGame_managerLua->
get_level()->entities[id].velocity_y = arg;
909 extern "C" int getEntityVelocityXLua(lua_State *L) {
910 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
911 lua_pushnumber(L, gGame_managerLua->
get_level()->entities[
id].velocity_x);
921 extern "C" int getEntityVelocityYLua(lua_State *L) {
922 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
923 lua_pushnumber(L, gGame_managerLua->
get_level()->entities[
id].velocity_y);
933 extern "C" int setEntityStaticLua(lua_State *L) {
934 auto id =
static_cast<unsigned long>(lua_tointeger(L, 1));
935 auto arg =
static_cast<bool>(lua_toboolean(L, 2));
936 gGame_managerLua->
get_level()->entities[id].set_static(arg);
946 extern "C" int getEntityXLua(lua_State *L) {
947 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
948 lua_pushnumber(L, gGame_managerLua->
get_level()->entities[
id].x);
958 extern "C" int getEntityYLua(lua_State *L) {
959 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
960 lua_pushnumber(L, gGame_managerLua->
get_level()->entities[
id].y);
972 extern "C" int getEntityTexWLua(lua_State *L) {
973 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
974 lua_pushnumber(L, gGame_managerLua->
get_level()->entities[
id].tex_w);
984 extern "C" int getEntityTexHLua(lua_State *L) {
985 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
986 lua_pushnumber(L, gGame_managerLua->
get_level()->entities[
id].tex_h);
996 extern "C" int setEntityTexWLua(lua_State *L) {
997 auto id =
static_cast<unsigned long>(lua_tonumber(L, 1));
998 auto tex_w =
static_cast<uint16_t
>(lua_tonumber(L, 2));
999 gGame_managerLua->
get_level()->entities[id].tex_w = tex_w;
1009 extern "C" int setEntityTexHLua(lua_State *L) {
1010 auto id =
static_cast<uint64_t
>(lua_tonumber(L, 1));
1011 auto tex_h =
static_cast<uint16_t
>(lua_tonumber(L, 2));
1012 gGame_managerLua->
get_level()->entities[id].tex_h = tex_h;
1022 extern "C" int setEntityTextureScaleLua(lua_State *L) {
1023 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1024 auto scale_x =
static_cast<float>(lua_tonumber(L, 2));
1025 auto scale_y =
static_cast<float>(lua_tonumber(L, 3));
1026 auto ent = &gGame_managerLua->
get_level()->entities[id];
1027 ent->tex_scale_x = scale_x;
1028 ent->tex_scale_y = scale_y;
1038 extern "C" int setEntityVisibleLua(lua_State *L) {
1039 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1040 auto arg =
static_cast<bool>(lua_toboolean(L, 2));
1041 gGame_managerLua->
get_level()->entities[id].set_visible(arg);
1051 extern "C" int setEntityTextureLua(lua_State *L) {
1052 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1053 std::string arg =
static_cast<std::string
>(lua_tostring(L, 2));
1054 gGame_managerLua->
get_level()->entities[id].texture = ST::hash_string(arg);
1060 extern "C" int mouseOverTextureLua(lua_State *L) {
1061 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1062 int32_t mouse_x = gGame_managerLua->
get_mouse_x();
1063 int32_t mouse_y = gGame_managerLua->
get_mouse_y();
1065 int32_t object_x =
object->x;
1066 int32_t object_y =
object->y;
1067 lua_pushboolean(L, mouse_x < object->tex_w + object_x && mouse_x > object_x && mouse_y > object_y + object->tex_h &&
1068 mouse_y < object_y);
1072 extern "C" int mouseOverLua(lua_State *L) {
1073 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1074 int32_t mouse_x = gGame_managerLua->
get_mouse_x();
1075 int32_t mouse_y = gGame_managerLua->
get_mouse_y();
1077 int32_t object_x =
object->x;
1078 int32_t object_y =
object->y;
1079 int32_t col_x_offset =
object->get_col_x_offset();
1080 int32_t col_y_offset =
object->get_col_y_offset();
1081 lua_pushboolean(L, mouse_x < object->get_col_x() + object_x + col_x_offset && mouse_x > object_x + col_x_offset
1082 && mouse_y > object_y + col_y_offset + object->
get_col_y() && mouse_y < object_y + col_y_offset);
1094 extern "C" int setEntityAffectedByPhysicsLua(lua_State *L) {
1095 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1096 auto arg =
static_cast<bool>(lua_toboolean(L, 2));
1097 if (gGame_managerLua->
get_level()->entities[id].is_affected_by_physics()) {
1099 --gGame_managerLua->
get_level()->physics_objects_count;
1102 ++gGame_managerLua->
get_level()->physics_objects_count;
1105 gGame_managerLua->
get_level()->entities[id].set_affected_by_physics(arg);
1115 extern "C" int entityCollidesLua(lua_State *L) {
1116 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1117 auto id2 =
static_cast<uint64_t
>(lua_tointeger(L, 2));
1119 lua_pushboolean(L, temp->entities[
id].is_active() && temp->entities[
id].collides(temp->entities[id2]));
1129 extern "C" int setEntityCollisionBoxLua(lua_State *L) {
1130 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1131 auto offset_x =
static_cast<int16_t
>(lua_tonumber(L, 2));
1132 auto offset_y =
static_cast<int16_t
>(lua_tonumber(L, 3));
1133 auto x =
static_cast<int16_t
>(lua_tonumber(L, 4));
1134 auto y =
static_cast<int16_t
>(lua_tonumber(L, 5));
1135 gGame_managerLua->
get_level()->entities[id].set_collision_box(offset_x, offset_y, x, y);
1145 extern "C" int getEntityColXLua(lua_State *L) {
1146 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1147 lua_pushnumber(L, gGame_managerLua->
get_level()->entities[
id].get_col_x());
1157 extern "C" int getEntityColYLua(lua_State *L) {
1158 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1159 lua_pushnumber(L, gGame_managerLua->
get_level()->entities[
id].get_col_y());
1169 extern "C" int getEntityColXOffsetLua(lua_State *L) {
1170 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1171 lua_pushnumber(L, gGame_managerLua->
get_level()->entities[
id].get_col_x_offset());
1181 extern "C" int getEntityColYOffsetLua(lua_State *L) {
1182 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1183 lua_pushnumber(L, gGame_managerLua->
get_level()->entities[
id].get_col_y_offset());
1192 extern "C" int pausePhysicsLua(lua_State *) {
1202 extern "C" int unpausePhysicsLua(lua_State *) {
1215 extern "C" int setEntityAnimationLua(lua_State *L) {
1216 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1217 auto arg =
static_cast<uint8_t
>(lua_tointeger(L, 2));
1218 gGame_managerLua->
get_level()->entities[id].animation = arg;
1228 extern "C" int setEntityAnimationNumLua(lua_State *L) {
1229 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1230 auto arg =
static_cast<uint8_t
>(lua_tointeger(L, 2));
1231 gGame_managerLua->
get_level()->entities[id].animation_num = arg;
1241 extern "C" int setEntitySpriteNumLua(lua_State *L) {
1242 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1243 auto arg =
static_cast<uint8_t
>(lua_tointeger(L, 2));
1244 gGame_managerLua->
get_level()->entities[id].sprite_num = arg;
1257 extern "C" int setGravityLua(lua_State *L) {
1258 auto arg =
static_cast<int8_t
>(lua_tointeger(L, 1));
1259 gGame_managerLua->gravity = arg;
1270 extern "C" int getGravityLua(lua_State *L) {
1271 lua_pushinteger(L, gGame_managerLua->gravity);
1281 extern "C" int setLevelFloorLua(lua_State *L) {
1282 auto arg =
static_cast<int32_t
>(lua_tointeger(L, 1));
1292 extern "C" int setVsyncLua(lua_State *L) {
1293 auto arg =
static_cast<bool>(lua_toboolean(L, 1));
1304 extern "C" int getVsyncStateLua(lua_State *L) {
1305 lua_pushboolean(L, gGame_managerLua->vsync_flag);
1315 extern "C" int setInternalResolutionLua(lua_State *L) {
1316 auto width =
static_cast<int16_t
>(lua_tointeger(L, 1));
1317 auto height =
static_cast<int16_t
>(lua_tointeger(L, 2));
1318 uint32_t width_height = width | (height << 16U);
1319 gMessage_busLua->
send_msg(
new message(SET_INTERNAL_RESOLUTION, width_height));
1329 extern "C" int getInternalResolutionLua(lua_State *L) {
1342 extern "C" int setWindowResolutionLua(lua_State *L) {
1343 auto width =
static_cast<int16_t
>(lua_tointeger(L, 1));
1344 auto height =
static_cast<int16_t
>(lua_tointeger(L, 2));
1345 uint32_t width_height = width | (height << 16U);
1346 gMessage_busLua->
send_msg(
new message(SET_WINDOW_RESOLUTION, width_height));
1356 extern "C" int getWindowResolutionLua(lua_State *L) {
1368 extern "C" int setBrightnessLua(lua_State *L) {
1369 auto arg =
static_cast<float>(lua_tonumber(L, 1));
1370 gMessage_busLua->
send_msg(
new message(SET_WINDOW_BRIGHTNESS, make_data<>(arg)));
1380 extern "C" int centerCameraLua(lua_State *L) {
1381 auto id =
static_cast<uint64_t
>(lua_tointeger(L, 1));
1392 extern "C" int setLevelSizeLua(lua_State *L) {
1393 auto x =
static_cast<int32_t
>(lua_tointeger(L, 1));
1394 auto y =
static_cast<int32_t
>(lua_tointeger(L, 2));
1395 gGame_managerLua->
get_level()->camera.limitX2 = x;
1396 gGame_managerLua->
get_level()->camera.limitY2 = y;
1405 extern "C" int endGameLua(lua_State *) {
1416 extern "C" int startLevelLua(lua_State *L) {
1417 std::string level =
static_cast<std::string
>(lua_tostring(L, 1));
1418 gMessage_busLua->
send_msg(
new message(START_LEVEL, make_data<std::string>(level)));
1428 extern "C" int reloadLevelLua(lua_State *L) {
1429 std::string level =
static_cast<std::string
>(lua_tostring(L, 1));
1430 gMessage_busLua->
send_msg(
new message(RELOAD_LEVEL, make_data<std::string>(level)));
1440 extern "C" int load_levelLua(lua_State *L) {
1441 std::string arg =
static_cast<std::string
>(lua_tostring(L, 1));
1442 gMessage_busLua->
send_msg(
new message(LOAD_LEVEL, make_data<std::string>(arg)));
1452 extern "C" int unload_levelLua(lua_State *L) {
1453 std::string level =
static_cast<std::string
>(lua_tostring(L, 1));
1454 gMessage_busLua->
send_msg(
new message(UNLOAD_LEVEL, make_data<std::string>(level)));
1464 extern "C" int loadAssetLua(lua_State *L) {
1465 std::string path =
static_cast<std::string
>(lua_tostring(L, 1));
1466 gMessage_busLua->
send_msg(
new message(LOAD_ASSET, make_data<std::string>(path)));
1476 extern "C" int unloadAssetLua(lua_State *L) {
1477 std::string path =
static_cast<std::string
>(lua_tostring(L, 1));
1478 gMessage_busLua->
send_msg(
new message(UNLOAD_ASSET, make_data<std::string>(path)));
1488 extern "C" int delayLua(lua_State *L) {
1489 auto ms =
static_cast<unsigned int>(lua_tointeger(L, 1));
1500 extern "C" int useLua(lua_State *L) {
1501 std::string arg =
static_cast<std::string
>(lua_tostring(L, 1));
1502 std::string temp =
"game/levels/";
1504 temp = temp +
"/" + arg;
1514 extern "C" int showMouseCursorLua(lua_State *) {
1524 extern "C" int hideMouseCursorLua(lua_State *) {
1535 extern "C" int setBackgroundLua(lua_State *L) {
1536 std::string texture =
static_cast<std::string
>(lua_tostring(L, 1));
1537 auto index =
static_cast<uint16_t
>(lua_tointeger(L, 2));
1538 auto parallax_speed =
static_cast<uint8_t
>(lua_tointeger(L, 3));
1539 gGame_managerLua->
get_level()->background[index] = ST::hash_string(texture);
1540 gGame_managerLua->
get_level()->parallax_speed[index] = parallax_speed;
1550 extern "C" int setBackgroundColorLua(lua_State *L) {
1551 auto r =
static_cast<uint8_t
>(lua_tointeger(L, 1));
1552 auto g =
static_cast<uint8_t
>(lua_tointeger(L, 2));
1553 auto b =
static_cast<uint8_t
>(lua_tointeger(L, 3));
1554 auto a =
static_cast<uint8_t
>(lua_tointeger(L, 4));
1556 gGame_managerLua->
get_level()->background_color = {r, g, b, a};
1566 extern "C" int setOverlayLua(lua_State *L) {
1567 std::string arg =
static_cast<std::string
>(lua_tostring(L, 1));
1568 auto spriteNum =
static_cast<uint8_t
>(lua_tointeger(L, 2));
1569 gGame_managerLua->
get_level()->overlay = ST::hash_string(arg);
1570 gGame_managerLua->
get_level()->overlay_sprite_num = spriteNum;
1582 extern "C" int getMouseXLua(lua_State *L) {
1583 lua_pushnumber(L, gGame_managerLua->
get_mouse_x());
1593 extern "C" int getMouseYLua(lua_State *L) {
1594 lua_pushnumber(L, gGame_managerLua->
get_mouse_y());
1599 extern "C" int rightTriggerLua(lua_State *L) {
1604 extern "C" int leftTriggerLua(lua_State *L) {
1609 extern "C" int rightStickHorizontalLua(lua_State *L) {
1614 extern "C" int leftStickHorizontalLua(lua_State *L) {
1619 extern "C" int rightStickVerticalLua(lua_State *L) {
1624 extern "C" int leftStickVerticalLua(lua_State *L) {
1629 extern "C" int controllerRumbleLua(lua_State *L) {
1630 auto strength =
static_cast<float>(lua_tonumber(L, 1));
1631 auto duration =
static_cast<uint16_t
>(lua_tonumber(L, 2));
1632 auto msg =
new message(CONTROLLER_RUMBLE, *
reinterpret_cast<uint32_t *
>(&strength));
1633 msg->base_data1 = duration;
1644 extern "C" int keyHeldLua(lua_State *L) {
1645 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1646 lua_pushboolean(L, gGame_managerLua->
key_held(arg));
1656 extern "C" int keyPressedLua(lua_State *L) {
1657 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1658 lua_pushboolean(L, gGame_managerLua->
key_pressed(arg));
1668 extern "C" int keyReleasedLua(lua_State *L) {
1669 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1670 lua_pushboolean(L, gGame_managerLua->
key_released(arg));
1674 extern "C" int setLeftStickVerticalThresholdLua(lua_State *L) {
1675 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1676 auto msg =
new message(SET_LEFT_JOYSTICK_VERTICAL_THRESHOLD,
static_cast<uint32_t
>(arg));
1681 extern "C" int setLeftStickHorizontalThresholdLua(lua_State *L) {
1682 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1683 auto msg =
new message(SET_LEFT_JOYSTICK_HORIZONTAL_THRESHOLD,
static_cast<uint32_t
>(arg));
1688 extern "C" int setRightStickVerticalThresholdLua(lua_State *L) {
1689 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1690 auto msg =
new message(SET_RIGHT_JOYSTICK_VERTICAL_THRESHOLD,
static_cast<uint32_t
>(arg));
1695 extern "C" int setRightStickHorizontalThresholdLua(lua_State *L) {
1696 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1697 auto msg =
new message(SET_RIGHT_JOYSTICK_HORIZONTAL_THRESHOLD,
static_cast<uint32_t
>(arg));
1702 extern "C" int setRightTriggerThresholdLua(lua_State *L) {
1703 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1704 auto msg =
new message(SET_RIGHT_TRIGGER_THRESHOLD,
static_cast<uint32_t
>(arg));
1709 extern "C" int setLeftTriggerThresholdLua(lua_State *L) {
1710 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1711 auto msg =
new message(SET_LEFT_TRIGGER_THRESHOLD,
static_cast<uint32_t
>(arg));
1724 extern "C" int setAudioEnabledLua(lua_State *L) {
1725 auto arg =
static_cast<bool>(lua_toboolean(L, 1));
1737 extern "C" int playMusicLua(lua_State *L) {
1738 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1739 auto volume =
static_cast<uint8_t
>(lua_tointeger(L, 2));
1740 auto loops =
static_cast<int8_t
>(lua_tointeger(L, 3));
1741 uint32_t result = arg | (volume << 16U) | (static_cast<uint8_t>(loops) << 24U);
1752 extern "C" int playSoundLua(lua_State *L) {
1753 auto arg =
static_cast<uint16_t
>(lua_tointeger(L, 1));
1754 auto volume =
static_cast<uint8_t
>(lua_tointeger(L, 2));
1755 auto loops =
static_cast<int8_t
>(lua_tointeger(L, 3));
1756 uint32_t result = arg | (volume << 16U) | (static_cast<uint8_t>(loops) << 24U);
1766 extern "C" int stopMusicLua(lua_State *) {
1767 auto msg_temp =
new message(STOP_MUSIC);
1768 gMessage_busLua->
send_msg(msg_temp);
1777 extern "C" int stopAllSoundsLua(lua_State *) {
1782 extern "C" int isAudioEnabledLua(lua_State *L) {
1783 lua_pushboolean(L, gGame_managerLua->audio_enabled);
1793 extern "C" int setMusicVolumeLua(lua_State *L) {
1794 auto arg =
static_cast<uint8_t
>(lua_tointeger(L, 1));
1805 extern "C" int setSoundsVolumeLua(lua_State *L) {
1806 auto arg =
static_cast<uint8_t
>(lua_tointeger(L, 1));
1817 extern "C" int getSoundsVolumeLua(lua_State *L) {
1818 lua_pushnumber(L, gGame_managerLua->sounds_volume_level);
1828 extern "C" int getMusicVolumeLua(lua_State *L) {
1829 lua_pushnumber(L, gGame_managerLua->music_volume_level);
1838 extern "C" int pauseMusicLua(lua_State *) {
1849 extern "C" int showCollisionsLua(lua_State *L) {
1850 auto arg =
static_cast<bool>(lua_toboolean(L, 1));
1862 extern "C" int logLua(lua_State *L) {
1863 auto type =
static_cast<uint8_t
>(lua_tointeger(L, 1));
1864 auto arg =
static_cast<std::string
>(lua_tostring(L, 2));
1866 gMessage_busLua->
send_msg(
new message(LOG_ERROR, make_data<std::string>(arg)));
1867 }
else if (type == 2) {
1868 gMessage_busLua->
send_msg(
new message(LOG_SUCCESS, make_data<std::string>(arg)));
1869 }
else if (type == 4) {
1870 gMessage_busLua->
send_msg(
new message(LOG_INFO, make_data<std::string>(arg)));
1881 extern "C" int showFpsLua(lua_State *L) {
1882 auto arg =
static_cast<bool>(lua_toboolean(L, 1));
1893 extern "C" int showMetricsLua(lua_State *L) {
1894 auto arg =
static_cast<bool>(lua_toboolean(L, 1));
1903 extern "C" int consoleClearLua(lua_State *) {
This class represents all static or dynamic objects in the game (excluding text, see ST::text)
int32_t get_col_y() const
This object contains all the data for a level and provides functions for loading and unloading a leve...
This class is responsible for managing all levels and the lua backend, it is the heart of the engine.
bool key_released(uint16_t arg) const
uint16_t get_internal_width() const
void center_camera_on_entity(uint64_t id)
uint16_t get_window_height() const
int16_t get_left_stick_vertical() const
bool key_held(uint16_t arg) const
int16_t get_left_trigger() const
int32_t get_mouse_x() const
int16_t get_right_stick_vertical() const
int16_t get_left_stick_horizontal() const
ST::level * get_level() const
uint16_t get_window_width() const
uint16_t get_internal_height() const
int32_t get_mouse_y() const
bool key_pressed(uint16_t arg) const
int16_t get_right_trigger() const
int16_t get_right_stick_horizontal() const
std::string get_active_level() const
This class handles all interaction with lua.
void set_global(const std::string &arg)
int initialize(message_bus *msg_bus, game_manager *game_mngr)
int8_t load_file(const std::string &)
void run_global(const std::string &arg)
int8_t run_file(const std::string &file)
int8_t run_script(const std::string &script)
The central messaging system of the engine. All subsystem make extensive use of it.
void send_msg(message *msg)
A message object passed around in the message bus. Holds anything created with make_data<>().