diff --git a/headers/enduro2d/core/input.hpp b/headers/enduro2d/core/input.hpp index 3517b91f..792bfff8 100644 --- a/headers/enduro2d/core/input.hpp +++ b/headers/enduro2d/core/input.hpp @@ -106,8 +106,8 @@ namespace e2d input(); ~input() noexcept final; - const class mouse& mouse() const noexcept; - const class keyboard& keyboard() const noexcept; + const mouse& mouse() const noexcept; + const keyboard& keyboard() const noexcept; void post_event(input_char_event evt) noexcept; void post_event(move_cursor_event evt) noexcept; diff --git a/samples/bin/library/scripts/emmy/components/actor.lua b/samples/bin/library/scripts/emmy/components/actor.lua new file mode 100644 index 00000000..d450a587 --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/actor.lua @@ -0,0 +1,8 @@ +---@class actor +local actor = { + ---@type node + node = {} +} + +---@type actor +_G.actor = _G.actor or actor diff --git a/samples/bin/library/scripts/emmy/components/behaviour.lua b/samples/bin/library/scripts/emmy/components/behaviour.lua new file mode 100644 index 00000000..a2c0ffae --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/behaviour.lua @@ -0,0 +1,22 @@ +---@class behaviour +local behaviour = { + ---@type boolean + enabled = true, + + ---@type boolean + disabled = false, + + ---@type table + meta = {} +} + +---@overload fun(self: behaviour) +---@param self behaviour +function behaviour.enable(self) end + +---@overload fun(self: behaviour) +---@param self behaviour +function behaviour.disable(self) end + +---@type behaviour +_G.behaviour = _G.behaviour or behaviour diff --git a/samples/bin/library/scripts/emmy/components/camera.lua b/samples/bin/library/scripts/emmy/components/camera.lua new file mode 100644 index 00000000..fb147ddc --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/camera.lua @@ -0,0 +1,31 @@ +---@class camera +local camera = { + ---@type boolean + enabled = true, + + ---@type boolean + disabled = false, + + ---@type integer + depth = 0, + + ---@type rect + viewport = rect.zero(), + + ---@type m4f + projection = m4f.identity(), + + ---@type color + background = color.white() +} + +---@overload fun(self: camera) +---@param self camera +function camera.enable(self) end + +---@overload fun(self: camera) +---@param self camera +function camera.disable(self) end + +---@type camera +_G.camera = _G.camera or camera diff --git a/samples/bin/library/scripts/emmy/components/flipbook_player.lua b/samples/bin/library/scripts/emmy/components/flipbook_player.lua new file mode 100644 index 00000000..fac4d32a --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/flipbook_player.lua @@ -0,0 +1,38 @@ +---@class flipbook_player +local flipbook_player = { + ---@type number + time = 0, + + ---@type number + speed = 1, + + ---@type boolean + looped = false, + + ---@type boolean + stopped = true, + + ---@type boolean + playing = false, + + ---@type str_hash + sequence = str_hash.new(), + + ---@type flipbook_asset + flipbook = nil +} + +---@overload fun(self: flipbook_player, time: number) +---@overload fun(self: flipbook_player, sequence: string) +---@overload fun(self: flipbook_player, sequence: str_hash) +---@param self flipbook_player +function flipbook_player.stop(self, ...) end + +---@overload fun(self: flipbook_player, time: number) +---@overload fun(self: flipbook_player, sequence: string) +---@overload fun(self: flipbook_player, sequence: str_hash) +---@param self flipbook_player +function flipbook_player.play(self, ...) end + +---@type flipbook_player +_G.flipbook_player = _G.flipbook_player or flipbook_player diff --git a/samples/bin/library/scripts/emmy/components/label.lua b/samples/bin/library/scripts/emmy/components/label.lua new file mode 100644 index 00000000..40e3606c --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/label.lua @@ -0,0 +1,53 @@ +---@class label +local label = { + ---@type string + text = "", + + ---@type font_asset + font = nil, + + ---@type color32 + tint = color32.white(), + + ---@type label_haligns + halign = label.haligns.center, + + ---@type label_valigns + valign = label.valigns.baseline, + + ---@type number + leading = 1, + + ---@type number + tracking = 0, + + ---@type number + text_width = 0, + + ---@type number + glyph_dilate = 0, + + ---@type number + outline_width = 0, + + ---@type color32 + outline_color = color32.white() +} + +---@class label_haligns +label.haligns = { + left = "left", + center = "center", + right = "right" +} + +---@class label_valigns +label.valigns = { + top = "top", + center = "center", + bottom = "bottom", + baseline = "baseline" +} + +---@type label +_G.label = _G.label or label diff --git a/samples/bin/library/scripts/emmy/components/model_renderer.lua b/samples/bin/library/scripts/emmy/components/model_renderer.lua new file mode 100644 index 00000000..a96d23ae --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/model_renderer.lua @@ -0,0 +1,8 @@ +---@class model_renderer +local model_renderer = { + ---@type model_asset + model = nil +} + +---@type model_renderer +_G.model_renderer = _G.model_renderer or model_renderer diff --git a/samples/bin/library/scripts/emmy/components/named.lua b/samples/bin/library/scripts/emmy/components/named.lua new file mode 100644 index 00000000..8fcce401 --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/named.lua @@ -0,0 +1,8 @@ +---@class named +local named = { + ---@type string + name = "" +} + +---@type named +_G.named = _G.named or named diff --git a/samples/bin/library/scripts/emmy/components/renderer.lua b/samples/bin/library/scripts/emmy/components/renderer.lua new file mode 100644 index 00000000..52a6b486 --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/renderer.lua @@ -0,0 +1,19 @@ +---@class renderer +local renderer = { + ---@type boolean + enabled = true, + + ---@type boolean + disabled = false +} + +---@overload fun(self: renderer) +---@param self renderer +function renderer.enable(self) end + +---@overload fun(self: renderer) +---@param self renderer +function renderer.disable(self) end + +---@type renderer +_G.renderer = _G.renderer or renderer diff --git a/samples/bin/library/scripts/emmy/components/scene.lua b/samples/bin/library/scripts/emmy/components/scene.lua new file mode 100644 index 00000000..0f728268 --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/scene.lua @@ -0,0 +1,22 @@ +---@class scene +local scene = { + ---@type boolean + enabled = true, + + ---@type boolean + disabled = false, + + ---@type integer + depth = 0 +} + +---@overload fun(self: scene) +---@param self scene +function scene.enable(self) end + +---@overload fun(self: scene) +---@param self scene +function scene.disable(self) end + +---@type scene +_G.scene = _G.scene or scene diff --git a/samples/bin/library/scripts/emmy/components/spine_player.lua b/samples/bin/library/scripts/emmy/components/spine_player.lua new file mode 100644 index 00000000..404de54f --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/spine_player.lua @@ -0,0 +1,226 @@ +---@class spine_player +local spine_player = { + ---@type spine_asset + spine = nil +} + +---@param self spine_player +---@param name string +---@return boolean +function spine_player.skin(self, name) end + +---@param self spine_player +---@param slot string +---@param name string +---@return boolean +function spine_player.attachment(self, slot, name) end + +---@param self spine_player +---@param name string +---@return boolean +function spine_player.has_skin(self, name) end + +---@param self spine_player +---@param name string +---@return boolean +function spine_player.has_animation(self, name) end + +---@param self spine_player +---@param cmd spine_player_command +function spine_player.add_command(self, cmd) end + +-- ----------------------------------------------------------------------------- +-- +-- events +-- +-- ----------------------------------------------------------------------------- + +---@alias spine_player_event spine_player_custom_evt | spine_player_end_evt | spine_player_complete_evt + +-- +-- custom_evt +-- + +---@class spine_player_custom_evt +spine_player.custom_evt = { + ---@type string + name = "", + + ---@type integer + int_value = 0, + + ---@type number + float_value = 0, + + ---@type string + string_value = "" +} + +---@param name string +---@return spine_player_custom_evt +function spine_player.custom_evt.new(name) end + +-- +-- end_evt +-- + +---@class spine_player_end_evt +spine_player.end_evt = { + ---@type string + message = "" +} + +---@param message string +---@return spine_player_end_evt +function spine_player.end_evt.new(message) end + +-- +-- complete_evt +-- + +---@class spine_player_complete_evt +spine_player.complete_evt = { + ---@type string + message = "" +} + +---@param message string +---@return spine_player_complete_evt +function spine_player.complete_evt.new(message) end + +-- ----------------------------------------------------------------------------- +-- +-- commands +-- +-- ----------------------------------------------------------------------------- + +---@alias spine_player_command spine_player_clear_track_cmd | spine_player_set_anim_cmd | spine_player_add_anim_cmd | spine_player_set_empty_anim_cmd | spine_player_add_empty_anim_cmd + +-- +-- clear_track_cmd +-- + +---@class spine_player_clear_track_cmd +spine_player.clear_track_cmd = { + ---@type integer + track = 0 +} + +---@param track integer +---@return spine_player_clear_track_cmd +function spine_player.clear_track_cmd.new(track) end + +-- +-- set_anim_cmd +-- + +---@class spine_player_set_anim_cmd +spine_player.set_anim_cmd = { + ---@type integer + track = 0, + + ---@type string + name = "", + + ---@type boolean + loop = false, + + ---@type string + end_message = "", + + ---@type string + complete_message = "" +} + +---@param track integer +---@param name string +---@return spine_player_set_anim_cmd +function spine_player.set_anim_cmd.new(track, name) end + +-- +-- add_anim_cmd +-- + +---@class spine_player_add_anim_cmd +spine_player.add_anim_cmd = { + ---@type integer + track = 0, + + ---@type string + name = "", + + ---@type boolean + loop = false, + + ---@type number + delay = 0, + + ---@type string + end_message = "", + + ---@type string + complete_message = "" +} + +---@param track integer +---@param name string +---@return spine_player_add_anim_cmd +function spine_player.add_anim_cmd.new(track, name) end + +-- +-- set_empty_anim_cmd +-- + +---@class spine_player_set_empty_anim_cmd +spine_player.set_empty_anim_cmd = { + ---@type integer + track = 0, + + ---@type number + mix_duration = 0, + + ---@type string + end_message = "", + + ---@type string + complete_message = "" +} + +---@param track integer +---@return spine_player_set_empty_anim_cmd +function spine_player.set_empty_anim_cmd.new(track) end + +-- +-- add_empty_anim_cmd +-- + +---@class spine_player_add_empty_anim_cmd +spine_player.add_empty_anim_cmd = { + ---@type integer + track = 0, + + ---@type number + delay = 0, + + ---@type number + mix_duration = 0, + + ---@type string + end_message = "", + + ---@type string + complete_message = "" +} + +---@param track integer +---@return spine_player_add_empty_anim_cmd +function spine_player.add_empty_anim_cmd.new(track) end + +-- ----------------------------------------------------------------------------- +-- +-- globals +-- +-- ----------------------------------------------------------------------------- + +---@type spine_player +_G.spine_player = _G.spine_player or spine_player diff --git a/samples/bin/library/scripts/emmy/components/sprite_renderer.lua b/samples/bin/library/scripts/emmy/components/sprite_renderer.lua new file mode 100644 index 00000000..574a0e96 --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/sprite_renderer.lua @@ -0,0 +1,25 @@ +---@class sprite_renderer +local sprite_renderer = { + ---@type color32 + tint = color32.white(), + + ---@type sprite_renderer_blendings + blending = sprite_renderer.blendings.normal, + + ---@type boolean + filtering = true, + + ---@type sprite_asset + sprite = nil +} + +---@class sprite_renderer_blendings +sprite_renderer.blendings = { + normal = "normal", + additive = "additive", + multiply = "multiply", + screen = "screen" +} + +---@type sprite_renderer +_G.sprite_renderer = _G.sprite_renderer or sprite_renderer diff --git a/samples/bin/library/scripts/emmy/core/debug.lua b/samples/bin/library/scripts/emmy/core/debug.lua index c30a422c..aeae4e4b 100644 --- a/samples/bin/library/scripts/emmy/core/debug.lua +++ b/samples/bin/library/scripts/emmy/core/debug.lua @@ -2,17 +2,21 @@ local debug = { } +---@param self debug ---@param message string -function debug:trace(message) end +function debug.trace(self, message) end +---@param self debug ---@param message string -function debug:warning(message) end +function debug.warning(self, message) end +---@param self debug ---@param message string -function debug:error(message) end +function debug.error(self, message) end +---@param self debug ---@param message string -function debug:fatal(message) end +function debug.fatal(self, message) end ---@type debug _G.the_debug = _G.the_debug or debug diff --git a/samples/bin/library/scripts/emmy/core/engine.lua b/samples/bin/library/scripts/emmy/core/engine.lua index ab296b5f..fcdd8a0f 100644 --- a/samples/bin/library/scripts/emmy/core/engine.lua +++ b/samples/bin/library/scripts/emmy/core/engine.lua @@ -6,10 +6,10 @@ local engine = { ---@type number delta_time = 0, - ---@type number + ---@type integer frame_rate = 0, - ---@type number + ---@type integer frame_count = 0, ---@type number diff --git a/samples/bin/library/scripts/emmy/core/input.lua b/samples/bin/library/scripts/emmy/core/input.lua index ebfd58e2..b46642ef 100644 --- a/samples/bin/library/scripts/emmy/core/input.lua +++ b/samples/bin/library/scripts/emmy/core/input.lua @@ -1,10 +1,10 @@ ---@class input local input = { ---@type mouse - mouse = {}, + mouse = nil, ---@type keyboard - keyboard = {} + keyboard = nil } ---@type input diff --git a/samples/bin/library/scripts/emmy/core/keyboard.lua b/samples/bin/library/scripts/emmy/core/keyboard.lua index e13d7b73..eddf0745 100644 --- a/samples/bin/library/scripts/emmy/core/keyboard.lua +++ b/samples/bin/library/scripts/emmy/core/keyboard.lua @@ -22,17 +22,20 @@ local keyboard = { just_released_keys = {} } +---@param self keyboard ---@param key string ---@return boolean -function keyboard:is_key_pressed(key) end +function keyboard.is_key_pressed(self, key) end +---@param self keyboard ---@param key string ---@return boolean -function keyboard:is_key_just_pressed(key) end +function keyboard.is_key_just_pressed(self, key) end +---@param self keyboard ---@param key string ---@return boolean -function keyboard:is_key_just_released(key) end +function keyboard.is_key_just_released(self, key) end ---@type keyboard _G.the_keyboard = _G.the_keyboard or keyboard diff --git a/samples/bin/library/scripts/emmy/core/mouse.lua b/samples/bin/library/scripts/emmy/core/mouse.lua index 0fb7d734..6fbe153b 100644 --- a/samples/bin/library/scripts/emmy/core/mouse.lua +++ b/samples/bin/library/scripts/emmy/core/mouse.lua @@ -25,17 +25,20 @@ local mouse = { just_released_buttons = {} } +---@param self mouse ---@param button string ---@return boolean -function mouse:is_button_pressed(button) end +function mouse.is_button_pressed(self, button) end +---@param self mouse ---@param button string ---@return boolean -function mouse:is_button_just_pressed(button) end +function mouse.is_button_just_pressed(self, button) end +---@param self mouse ---@param button string ---@return boolean -function mouse:is_button_just_released(button) end +function mouse.is_button_just_released(self, button) end ---@type mouse _G.the_mouse = _G.the_mouse or mouse diff --git a/samples/bin/library/scripts/emmy/core/window.lua b/samples/bin/library/scripts/emmy/core/window.lua index 5a23edbf..4a9e4431 100644 --- a/samples/bin/library/scripts/emmy/core/window.lua +++ b/samples/bin/library/scripts/emmy/core/window.lua @@ -34,13 +34,17 @@ local window = { should_close = false } -function window:hide() end +---@param self window +function window.hide(self) end -function window:show() end +---@param self window +function window.show(self) end -function window:restore() end +---@param self window +function window.restore(self) end -function window:minimize() end +---@param self window +function window.minimize(self) end ---@type window _G.the_window = _G.the_window or window diff --git a/samples/bin/library/scripts/emmy/high/gobject.lua b/samples/bin/library/scripts/emmy/high/gobject.lua new file mode 100644 index 00000000..89f9c994 --- /dev/null +++ b/samples/bin/library/scripts/emmy/high/gobject.lua @@ -0,0 +1,47 @@ +---@class gobject +local gobject = { + ---@type boolean + alive = true, + + ---@type boolean + valid = true, + + ---@type actor + actor = nil, + + ---@type behaviour + behaviour = nil, + + ---@type camera + camera = nil, + + ---@type flipbook_player + flipbook_player = nil, + + ---@type label + label = nil, + + ---@type model_renderer + model_renderer = nil, + + ---@type named + named = nil, + + ---@type renderer + renderer = nil, + + ---@type scene + scene = nil, + + ---@type spine_player + spine_player = nil, + + ---@type sprite_renderer + sprite_renderer = nil +} + +---@param self gobject +function gobject.destroy(self) end + +---@type gobject +_G.gobject = _G.gobject or gobject diff --git a/samples/bin/library/scripts/emmy/high/node.lua b/samples/bin/library/scripts/emmy/high/node.lua new file mode 100644 index 00000000..2856bf52 --- /dev/null +++ b/samples/bin/library/scripts/emmy/high/node.lua @@ -0,0 +1,113 @@ +---@class node +local node = { + ---@type t3f + transform = t3f.identity(), + + ---@type v3f + translation = v3f.zero(), + + ---@type q4f + rotation = q4f.identity(), + + ---@type v3f + scale = v3f.unit(), + + ---@type m4f + local_matrix = m4f.identity(), + + ---@type m4f + world_matrix = m4f.identity(), + + ---@type node + root = nil, + + ---@type node + parent = nil, + + ---@type integer + child_count = 0, + + ---@type integer + child_count_recursive = 0, + + ---@type node + first_child = nil, + + ---@type node + last_child = nil, + + ---@type node + prev_sibling = nil, + + ---@type node + next_sibling = nil +} + +---@param self node +---@return boolean +function node.remove_from_parent(self) end + +---@param self node +---@return integer +function node.remove_all_children(self) end + +---@param self node +---@param child node +---@return boolean +function node.add_child(self, child) end + +---@param self node +---@param child node +---@return boolean +function node.add_child_to_back(self, child) end + +---@param self node +---@param child node +---@return boolean +function node.add_child_to_front(self, child) end + +---@param self node +---@param before node +---@param child node +---@return boolean +function node.add_child_before(self, before, child) end + +---@param self node +---@param after node +---@param child node +---@return boolean +function node.add_child_after(self, after, child) end + +---@param self node +---@param sibling node +---@return boolean +function node.add_sibling_before(self, sibling) end + +---@param self node +---@param sibling node +---@return boolean +function node.add_sibling_after(self, sibling) end + +---@param self node +---@param child node +---@return boolean +function node.remove_child(self, child) end + +---@param self node +---@return boolean +function node.send_backward(self) end + +---@param self node +---@return boolean +function node.bring_to_back(self) end + +---@param self node +---@return boolean +function node.send_forward(self) end + +---@param self node +---@return boolean +function node.bring_to_front(self) end + +---@type node +_G.node = _G.node or node diff --git a/samples/bin/library/scripts/emmy/high/world.lua b/samples/bin/library/scripts/emmy/high/world.lua new file mode 100644 index 00000000..3848e316 --- /dev/null +++ b/samples/bin/library/scripts/emmy/high/world.lua @@ -0,0 +1,15 @@ +---@class world +local world = { +} + +---@overload fun(): gobject +---@overload fun(prefab: prefab): gobject +---@overload fun(parent: node): gobject +---@overload fun(prefab: prefab, parent: node): gobject +---@overload fun(parent: node, transform: t3f): gobject +---@overload fun(prefab: prefab, parent: node, transform: t3f): gobject +---@return gobject +function world:instantiate(...) end + +---@type world +_G.the_world = _G.the_world or world diff --git a/sources/enduro2d/high/bindings/core_binds/dbgui_binds.cpp b/sources/enduro2d/high/bindings/core_binds/dbgui_binds.cpp index 91a68dd3..b347277a 100644 --- a/sources/enduro2d/high/bindings/core_binds/dbgui_binds.cpp +++ b/sources/enduro2d/high/bindings/core_binds/dbgui_binds.cpp @@ -13,8 +13,12 @@ namespace e2d::bindings::core sol::no_constructor, "visible", sol::property( - &dbgui::visible, - &dbgui::toggle_visible) + [](const dbgui& d) -> bool { + return d.visible(); + }, + [](dbgui& d, bool yesno){ + d.toggle_visible(yesno); + }) ); } } diff --git a/sources/enduro2d/high/bindings/core_binds/engine_binds.cpp b/sources/enduro2d/high/bindings/core_binds/engine_binds.cpp index bb7d2c74..2adae78c 100644 --- a/sources/enduro2d/high/bindings/core_binds/engine_binds.cpp +++ b/sources/enduro2d/high/bindings/core_binds/engine_binds.cpp @@ -12,11 +12,25 @@ namespace e2d::bindings::core l.new_usertype("engine", sol::no_constructor, - "time", sol::property(&engine::time), - "delta_time", sol::property(&engine::delta_time), - "frame_rate", sol::property(&engine::frame_rate), - "frame_count", sol::property(&engine::frame_count), - "realtime_time", sol::property(&engine::realtime_time) + "time", sol::property([](const engine& e) -> f32 { + return e.time(); + }), + + "delta_time", sol::property([](const engine& e) -> f32 { + return e.delta_time(); + }), + + "frame_rate", sol::property([](const engine& e) -> u32 { + return e.frame_rate(); + }), + + "frame_count", sol::property([](const engine& e) -> u32 { + return e.frame_count(); + }), + + "realtime_time", sol::property([](const engine& e) -> f32 { + return e.realtime_time(); + }) ); } } diff --git a/sources/enduro2d/high/bindings/core_binds/input_binds.cpp b/sources/enduro2d/high/bindings/core_binds/input_binds.cpp index 8269d2fc..b32deee0 100644 --- a/sources/enduro2d/high/bindings/core_binds/input_binds.cpp +++ b/sources/enduro2d/high/bindings/core_binds/input_binds.cpp @@ -39,26 +39,39 @@ namespace e2d::bindings::core l.new_usertype("input", sol::no_constructor, - "mouse", sol::property(&input::mouse), - "keyboard", sol::property(&input::keyboard) + "mouse", sol::property([](const input& i) -> const mouse& { + return i.mouse(); + }), + + "keyboard", sol::property([](const input& i) -> const keyboard& { + return i.keyboard(); + }) ); l.new_usertype("mouse", sol::no_constructor, - "cursor_pos", sol::property([](const mouse& m){ + "cursor_pos", sol::property([](const mouse& m) -> v2f { return m.cursor_pos(); }), - "scroll_delta", sol::property([](const mouse& m){ + "scroll_delta", sol::property([](const mouse& m) -> v2f { return m.scroll_delta(); }), - "is_any_button_pressed", sol::property(&mouse::is_any_button_pressed), - "is_any_button_just_pressed", sol::property(&mouse::is_any_button_just_pressed), - "is_any_button_just_released", sol::property(&mouse::is_any_button_just_released), + "is_any_button_pressed", sol::property([](const mouse& m) -> bool { + return m.is_any_button_pressed(); + }), - "is_button_pressed", [](const mouse& m, const char* n){ + "is_any_button_just_pressed", sol::property([](const mouse& m) -> bool { + return m.is_any_button_just_pressed(); + }), + + "is_any_button_just_released", sol::property([](const mouse& m) -> bool { + return m.is_any_button_just_released(); + }), + + "is_button_pressed", [](const mouse& m, str_view n) -> bool { mouse_button btn = mouse_button::unknown; if ( parse_mouse_button(n, btn) ) { return m.is_button_pressed(btn); @@ -70,7 +83,7 @@ namespace e2d::bindings::core return false; }, - "is_button_just_pressed", [](const mouse& m, const char* n){ + "is_button_just_pressed", [](const mouse& m, str_view n) -> bool { mouse_button btn = mouse_button::unknown; if ( parse_mouse_button(n, btn) ) { return m.is_button_just_pressed(btn); @@ -82,7 +95,7 @@ namespace e2d::bindings::core return false; }, - "is_button_just_released", [](const mouse& m, const char* n){ + "is_button_just_released", [](const mouse& m, str_view n) -> bool { mouse_button btn = mouse_button::unknown; if ( parse_mouse_button(n, btn) ) { return m.is_button_just_released(btn); @@ -94,15 +107,15 @@ namespace e2d::bindings::core return false; }, - "pressed_buttons", sol::property([](const mouse& m){ + "pressed_buttons", sol::property([](const mouse& m) -> vector { return convert_buttons_to_strings(m.pressed_buttons()); }), - "just_pressed_buttons", sol::property([](const mouse& m){ + "just_pressed_buttons", sol::property([](const mouse& m) -> vector { return convert_buttons_to_strings(m.just_pressed_buttons()); }), - "just_released_buttons", sol::property([](const mouse& m){ + "just_released_buttons", sol::property([](const mouse& m) -> vector { return convert_buttons_to_strings(m.just_released_buttons()); }) ); @@ -110,15 +123,23 @@ namespace e2d::bindings::core l.new_usertype("keyboard", sol::no_constructor, - "input_text", sol::property([](const keyboard& k){ + "input_text", sol::property([](const keyboard& k) -> str { return make_utf8(k.input_text()); }), - "is_any_key_pressed", sol::property(&keyboard::is_any_key_pressed), - "is_any_key_just_pressed", sol::property(&keyboard::is_any_key_just_pressed), - "is_any_key_just_released", sol::property(&keyboard::is_any_key_just_released), + "is_any_key_pressed", sol::property([](const keyboard& k) -> bool { + return k.is_any_key_pressed(); + }), - "is_key_pressed", [](const keyboard& k, const char* n){ + "is_any_key_just_pressed", sol::property([](const keyboard& k) -> bool { + return k.is_any_key_just_pressed(); + }), + + "is_any_key_just_released", sol::property([](const keyboard& k) -> bool { + return k.is_any_key_just_released(); + }), + + "is_key_pressed", [](const keyboard& k, str_view n) -> bool { keyboard_key key = keyboard_key::unknown; if ( parse_keyboard_key(n, key) ) { return k.is_key_pressed(key); @@ -130,7 +151,7 @@ namespace e2d::bindings::core return false; }, - "is_key_just_pressed", [](const keyboard& k, const char* n){ + "is_key_just_pressed", [](const keyboard& k, str_view n) -> bool { keyboard_key key = keyboard_key::unknown; if ( parse_keyboard_key(n, key) ) { return k.is_key_just_pressed(key); @@ -142,7 +163,7 @@ namespace e2d::bindings::core return false; }, - "is_key_just_released", [](const keyboard& k, const char* n){ + "is_key_just_released", [](const keyboard& k, str_view n) -> bool { keyboard_key key = keyboard_key::unknown; if ( parse_keyboard_key(n, key) ) { return k.is_key_just_released(key); @@ -154,15 +175,15 @@ namespace e2d::bindings::core return false; }, - "pressed_keys", sol::property([](const keyboard& k){ + "pressed_keys", sol::property([](const keyboard& k) -> vector { return convert_keys_to_strings(k.pressed_keys()); }), - "just_pressed_keys", sol::property([](const keyboard& k){ + "just_pressed_keys", sol::property([](const keyboard& k) -> vector { return convert_keys_to_strings(k.just_pressed_keys()); }), - "just_released_keys", sol::property([](const keyboard& k){ + "just_released_keys", sol::property([](const keyboard& k) -> vector { return convert_keys_to_strings(k.just_released_keys()); }) ); diff --git a/sources/enduro2d/high/bindings/core_binds/window_binds.cpp b/sources/enduro2d/high/bindings/core_binds/window_binds.cpp index 325d1d63..149c4f40 100644 --- a/sources/enduro2d/high/bindings/core_binds/window_binds.cpp +++ b/sources/enduro2d/high/bindings/core_binds/window_binds.cpp @@ -12,19 +12,45 @@ namespace e2d::bindings::core l.new_usertype("window", sol::no_constructor, - "hide", &window::hide, - "show", &window::show, - "restore", &window::restore, - "minimize", &window::minimize, + "hide", [](window& w) { + w.hide(); + }, - "enabled", sol::property(&window::enabled), - "visible", sol::property(&window::visible), - "focused", sol::property(&window::focused), - "minimized", sol::property(&window::minimized), + "show", [](window& w) { + w.show(); + }, + + "restore", [](window& w) { + w.restore(); + }, + + "minimize", [](window& w) { + w.minimize(); + }, + + "enabled", sol::property([](const window& w) -> bool { + return w.enabled(); + }), + + "visible", sol::property([](const window& w) -> bool { + return w.visible(); + }), + + "focused", sol::property([](const window& w) -> bool { + return w.focused(); + }), + + "minimized", sol::property([](const window& w) -> bool { + return w.minimized(); + }), "fullscreen", sol::property( - &window::fullscreen, - &window::toggle_fullscreen), + [](const window& w) -> bool { + return w.fullscreen(); + }, + [](window& w, bool yesno){ + w.toggle_fullscreen(yesno); + }), "cursor_hidden", sol::property( &window::is_cursor_hidden, @@ -36,25 +62,33 @@ namespace e2d::bindings::core } }), - "real_size", sol::property([](const window& w){ + "real_size", sol::property([](const window& w) -> v2f { return w.real_size().cast_to(); }), - "virtual_size", sol::property([](const window& w){ + "virtual_size", sol::property([](const window& w) -> v2f { return w.virtual_size().cast_to(); }), - "framebuffer_size", sol::property([](const window& w){ + "framebuffer_size", sol::property([](const window& w) -> v2f { return w.framebuffer_size().cast_to(); }), "title", sol::property( - &window::title, - &window::set_title), + [](const window& w) -> str { + return w.title(); + }, + [](window& w, str_view t){ + w.set_title(t); + }), "should_close", sol::property( - &window::should_close, - &window::set_should_close) + [](const window& w) -> bool { + return w.should_close(); + }, + [](window& w, bool yesno){ + w.set_should_close(yesno); + }) ); } } diff --git a/sources/enduro2d/high/bindings/high_binds/components/actor_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/actor_binds.cpp index 0914fef3..9a29df58 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/actor_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/actor_binds.cpp @@ -1,8 +1,8 @@ /******************************************************************************* -* This file is part of the "Enduro2D" -* For conditions of distribution and use, see copyright notice in LICENSE.md -* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) -******************************************************************************/ + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ #include "../_high_binds.hpp" @@ -12,10 +12,12 @@ namespace e2d::bindings::high { void bind_actor(sol::state& l) { - l["e2d"].get_or_create() - ["components"].get_or_create() - .new_usertype>("actor", - "node", sol::property([](const gcomponent& a){ return a->node(); }) + l.new_usertype>("actor", + sol::no_constructor, + + "node", sol::property([](gcomponent& c) -> node_iptr { + return c->node(); + }) ); } } diff --git a/sources/enduro2d/high/bindings/high_binds/components/behaviour_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/behaviour_binds.cpp index 3e460c6b..4e4aeeac 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/behaviour_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/behaviour_binds.cpp @@ -1,23 +1,58 @@ /******************************************************************************* -* This file is part of the "Enduro2D" -* For conditions of distribution and use, see copyright notice in LICENSE.md -* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) -******************************************************************************/ + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ #include "../_high_binds.hpp" #include #include +#include namespace e2d::bindings::high { void bind_behaviour(sol::state& l) { - l["e2d"].get_or_create() - ["components"].get_or_create() - .new_usertype>("behaviour", - "meta", sol::property( - [](const gcomponent& b){ return b->meta(); }, - [](gcomponent& b, sol::table v){ b->meta(std::move(v)); }) + l.new_usertype>("behaviour", + sol::no_constructor, + + "enable", [](gcomponent& c){ + c.owner().component>().remove(); + }, + + "disable", [](gcomponent& c){ + c.owner().component>().ensure(); + }, + + "enabled", sol::property( + [](const gcomponent& c) -> bool { + return !c.owner().component>().exists(); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + c.owner().component>().remove(); + } else { + c.owner().component>().ensure(); + } + } + ), + + "disabled", sol::property( + [](const gcomponent& c) -> bool { + return c.owner().component>().exists(); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + c.owner().component>().ensure(); + } else { + c.owner().component>().remove(); + } + } + ), + + "meta", sol::property([](const gcomponent& c) -> sol::table { + return c->meta(); + }) ); } } diff --git a/sources/enduro2d/high/bindings/high_binds/components/camera_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/camera_binds.cpp index a8324096..fadae356 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/camera_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/camera_binds.cpp @@ -1,35 +1,86 @@ /******************************************************************************* -* This file is part of the "Enduro2D" -* For conditions of distribution and use, see copyright notice in LICENSE.md -* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) -******************************************************************************/ + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ #include "../_high_binds.hpp" #include #include +#include namespace e2d::bindings::high { void bind_camera(sol::state& l) { - l["e2d"].get_or_create() - ["components"].get_or_create() - .new_usertype>("camera", + l.new_usertype>("camera", + sol::no_constructor, + + "enable", [](gcomponent& c){ + c.owner().component>().remove(); + }, + + "disable", [](gcomponent& c){ + c.owner().component>().ensure(); + }, + + "enabled", sol::property( + [](const gcomponent& c) -> bool { + return !c.owner().component>().exists(); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + c.owner().component>().remove(); + } else { + c.owner().component>().ensure(); + } + } + ), + + "disabled", sol::property( + [](const gcomponent& c) -> bool { + return c.owner().component>().exists(); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + c.owner().component>().ensure(); + } else { + c.owner().component>().remove(); + } + } + ), + "depth", sol::property( - [](const gcomponent& b){ return b->depth(); }, - [](gcomponent& b, i32 v){ b->depth(v); }), + [](const gcomponent& c) -> i32 { + return c->depth(); + }, + [](gcomponent& c, i32 v){ + c->depth(v); + }), + "viewport", sol::property( - [](const gcomponent& b){ return b->viewport().cast_to(); }, - [](gcomponent& b, const b2f& v){ b->viewport(v.cast_to()); }), + [](const gcomponent& c) -> b2f { + return c->viewport().cast_to(); + }, + [](gcomponent& c, const b2f& v){ + c->viewport(v.cast_to()); + }), + "projection", sol::property( - [](const gcomponent& b){ return b->projection(); }, - [](gcomponent& b, const m4f& v){ b->projection(v); }), - "target", sol::property( - [](const gcomponent& b){ return b->target(); }, - [](gcomponent& b, const render_target_ptr& v){ b->target(v); }), + [](const gcomponent& c) -> m4f { + return c->projection(); + }, + [](gcomponent& c, const m4f& v){ + c->projection(v); + }), + "background", sol::property( - [](const gcomponent& b){ return b->background(); }, - [](gcomponent& b, const color& v){ b->background(v); }) + [](const gcomponent& c) -> color { + return c->background(); + }, + [](gcomponent& c, const color& v){ + c->background(v); + }) ); } } diff --git a/sources/enduro2d/high/bindings/high_binds/components/flipbook_player_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/flipbook_player_binds.cpp index d3697639..a8b82d28 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/flipbook_player_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/flipbook_player_binds.cpp @@ -1,8 +1,8 @@ /******************************************************************************* -* This file is part of the "Enduro2D" -* For conditions of distribution and use, see copyright notice in LICENSE.md -* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) -******************************************************************************/ + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ #include "../_high_binds.hpp" @@ -12,37 +12,74 @@ namespace e2d::bindings::high { void bind_flipbook_player(sol::state& l) { - l["e2d"].get_or_create() - ["components"].get_or_create() - .new_usertype>("flipbook_player", + l.new_usertype>("flipbook_player", + sol::no_constructor, + "time", sol::property( - [](const gcomponent& b){ return b->time(); }, - [](gcomponent& b, f32 v){ b->time(v); }), + [](const gcomponent& c) -> f32 { + return c->time(); + }, + [](gcomponent& c, f32 v){ + c->time(v); + }), + "speed", sol::property( - [](const gcomponent& b){ return b->speed(); }, - [](gcomponent& b, f32 v){ b->speed(v); }), + [](const gcomponent& c) -> f32 { + return c->speed(); + }, + [](gcomponent& c, f32 v){ + c->speed(v); + }), + "looped", sol::property( - [](const gcomponent& b){ return b->looped(); }, - [](gcomponent& b, bool v){ b->looped(v); }), + [](const gcomponent& c) -> bool { + return c->looped(); + }, + [](gcomponent& c, bool v){ + c->looped(v); + }), + "stopped", sol::property( - [](const gcomponent& b){ return b->stopped(); }, - [](gcomponent& b, bool v){ b->stopped(v); }), + [](const gcomponent& c) -> bool { + return c->stopped(); + }, + [](gcomponent& c, bool v){ + c->stopped(v); + }), + "playing", sol::property( - [](const gcomponent& b){ return b->playing(); }, - [](gcomponent& b, bool v){ b->playing(v); }), + [](const gcomponent& c) -> bool { + return c->playing(); + }, + [](gcomponent& c, bool v) { + c->playing(v); + }), + "sequence", sol::property( - [](const gcomponent& b){ return b->sequence(); }, - [](gcomponent& b, str_hash v){ b->sequence(v); }), + [](const gcomponent& c) -> str_hash { + return c->sequence(); + }, + [](gcomponent& c, str_hash v){ + c->sequence(v); + }), + "flipbook", sol::property( - [](const gcomponent& b){ return b->flipbook(); }, - [](gcomponent& b, const flipbook_asset::ptr& v){ b->flipbook(v); }), + [](const gcomponent& c) -> flipbook_asset::ptr { + return c->flipbook(); + }, + [](gcomponent& c, const flipbook_asset::ptr& v){ + c->flipbook(v); + }), "stop", sol::overload( - [](gcomponent& b, f32 v){ b->stop(v); }, - [](gcomponent& b, str_hash v){ b->stop(v); }), + [](gcomponent& c, f32 v){ c->stop(v); }, + [](gcomponent& c, str_view v){ c->stop(v); }, + [](gcomponent& c, str_hash v){ c->stop(v); }), + "play", sol::overload( - [](gcomponent& b, f32 v){ b->play(v); }, - [](gcomponent& b, str_hash v){ b->play(v); }) + [](gcomponent& c, f32 v){ c->play(v); }, + [](gcomponent& c, str_view v){ c->play(v); }, + [](gcomponent& c, str_hash v){ c->play(v); }) ); } } diff --git a/sources/enduro2d/high/bindings/high_binds/components/label_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/label_binds.cpp index cf1c19d2..3a887d36 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/label_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/label_binds.cpp @@ -1,8 +1,8 @@ /******************************************************************************* -* This file is part of the "Enduro2D" -* For conditions of distribution and use, see copyright notice in LICENSE.md -* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) -******************************************************************************/ + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ #include "../_high_binds.hpp" @@ -12,102 +12,111 @@ namespace e2d::bindings::high { void bind_label(sol::state& l) { - l["e2d"].get_or_create() - ["components"].get_or_create() - .new_usertype>("label", + l.new_usertype>("label", + sol::no_constructor, + "text", sol::property( - [](const gcomponent