diff options
| author | ne_mene <[email protected]> | 2026-04-02 13:23:18 +0200 |
|---|---|---|
| committer | ne_mene <[email protected]> | 2026-04-02 13:23:18 +0200 |
| commit | 70c035688f47ced28a5fc10b56250e34d998b61b (patch) | |
| tree | 190e0e6654bd2486dbc1a8588afafc3414d939a0 /src | |
| parent | 474f1fcc62c67667d83895cb7cd34fa30c166a0d (diff) | |
speck editor: prop refactor, file prop changing
Diffstat (limited to 'src')
| -rw-r--r-- | src/scenes/speck_editor.lua | 135 |
1 files changed, 72 insertions, 63 deletions
diff --git a/src/scenes/speck_editor.lua b/src/scenes/speck_editor.lua index 573914e..1484abe 100644 --- a/src/scenes/speck_editor.lua +++ b/src/scenes/speck_editor.lua @@ -1,61 +1,71 @@ - -register_comp("Speck_Editor", function (editor) +register_comp("Speck_Editor", function(editor) editor.filepath = "res/speck/test.speck.lua" add_comp(editor, "Speck_System", editor.filepath) end) local PROPERTY_CUSTOM = { - spawn_shape = {"Point", "Circle", "Rectangle"}, - spawn_amount_min = {min = 1, max = 64, step = 1}, - spawn_amount_max = {min = 1, max = 64, step = 1}, - spawn_width = {min = 0, max = 1024, step = 1}, - spawn_height = {min = 0, max = 1024, step = 1}, - spawn_radius = {min = 0, max = 1024, step = 1}, - scale_curve = {}, - scale_start_min = {min = 0, max = 16}, - scale_start_max = {min = 0, max = 16}, - forcex = {min = -2048, max = 2048}, - forcey = {min = -2048, max = 2048}, - damping = {min = 0, max = 128}, - initial_velx_max = {min = 0, max = 2048}, - initial_velx_min = {min = 0, max = 2048}, - initial_vely_max = {min = 0, max = 2048}, - initial_vely_min = {min = 0, max = 2048}, - spread = {min = 0, max = 360}, - lifetime_min = {min = 0, max = 32}, - lifetime_max = {min = 0, max = 32}, - interval = {min = 0, max = 32, step = 0.01}, - texture_path = {}, - gradient = {}, + spawn_shape = { "Point", "Circle", "Rectangle" }, + spawn_amount_min = { min = 1, max = 64, step = 1 }, + spawn_amount_max = { min = 1, max = 64, step = 1 }, + spawn_width = { min = 0, max = 1024, step = 1 }, + spawn_height = { min = 0, max = 1024, step = 1 }, + spawn_radius = { min = 0, max = 1024, step = 1 }, + scale_curve = {}, + scale_start_min = { min = 0, max = 16 }, + scale_start_max = { min = 0, max = 16 }, + forcex = { min = -2048, max = 2048 }, + forcey = { min = -2048, max = 2048 }, + damping = { min = 0, max = 128 }, + initial_velx_max = { min = 0, max = 2048 }, + initial_velx_min = { min = 0, max = 2048 }, + initial_vely_max = { min = 0, max = 2048 }, + initial_vely_min = { min = 0, max = 2048 }, + spread = { min = 0, max = 360 }, + lifetime_min = { min = 0, max = 32 }, + lifetime_max = { min = 0, max = 32 }, + interval = { min = 0, max = 32, step = 0.01 }, + texture_path = { is_file = true, directory = "res/img/" }, + gradient = { is_file = true, directory = "res/img/" }, } for key, _ in pairs(EASING_FUNCTIONS) do - PROPERTY_CUSTOM.scale_curve[#PROPERTY_CUSTOM.scale_curve+1] = key + PROPERTY_CUSTOM.scale_curve[#PROPERTY_CUSTOM.scale_curve + 1] = key end local PROPERTY_TYPES = { - ["number"] = function (name, value, custom) + ["number"] = function(props, name, value, custom) custom = custom or {} - im.layout({0.5, 1}) + im.layout({ 0.5, 1 }) im.text(name) im.text(tostring(value)) im.layout() - return im.slider(value, custom.min or 0, custom.max or 1, custom.step or 0.1) + props[name] = im.slider(value, custom.min or 0, custom.max or 1, custom.step or 0.1) end, - ["boolean"] = function (name, value, _) - im.layout({0.25, 0.5, 1}) + ["boolean"] = function(props, name, value) + im.layout({ 0.25, 0.5, 1 }) im.text(name) im.text(tostring(value)) if im.button("Toggle") then - return not value + props[name] = not value end end, - ["string"] = function (name, value) - im.layout({0.25, 1}) + ["string"] = function(props, name, value, custom) + im.layout({ 0.25, 0.8, 1 }) im.text(name) im.text(value) + if custom.is_file then + if im.button("Change") then + + lw.showFileDialog("openfile", function(files, _, _) + if not files[1] or files[1] == "" then + return + end + + props[name] = trunc_filename_to_res(files[1]) + end, { defaultname = custom.directory or "" }) + end + end im.layout() - return value end, } @@ -67,40 +77,39 @@ local function speck_editor_ui_sys(editor) local system = editor.speck_sys im.begin_window("Speck Editor", 5, 5, 400, 1024, {}) - im.text("Properties:") - 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]) - end + im.text("Properties:") + for _, prop in ipairs(SPECK_EXPORTED_ARGS) do + local func = PROPERTY_TYPES[type(system[prop])] + if func then + func(editor.speck_sys, prop, system[prop], PROPERTY_CUSTOM[prop]) end + end - im.text("File:") - if im.button("Open") then - editor.filepath = lw.showFileDialog("savefile", function (files, _, _) - if not files[1] or files[1] == "" then - return - end - - editor.filepath = trunc_filename_to_res(files[1]) - editor.speck_sys = load_speck_sys_non_cached(editor.filepath) + im.text("File:") + if im.button("Open") then + editor.filepath = lw.showFileDialog("savefile", function(files, _, _) + if not files[1] or files[1] == "" then + return + end - end, {defaultname = "res/speck/"}) - end + editor.filepath = trunc_filename_to_res(files[1]) + editor.speck_sys = load_speck_sys_non_cached(editor.filepath) + end, { defaultname = "res/speck/" }) + end - if im.button("Save as") then - editor.filepath = lw.showFileDialog("savefile", function (files, _, _) - if not files[1] or files[1] == "" then - return - end + if im.button("Save as") then + editor.filepath = lw.showFileDialog("savefile", function(files, _, _) + if not files[1] or files[1] == "" then + return + end - editor.filepath = trunc_filename_to_res(files[1]) - save(editor) - end, {defaultname = "res/speck/"}) - end - if im.button("Save") then + editor.filepath = trunc_filename_to_res(files[1]) save(editor) - end + end, { defaultname = "res/speck/" }) + end + if im.button("Save") then + save(editor) + end im.end_window() end @@ -116,7 +125,7 @@ function start_speck_editor() 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, "Position", SCR_WIDTH / 2, SCR_HEIGHT / 2) add_comp(editor, "Speck_Editor") return scn end |
