commit 54344b234010dac979a3236a37eb7eebc9669742 Author: Wuzzy Date: Thu Dec 15 23:27:11 2016 +0100 Initial commit diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..93440a2 --- /dev/null +++ b/depends.txt @@ -0,0 +1,2 @@ +doc +doc_items diff --git a/doc.lua b/doc.lua new file mode 100644 index 0000000..c4d635f --- /dev/null +++ b/doc.lua @@ -0,0 +1,151 @@ +-- Very simple text-based category +-- This category contains entries with +doc.new_category("example1", { + name = "Text Example", + -- This category uses a preset formspec builder for displaying simple text + build_formspec = doc.entry_builders.text +}) + +-- Entry for the aforementioned category +doc.new_entry("example1", "text", { + name = "Text example", + -- For this category, the data is simply the text to be displayed + data = "Lorem Minetest dolor sit amet. Bla bla bla bla Minetest bla bla bla bla Mese bla. Bla bla bla bla bla, celeron55 bla bla, bla.", +}) + +-- Category with hidden entry +doc.new_category("example_hide", { + name = "Example Hidden", + build_formspec = doc.entry_builders.text +}) + +doc.new_entry("example_hide", "hidden" { + name = "Hidden Entry", + hidden = true + data = "This entry is hidden.", +}) + +--[[ A simple category with 3 entries: Cities ]] +doc.new_category("example2", { + name="Example: Cities", + description="Example category: Quick information about the cities of the world", + -- This is a manual formspec builder: This will parse the entry data and turns it into nice formspec widgets + build_formspec = function(data) + return "label[0,1;Description: "..minetest.formspec_escape(data.description).."]" .. + "label[0,2;Population: "..data.population.."]" + end, +}) + +doc.new_entry("example2", "london", { + name="London", + -- This data are then put into the previous build_formspec + data = { + description = "London is the capital of the United Kingdom.", + population = 8538689, + }, +}) +doc.new_entry("example2", "shanghai", { + name="Shanghai", + data = { + description = "Shanghai lies in China and is one of the biggest cities in the world.", + population = 23019148, + }, +}) +doc.new_entry("example2", "tripoli", { + name="Tripoli", + data = { + description = "Tripoli is the capital of Lybia.", + population = 1780000, + }, +}) + +--[[ Formspec category: This category shows how you can use widgets in entries to interact with them ]] +doc.new_category("example3", { + name="Example: Formspec", + description="Example category for manual freeform formspec entries", + -- This category uses one of the formspec entries + build_formspec = doc.entry_builders.formspec, +}) + +doc.new_entry("example3", "simple", { + name="Label", + -- For the formspec type being used, the data is the raw formspec data + data = "label[5,5;Just a label.]" +}) +doc.new_entry("example3", "widgets", { + name="Widget Chaos", + -- Just some meaningless widgets for demonstration purposes + data = "label[0,1;Label]label[0,2;Label 2]button[0,3;3,1;example_ignored;Button]textlist[0,4;4,4;example_ignored2;A,B,C,D;]scrollbar[4,1;2,0.2;horizontal;example_ignored3;0]", +}) +doc.new_entry("example3", "testbutton", { + name="Event Button", + -- This button actually will be used for an event … + data = "button[2,2;3,1;example_button;Event]", +}) + +-- … and here we react on the event by writing something into the chat +minetest.register_on_player_receive_fields(function(player, formname, fields) + -- Condition 1: This checks if the player is even using the entry tab. This check is always the same + if formname == "doc:entry" then + local playername = player:get_player_name() + -- Condition 2: this check is required to make sure we “listen” to the correct entry + local category_id, entry_id = doc.get_selection(playername) + if category_id == "example3" and entry_id == "testbutton" then + -- Condition 3: Has the widget we actually care about been pressed? + if fields.example_button then + -- All conditions are met! Now the custom action can be executed + minetest.chat_send_player(playername, "You have pressed the event button!") + end + end + end +end) + +--[[ This category shows off the gallery widget ]] +doc.new_category("example4", { + name="Example: Galleries", + build_formspec = function(data, playername) + local formspec = "" + -- Mostly using default values, but we want an aspect ratio of 1:1 (square). + formspec = formspec .. doc.widgets.gallery(data, playername, nil, nil, 1) + return formspec + end, +}) + +-- Several gallery entries +doc.new_entry("example4", "gallery2", { + name="Gallery with 2 images", + data = {{image="default_grass.png"}, {image="default_book.png"}}, +}) + +doc.new_entry("example4", "gallery3", { + name="Gallery with 3 images", + data = {{image="default_grass.png"}, {image="default_book.png"}, {image="default_papyrus.png"}}, +}) + +doc.new_entry("example4", "gallery4", { + name="Gallery with 4 images", + data = {{image="default_dirt.png"}, {image="default_leaves.png"}, {image="default_brick.png"}, {image="default_gold_block.png"}}, +}) + +doc.new_entry("example4", "gallery5", { + name="Gallery with 5 images", + data = {{image="default_dirt.png"}, {image="default_leaves.png"}, {image="default_brick.png"}, {image="default_gold_block.png"}, {image="default_bronze_block.png"}}, +}) + +doc.new_entry("example4", "gallery6", { + name="Gallery with 6 images", + data = {{image="default_grass.png"},{image="default_dirt.png"}, {image="default_leaves.png"}, {image="default_brick.png"}, {image="default_gold_block.png"}, {image="default_bronze_block.png"}}, +}) +doc.new_entry("example4", "gallery7", { + name="Gallery with 7 item images", + data = { + {image="default:bookshelf", imagetype="item"}, + {image="default:grass_5", imagetype="item"}, + {image="default:dirt", imagetype="item"}, + {image="default:fence_wood", imagetype="item"}, + {image="default:flint", imagetype="item"}, + {image="default:goldblock", imagetype="item"}, + {image="default:bronzeblock", imagetype="item"}}, +}) + + diff --git a/doc_items.lua b/doc_items.lua new file mode 100644 index 0000000..fd9508c --- /dev/null +++ b/doc_items.lua @@ -0,0 +1,21 @@ +doc.sub.items.register_factoid("nodes", "damage", function(id) + return "FACTOID: damage." +end) +doc.sub.items.register_factoid("nodes", "movement", function(id) + return "FACTOID: movement." +end) +doc.sub.items.register_factoid("nodes", "sound", function(id) + return "FACTOID: sound." +end) +doc.sub.items.register_factoid("nodes", "gravity", function(id) + return "FACTOID: gravity." +end) +doc.sub.items.register_factoid("nodes", "drop_destroy", function(id) + return "FACTOID: drop_destroy." +end) +doc.sub.items.register_factoid("nodes", "light", function(id) + return "FACTOID: light." +end) +doc.sub.items.register_factoid("nodes", "mining", function(id) + return "FACTOID: mining." +end) diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..e9eee64 --- /dev/null +++ b/init.lua @@ -0,0 +1,2 @@ +dofile(minetest.get_modpath("doc_example").."/doc.lua") +dofile(minetest.get_modpath("doc_example").."/doc_items.lua") diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..a2609d2 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = doc_example