From 828eee340929573cfc4045f8c28d24b775f99e89 Mon Sep 17 00:00:00 2001 From: ne_mene Date: Tue, 31 Mar 2026 14:58:00 +0200 Subject: speck editor: saving --- src/scenes/speck_editor.lua | 53 +++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/scenes/speck_editor.lua b/src/scenes/speck_editor.lua index 6dbc605..96176d0 100644 --- a/src/scenes/speck_editor.lua +++ b/src/scenes/speck_editor.lua @@ -1,22 +1,7 @@ -function start_speck_editor() - local scn = new_scene() - set_scene(scn) - - event_bind(scn.on_update, "Speck_System", speck_update_sys) - - event_bind(scn.on_draw, "Speck_System", speck_draw_sys) - - event_bind(scn.on_ui, "Speck_Editor", speck_editor_ui_sys) - - local editor = new_entity() - add_comp(editor, "Position", SCR_WIDTH/2, SCR_HEIGHT/2) - add_comp(editor, "Speck_Editor") - return scn -end - register_comp("Speck_Editor", function (editor) - add_comp(editor, "Speck_System", "res/speck/test.speck.lua") + editor.filepath = "res/speck/test.speck.lua" + add_comp(editor, "Speck_System", editor.filepath) end) local PROPERTY_CUSTOM = { @@ -64,12 +49,16 @@ local PROPERTY_TYPES = { end } -function speck_editor_ui_sys(editor) +local function save(editor) + export_speck_sys(editor.speck_sys, editor.filepath) +end + +local function speck_editor_ui_sys(editor) local system = editor.speck_sys im.begin_window("Speck Editor", 5, 5, 256, 1024, {}) im.text("Properties:") - for i, prop in ipairs(SPECK_EXPORTED_ARGS) do + for _, prop in ipairs(SPECK_EXPORTED_ARGS) do local func = PROPERTY_TYPES[type(system[prop])] if func then system[prop] = func(prop, system[prop], PROPERTY_CUSTOM[prop]) @@ -77,10 +66,32 @@ function speck_editor_ui_sys(editor) end im.text("File:") + -- TODO: implement these guys im.button("New") im.button("Open") - im.button("Save as") - im.button("Save") + + if im.button("Save as") then + save(editor) + end + if im.button("Save") then + save(editor) + end im.end_window() end + +function start_speck_editor() + local scn = new_scene() + set_scene(scn) + + event_bind(scn.on_update, "Speck_System", speck_update_sys) + + event_bind(scn.on_draw, "Speck_System", speck_draw_sys) + + event_bind(scn.on_ui, "Speck_Editor", speck_editor_ui_sys) + + local editor = new_entity() + add_comp(editor, "Position", SCR_WIDTH/2, SCR_HEIGHT/2) + add_comp(editor, "Speck_Editor") + return scn +end -- cgit v1.3-2-g0d8e