### Valid Properties
* button, button_exit
- * bgcolor - color, sets button tint
- * textcolor - color, default white
- * border - boolean, draw border. Set to false to hide the bevelled button pane. Default true.
- * noclip - boolean, set to true to allow the element to exceed formspec bounds.
+ * alpha - boolean, whether to draw alpha in bgimg. Default true.
+ * bgcolor - color, sets button tint.
* bgimg - standard image. Defaults to none.
* bgimg_pressed - image when pressed. Defaults to bgimg when not provided.
- * alpha - boolean, whether to draw alpha in bgimg. Default true.
+ * border - boolean, draw border. Set to false to hide the bevelled button pane. Default true.
+ * noclip - boolean, set to true to allow the element to exceed formspec bounds.
+ * textcolor - color, default white.
* checkbox
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
* scrollbar
* dropdown
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
* field, pwdfield, textarea
- * noclip - boolean, set to true to allow the element to exceed formspec bounds.
* border - set to false to hide the textbox background and border. Default true.
+ * noclip - boolean, set to true to allow the element to exceed formspec bounds.
* textcolor - color. Default white.
* label, vertlabel
- * bgcolor - color. Default unset.
- * textcolor - color. Default white.
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
- * border - boolean, set to true to get a border. Default true.
-* image_button, item_image_button
+* image_button
+ * alpha - boolean, whether to draw alpha in bgimg. Default true.
+ * border - boolean, draw border. Set to false to hide the bevelled button pane. Default false.
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
+* item_image_button
* border - boolean, draw border. Set to false to hide the bevelled button pane. Default false.
- * alpha - boolean, whether to draw alpha in bgimg. Default true.
+ * noclip - boolean, set to true to allow the element to exceed formspec bounds.
* tabheader
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
* textcolor - color. Default white.
--- /dev/null
+local clip_fs = [[\r
+ style_type[label;noclip=%c]\r
+ style_type[button;noclip=%c]\r
+ style_type[image_button;noclip=%c]\r
+ style_type[item_image_button;noclip=%c]\r
+ style_type[tabheader;noclip=%c]\r
+ style_type[field;noclip=%c]\r
+ style_type[textarea;noclip=%c]\r
+ style_type[checkbox;noclip=%c]\r
+ style_type[dropdown;noclip=%c]\r
+ style_type[scrollbar;noclip=%c]\r
+ style_type[table;noclip=%c]\r
+\r
+ label[0,0;A clipping test]\r
+ button[0,1;3,0.8;x;A clipping test]\r
+ image_button[0,2;3,0.8;bubble.png;x2;A clipping test]\r
+ item_image_button[0,3;3,0.8;default:sword_steel;x3;A clipping test]\r
+ tabheader[0,4.7;3,0.63;x4;Clip,Test,Text,Tabs;1;false;false]\r
+ field[0,5;3,0.8;x5;Title;]\r
+ textarea[0,6;3,1;x6;Title;]\r
+ checkbox[0,7.5;x7;This is a test;true]\r
+ dropdown[0,8;3,0.8;x8;Select An Item,One,Two,Three,Four,Five;1]\r
+ scrollbar[0,9;3,0.8;horizontal;x9;3]\r
+ tablecolumns[text;text]\r
+ table[0,10;3,1;x10;one,two,three,four;1]\r
+]]\r
+\r
+\r
+local style_fs = [[\r
+ style[one_btn1;bgcolor=red;textcolor=yellow]\r
+ button[0,0;2.5,0.8;one_btn1;Button]\r
+\r
+ style[one_btn2;border=false;textcolor=cyan]\r
+ button[0,1.05;2.5,0.8;one_btn2;Text Button]\r
+\r
+ style[one_btn3;bgimg=bubble.png;bgimg_pressed=heart.png]\r
+ button[0,2.1;1,1;one_btn3;Bor]\r
+\r
+ style[one_btn4;bgimg=bubble.png;bgimg_pressed=heart.png;border=false]\r
+ button[1.25,2.1;1,1;one_btn4;Bub]\r
+\r
+ style[one_btn5;bgimg=bubble.png;bgimg_pressed=heart.png;border=false;alpha=false]\r
+ button[0,3.35;1,1;one_btn5;Alph]\r
+\r
+ style[one_btn6;border=true]\r
+ image_button[0,4.6;1,1;bubble.png;one_btn6;Border]\r
+\r
+ style[one_btn7;border=false]\r
+ image_button[1.25,4.6;1,1;bubble.png;one_btn7;NoBor]\r
+\r
+ style[one_btn8;border=false]\r
+ image_button[0,5.85;1,1;bubble.png;one_btn8;Border;false;true;heart.png]\r
+\r
+ style[one_btn9;border=true]\r
+ image_button[1.25,5.85;1,1;bubble.png;one_btn9;NoBor;false;false;heart.png]\r
+\r
+ style[one_btn10;alpha=false]\r
+ image_button[0,7.1;1,1;bubble.png;one_btn10;NoAlpha]\r
+\r
+ style[one_btn11;alpha=true]\r
+ image_button[1.25,7.1;1,1;bubble.png;one_btn11;Alpha]\r
+\r
+ style[one_btn12;border=true]\r
+ item_image_button[0,8.35;1,1;default:sword_steel;one_btn12;Border]\r
+\r
+ style[one_btn13;border=false]\r
+ item_image_button[1.25,8.35;1,1;default:sword_steel;one_btn13;NoBor]\r
+\r
+\r
+ container[2.75,0]\r
+\r
+ style[one_tb1;textcolor=Yellow]\r
+ tabheader[0,3;2.5,0.63;one_tb1;Yellow,Text,Tabs;1;false;false]\r
+\r
+ style[one_f1;textcolor=yellow]\r
+ field[0,4.25;2.5,0.8;one_f1;Field One;Yellow Text]\r
+\r
+ style[one_f2;border=false;textcolor=cyan]\r
+ field[0,5.75;2.5,0.8;one_f2;Field Two;Borderless Cyan Text]\r
+\r
+ style[one_f3;textcolor=yellow]\r
+ textarea[0,7.025;2.5,0.8;one_f3;Label;]] ..\r
+ minetest.formspec_escape("Yellow Text\nLine two") .. [[ ]\r
+\r
+ style[one_f4;border=false;textcolor=cyan]\r
+ textarea[0,8.324999999999999;2.5,0.8;one_f4;Label;]] ..\r
+ minetest.formspec_escape("Borderless Cyan Text\nLine two") .. [[ ]\r
+\r
+ container_end[]\r
+]]\r
+\r
+--style_type[label;textcolor=green]\r
+--label[0,0;Green]\r
+--style_type[label;textcolor=blue]\r
+--label[0,1;Blue]\r
+--style_type[label;textcolor=;border=true]\r
+--label[1.2,0;Border]\r
+--style_type[label;border=true;bgcolor=red]\r
+--label[1.2,1;Background]\r
+--style_type[label;border=;bgcolor=]\r
+--label[0.75,2;Reset]\r
+\r
+\r
+local pages = {\r
+ [[\r
+ size[12,12]\r
+ real_coordinates[true]\r
+ image_button[0,0;1,1;logo.png;;1x1]\r
+ image_button[1,0;2,2;logo.png;;2x2]\r
+ button[0,2;1,1;;1x1]\r
+ button[1,2;2,2;;2x2]\r
+ item_image[0,4;1,1;air]\r
+ item_image[1,4;2,2;air]\r
+ item_image_button[0,6;1,1;test:node;;1x1]\r
+ item_image_button[1,6;2,2;test:node;;2x2]\r
+ field[3,.5;3,.5;name;Field;text]\r
+ pwdfield[6,.5;3,1;name;Password Field]\r
+ field[3,1;3,1;;Read-Only Field;text]\r
+ textarea[3,2;3,.5;name;Textarea;text]\r
+ textarea[6,2;3,2;name;Textarea;text\nmore text]\r
+ textarea[3,3;3,1;;Read-Only Textarea;text\nmore text]\r
+ textlist[3,4;3,2;name;Textlist,Perfect Coordinates;1;false]\r
+ tableoptions[highlight=#ABCDEF75;background=#00000055;border=false]\r
+ table[6,4;3,2;name;Table,Cool Stuff,Foo,Bar;2]\r
+ dropdown[3,6;3,1;name;This,is,a,dropdown;1]\r
+ dropdown[6,6;3,2;name;I,am,a,bigger,dropdown;5]\r
+ image[0,8;3,2;ignore.png]\r
+ box[3,7;3,1;#00A3FF]\r
+ checkbox[3,8;name;Check me!;false]\r
+ checkbox[3,9;name;Uncheck me now!;true]\r
+ scrollbar[0,11.5;11.5,.5;horizontal;name;500]\r
+ scrollbar[11.5,0;.5,11.5;vertical;name;0]\r
+ list[current_player;main;6,8;3,2;1]\r
+ button[9,0;2.5,1;name;]\r
+ button[9,1;2.5,1;name;]\r
+ button[9,2;2.5,1;name;]\r
+ label[9,0;This is a label.\nLine\nLine\nLine\nEnd]\r
+ button[9,3;1,1;name;]\r
+ vertlabel[9,4;VERT]\r
+ label[10,3;HORIZ]\r
+ tabheader[6.5,0;6,0.65;name;Tab 1,Tab 2,Tab 3,Secrets;1;false;false]\r
+ ]],\r
+\r
+ "size[12,12]real_coordinates[true]" ..\r
+ "label[0.375,0.375;Styled]" ..\r
+ "label[6.375,0.375;Unstyled]" ..\r
+ "box[0,0.75;12,0.1;#999]" ..\r
+ "box[6,0.85;0.1,11.15;#999]" ..\r
+ "container[0.375,1.225]" ..\r
+ style_fs ..\r
+ "container_end[]container[6.375,1.225]" ..\r
+ style_fs:gsub("one_", "two_"):gsub("style%[[^%]]+%]", ""):gsub("style_type%[[^%]]+%]", "") ..\r
+ "container_end[]",\r
+\r
+ "size[12,12]real_coordinates[true]" ..\r
+ "label[0.1,0.5;Clip]" ..\r
+ "container[-2.5,1]" .. clip_fs:gsub("%%c", "false") .. "container_end[]" ..\r
+ "label[11,0.5;Noclip]" ..\r
+ "container[11.5,1]" .. clip_fs:gsub("%%c", "true") .. "container_end[]",\r
+}\r
+\r
+local function show_test_formspec(pname, page_id)\r
+ page_id = page_id or 2\r
+\r
+ local fs = pages[page_id] .. "tabheader[0,0;6,0.65;maintabs;Real Coord,Styles,Noclip;" .. page_id .. ";false;false]"\r
+\r
+ minetest.show_formspec(pname, "test:formspec", fs)\r
+end\r
+\r
+minetest.register_on_player_receive_fields(function(player, formname, fields)\r
+ if formname ~= "test:formspec" then\r
+ return false\r
+ end\r
+\r
+ if fields.maintabs then\r
+ show_test_formspec(player:get_player_name(), tonumber(fields.maintabs))\r
+ return true\r
+ end\r
+\r
+end)\r
+\r
+minetest.register_node("test:node", {\r
+ tiles = { "air.png" }\r
+})\r
+\r
+minetest.register_chatcommand("formspec", {\r
+ func = function(name)\r
+ if not minetest.get_player_by_name(name) then\r
+ return false, "You need to be online!"\r
+ end\r
+\r
+ show_test_formspec(name)\r
+ return true, "Opened formspec"\r
+ end,\r
+})\r
-- Mod: test
--
+
-- Try out PseudoRandom
pseudo = PseudoRandom(13)
assert(pseudo:next() == 22290)
assert(pseudo:next() == 13854)
-
---
--- HP Change Reasons
---
-local expect = nil
-local function run_hpchangereason_tests(player)
- expect = { type = "set_hp", from = "mod" }
- player:set_hp(3)
- assert(expect == nil)
-
- expect = { a = 234, type = "set_hp", from = "mod" }
- player:set_hp(7, { a= 234 })
- assert(expect == nil)
-
- expect = { df = 3458973454, type = "fall", from = "mod" }
- player:set_hp(10, { type = "fall", df = 3458973454 })
- assert(expect == nil)
-end
-minetest.register_on_player_hpchange(function(player, hp, reason)
- if not expect then
- return
- end
-
- for key, value in pairs(reason) do
- assert(expect[key] == value)
- end
-
- for key, value in pairs(expect) do
- assert(reason[key] == value)
- end
-
- expect = nil
-end)
-
-
-local function run_player_meta_tests(player)
- local meta = player:get_meta()
- meta:set_string("foo", "bar")
- assert(meta:contains("foo"))
- assert(meta:get_string("foo") == "bar")
- assert(meta:get("foo") == "bar")
-
- local meta2 = player:get_meta()
- assert(meta2:get_string("foo") == "bar")
- assert(meta2:get("foo") == "bar")
- assert(meta:equals(meta2))
- assert(player:get_attribute("foo") == "bar")
-
- meta:set_string("bob", "dillan")
- assert(meta:get_string("foo") == "bar")
- assert(meta:get_string("bob") == "dillan")
- assert(meta:get("bob") == "dillan")
- assert(meta2:get_string("foo") == "bar")
- assert(meta2:get_string("bob") == "dillan")
- assert(meta2:get("bob") == "dillan")
- assert(meta:equals(meta2))
- assert(player:get_attribute("foo") == "bar")
- assert(player:get_attribute("bob") == "dillan")
-
- meta:set_string("foo", "")
- assert(not meta:contains("foo"))
- assert(meta:get("foo") == nil)
- assert(meta:get_string("foo") == "")
- assert(meta:equals(meta2))
-end
-
-local function run_player_tests(player)
- run_hpchangereason_tests(player)
- run_player_meta_tests(player)
- minetest.chat_send_all("All tests pass!")
-end
-minetest.register_on_joinplayer(run_player_tests)
-
-
-local function test_get_craft_result()
- minetest.log("info", "test_get_craft_result()")
- -- normal
- local input = {
- method = "normal",
- width = 2,
- items = {"", "default:coal_lump", "", "default:stick"}
- }
- minetest.log("info", "torch crafting input: "..dump(input))
- local output, decremented_input = minetest.get_craft_result(input)
- minetest.log("info", "torch crafting output: "..dump(output))
- minetest.log("info", "torch crafting decremented input: "..dump(decremented_input))
- assert(output.item)
- minetest.log("info", "torch crafting output.item:to_table(): "..dump(output.item:to_table()))
- assert(output.item:get_name() == "default:torch")
- assert(output.item:get_count() == 4)
- -- fuel
- local input = {
- method = "fuel",
- width = 1,
- items = {"default:coal_lump"}
- }
- minetest.log("info", "coal fuel input: "..dump(input))
- local output, decremented_input = minetest.get_craft_result(input)
- minetest.log("info", "coal fuel output: "..dump(output))
- minetest.log("info", "coal fuel decremented input: "..dump(decremented_input))
- assert(output.time)
- assert(output.time > 0)
- -- cook
- local input = {
- method = "cooking",
- width = 1,
- items = {"default:cobble"}
- }
- minetest.log("info", "cobble cooking input: "..dump(output))
- local output, decremented_input = minetest.get_craft_result(input)
- minetest.log("info", "cobble cooking output: "..dump(output))
- minetest.log("info", "cobble cooking decremented input: "..dump(decremented_input))
- assert(output.time)
- assert(output.time > 0)
- assert(output.item)
- minetest.log("info", "cobble cooking output.item:to_table(): "..dump(output.item:to_table()))
- assert(output.item:get_name() == "default:stone")
- assert(output.item:get_count() == 1)
-end
-test_get_craft_result()
+dofile(minetest.get_modpath("test") .. "/player.lua")
+dofile(minetest.get_modpath("test") .. "/formspec.lua")
--- /dev/null
+--
+-- Minimal Development Test
+-- Mod: test
+--
+
+--
+-- HP Change Reasons
+--
+local expect = nil
+local function run_hpchangereason_tests(player)
+ expect = { type = "set_hp", from = "mod" }
+ player:set_hp(3)
+ assert(expect == nil)
+
+ expect = { a = 234, type = "set_hp", from = "mod" }
+ player:set_hp(7, { a= 234 })
+ assert(expect == nil)
+
+ expect = { df = 3458973454, type = "fall", from = "mod" }
+ player:set_hp(10, { type = "fall", df = 3458973454 })
+ assert(expect == nil)
+end
+minetest.register_on_player_hpchange(function(player, hp, reason)
+ if not expect then
+ return
+ end
+
+ for key, value in pairs(reason) do
+ assert(expect[key] == value)
+ end
+
+ for key, value in pairs(expect) do
+ assert(reason[key] == value)
+ end
+
+ expect = nil
+end)
+
+
+local function run_player_meta_tests(player)
+ local meta = player:get_meta()
+ meta:set_string("foo", "bar")
+ assert(meta:contains("foo"))
+ assert(meta:get_string("foo") == "bar")
+ assert(meta:get("foo") == "bar")
+
+ local meta2 = player:get_meta()
+ assert(meta2:get_string("foo") == "bar")
+ assert(meta2:get("foo") == "bar")
+ assert(meta:equals(meta2))
+ assert(player:get_attribute("foo") == "bar")
+
+ meta:set_string("bob", "dillan")
+ assert(meta:get_string("foo") == "bar")
+ assert(meta:get_string("bob") == "dillan")
+ assert(meta:get("bob") == "dillan")
+ assert(meta2:get_string("foo") == "bar")
+ assert(meta2:get_string("bob") == "dillan")
+ assert(meta2:get("bob") == "dillan")
+ assert(meta:equals(meta2))
+ assert(player:get_attribute("foo") == "bar")
+ assert(player:get_attribute("bob") == "dillan")
+
+ meta:set_string("foo", "")
+ assert(not meta:contains("foo"))
+ assert(meta:get("foo") == nil)
+ assert(meta:get_string("foo") == "")
+ assert(meta:equals(meta2))
+end
+
+local function run_player_tests(player)
+ run_hpchangereason_tests(player)
+ run_player_meta_tests(player)
+ minetest.chat_send_all("All tests pass!")
+end
+minetest.register_on_joinplayer(run_player_tests)
+
+
+local function test_get_craft_result()
+ minetest.log("info", "test_get_craft_result()")
+ -- normal
+ local input = {
+ method = "normal",
+ width = 2,
+ items = {"", "default:coal_lump", "", "default:stick"}
+ }
+ minetest.log("info", "torch crafting input: "..dump(input))
+ local output, decremented_input = minetest.get_craft_result(input)
+ minetest.log("info", "torch crafting output: "..dump(output))
+ minetest.log("info", "torch crafting decremented input: "..dump(decremented_input))
+ assert(output.item)
+ minetest.log("info", "torch crafting output.item:to_table(): "..dump(output.item:to_table()))
+ assert(output.item:get_name() == "default:torch")
+ assert(output.item:get_count() == 4)
+ -- fuel
+ local input = {
+ method = "fuel",
+ width = 1,
+ items = {"default:coal_lump"}
+ }
+ minetest.log("info", "coal fuel input: "..dump(input))
+ local output, decremented_input = minetest.get_craft_result(input)
+ minetest.log("info", "coal fuel output: "..dump(output))
+ minetest.log("info", "coal fuel decremented input: "..dump(decremented_input))
+ assert(output.time)
+ assert(output.time > 0)
+ -- cook
+ local input = {
+ method = "cooking",
+ width = 1,
+ items = {"default:cobble"}
+ }
+ minetest.log("info", "cobble cooking input: "..dump(output))
+ local output, decremented_input = minetest.get_craft_result(input)
+ minetest.log("info", "cobble cooking output: "..dump(output))
+ minetest.log("info", "cobble cooking decremented input: "..dump(decremented_input))
+ assert(output.time)
+ assert(output.time > 0)
+ assert(output.item)
+ minetest.log("info", "cobble cooking output.item:to_table(): "..dump(output.item:to_table()))
+ assert(output.item:get_name() == "default:stone")
+ assert(output.item:get_count() == 1)
+end
+test_get_craft_result()
auto style = getStyleForElement("label", spec.fname);
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
- e->setDrawBorder(style.getBool(StyleSpec::BORDER, false));
e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
- if (style.isNotDefault(StyleSpec::BGCOLOR)) {
- e->setBackgroundColor(style.getColor(StyleSpec::BGCOLOR));
- }
m_fields.push_back(spec);
}
auto style = getStyleForElement("vertlabel", spec.fname, "label");
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
- e->setDrawBorder(style.getBool(StyleSpec::BORDER, false));
e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
- if (style.isNotDefault(StyleSpec::BGCOLOR)) {
- e->setBackgroundColor(style.getColor(StyleSpec::BGCOLOR));
- }
m_fields.push_back(spec);
return;