Fix autorun checkbox state tracking

This commit is contained in:
luk3yx 2024-01-22 21:55:53 +13:00
parent 859a2c5a7b
commit 31f7314591
1 changed files with 10 additions and 2 deletions

View File

@ -97,7 +97,13 @@ function snippets.update_console(name)
minetest.formspec_escape(snippet .. ', owner: ' .. owner) .. ';' .. minetest.formspec_escape(snippet .. ', owner: ' .. owner) .. ';' ..
code .. ']' code .. ']'
if selected_snippet then if selected_snippet then
formspec = formspec .. 'checkbox[12.7,5.05;autorun;Autorun;'..tostring(def and (def.autorun or false))..']' local autorun
if form.context.autorun == nil then
autorun = def and def.autorun or false
else
autorun = form.context.autorun
end
formspec = formspec .. 'checkbox[12.7,5.05;autorun;Autorun;' .. tostring(autorun) .. ']'
end end
form:set_formspec(formspec) form:set_formspec(formspec)
@ -194,6 +200,7 @@ local function saveform_callback(saveform, fields)
owner = name, owner = name,
code = form.context.code, code = form.context.code,
persistent = true, persistent = true,
autorun = form.context.autorun
}) })
form.context.selected_snippet = filename form.context.selected_snippet = filename
@ -231,6 +238,7 @@ function callback(form, fields)
if form.context.selected_snippet == selected then return end if form.context.selected_snippet == selected then return end
form.context.selected_snippet = selected form.context.selected_snippet = selected
form.context.text = nil form.context.text = nil
form.context.autorun = nil
local def = snippets.registered_snippets[selected] local def = snippets.registered_snippets[selected]
form.context.code = def and def.code or '' form.context.code = def and def.code or ''
snippets.update_console(name) snippets.update_console(name)
@ -256,7 +264,7 @@ function callback(form, fields)
saveform:add_callback(saveform_callback) saveform:add_callback(saveform_callback)
saveform:show() saveform:show()
elseif fields.autorun and form.context.selected_snippet then elseif fields.autorun and form.context.selected_snippet then
form.context.autorun = fields.autorun == "true" form.context.autorun = minetest.is_yes(fields.autorun)
elseif fields.quit then elseif fields.quit then
form.text = nil form.text = nil
end end