Compare commits
5 Commits
72c7788e95
...
c238449cbe
Author | SHA1 | Date |
---|---|---|
|
c238449cbe | |
|
066a130558 | |
|
f21d03735e | |
|
e8871b4f1a | |
|
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 +0,0 @@
|
|||
not_in_creative = 1
|
|
@ -0,0 +1,6 @@
|
|||
![Demo Image](screenshots/form_editor.png)
|
||||
|
||||
# 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.
|
Binary file not shown.
After Width: | Height: | Size: 380 KiB |
88
init.lua
88
init.lua
|
@ -1,10 +1,7 @@
|
|||
-- debugger/init.lua
|
||||
|
||||
local modstorage = core.get_mod_storage()
|
||||
debugger = {}
|
||||
|
||||
debugger.modpath = minetest.get_modpath("debugger")
|
||||
local modpath = debugger.modpath
|
||||
|
||||
-- Logger
|
||||
function debugger.log(content, log_type)
|
||||
assert(content, "debugger.log: content nil")
|
||||
|
@ -12,11 +9,82 @@ function debugger.log(content, log_type)
|
|||
minetest.log(log_type, "[debugger] "..content)
|
||||
end
|
||||
|
||||
-- Load Settings
|
||||
local Settings = Settings(modpath.."/config.txt"):to_table()
|
||||
debugger.CREATIVE = 1
|
||||
|
||||
if Settings then
|
||||
debugger.CREATIVE = Settings.not_in_creative or 1
|
||||
else
|
||||
debugger.CREATIVE = 1
|
||||
local forms = {}
|
||||
|
||||
-- Load forms
|
||||
local function load_formdata()
|
||||
local res = minetest.deserialize(modstorage:get_string("forms"))
|
||||
if type(res) == "table" then
|
||||
forms = res
|
||||
end
|
||||
end
|
||||
|
||||
-- Load all forms
|
||||
load_formdata()
|
||||
|
||||
-- Save forms
|
||||
function save_formdata()
|
||||
modstorage:set_string("forms", 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]
|
||||
box[-0.27,-0.3;13,12.68;#FFFFFF00]
|
||||
]]..table.concat(output)..[[
|
||||
textarea[13.03,-0.35;7.58,13.9;input;;]]..minetest.formspec_escape(form_string)..[[]
|
||||
button[12.75,11.64;2.5,1;refresh;Refresh and Save]
|
||||
label[15.3,11.8;Elements are separated by a newline.]
|
||||
]]
|
||||
end
|
||||
|
||||
-- Register chatcommand
|
||||
minetest.register_chatcommand("form_editor", {
|
||||
param = "<edit/preview>",
|
||||
description = "Formspec Creator",
|
||||
privs = {debug=true},
|
||||
func = function(param)
|
||||
local name = "fake_player"
|
||||
local form_string = forms[name] or ""
|
||||
print(param)
|
||||
if param == "preview" then
|
||||
-- Show formspec
|
||||
minetest.show_formspec("debugger:form_preview", form_string)
|
||||
else
|
||||
-- Show formspec editor
|
||||
minetest.show_formspec("debugger:form_editor", get_editor_formspec(name))
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- [event] On Receive Fields
|
||||
minetest.register_on_formspec_input(function(formname, fields)
|
||||
print(formname)
|
||||
print(dump(fields))
|
||||
if formname == "debugger:form_editor" then
|
||||
local name = "fake_player"
|
||||
|
||||
if fields.refresh then
|
||||
forms[name] = fields.input
|
||||
|
||||
-- Update formspec editor
|
||||
minetest.show_formspec("debugger:form_editor", get_editor_formspec(name))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 255 B |
Loading…
Reference in New Issue