-
Notifications
You must be signed in to change notification settings - Fork 1
/
cw_lua_interp.hpp
1011 lines (972 loc) · 42.5 KB
/
cw_lua_interp.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef AST_ASL_HPP
#define AST_ASL_HPP
#define ALIB_FORCE_INLINE_RUNNERS
#include "utils.hpp"
#include "LUA_INCLUDE.h"
#include "settings.h"
#include <random>
#include "engine.hpp"
#include "renderer.hpp"
#include "Vectors.hpp"
#include "Audio.hpp"
#include "physics.hpp"
#include "cwlib/cwlib.hpp"
#include "lua.hpp"
#include "imgui/imgui.h"
void setGlobalLuaF(lua_State* state, const char* _name, lua_CFunction _f) {
lua_pushcfunction(state, _f);
lua_setglobal(state, _name);
}
void setGlobalLuaNum(lua_State* state, const char* _name, lua_Number num) {
lua_pushnumber(state, num);
lua_setglobal(state, _name);
}
void deleteGlobalLua(lua_State* state, const char* name) {
lua_pushnil(state);
lua_setglobal(state, name);
}
struct lu_SDL_Window_impl {
bool wantsShowCursor = true;
static inline SDL_Window* __win{};
static inline SDL_Renderer* __rend{};
std::string __name = "Unnamed Game";
bool noclip = false;
bool debug = true;
bool debug_window_open = true;
bool is_editor = false;
bool debug_window_active = true;
bool is_interaction_open = false;
std::unordered_map<std::string, luabridge::LuaRef> events;
std::vector < std::pair<std::pair<double, double>, luabridge::LuaRef>> asyncTasks = {};
std::unordered_map<std::string, int> conds;
Sprite* player_sprite;;
void Update() {
//SDL_ShowCursor(wantsShowCursor? SDL_ENABLE : SDL_DISABLE);
SDL_SetWindowTitle(__win, __name.c_str());
Window::WindowInstance->debug = this->debug;
Window::WindowInstance->debug_window_open = this->debug_window_open;
this->debug_window_active = Window::WindowInstance->debug_window_active;
this->is_editor = getbitv(Window::WindowInstance->data, 8) != 0;
}
//std::string __get_name() { return __name; }
//void __set_name(std::string ___name) { this->__name = ___name; }
static inline lu_SDL_Window_impl* __INSTANCE = nullptr;
};
int __calc_uv_pair(int from, int base, int amt) {
if (from == 0) { return base * amt; }
if (amt == 0) { return from; }
return from + ((base * (amt)) - base);
}
void lu_cw_set_overlay_tile(int x_tile, int y_tile) {
Win->scene->ui_img_elem_assets.at("overlay")->uv.x = x_tile;
Win->scene->ui_img_elem_assets.at("overlay")->uv.y = y_tile;
}
void lu_cw_addcond(std::string name, int data) {
lu_SDL_Window_impl::__INSTANCE->conds.insert(std::make_pair(name, data));
}
int lu_cw_getcond(std::string name) {
if (!lu_SDL_Window_impl::__INSTANCE->conds.contains(name)) {
return 0;
}
return lu_SDL_Window_impl::__INSTANCE->conds.at(name);
}
void lu_cw_register_event(std::string name, luabridge::LuaRef f) {
if (!f.isFunction()) {
cwError::push(cwError::CW_ERROR);
std::string t_name = lua_typename(state, f.type());
cwError::serrof("Unable to register event %s : Event needs to be a function. Got %s", name.c_str(), t_name.c_str());
cwError::pop();
}
lu_SDL_Window_impl::__INSTANCE->events.insert(std::make_pair(name, f));
}
void lu_cw_unregister_event(std::string name) {
std::unordered_map<std::string, luabridge::LuaRef>& events_ = lu_SDL_Window_impl::__INSTANCE->events;
if (events_.contains(name)) {
events_.erase(name);
}
}
Window* windowInstance;
SDL_Renderer* __sdlRenderer;
SDL_Window* __sdlWindow;
double* _lu_deltaTime;
double* _lu_deltaTimeUS;
double* _lu_deltaTimeSCALE;
double* _lu_deltaTimefps;
void __lu_RenderTaskImpl();
void initDataLua(SDL_Renderer* renderOBJ, SDL_Window* __winObj, double* _ludt, double* _ludtsc, double* _ludtus, double* _ludt_fps) {
__sdlWindow = __winObj;
__sdlRenderer = renderOBJ;
windowInstance = Win;
lu_SDL_Window_impl::__INSTANCE = new lu_SDL_Window_impl();
lu_SDL_Window_impl::__win = __winObj;
lu_SDL_Window_impl::__rend = renderOBJ;
_lu_deltaTime = _ludt;
_lu_deltaTimeSCALE = _ludtsc;
_lu_deltaTimeUS = _ludtus;
_lu_deltaTimefps = _ludt_fps;
}
void lu_cw_loadScene(std::string sceneName) {
if (!alib_endswith(sceneName.c_str(), ".cwl")) {
sceneName.append(".cwl");
}
if (alib_file_exists(sceneName.c_str())) {
if (Win->scene != nullptr) {
Win->scene->Discard();
}
Window::WindowInstance->scene = new cwLayout(sceneName.c_str());
return;
}
cwError::sstate(cwError::CW_ERROR);
cwError::serrof("Scene %s doesn't exist!", sceneName.c_str());
}
void lu_cw_unloadScene() {
if (Win->scene != nullptr) {
Win->scene->Discard();
Win->scene = nullptr;
}
}
void lu_cw_reloadScene() {
if (SUCCEEDED(Win->scene)) {
std::string _name = Win->scene->name;
Win->scene->Discard();
Window::WindowInstance->scene = new cwLayout(_name.c_str());
return;
}
}
struct lu_col {
int r, g, b, a;
// Needs to fit AT LEAST 32 bits
void setColorL(int32_t c) {
r = alib_get_byte(&c, 0);
g = alib_get_byte(&c, 1);
b = alib_get_byte(&c, 2);
a = alib_get_byte(&c, 3);
}
lu_col(int _r, int _g, int _b, int _a = 255) {
r = _r;
g = _g;
b = _b;
a = _a;
}
};
void lu_logerr(std::string str) {
Win->cons.pushlnf("%serr : %s" + str, ImRGB(255,128,128).tostring(), ImRGB::resetstr());
};
void lu_logsil(std::string str) {
printf(str.c_str());
};
void lu_logdeb(std::string str) {
Win->cons.pushlnf("%sdebug : %s" + str, ImRGB(200, 200, 128).tostring(), ImRGB::resetstr());
};
void lu_logmsg(std::string str) {
cwError::sstate(cwError::CW_MESSAGE);
cwError::serror(str.c_str());
};
void lu_logwrn(std::string str) {
Win->cons.pushlnf("%swarn : %s" + str, ImRGB(255, 255, 128).tostring(), ImRGB::resetstr());
};
void lu_logvrb(std::string str) {
Win->cons.pushlnf("%swarn : %s" + str, ImRGB(160, 160, 200).tostring(), ImRGB::resetstr());
};
#define alu_global luabridge::getGlobalNamespace(state)
void do_n(int amt, std::function<void()> __run) {
for (int i = 0; i < amt; i++) {
__run();
}
}
std::map<std::string, const luabridge::LuaRef> __lu_preupdate__funcs;
std::map<std::string, const luabridge::LuaRef> __lu_prerender__funcs;
std::map<std::string, const luabridge::LuaRef> __lu_update__funcs;
std::map<std::string, const luabridge::LuaRef> __lu_postupdate__funcs;
std::map<std::string, const luabridge::LuaRef> __lu_start__funcs;
std::map<std::string, const luabridge::LuaRef> __lu_render__funcs;
std::map<std::string, const luabridge::LuaRef> __lu_on_interact_funcs;
std::unordered_map < std::string, const luabridge::LuaRef > __lu_on_collide_funcs;
void lu_cw_add_preu(std::string __name, const luabridge::LuaRef __preufunc) {
__lu_preupdate__funcs.insert({ __name, __preufunc});
}
void lu_cw_add_update(std::string __name, const luabridge::LuaRef __ufunc) {
__lu_update__funcs.insert({__name, __ufunc});
}
void lu_cw_add_postu(std::string __name, const luabridge::LuaRef __postufunc) {
__lu_postupdate__funcs.insert({ __name, __postufunc});
}
void lu_cw_add_start(std::string __name, const luabridge::LuaRef __sfunc) {
__lu_start__funcs.insert({ __name, __sfunc});
}
void lu_cw_add_prer(std::string __name, const luabridge::LuaRef __preufunc) {
__lu_prerender__funcs.insert({ __name, __preufunc });
}
void lu_cw_add_render(std::string __name, const luabridge::LuaRef __preufunc) {
__lu_render__funcs.insert({ __name, __preufunc });
}
void lu_cw_add_on_interact(std::string col_id, const luabridge::LuaRef __preufunc) {
__lu_on_interact_funcs.insert({ col_id, __preufunc });
}
void lu_cw_add_on_collide(std::string source_collider, std::string on_collide_id, const luabridge::LuaRef __preufunc) {
__lu_on_collide_funcs.insert({ (source_collider + on_collide_id) , __preufunc });
}
void lu_cw_del_preu(std::string __name) {
__lu_preupdate__funcs.erase(__name);
}
void lu_cw_del_render(std::string __name) {
__lu_render__funcs.erase(__name);
}
void lu_cw_del_update(std::string __name) {
__lu_update__funcs.erase(__name);
}
void lu_cw_del_postu(std::string __name) {
__lu_postupdate__funcs.erase( __name);
}
void lu_cw_del_start(std::string __name) {
__lu_start__funcs.erase(__name);
}
void lu_cw_del_prer(std::string __name) {
__lu_prerender__funcs.erase(__name);
}
void lu_cw_del_on_interact(std::string __name) {
__lu_on_interact_funcs.erase(__name);
}
void lu_cw_del_on_collide(std::string col__name, std::string on_collide_id) {
__lu_on_collide_funcs.erase((col__name+on_collide_id));
}
std::function< void(RectCollider2d*, MeshLine*) > RectCollider2d::OnLineHitRect = [](RectCollider2d* _this, MeshLine* source) {
std::string v = _this->id + source->id;
if (__lu_on_collide_funcs.contains(v)) {
__lu_on_collide_funcs.at(v)();
}
else if (__lu_on_collide_funcs.contains(_this->id + "any")) {
__lu_on_collide_funcs.at(_this->id + "any")();
}
};
std::function< void(RectCollider2d*, RectCollider2d*) > RectCollider2d::OnColliderHit = [](RectCollider2d* _this, RectCollider2d* source) {
std::string v = _this->id + source->id;
if (__lu_on_collide_funcs.contains(v)) {
__lu_on_collide_funcs.at(v)();
}
else if (__lu_on_collide_funcs.contains(_this->id + "any")) {
__lu_on_collide_funcs.at(_this->id + "any")();
}
};
Window::Component __lu_component_impl;
void lu_cw_start_func_impl() {
for (int i = 0; i < __lu_start__funcs.size(); i++) {
luabridge::LuaRef _ref = __lu_start__funcs.begin()++->second;
if (_ref.isFunction()) { _ref(); }
}
}
void lu_cw____update_func_impl() {
for (int i = 0; i < __lu_update__funcs.size(); i++) {
luabridge::LuaRef _ref = __lu_update__funcs.begin()++->second;
if (_ref.isFunction()) { _ref(); }
}
}
void lu_cw_posupdate_func_impl() {
for (int i = 0; i < __lu_postupdate__funcs.size(); i++) {
luabridge::LuaRef _ref = __lu_postupdate__funcs.begin()++->second;
if (_ref.isFunction()) { _ref(); }
}
lu_SDL_Window_impl::__INSTANCE->Update();
}
void lu_cw_preupdate_func_impl() {
auto& tasks = lu_SDL_Window_impl::__INSTANCE->asyncTasks;
for (int i = 0; i < tasks.size(); i++) {
auto& ref = tasks.at(i);
if (ref.first.first /*delta*/ > ref.first.second /*delay*/) {
if (!ref.second) { return; }
ref.second();
tasks.erase(tasks.begin() + i);
continue;
}
ImGuiIO& io = ImGui::GetIO();
ref.first.first += io.DeltaTime;
}
for (int i = 0; i < __lu_preupdate__funcs.size(); i++) {
luabridge::LuaRef _ref = __lu_preupdate__funcs.begin()++->second;
if (_ref.isFunction()) { _ref(); }
}
}
void lu_cw_prerender_func_impl() {
for (int i = 0; i < __lu_prerender__funcs.size(); i++) {
luabridge::LuaRef _ref = __lu_prerender__funcs.begin()++->second;
if (_ref.isFunction()) { _ref(); }
}
}
void lu_cw_render_func_impl() {
for (int i = 0; i < __lu_render__funcs.size(); i++) {
luabridge::LuaRef _ref = __lu_render__funcs.begin()++->second;
if (_ref.isFunction()) { _ref(); }
}
__lu_RenderTaskImpl();
}
luabridge::LuaRef __lu_on_move = 0;
luabridge::LuaRef __lu_on_click = 0;
luabridge::LuaRef __lu_on_keypress = 0;
luabridge::LuaRef __lu_on_keyrelease = 0;
luabridge::LuaRef __lu_on_keyhold = 0;
inline void lu_do_on(const std::string& do_s, luabridge::LuaRef __func) {
if (!__func.isFunction()) {
luaL_error(state, "function not found");
}
if (alib_costr(do_s, "key_press")) {
__lu_on_keypress = __func;
Window::WindowInstance->keyboard.onKeyPress = __lu_on_keypress;
}
if (alib_costr(do_s, "key_release")) {
__lu_on_keyrelease = __func;
Window::WindowInstance->keyboard.onKeyRelease = __lu_on_keyrelease;
}
if (alib_costr(do_s, "key_hold")) {
__lu_on_keyhold = __func;
Window::WindowInstance->keyboard.onKeyHold = __lu_on_keyhold;
}
if (alib_costr(do_s, "mouse_click")) {
__lu_on_click = __func;
Window::WindowInstance->mouse.onClick = __lu_on_click;
}
if (alib_costr(do_s, "mouse_move")) {
__lu_on_move = __func;
Window::WindowInstance->mouse.onMove = __lu_on_move;
}
}
lu_SDL_Window_impl* lu_cw_get_window() {
return lu_SDL_Window_impl::__INSTANCE;
}
struct lu_SDL_Rect_impl : public SDL_Rect{
void set_bulk(int x, int y, int w, int h) { *this= { x,y,w,h }; }
std::array<int, 4> get_bulk() { return {this->x,this->y, this->w, this->h}; }
};
bool lu_cw_keypressedf(int key) { return Window::WindowInstance->keyboard.GetKeyPressed(key); }
bool lu_cw_keydownf(int key) { return Window::WindowInstance->keyboard.GetKey(key); }
bool lu_cw_keyupf(int key) { return !Window::WindowInstance->keyboard.GetKey(key); }
bool lu_cw_keys_down(std::vector<int> keys) {
for (int i = 0; i < keys.size(); i++) {
if (!Window::WindowInstance->keyboard.GetKey(keys[i])) { return false; }
}
return true;
}
bool lu_cw_keys_up(std::vector<int> keys) {
for (int i = 0; i < keys.size(); i++) {
if (Window::WindowInstance->keyboard.GetKey(keys[i])) { return false; }
}
return true;
}
std::vector<std::function<void()>> __renderTasks;
RectCollider2d* lu_new_froms(Sprite* sprite, int __layer) {
RectCollider2d* r_re = new RectCollider2d();
r_re->rect = &sprite->rect;
r_re->recalc();
r_re->layer = __layer;
return r_re;
}
Vector2 lu_cw_get_cursor_pos() { return {(double)Window::WindowInstance->mouse.x, (double)Window::WindowInstance->mouse.y }; }
Vector2 lu_cw_get_cursor_delta() { return { (double)Window::WindowInstance->mouse.dx, (double)Window::WindowInstance->mouse.dy }; }
bool lu_cw_get_mouse_ld() { return Window::WindowInstance->mouse.m1d; }
bool lu_cw_get_mouse_md() { return Window::WindowInstance->mouse.m2d; }
bool lu_cw_get_mouse_rd() { return Window::WindowInstance->mouse.m3d; }
bool lu_cw_get_mouse_t1d() { return Window::WindowInstance->mouse.mt1d; }
bool lu_cw_get_mouse_t2d() { return Window::WindowInstance->mouse.mt2d; }
double lu_get_dt_scaled() { return *_lu_deltaTime; }
double lu_get_dt_scale_val() { return *_lu_deltaTimeSCALE; }
double lu_get_dt_unscaled() { return *_lu_deltaTimeUS; }
double lu_get_dt_fps() { return *_lu_deltaTimefps; }
void lu_new_textbox(std::string label, std::string m_text, luabridge::LuaRef on_complete_func) {
new UI::GameTextBox(label, m_text, on_complete_func);
}
UI::GameOptionsBox* lu_new_optionsbox(std::string title, ABTDataStub options, luabridge::LuaRef on_complete) {
return new UI::GameOptionsBox(title, options, on_complete);
}
UI::GameOptionsBox* lu_new_optionsbox_WITHALIGNMENT(std::string title, ABTDataStub options, luabridge::LuaRef on_complete, int alignment) {
return new UI::GameOptionsBox(title, options, on_complete, alignment);
}
CWItem* lu_cw_get_item(std::string id) {
for (int i = 0; i < Window::WindowInstance->scene->scene_placed_items.size(); i++) {
CWItem* m_i = Window::WindowInstance->scene->scene_placed_items.at(i);
if (m_i->data.get_string("id") == id) {
return m_i;
}
}
return nullptr;
}
bool has_modified_item = false;
inline void lu_cw_render_player_inventory(CWInventory* inv) {
if (inv) {
int columns = 9;
int rows = ceil(inv->INVENTORY_MAX / 9);
if (inv->INVENTORY_MAX < 9 || rows == 0) {
rows = 1;
columns = inv->INVENTORY_MAX;
}
float padding = 8;
int i = 0;
int SIZE = 48;
float m_ElemWidth = SIZE + padding;
float size_x = columns * (SIZE + padding);
float size_y = rows * (SIZE + padding);
ImGuiIO& io = ImGui::GetIO();
float w_pos_x = (io.DisplaySize.x * 0.5f) - (size_x * 0.5f);
float w_pos_y = (io.DisplaySize.y * 0.5f) - (size_y * 0.5f);
ImGui::SetNextWindowPos({ w_pos_x, w_pos_y });
ImGui::SetNextWindowSize({ size_x, size_y });
ImGui::Begin("###m_MGUIInv", 0, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImVec2 p = ImGui::GetWindowPos();
ImVec2 tsz = ImGui::CalcTextSize(inv->title.c_str());
ImVec2 textPos = { p.x, p.y - tsz.y };
ImGui::PushStyleColor(ImGuiCol_Text, ImRGB(0, 0, 0, 128));
ImGui::TextForeground(inv->title, { textPos.x + 1, textPos.y + 1 });
ImGui::TextForeground(inv->title, { textPos.x + 2, textPos.y + 2 });
ImGui::PopStyleColor();
ImGui::TextForeground(inv->title, { textPos.x, textPos.y });
CWItem* m_item = nullptr;
for (int y = 0; y < rows && i < inv->INVENTORY_MAX; y++) {
for (int x = 0; x < columns && i < inv->INVENTORY_MAX; x++) {
float stx = ((SIZE + padding) * x) + w_pos_x + (padding * 0.5f);
float sty = ((SIZE + padding) * y) + w_pos_y + (padding * 0.5f);
ImColor bgc = { 128,128,128,32 };
ImColor bdc = { 128,128,128,32 };
ImGui::RectFilled({ stx, sty }, { (float)SIZE, (float)SIZE }, bgc, 4);
ImGui::RectUnfilled({ stx, sty }, { (float)SIZE, (float)SIZE }, bgc, 4, 1);
ImRect R = { stx, sty, (float)SIZE + stx, (float)SIZE + sty };
if (m_item = inv->GetItemInSlot(i)) {
m_item->ItemSprite->Update();
float iw = m_item->ItemSprite->surf->w;
float ih = m_item->ItemSprite->surf->h;
float sx = ((m_ElemWidth)*x) + w_pos_x + padding * 1.5f;
float sy = ((m_ElemWidth)*y) + w_pos_y + padding * 1.5f;
float ux = (float)m_item->ItemSprite->uv_final.x;
float uy = (float)m_item->ItemSprite->uv_final.y;
float uw = (float)m_item->ItemSprite->uv_final.w;
float uh = (float)m_item->ItemSprite->uv_final.h;
float rx = 0;
float ry = 0;
if (uw > uh) {
rx = (padding - SIZE) - padding;
ry = (padding - SIZE * uh / uw) - padding;
}
else {
rx = (SIZE * uw / uh) - padding;
ry = (SIZE)-padding;
}
ImVec2 uv0 = ImVec2(ux / iw, uy / ih);
ImVec2 uv1 = ImVec2((ux + uw) / iw, (uy + uh) / ih);
alib_clampptr(&m_item->GUIScale, 0.f, 1.f);
ImGui::IMImagePositioned(m_item->ItemSprite->m_ImTex, { sx,sy }, { rx * m_item->GUIScale, ry * m_item->GUIScale }, uv0, uv1);
if (ImGui::IsMouseHoveringRect(R.Min, R.Max, false)) {
if (!ImGui::IsMouseClicked(ImGuiButtonFlags_MouseButtonLeft)) {
std::string m_nt = m_item->data.get_string("name");
std::string m_tt = " " + m_item->data.get_string("tooltip") + '\t';
ImVec2 m_title = ImGui::CalcTextSize(m_nt.c_str());
ImVec2 m_tooltip = ImGui::CalcTextSize(m_tt.c_str());
ImVec2 m_CursorPos = { io.MousePos.x + 16, io.MousePos.y };
ImVec2 m_size = { alib_max(m_title.x, m_tooltip.x), m_title.y + m_tooltip.y + (padding * 2) };
ImGui::ForegroundRectFilled(m_CursorPos, m_size, bgc, 4);
ImGui::ForegroundRectUnfilled(m_CursorPos, m_size, bdc, 4, 1);
ImGui::PushStyleColor(ImGuiCol_Text, ImRGB(0, 0, 0, 128));
ImGui::IMTextForeground(alib_strfmt("%s\n %s", m_nt.c_str(), m_tt.c_str()), { m_CursorPos.x + 1,m_CursorPos.y + 1 });
ImGui::IMTextForeground(alib_strfmt("%s\n %s", m_nt.c_str(), m_tt.c_str()), { m_CursorPos.x + 2,m_CursorPos.y + 2 });
ImGui::PopStyleColor();
ImGui::IMTextForeground(alib_strfmt("%s\n %s", m_nt.c_str(), m_tt.c_str()), m_CursorPos);
}
else {
m_item->OnClick();
}
}
}
i++;
}
}
ImGui::End();
}
}
inline void defineLuaImpl() {
__lu_component_impl.Start = &lu_cw_start_func_impl;
__lu_component_impl.Update = &lu_cw____update_func_impl;
__lu_component_impl.PreUpdate = &lu_cw_preupdate_func_impl;
__lu_component_impl.PostUpdate = &lu_cw_posupdate_func_impl;
__lu_component_impl.PreRender = &lu_cw_prerender_func_impl;
__lu_component_impl.Render = &lu_cw_render_func_impl;
initLUA(state);
luaL_openlibs(state);
luaopen_base(state);
deleteGlobalLua(state, "utf8");
assignInputData(alu_global);
alu_global.beginNamespace("CWSettings")
.addFunction("save", &CWSettings::Save)
.addFunction("load", &CWSettings::Parse)
.beginNamespace("rendering")
.addVariable("always_show_borders", &CWSettings::Rendering::ALWAYS_SHOW_BORDERS)
.endNamespace()
.beginNamespace("keybinds")
.addVariable("use", &CWSettings::KeyBinds::USE, false)
.addVariable("up", &CWSettings::KeyBinds::UP, false)
.addVariable("down", &CWSettings::KeyBinds::DOWN, false)
.addVariable("left", &CWSettings::KeyBinds::LEFT, false)
.addVariable("right", &CWSettings::KeyBinds::RIGHT, false)
.addVariable("pause", &CWSettings::KeyBinds::PAUSE, false)
.addVariable("inventory", &CWSettings::KeyBinds::INVENTORY, false)
.endNamespace()
.endNamespace();
alu_global.beginNamespace("input")
.addFunction("key_pressed", &lu_cw_keypressedf)
.addFunction("key_up", &lu_cw_keyupf)
.addFunction("key_down", &lu_cw_keydownf)
.addFunction("keys_down", lu_cw_keys_down)
.addFunction("keys_up", lu_cw_keys_up)
.addFunction("getKeyName", &Input::GetKeyName)
.addFunction("getKeyNameFriendly", &Input::GetKeyNameFriendly)
.beginNamespace("mouse")
.addProperty("position", &lu_cw_get_cursor_pos)
.addProperty("delta", &lu_cw_get_cursor_delta)
.addProperty("left", &lu_cw_get_mouse_ld)
.addProperty("right", &lu_cw_get_mouse_rd)
.addProperty("middle", &lu_cw_get_mouse_md)
.endNamespace()
.endNamespace();
setGlobalLuaNum(state, "c_empty", COL_EMPTY);
setGlobalLuaNum(state, "c_player", COL_PLAYER);
setGlobalLuaNum(state, "c_entity", COL_ENT);
setGlobalLuaNum(state, "c_object", COL_OBJ);
setGlobalLuaNum(state, "c_trigger", COL_TRG);
setGlobalLuaNum(state, "c_solid", COL_SOLID);
setGlobalLuaNum(state, "COL_EMPTY", COL_EMPTY);
setGlobalLuaNum(state, "COL_PLAYER", COL_PLAYER);
setGlobalLuaNum(state, "COL_ENTITY", COL_ENT);
setGlobalLuaNum(state, "COL_OBJECT", COL_OBJ);
setGlobalLuaNum(state, "COL_TRIGGER", COL_TRG);
setGlobalLuaNum(state, "COL_SOLID", COL_SOLID);
alu_global.beginClass<CWItem>("CWItem")
.addData("data", &CWItem::data)
.addData("sprite", &CWItem::ItemSprite)
.addData("can_be_used", &CWItem::can_be_used)
.addData("can_be_dropped", &CWItem::can_be_dropped)
.addData("can_be_equipped", &CWItem::can_be_equipped)
.addFunction("set_on_click", &CWItem::set_click_func)
.addFunction("isInWorld", &CWItem::isInWorld)
.addFunction("move", &CWItem::SendToInventory)
.endClass();
alu_global.beginClass<CWInventory>("CWInventory")
.addConstructor<CWInventory(*)(std::string)>()
.addData("title", &CWInventory::title)
.addData("max_items", &CWInventory::INVENTORY_MAX)
.addFunction("drop", &CWInventory::DropItemInSlot)
.addFunction("getSlotOfID", &CWInventory::GetSlotOfItemByID)
.addFunction("getItemInSlot", &CWInventory::GetItemInSlot)
.addFunction("setItemInSlot", &CWInventory::SetItemInSlot)
.addFunction("containsID", &CWInventory::containsItemID)
.addStaticFunction("assign", &CWInventory::setGlobalInventory)
.addStaticFunction("getinventory", &CWInventory::getInventoryByID)
.endClass();
alu_global.beginClass<ABTDataStub>("ABT")
.addFunction("setFloat", &ABTDataStub::set_float)
.addFunction("addFloat", &ABTDataStub::add_float)
.addFunction("getFloat", &ABTDataStub::get_float)
.addFunction("setInt", &ABTDataStub::set_int)
.addFunction("addInt", &ABTDataStub::add_int)
.addFunction("getInt", &ABTDataStub::get_int)
.addFunction("setString", &ABTDataStub::set_string)
.addFunction("addString", &ABTDataStub::add_string)
.addFunction("getString", &ABTDataStub::get_string)
.addFunction("setBool", &ABTDataStub::set_bool)
.addFunction("addBool", &ABTDataStub::add_bool)
.addFunction("getBool", &ABTDataStub::get_bool)
.addFunction("clear", &ABTDataStub::clear)
.addFunction("keys", &ABTDataStub::get_keys)
.addFunction("contains", &ABTDataStub::m_contains)
.addFunction("serialize", &ABTDataStub::serialize_json)
.addFunction("deserialize", &ABTDataStub::deserialize_json)
.addConstructor<ABTDataStub(*)()>()
.endClass();
alu_global.beginClass<lu_SDL_Window_impl>("WindowImpl")
.addData("name", &lu_SDL_Window_impl::__name)
.addData("debug", &lu_SDL_Window_impl::debug)
.addData("debug_window", &lu_SDL_Window_impl::debug_window_open)
.addData("debug_window_active", &lu_SDL_Window_impl::debug_window_active, false)
.addData("is_editor", &lu_SDL_Window_impl::is_editor, false)
.addData("noclip", &lu_SDL_Window_impl::noclip)
.addData("cursor_show", &lu_SDL_Window_impl::wantsShowCursor)
.endClass();
alu_global.beginClass<Vector2>("Vector2")
.addStaticFunction("new", &Vector2::lu_new) // ctor
.addConstructor<Vector2(*)(int, int)>()
.addStaticFunction("distance", &Vector2::distance)
.addData("x", &Vector2::x)
.addData("y", &Vector2::y)
.addStaticData("up", &Vector2::up, false)
.addStaticData("right", &Vector2::right, false)
.addStaticFunction("invert", &Vector2::lu_invert)
.addStaticFunction("abs", &Vector2::lu_abs)
.addFunction("magnitude", &Vector2::magnitude)
.addFunction("normalize", &Vector2::normalize)
.addStaticFunction("cross", &Vector2::cross)
.addStaticFunction("dot", &Vector2::dot)
.addStaticFunction("angle", &Vector2::angle)
.addFunction("clamp_magnitude", &Vector2::clamp_magnitude)
.addFunction("__add", &Vector2::luaL__add)
.addFunction("__sub", &Vector2::luaL__sub)
.addFunction("__mul", &Vector2::luaL__mul)
.addFunction("__div", &Vector2::luaL__div)
.addFunction("__unm", &Vector2::luaL__unm)
.addFunction("__eq", &Vector2::luaL__eq)
.addFunction("__lt", &Vector2::luaL__lt)
.addFunction("__le", &Vector2::luaL__le)
.endClass();
alu_global.beginClass<MeshLine>("Line")
.addConstructor<void(*)(double, double, double, double)>()
.addConstructor<void(*)(Vector2, Vector2)>()
.addStaticFunction("new", &MeshLine::lu_new)
.addData("start", &MeshLine::start)
.addData("end", &MeshLine::end)
.addData("layer", &MeshLine::layer)
.addData("id", &MeshLine::coll_id)
.addFunction("set_freestanding", &MeshLine::set_freestanding)
.addFunction("erase_freestanding", &MeshLine::erase_freestanding)
.endClass();
alu_global.beginClass<VectorRect>("Rect")
.addStaticFunction("new", &VectorRect::lu_new)
.addConstructor<VectorRect(*)(int, int, int, int)>()
.addData("x", &VectorRect::x)
.addData("y", &VectorRect::y)
.addData("w", &VectorRect::w)
.addData("h", &VectorRect::h)
.addStaticFunction("intersects", &VectorRect::lu_intersects)
.endClass();
alu_global.beginClass<SDL_Rect>("SDL_Rect")
.addData("x", &SDL_Rect::x)
.addData("y", &SDL_Rect::y)
.addData("w", &SDL_Rect::w)
.addData("h", &SDL_Rect::h)
.addConstructor<SDL_Rect* (*)(int, int, int, int)>()
.endClass();
alu_global.beginNamespace("cdecl")
.addConstant("NDEBUG", NDEBUG)
.beginClass < std::function<void()>>("std_function_void_0a")
.addFunction("call", &std::function<void()>::operator())
.endClass()
.endNamespace();
alu_global.beginClass<Transform>("Transform")
.addData("angle", &Transform::angle)
.addData("origin", &Transform::origin)
.addData("position", &Transform::position)
.addData("scale", &Transform::scale)
.endClass();
alu_global.beginClass<SpriteAnimationMeta>("SpriteMeta")
.addConstructor<SpriteAnimationMeta(*)(int, float)>()
.addData("animate", &SpriteAnimationMeta::animate)
.addData("animate_once", &SpriteAnimationMeta::animate_once)
.addData("resets", &SpriteAnimationMeta::reset_after_once)
.addData("frame", &SpriteAnimationMeta::CURRENT_FRAME)
.addData("delay", &SpriteAnimationMeta::delay)
.addFunction("set_on_loop", &SpriteAnimationMeta::set_loop_func)
.endClass();
alu_global.beginClass<Sprite>("Sprite")
.addStaticFunction("new", Sprite::luaNew)
.addConstructor<Sprite(*)(const char*)>()
.addData("meta", &Sprite::meta)
.addData("alpha", &Sprite::alpha)
.addData("centered", &Sprite::center)
.addData("enabled", &Sprite::enabled)
.addData("name", &Sprite::name)
.addProperty("id",
std::function <std::string(const Sprite*)>([](const Sprite* s) {
return s->identifier;
}),
std::function <void(Sprite*, std::string)>([](Sprite* s, std::string id) {
s->setID(id);
})
)
.addData("is_rendering", &Sprite::isRendering)
.addData("center_position", &Sprite::center_position)
.addData("layer", &Sprite::layer)
.addData("uv", &Sprite::uv)
.addData("transform", &Sprite::transform)
.addData("tile", &Sprite::uv_tile)
.addData("uv_final", &Sprite::uv_final, false)
.addFunction("set_uv", &Sprite::lua_set_uv)
.addFunction("lock", &Sprite::lockCamera)
.addFunction("unlock", &Sprite::unlockCamera)
.addFunction("update", &Sprite::Update)
.addData("pixel_sz", &Sprite::pixel_size, false)
.endClass();
alu_global.beginNamespace("cw")
.addFunction("get_item", &lu_cw_get_item)
.addFunction("addcond", &lu_cw_addcond)
.addFunction("getcond", &lu_cw_getcond)
.addFunction("load", &lu_cw_loadScene)
.addFunction("unload", &lu_cw_unloadScene)
.addFunction("reload", &lu_cw_reloadScene)
.addFunction("add_start", &lu_cw_add_start)
.addFunction("add_pre_update", &lu_cw_add_preu)
.addFunction("add_update", &lu_cw_add_update)
.addFunction("add_post_update", &lu_cw_add_postu)
.addFunction("add_pre_render", &lu_cw_add_prer)
.addFunction("delete_pre_render", &lu_cw_del_prer)
.addFunction("add_render_task", &lu_cw_add_render)
.addFunction("delete_render_task", &lu_cw_del_render)
.addFunction("delete_start", &lu_cw_del_start)
.addFunction("delete_pre_update", &lu_cw_del_preu)
.addFunction("delete_update", &lu_cw_del_update)
.addFunction("delete_post_update", &lu_cw_del_postu)
.addFunction("get_window", &lu_cw_get_window)
.addFunction("run_async", std::function<void(double, luabridge::LuaRef)>([](double delay, luabridge::LuaRef func) {
if (!func.isFunction()) {
cwError::push(cwError::CW_ERROR);
std::string t_name = lua_typename(state, func.type());
cwError::serrof("Unable to register async event : Event needs to be a function. Got %s", t_name.c_str());
cwError::pop();
return;
}
lu_cw_get_window()->asyncTasks.push_back(std::make_pair(std::make_pair(0, delay), func));
}))
.addFunction("set_overlay_enabled", std::function<void(bool)>([](bool s) {
setbitv(Window::WindowInstance->data, 2, s);
}))
.addFunction("overlay_uv", lu_cw_set_overlay_tile)
.addFunction("on", &lu_do_on)
.addFunction("re", &lu_cw_register_event)
.addFunction("ue", &lu_cw_unregister_event)
.addFunction("ce", std::function<void(std::string)>([](std::string name) {
std::unordered_map<std::string, luabridge::LuaRef> events = lu_SDL_Window_impl::__INSTANCE->events;
if (events.contains(name)) {
events.at(name)();
}
}))
.addFunction("add_interaction", &lu_cw_add_on_interact)
.addFunction("delete_interaction", &lu_cw_del_on_interact)
.addFunction("add_collision", &lu_cw_add_on_collide)
.addFunction("delete_collision", &lu_cw_del_on_collide)
.addFunction("get_sprite", &Sprite::getElementByID)
.addFunction("get_particle", &ParticleEffect::getElementByID)
.addFunction("associate_player", std::function<void(Sprite*)>([](Sprite* s) {
lu_cw_get_window()->player_sprite = s;
}))
.addFunction("get_player", std::function<Sprite * ()>([]() {
return lu_cw_get_window()->player_sprite;
}))
.addVariable("is_interacting", &UI::GameTextBox::isInteracting)
.addFunction("m_runInteraction", std::function <bool(std::string)>([](std::string id) -> bool {
if (UI::GameTextBox::isInteracting) {
return false;
}
CWItem* i = nullptr;
if (i = Window::WindowInstance->scene->getItemByID(id)) {
i->SendToInventory(CWInventory::getInventoryByID("player_inventory"));
return true;
}
if (!__lu_on_interact_funcs.contains(id)) { return false; }
__lu_on_interact_funcs.at(id)();
return true;
}))
.beginNamespace("Camera")
.addProperty("position", Camera::lu_GetPosition, Camera::lu_SetPosition)
.addFunction("target", Camera::lu_SetTarget)
.addProperty("zoom", Camera::lu_GetScale, Camera::lu_SetScale)
.endNamespace()
.endNamespace();
alu_global.beginNamespace("Time")
.addProperty("DeltaTime", &lu_get_dt_scaled)
.addVariable("DeltaTimeUnscaled", &Time::DeltaTimeUnscaled, false)
.addVariable("fps", &Time::fps, false)
.addProperty("DeltaTimeScale", &lu_get_dt_scale_val)
.beginClass<Time::Timer>("Timer")
.addConstructor<Time::Timer(*)()>()
.addData("elapsed", &Time::Timer::elapsed, false)
.addFunction("start", &Time::Timer::Start)
.addFunction("end", &Time::Timer::End)
.endClass()
.endNamespace();
alu_global.beginNamespace("console")
.addFunction("log", &lu_logmsg)
.addFunction("error", &lu_logerr)
.addFunction("warn", &lu_logwrn)
.addFunction("debug", &lu_logdeb)
.addFunction("cout", &lu_logsil)
.endNamespace();
alu_global
.addFunction("print", &lu_logsil) // Override print, and have it print to the debug console.
;
alu_global.beginClass<RectCollider2d>("RectCollider")
.addStaticFunction("new", &RectCollider2d::lu_new_fromi)
.addStaticFunction("new_centered", &RectCollider2d::lu_new_fromic)
.addStaticFunction("from_rect", &RectCollider2d::lu_new_fromr)
.addStaticFunction("from_sprite", &lu_new_froms)
.addData("layer", &RectCollider2d::layer)
.addProperty("id",
std::function <std::string(const RectCollider2d*)>([](const RectCollider2d* s) {
return s->id;
}),
std::function <void(RectCollider2d*, std::string)>([](RectCollider2d* s, std::string id) {
s->id = id;
})
)
.addProperty("x",
std::function <int(const RectCollider2d*)>([](const RectCollider2d* r) {return r->rect->x; }),
std::function <void(RectCollider2d*, int)>([](RectCollider2d* r, int v) {r->rect->x = v; })
)
.addProperty("y",
std::function <int(const RectCollider2d*)>([](const RectCollider2d* r) {return r->rect->y; }),
std::function <void(RectCollider2d*, int)>([](RectCollider2d* r, int v) {r->rect->y = v; })
)
.addProperty("w",
std::function <int(const RectCollider2d*)>([](const RectCollider2d* r) {return r->rect->w; }),
std::function <void(RectCollider2d*, int)>([](RectCollider2d* r, int v) {r->rect->w = v; })
)
.addProperty("h",
std::function <int(const RectCollider2d*)>([](const RectCollider2d* r) {return r->rect->h; }),
std::function <void(RectCollider2d*, int)>([](RectCollider2d* r, int v) {r->rect->h = v; })
)
.addStaticFunction("dump_debug", &RectCollider2d::dump_debug)
.endClass();
// I despise programming like this
alu_global.beginNamespace("Raycast")
.addFunction("line", &Collider::Raycast::Test) // Raycast and check for specific type of collider
.addFunction("circle", &Collider::Raycast::TestCircle)
.addFunction("cone", &Collider::Raycast::TestCone)
.addFunction("any_line", &Collider::Raycast::TestAnyLine)
.addFunction("any_circle", &Collider::Raycast::TestAnyCircle)
.addFunction("any_cone", &Collider::Raycast::TestAnyCone)
.addFunction("any_line_except", &Collider::Raycast::TestExcept)
.addFunction("any_circle_except", &Collider::Raycast::TestCircleExcept)
.addFunction("any_cone_except", &Collider::Raycast::TestConeExcept)
.endNamespace();
alu_global.beginNamespace("RaycastHit")
.addVariable("start", &Collider::Hit::start, false)
.addVariable("end", &Collider::Hit::end, false)
.addVariable("length", &Collider::Hit::length, false)
.addVariable("pos", &Collider::Hit::pos, false)
.addVariable("hasHit", &Collider::Hit::hasHit, false)
.addVariable("layer", &Collider::Hit::layer, false)
.addVariable("id", &Collider::Hit::col_id, false)
.endNamespace();
alu_global.beginClass<ParticleEffects::stub>("ParticleEffectType")
.addData("meta", &ParticleEffects::stub::meta)
.addData("uv", &ParticleEffects::stub::uv)
.addData("id", &ParticleEffects::stub::id)
.addStaticData("RAIN", &ParticleEffects::RAIN, false)
.addStaticData("BLOOD", &ParticleEffects::BLOOD, false)
.addStaticData("SNOW", &ParticleEffects::SNOW, false)
.addStaticData("FLAME", &ParticleEffects::FLAME, false)
.endClass();
alu_global.beginClass<ParticleEffect>("Particle")
.addConstructor<ParticleEffect* (*)(ParticleEffects::stub, int)>()
.addData("uv", &ParticleEffect::m_uv)
.addProperty("direction",
std::function<float(const ParticleEffect*)>([](const ParticleEffect* e) {return alib_rad2deg(e->m_dir_angle_rad); }),
std::function<void(ParticleEffect*, float)>([](ParticleEffect* e, float a) {
e->m_dir_angle_rad = alib_deg2rad(a);
}))
.addData("layer", &ParticleEffect::m_layer)
.addData("lifetime", &ParticleEffect::m_lifetime)
.addData("pos", &ParticleEffect::start_pos)
.addData("randomness", &ParticleEffect::m_randomness)
.addFunction("add", &ParticleEffect::append)
.addFunction("remove", &ParticleEffect::pop)
.endClass();
alu_global.beginNamespace("math")
.addFunction("lerp", std::function <Vector2(Vector2, Vector2, float percent)>([](Vector2 start, Vector2 end, float percent) -> Vector2 {
return (start + (end - start) * percent);
}))
.addFunction("clerp", std::function <Vector2(Vector2, Vector2, float percent)>([](Vector2 start, Vector2 end, float percent) -> Vector2 {
return alib_clamp((start + (end - start) * percent), start, end);
}))
.endNamespace();
alu_global.beginClass<AudioWAV>("Audio")
.addFunction("name", &AudioWAV::name)
.addConstructor<AudioWAV* (*)(std::string)>()
//.addStaticFunction("new", &AudioWAV::lu_new)
.addFunction("end", &AudioWAV::operator~)
.addFunction("play", &AudioWAV::Play)
.addFunction("stop", &AudioWAV::Stop)
.addFunction("play_set_volume", &AudioWAV::SetVolume)
.addFunction("play_get_volume", &AudioWAV::GetVolume)
.addFunction("set_pos", std::function<void(AudioWAV*, Vector2)>([](AudioWAV* w, Vector2 p) {
Vector2 t = *Camera::GetInstance()->m_target;
Mix_SetPosition(w->selectedChannel, Vector2::angle(t, p), Vector2::distancef(t, p));
}))
.addFunction("get_error", &AudioWAV::GetError)
.addData("left", &AudioWAV::pan_left, true)
.addData("right", &AudioWAV::pan_right, true)
.addData("distance", &AudioWAV::pan_left, true)
.addData("volume", &AudioWAV::volume, true)
//.addProperty("volume", &AudioWAV::GetVolume, &AudioWAV::SetVolume)
.endClass();
alu_global.beginClass<lu_col>("Color")
.addConstructor<lu_col(*)(int, int, int, int)>()
.addConstructor<lu_col(*)(int, int, int)>()
.addData("r", &lu_col::r, true)
.addData("g", &lu_col::g, true)
.addData("b", &lu_col::b, true)
.addData("a", &lu_col::a, true)
.endClass();
alu_global.beginNamespace("Alignment")
.addConstant("left", UI::Alignment::LEFT)
.addConstant("right", UI::Alignment::RIGHT)
.addConstant("center", UI::Alignment::CENTER)
.addConstant("top", UI::Alignment::TOP)
.addConstant("bottom", UI::Alignment::BOTTOM)
.endNamespace();
alu_global.beginClass<UI::GameOptionsBox>("__GameOptionBox")
.addData("alignment", &UI::GameOptionsBox::alignment)
.addData("title", &UI::GameOptionsBox::title)
.addData("options", &UI::GameOptionsBox::options)
.endClass();
alu_global.beginNamespace("Render")
.addFunction("SetDrawColor", std::function<void(lu_col)>([](lu_col _col) {
SDL_SetRenderDrawColor(__sdlRenderer, _col.r, _col.g, _col.b, _col.a);
}))
.addFunction("DrawLine", std::function<void(Vector2, Vector2)>([&](Vector2 start, Vector2 end) {
SDL_RenderDrawLine(__sdlRenderer, start.x, start.y, end.x, end.y);
}))
.addFunction("DrawRect", std::function<void(VectorRect)>([&](VectorRect r) {
SDL_Rect _r = r;
SDL_RenderDrawRect(__sdlRenderer, &_r);
}))
.addFunction("Clear", std::function<void()>([&]() {
SDL_RenderClear(__sdlRenderer);
}))
.addFunction("DrawText", &ImGui::TextForeground)
.addFunction("TextBox", &lu_new_textbox)
.addFunction("OptionsBox", &lu_new_optionsbox)
.addFunction("OptionsBoxAligned", &lu_new_optionsbox_WITHALIGNMENT)
.addFunction("Inventory", &lu_cw_render_player_inventory)
.endNamespace();
int status = luaL_dostring(state, R"(
printf = function(s,...)
return print(s:format(...))
end -- function
io.stderr:setvbuf "no"
--collectgarbage("stop")
dofile("lib/debug.lua")
function foldr(f, ...)
if select('#', ...) < 2 then return ... end
local function helper(x, ...)
if select('#', ...) == 0 then
return x
end
return f(x, helper(...))
end
return helper(...)
end
)");//
if (status) {
// since the error message includes the script which we're trying
// to parse, the result has unbounded length; so use another
// ostringstream to hold the error message
std::ostringstream errmsg;
int parseError1_pos = lua_gettop(state);
std::cout << "Errors parsing the following script:" << std::endl;
std::cout << "debug.lua" << std::endl << std::endl;
std::cout << "Parser error when interpreting as an expression:" << std::endl;
std::cout << lua_tostring(state, parseError1_pos) << std::endl << std::endl;
}
}
alib_inline_run _nn([&]() {
defineLuaImpl();
});
void __lu_RenderTaskImpl() {