Formspec json

From Minetest Developer Wiki
Jump to: navigation, search

Currently the formspec is described in a bad format:

 "size[1,2]"..
 "image[5,6;7,8;b.png]"..
 "background[10,11;12,13;a.png]"

A way to fix this would be to use a JSON-based formspec description language:

 {
   {"type": "size", "x": 1,"y": 2},
   {"type": "image", "x": 5, "y": 6, "w": 7, "h": 8, "image": "b.png"},
   {"type": "background", "x": 10, "y": 11, "w": 12, "h": 13, "image": "a.png"}
 }

This would allow you to have default values for parameters. You could then add a JSON serialization function to the API, allowing for use of Lua tables, like so:

 local formspec = minetest.write_json({
   {type="size", x=1, y=2},
   {type="image", x=5, y=6, w=7, h=8, image="b.png"},
   {type="background", "x=10, y=11, w=12, h=13, image="a.png"},
 })
 player:set_inventory_formspec(formspec)

Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox