Skip to content

Commit 4f7fa8d

Browse files
committedAug 3, 2019
Add formspec testing to test mod in minimal
1 parent 9541165 commit 4f7fa8d

File tree

5 files changed

+333
-139
lines changed

5 files changed

+333
-139
lines changed
 

‎doc/lua_api.txt

+11-11
Original file line numberDiff line numberDiff line change
@@ -2449,13 +2449,13 @@ Some types may inherit styles from parent types.
24492449
### Valid Properties
24502450

24512451
* button, button_exit
2452-
* bgcolor - color, sets button tint
2453-
* textcolor - color, default white
2454-
* border - boolean, draw border. Set to false to hide the bevelled button pane. Default true.
2455-
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2452+
* alpha - boolean, whether to draw alpha in bgimg. Default true.
2453+
* bgcolor - color, sets button tint.
24562454
* bgimg - standard image. Defaults to none.
24572455
* bgimg_pressed - image when pressed. Defaults to bgimg when not provided.
2458-
* alpha - boolean, whether to draw alpha in bgimg. Default true.
2456+
* border - boolean, draw border. Set to false to hide the bevelled button pane. Default true.
2457+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2458+
* textcolor - color, default white.
24592459
* checkbox
24602460
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
24612461
* scrollbar
@@ -2465,18 +2465,18 @@ Some types may inherit styles from parent types.
24652465
* dropdown
24662466
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
24672467
* field, pwdfield, textarea
2468-
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
24692468
* border - set to false to hide the textbox background and border. Default true.
2469+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
24702470
* textcolor - color. Default white.
24712471
* label, vertlabel
2472-
* bgcolor - color. Default unset.
2473-
* textcolor - color. Default white.
24742472
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2475-
* border - boolean, set to true to get a border. Default true.
2476-
* image_button, item_image_button
2473+
* image_button
2474+
* alpha - boolean, whether to draw alpha in bgimg. Default true.
2475+
* border - boolean, draw border. Set to false to hide the bevelled button pane. Default false.
24772476
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2477+
* item_image_button
24782478
* border - boolean, draw border. Set to false to hide the bevelled button pane. Default false.
2479-
* alpha - boolean, whether to draw alpha in bgimg. Default true.
2479+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
24802480
* tabheader
24812481
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
24822482
* textcolor - color. Default white.

