[wip][mod] FormSpec mini API [formspeccer]

User avatar
taikedz
Member
 
Posts: 587
Joined: Sun May 15, 2016 11:11
GitHub: taikedz
IRC: DuCake
In-game: DuCake

[wip][mod] FormSpec mini API [formspeccer]

by taikedz » Mon Oct 17, 2016 01:15

A little API that is intended to help in the creation of form specs.


The form spec sublanguage is a little fiddly, so this API is intended to make it resemble other APIs by making it table-based.

Example:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local formname = "mymod:myform"

formspeccer:newform(formname,"10,7") -- a new form , 10x7

formspeccer:add_field(formname,{
    name="field1",
    label="Your name",
    value="Sam", -- optional pre-populated value for the form
})

formspeccer:add_button(
    {
        name="send",
        label="Send!",
        xy="2,3",
        wh="1,1",
    },
    true -- optional , makes it an exit button
)

-- just show the form to a player
formspeccer:show(player,"mymod:myform")
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: [wip][mod] FormSpec mini API [formspeccer]

by azekill_DIABLO » Mon Oct 17, 2016 10:58

awesome!
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

bell07
Member
 
Posts: 140
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [wip][mod] FormSpec mini API [formspeccer]

by bell07 » Mon Oct 17, 2016 22:01

Bookmarked.

Great work!

I play with thought to start a new mod for for formspec widgets library. And your API will be really welcome for the widgets. So maybe we working together in the feature.
The planned widgets are some "full-featured" easy to use formspec generators like "Open file dialog" and some framework modules like "tabbed screen". Yu can find a small "as-needed-by-project-prototype" in https://github.com/bell07/minetest-town ... idgets.lua
 

User avatar
Naj
Member
 
Posts: 170
Joined: Sat Sep 19, 2015 21:14
GitHub: pyrollo
In-game: naj

Re: [wip][mod] FormSpec mini API [formspeccer]

by Naj » Tue Oct 18, 2016 09:08

I worked a bit on a formspec API.

It's using object but I find it too heavy. I love the table style. Much better.

I'll publish code soon. I worked on auto placing / sizing and on event handling.

It could be good to have a good and common formspec framework.
 

User avatar
taikedz
Member
 
Posts: 587
Joined: Sun May 15, 2016 11:11
GitHub: taikedz
IRC: DuCake
In-game: DuCake

Re: [wip][mod] FormSpec mini API [formspeccer]

by taikedz » Tue Oct 18, 2016 10:23

Nice one Naj, would love to see the code you have so far

bell07 interesting - are you wanting to make some sort of pre-made generalized forms?
 

bell07
Member
 
Posts: 140
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [wip][mod] FormSpec mini API [formspeccer]

by bell07 » Tue Oct 18, 2016 20:03

My idea is a framework that handle all formspec related methods like, on_receive_fields, *metadata_inventory*, set_string "formspec" and maybe other in one. So the next pseudo-code should be possible (if lua syntax correct oO).

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local nodedef = {....definition ...}
specwidget.add_interface(nodedef)
register_node("mynode", nodedef)

local form = nodedef.specwidget:newform("selection", "10x10")
form:add_selector("Please select file", {"file1","file2","file3"}, "10x8")
form:add_button("open", { label="open", on_press = function print(file) end }
form:add_button("cancel", { label = "cancel", on_press = function parent.specwidget:set_active(form2) end }

local form2 = nodedef.specwidget:newform("selection", "8x8")
..
..
..

local node = minetest.get_node({1,2,3})
node.specwidget:set_active(form)


Do you have any sample how to use your API? Currently I miss the way to handle the on_receive_fields
 

User avatar
taikedz
Member
 
Posts: 587
Joined: Sun May 15, 2016 11:11
GitHub: taikedz
IRC: DuCake
In-game: DuCake

Re: [wip][mod] FormSpec mini API [formspeccer]

by taikedz » Fri Oct 21, 2016 13:44

API added to current implementation.

I am thinking I might want to re-write it for better flexibility.... I will try not to break any documented API at this point..... but no promises!

bell07 - some comments might help...

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
form:add_button("open", { label="open", on_press = function print(file) end }
form:add_button("cancel", { label = "cancel", on_press = function parent.specwidget:set_active(form2) end }


They way I read this, I understand that you want to be able to supply a function through on_press that will be called in the receive_fields callback, conditional on the button being the one that was pressed... So essentially you are also generating a switching function based on all the buttons with on_press on it....

I think that would work...... certainly looks promising and a rather much cleaner way, for the modder's perspecitve, of tying funcitonality to the node... but..... I expect there would also need to be a way of adding a final custom handler... for when player uses the Enter key.... I'm pretty sure there's something buging me about this approach for a reason.... can't seem to put my finger on it...
Last edited by taikedz on Fri Oct 21, 2016 13:50, edited 1 time in total.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [wip][mod] FormSpec mini API [formspeccer]

by rubenwardy » Fri Oct 21, 2016 13:48

smartfs has bindings for events such as button presses.

However, it uses parameters rather than a table to make elements, so that doesn't look as nice.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local btn = state:button(1, 1, 2, 2, "name", "label")
btn:click(function()
    minetest.chat_send_player(name, "You clicked a button!")
end)
 

User avatar
taikedz
Member
 
Posts: 587
Joined: Sun May 15, 2016 11:11
GitHub: taikedz
IRC: DuCake
In-game: DuCake

Re: [wip][mod] FormSpec mini API [formspeccer]

by taikedz » Fri Oct 21, 2016 13:59

rubenwardy -- hmm. Didn't see smartfs

I did try to check first if someone else had done this already. I didn't really set out to duplicate efforts.... :-/

There are quite a few new elements to formspecs since you last updated the code it seems.... are you still intending to maintain smartfs?
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [wip][mod] FormSpec mini API [formspeccer]

by rubenwardy » Fri Oct 21, 2016 16:01

I would like to, but I'm lacking time to do so - what with being a core developer and also a uni student
 

User avatar
taikedz
Member
 
Posts: 587
Joined: Sun May 15, 2016 11:11
GitHub: taikedz
IRC: DuCake
In-game: DuCake

Re: [wip][mod] FormSpec mini API [formspeccer]

by taikedz » Fri Oct 21, 2016 16:06

OK - well what I'll probably do is an implementation of a couple of simple mods I have here against smartfs, and see which direction I want to continue effort on...

If I do have suggestions should I send to minetest-mods fork or your fork?
 

bell07
Member
 
Posts: 140
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [wip][mod] FormSpec mini API [formspeccer]

by bell07 » Fri Oct 21, 2016 19:38

Thank you @rubenwardy for mention smartfs. I fail to see it too. For now I play with them for better understanding. The first challenge for me is the smartfs and formspeccer are both for "player inventory" that will be opened trough show(player..) method. But my first mods uses nodemeta inventory. So I have to do this integration by myself.
By the way, I found this info: http://dev.minetest.net/Lua_Table_Formspec. Any presumption when it will be implemented?
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [wip][mod] FormSpec mini API [formspeccer]

by rubenwardy » Fri Oct 21, 2016 22:43

The minetest-mods is the main one
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 9 guests

cron