Compare commits

...

5 Commits

Author SHA1 Message Date
red-001 c238449cbe hack together csm support 2017-03-19 19:43:36 +00:00
red-001 066a130558 add back init 2017-03-19 19:22:07 +00:00
red-001 f21d03735e remove init 2017-03-19 19:21:45 +00:00
octacian e8871b4f1a Form Editor: Rework formspec 2017-02-04 19:24:21 -08:00
octacian d64fcbb740 Add formspec editor 2017-02-04 18:53:32 -08:00
7 changed files with 89 additions and 17 deletions

View File

@ -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

View File

@ -1 +0,0 @@
not_in_creative = 1

6
doc/form_editor.md Normal file
View File

@ -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

View File

@ -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)

View File

@ -1 +0,0 @@
name = debugger

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B