Add formspec editor
This commit is contained in:
parent
72c7788e95
commit
d64fcbb740
10
README.md
10
README.md
@ -6,8 +6,8 @@ This is meant to be a simple tool for developers to use while attempting to debu
|
||||
Future tools and/or buttons are hidden from the creative inventory by default. To allow access in creative rather than just via `/giveme`, set `not_in_creative` to `0` in the `config.txt`.
|
||||
|
||||
### Planned Features
|
||||
* Meta/Inv Editor
|
||||
* Run Lua Code Under Environment (server won't crash)
|
||||
* In-Game Formspec Editor
|
||||
* In-Game HUD Editor (?)
|
||||
* ..and possibly more
|
||||
- [ ] Meta/Inv Editor
|
||||
- [ ] Run Lua Code Under Environment (server won't crash)
|
||||
- [x] In-Game Formspec Editor (doc/form_editor.md)
|
||||
- [ ] In-Game HUD Editor (?)
|
||||
<br /> ..and possibly more
|
@ -1 +1,2 @@
|
||||
not_in_creative = 1
|
||||
formspec_editor = true
|
||||
|
6
doc/form_editor.md
Normal file
6
doc/form_editor.md
Normal file
@ -0,0 +1,6 @@
|
||||

|
||||
|
||||
# Formspec Editor
|
||||
The formspec editor is a very simple tool for the purpose of making formspec creation easier. Traditionally, you would have to reload Minetest every time you made the smallest change. However, with this formspec editor, simply put your formspec in the textarea, click refresh, and the formspec will be displayed on the right.
|
||||
|
||||
The formspec editor can be accessed in two ways. You can get the "Formspec Editor" item in the creative inventory or with `/giveme debugger:form_editor`, then left-click to edit or right-click to preview the form without the editor interface. You can also use the chatcommand `/form_editor` to access the editor. This command requires that you have the `debug` privilege. Providing no parameters or `edit` will show the editor, while `preview` will show the form without the editor interface.
|
BIN
doc/screenshots/form_editor.png
Normal file
BIN
doc/screenshots/form_editor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 526 KiB |
103
form_editor.lua
Normal file
103
form_editor.lua
Normal file
@ -0,0 +1,103 @@
|
||||
-- debugger/form_editor.lua
|
||||
|
||||
local forms = {}
|
||||
local path = minetest.get_worldpath()
|
||||
|
||||
-- Load forms
|
||||
local function load_formdata()
|
||||
local res = io.open(path.."/debugger_form_editor.txt", "r")
|
||||
if res then
|
||||
res = minetest.deserialize(res:read("*all"))
|
||||
if type(res) == "table" then
|
||||
forms = res
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Load all forms
|
||||
load_formdata()
|
||||
|
||||
-- Save forms
|
||||
function save_formdata()
|
||||
io.open(path.."/debugger_form_editor.txt", "w"):write(minetest.serialize(forms))
|
||||
end
|
||||
|
||||
-- Register on shutdown
|
||||
minetest.register_on_shutdown(save_formdata)
|
||||
|
||||
-- Editor formspec
|
||||
local function get_editor_formspec(name)
|
||||
local form_string = forms[name] or ""
|
||||
|
||||
local output = form_string:split("\n")
|
||||
|
||||
for i, line in ipairs(output) do
|
||||
output[i] = line
|
||||
end
|
||||
|
||||
return [[
|
||||
size[20,12]
|
||||
textarea[0,0;10.38,13.5;input;Form String (Separate elements with newline);]]..minetest.formspec_escape(form_string)..[[]
|
||||
button[-0.26,11.62;4,1;refresh;Refresh and Save]
|
||||
box[9.95,0;10,11.69;#FFFFFF00]
|
||||
container[10,0]
|
||||
]]..table.concat(output)..[[
|
||||
container_end[]
|
||||
]]
|
||||
end
|
||||
|
||||
-- Register chatcommand
|
||||
minetest.register_chatcommand("form_editor", {
|
||||
param = "<edit/preview>",
|
||||
description = "Formspec Creator",
|
||||
privs = {debug=true},
|
||||
func = function(name, param)
|
||||
local form_string = forms[name] or ""
|
||||
|
||||
if param == "preview" then
|
||||
-- Show formspec
|
||||
minetest.show_formspec(name, "debugger:form_preview", form_string)
|
||||
else
|
||||
-- Show formspec editor
|
||||
minetest.show_formspec(name, "debugger:form_editor", get_editor_formspec(name))
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Register tool
|
||||
minetest.register_craftitem("debugger:form_editor", {
|
||||
description = "[DEBUG] Formspec Editor",
|
||||
inventory_image = "debugger_form_editor.png",
|
||||
stack_max = 1,
|
||||
groups = { not_in_creative_inventory = debugger.CREATIVE },
|
||||
|
||||
-- [on_use] Show editor
|
||||
on_use = function(itemstack, player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- Show formspec editor
|
||||
minetest.show_formspec(name, "debugger:form_editor", get_editor_formspec(name))
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, player)
|
||||
local name = player:get_player_name()
|
||||
local form_string = forms[name] or ""
|
||||
|
||||
-- Show formspec
|
||||
minetest.show_formspec(name, "debugger:form_preview", form_string)
|
||||
end,
|
||||
})
|
||||
|
||||
-- [event] On Receive Fields
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "debugger:form_editor" then
|
||||
local name = player:get_player_name()
|
||||
|
||||
if fields.refresh then
|
||||
forms[name] = fields.input
|
||||
|
||||
-- Update formspec editor
|
||||
minetest.show_formspec(name, "debugger:form_editor", get_editor_formspec(name))
|
||||
end
|
||||
end
|
||||
end)
|
5
init.lua
5
init.lua
@ -20,3 +20,8 @@ if Settings then
|
||||
else
|
||||
debugger.CREATIVE = 1
|
||||
end
|
||||
|
||||
-- Load formspec editor
|
||||
if Settings.formspec_editor ~= false then
|
||||
dofile(modpath.."/form_editor.lua")
|
||||
end
|
||||
|
BIN
textures/debugger_form_editor.png
Normal file
BIN
textures/debugger_form_editor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 255 B |
Loading…
x
Reference in New Issue
Block a user