‎games/minimal/mods/test/formspec.lua

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
local clip_fs = [[
2+
style_type[label;noclip=%c]
3+
style_type[button;noclip=%c]
4+
style_type[image_button;noclip=%c]
5+
style_type[item_image_button;noclip=%c]
6+
style_type[tabheader;noclip=%c]
7+
style_type[field;noclip=%c]
8+
style_type[textarea;noclip=%c]
9+
style_type[checkbox;noclip=%c]
10+
style_type[dropdown;noclip=%c]
11+
style_type[scrollbar;noclip=%c]
12+
style_type[table;noclip=%c]
13+
14+
label[0,0;A clipping test]
15+
button[0,1;3,0.8;x;A clipping test]
16+
image_button[0,2;3,0.8;bubble.png;x2;A clipping test]
17+
item_image_button[0,3;3,0.8;default:sword_steel;x3;A clipping test]
18+
tabheader[0,4.7;3,0.63;x4;Clip,Test,Text,Tabs;1;false;false]
19+
field[0,5;3,0.8;x5;Title;]
20+
textarea[0,6;3,1;x6;Title;]
21+
checkbox[0,7.5;x7;This is a test;true]
22+
dropdown[0,8;3,0.8;x8;Select An Item,One,Two,Three,Four,Five;1]
23+
scrollbar[0,9;3,0.8;horizontal;x9;3]
24+
tablecolumns[text;text]
25+
table[0,10;3,1;x10;one,two,three,four;1]
26+
]]
27+
28+
29+
local style_fs = [[
30+
style[one_btn1;bgcolor=red;textcolor=yellow]
31+
button[0,0;2.5,0.8;one_btn1;Button]
32+
33+
style[one_btn2;border=false;textcolor=cyan]
34+
button[0,1.05;2.5,0.8;one_btn2;Text Button]
35+
36+
style[one_btn3;bgimg=bubble.png;bgimg_pressed=heart.png]
37+
button[0,2.1;1,1;one_btn3;Bor]
38+
39+
style[one_btn4;bgimg=bubble.png;bgimg_pressed=heart.png;border=false]
40+
button[1.25,2.1;1,1;one_btn4;Bub]
41+
42+
style[one_btn5;bgimg=bubble.png;bgimg_pressed=heart.png;border=false;alpha=false]
43+
button[0,3.35;1,1;one_btn5;Alph]
44+
45+
style[one_btn6;border=true]
46+
image_button[0,4.6;1,1;bubble.png;one_btn6;Border]
47+
48+
style[one_btn7;border=false]
49+
image_button[1.25,4.6;1,1;bubble.png;one_btn7;NoBor]
50+
51+
style[one_btn8;border=false]
52+
image_button[0,5.85;1,1;bubble.png;one_btn8;Border;false;true;heart.png]
53+
54+
style[one_btn9;border=true]
55+
image_button[1.25,5.85;1,1;bubble.png;one_btn9;NoBor;false;false;heart.png]
56+
57+
style[one_btn10;alpha=false]
58+
image_button[0,7.1;1,1;bubble.png;one_btn10;NoAlpha]
59+
60+
style[one_btn11;alpha=true]
61+
image_button[1.25,7.1;1,1;bubble.png;one_btn11;Alpha]
62+
63+
style[one_btn12;border=true]
64+
item_image_button[0,8.35;1,1;default:sword_steel;one_btn12;Border]
65+
66+
style[one_btn13;border=false]
67+
item_image_button[1.25,8.35;1,1;default:sword_steel;one_btn13;NoBor]
68+
69+
70+
container[2.75,0]
71+
72+
style[one_tb1;textcolor=Yellow]
73+
tabheader[0,3;2.5,0.63;one_tb1;Yellow,Text,Tabs;1;false;false]
74+
75+
style[one_f1;textcolor=yellow]
76+
field[0,4.25;2.5,0.8;one_f1;Field One;Yellow Text]
77+
78+
style[one_f2;border=false;textcolor=cyan]
79+
field[0,5.75;2.5,0.8;one_f2;Field Two;Borderless Cyan Text]
80+
81+
style[one_f3;textcolor=yellow]
82+
textarea[0,7.025;2.5,0.8;one_f3;Label;]] ..
83+
minetest.formspec_escape("Yellow Text\nLine two") .. [[ ]
84+
85+
style[one_f4;border=false;textcolor=cyan]
86+
textarea[0,8.324999999999999;2.5,0.8;one_f4;Label;]] ..
87+
minetest.formspec_escape("Borderless Cyan Text\nLine two") .. [[ ]
88+
89+
container_end[]
90+
]]
91+
92+
--style_type[label;textcolor=green]
93+
--label[0,0;Green]
94+
--style_type[label;textcolor=blue]
95+
--label[0,1;Blue]
96+
--style_type[label;textcolor=;border=true]
97+
--label[1.2,0;Border]
98+
--style_type[label;border=true;bgcolor=red]
99+
--label[1.2,1;Background]
100+
--style_type[label;border=;bgcolor=]
101+
--label[0.75,2;Reset]
102+
103+
104+
local pages = {
105+
[[
106+
size[12,12]
107+
real_coordinates[true]
108+
image_button[0,0;1,1;logo.png;;1x1]
109+
image_button[1,0;2,2;logo.png;;2x2]
110+
button[0,2;1,1;;1x1]
111+
button[1,2;2,2;;2x2]
112+
item_image[0,4;1,1;air]
113+
item_image[1,4;2,2;air]
114+
item_image_button[0,6;1,1;test:node;;1x1]
115+
item_image_button[1,6;2,2;test:node;;2x2]
116+
field[3,.5;3,.5;name;Field;text]
117+
pwdfield[6,.5;3,1;name;Password Field]
118+
field[3,1;3,1;;Read-Only Field;text]
119+
textarea[3,2;3,.5;name;Textarea;text]
120+
textarea[6,2;3,2;name;Textarea;text\nmore text]
121+
textarea[3,3;3,1;;Read-Only Textarea;text\nmore text]
122+
textlist[3,4;3,2;name;Textlist,Perfect Coordinates;1;false]
123+
tableoptions[highlight=#ABCDEF75;background=#00000055;border=false]
124+
table[6,4;3,2;name;Table,Cool Stuff,Foo,Bar;2]
125+
dropdown[3,6;3,1;name;This,is,a,dropdown;1]
126+
dropdown[6,6;3,2;name;I,am,a,bigger,dropdown;5]
127+
image[0,8;3,2;ignore.png]
128+
box[3,7;3,1;#00A3FF]
129+
checkbox[3,8;name;Check me!;false]
130+
checkbox[3,9;name;Uncheck me now!;true]
131+
scrollbar[0,11.5;11.5,.5;horizontal;name;500]
132+
scrollbar[11.5,0;.5,11.5;vertical;name;0]
133+
list[current_player;main;6,8;3,2;1]
134+
button[9,0;2.5,1;name;]
135+
button[9,1;2.5,1;name;]
136+
button[9,2;2.5,1;name;]
137+
label[9,0;This is a label.\nLine\nLine\nLine\nEnd]
138+
button[9,3;1,1;name;]
139+
vertlabel[9,4;VERT]
140+
label[10,3;HORIZ]
141+
tabheader[6.5,0;6,0.65;name;Tab 1,Tab 2,Tab 3,Secrets;1;false;false]
142+
]],
143+
144+
"size[12,12]real_coordinates[true]" ..
145+
"label[0.375,0.375;Styled]" ..
146+
"label[6.375,0.375;Unstyled]" ..
147+
"box[0,0.75;12,0.1;#999]" ..
148+
"box[6,0.85;0.1,11.15;#999]" ..
149+
"container[0.375,1.225]" ..
150+
style_fs ..
151+
"container_end[]container[6.375,1.225]" ..
152+
style_fs:gsub("one_", "two_"):gsub("style%[[^%]]+%]", ""):gsub("style_type%[[^%]]+%]", "") ..
153+
"container_end[]",
154+
155+
"size[12,12]real_coordinates[true]" ..
156+
"label[0.1,0.5;Clip]" ..
157+
"container[-2.5,1]" .. clip_fs:gsub("%%c", "false") .. "container_end[]" ..
158+
"label[11,0.5;Noclip]" ..
159+
"container[11.5,1]" .. clip_fs:gsub("%%c", "true") .. "container_end[]",
160+
}
161+
162+
local function show_test_formspec(pname, page_id)
163+
page_id = page_id or 2
164+
165+
local fs = pages[page_id] .. "tabheader[0,0;6,0.65;maintabs;Real Coord,Styles,Noclip;" .. page_id .. ";false;false]"
166+
167+
minetest.show_formspec(pname, "test:formspec", fs)
168+
end
169+
170+
minetest.register_on_player_receive_fields(function(player, formname, fields)
171+
if formname ~= "test:formspec" then
172+
return false
173+
end
174+
175+
if fields.maintabs then
176+
show_test_formspec(player:get_player_name(), tonumber(fields.maintabs))
177+
return true
178+
end
179+
180+
end)
181+
182+
minetest.register_node("test:node", {
183+
tiles = { "air.png" }
184+
})
185+
186+
minetest.register_chatcommand("formspec", {
187+
func = function(name)
188+
if not minetest.get_player_by_name(name) then
189+
return false, "You need to be online!"
190+
end
191+
192+
show_test_formspec(name)
193+
return true, "Opened formspec"
194+
end,
195+
})

‎games/minimal/mods/test/init.lua

+3-120
Original file line numberDiff line numberDiff line change
@@ -3,128 +3,11 @@
33
-- Mod: test
44
--
55

6+
67
-- Try out PseudoRandom
78
pseudo = PseudoRandom(13)
89
assert(pseudo:next() == 22290)
910
assert(pseudo:next() == 13854)
1011

11-
12-
--
13-
-- HP Change Reasons
14-
--
15-
local expect = nil
16-
local function run_hpchangereason_tests(player)
17-
expect = { type = "set_hp", from = "mod" }
18-
player:set_hp(3)
19-
assert(expect == nil)
20-
21-
expect = { a = 234, type = "set_hp", from = "mod" }
22-
player:set_hp(7, { a= 234 })
23-
assert(expect == nil)
24-
25-
expect = { df = 3458973454, type = "fall", from = "mod" }
26-
player:set_hp(10, { type = "fall", df = 3458973454 })
27-
assert(expect == nil)
28-
end
29-
minetest.register_on_player_hpchange(function(player, hp, reason)
30-
if not expect then
31-
return
32-
end
33-
34-
for key, value in pairs(reason) do
35-
assert(expect[key] == value)
36-
end
37-
38-
for key, value in pairs(expect) do
39-
assert(reason[key] == value)
40-
end
41-
42-
expect = nil
43-
end)
44-
45-
46-
local function run_player_meta_tests(player)
47-
local meta = player:get_meta()
48-
meta:set_string("foo", "bar")
49-
assert(meta:contains("foo"))
50-
assert(meta:get_string("foo") == "bar")
51-
assert(meta:get("foo") == "bar")
52-
53-
local meta2 = player:get_meta()
54-
assert(meta2:get_string("foo") == "bar")
55-
assert(meta2:get("foo") == "bar")
56-
assert(meta:equals(meta2))
57-
assert(player:get_attribute("foo") == "bar")
58-
59-
meta:set_string("bob", "dillan")
60-
assert(meta:get_string("foo") == "bar")
61-
assert(meta:get_string("bob") == "dillan")
62-
assert(meta:get("bob") == "dillan")
63-
assert(meta2:get_string("foo") == "bar")
64-
assert(meta2:get_string("bob") == "dillan")
65-
assert(meta2:get("bob") == "dillan")
66-
assert(meta:equals(meta2))
67-
assert(player:get_attribute("foo") == "bar")
68-
assert(player:get_attribute("bob") == "dillan")
69-
70-
meta:set_string("foo", "")
71-
assert(not meta:contains("foo"))
72-
assert(meta:get("foo") == nil)
73-
assert(meta:get_string("foo") == "")
74-
assert(meta:equals(meta2))
75-
end
76-
77-
local function run_player_tests(player)
78-
run_hpchangereason_tests(player)
79-
run_player_meta_tests(player)
80-
minetest.chat_send_all("All tests pass!")
81-
end
82-
minetest.register_on_joinplayer(run_player_tests)
83-
84-
85-
local function test_get_craft_result()
86-
minetest.log("info", "test_get_craft_result()")
87-
-- normal
88-
local input = {
89-
method = "normal",
90-
width = 2,
91-
items = {"", "default:coal_lump", "", "default:stick"}
92-
}
93-
minetest.log("info", "torch crafting input: "..dump(input))
94-
local output, decremented_input = minetest.get_craft_result(input)
95-
minetest.log("info", "torch crafting output: "..dump(output))
96-
minetest.log("info", "torch crafting decremented input: "..dump(decremented_input))
97-
assert(output.item)
98-
minetest.log("info", "torch crafting output.item:to_table(): "..dump(output.item:to_table()))
99-
assert(output.item:get_name() == "default:torch")
100-
assert(output.item:get_count() == 4)
101-
-- fuel
102-
local input = {
103-
method = "fuel",
104-
width = 1,
105-
items = {"default:coal_lump"}
106-
}
107-
minetest.log("info", "coal fuel input: "..dump(input))
108-
local output, decremented_input = minetest.get_craft_result(input)
109-
minetest.log("info", "coal fuel output: "..dump(output))
110-
minetest.log("info", "coal fuel decremented input: "..dump(decremented_input))
111-
assert(output.time)
112-
assert(output.time > 0)
113-
-- cook
114-
local input = {
115-
method = "cooking",
116-
width = 1,
117-
items = {"default:cobble"}
118-
}
119-
minetest.log("info", "cobble cooking input: "..dump(output))
120-
local output, decremented_input = minetest.get_craft_result(input)
121-
minetest.log("info", "cobble cooking output: "..dump(output))
122-
minetest.log("info", "cobble cooking decremented input: "..dump(decremented_input))
123-
assert(output.time)
124-
assert(output.time > 0)
125-
assert(output.item)
126-
minetest.log("info", "cobble cooking output.item:to_table(): "..dump(output.item:to_table()))
127-
assert(output.item:get_name() == "default:stone")
128-
assert(output.item:get_count() == 1)
129-
end
130-
test_get_craft_result()
12+
dofile(minetest.get_modpath("test") .. "/player.lua")
13+
dofile(minetest.get_modpath("test") .. "/formspec.lua")

0 commit comments

Comments
 (0)
Please sign in to comment.