Compare commits

...

5 Commits

Author SHA1 Message Date
Wuzzy ed98637211 Update alias syntax 2016-12-28 17:34:06 +01:00
Wuzzy ee7763eb42 Minor README change 2016-12-28 15:48:40 +01:00
Wuzzy 3a27442228 Use new doc syntax to add entries and categories 2016-12-28 15:48:27 +01:00
Wuzzy c752876077 Use speaking category names 2016-12-20 19:08:45 +01:00
Wuzzy 8ad3bc33cb Comments for gallery 2016-12-20 19:07:59 +01:00
3 changed files with 38 additions and 26 deletions

View File

@ -2,7 +2,8 @@
This mod is for modders who want to learn how to use the APIs of the mods
`doc`, `doc_items` and `doc_identifier` from the Help modpack.
It is useless for anyone else. This mod should only be used for testing
and not in production.
and learning. not for actual playing or for servers, as it will only clutter
the the help categories.
It demonstrates the usage of the APIs of the Help mods. This should help you
in getting started with this modpack.

59
doc.lua
View File

@ -9,17 +9,23 @@ function used in category definitions. ]]
-- Let's start with a very simple text-based category.
-- This category only contains simple text.
doc.new_category("example1", {
doc.add_category("example1", {
-- This name is for humans and mandatory
name = "Text Examples",
name = "Example: Text",
-- This category uses a preset formspec builder for simple text
build_formspec = doc.entry_builders.text
--[[ Reminder: build_formspec determines how the entry data will be presented
to the user ]]
})
doc.add_category("sexample", {
name = "Example: Empty",
})
-- Entries for the aforementioned category. We add 2 entries.
doc.new_entry("example1", "text", {
doc.add_entry("example1", "text", {
-- This is for the entry title in the user interface, it's mandatory.
name = "Text example",
-- For this category, the entry data is simply the text to be displayed
@ -27,7 +33,7 @@ doc.new_entry("example1", "text", {
})
-- We will use this entry in doc_identifier.lua
doc.new_entry("example1", "entity", {
doc.add_entry("example1", "entity", {
name = "Entity entry",
data = "This is the entry for the entity (added in doc_identifier.lua). The example entity is just a simple cube which floats in the air. Punch it to destroy it.",
})
@ -37,15 +43,15 @@ doc.new_entry("example1", "entity", {
--[[ Category with hidden entry.
This is a category like the one before, but this time, we add a hidden entry.
]]
doc.new_category("example_hide", {
name = "Example Hidden",
doc.add_category("example_hide", {
name = "Example: Hidden entry",
build_formspec = doc.entry_builders.text
})
-- This entry will start hidden. The user will not see it until it gets
-- revealed by using doc.mark_entry_as_revealed. Note that you should
-- NOT hide entries if there is no way for the player to reveal them.
doc.new_entry("example_hide", "hidden", {
doc.add_entry("example_hide", "hidden", {
name = "Hidden Entry",
hidden = true,
data = "This entry is hidden.",
@ -70,7 +76,7 @@ reveal entries. ;-) ]]
--[[ A simple category with 3 entries: Cities.
Now we're getting somewhere! This time, we define a custom build_formspec
function to display entry data dynamically. ]]
doc.new_category("example2", {
doc.add_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
@ -94,7 +100,7 @@ doc.new_category("example2", {
end,
})
doc.new_entry("example2", "london", {
doc.add_entry("example2", "london", {
name="London",
-- Reminder: This data is put into the previous build_formspec function
data = {
@ -102,14 +108,14 @@ doc.new_entry("example2", "london", {
population = 8538689,
},
})
doc.new_entry("example2", "shanghai", {
doc.add_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", {
doc.add_entry("example2", "tripoli", {
name="Tripoli",
data = {
description = "Tripoli is the capital of Lybia.",
@ -120,7 +126,7 @@ doc.new_entry("example2", "tripoli", {
-------------------------------------------------------------------------------
--[[ Formspec category: This category shows how you can add widgets in entries
and even interact with them ]]
doc.new_category("example3", {
doc.add_category("example3", {
name="Example: Formspec",
description="Example category for manual free-form formspec entries",
--[[ This is a built-in formspec builder. In this case, the entry data
@ -137,7 +143,7 @@ doc.new_category("example3", {
})
-- Just an entry with a label (BAD example)
doc.new_entry("example3", "simple_bad", {
doc.add_entry("example3", "simple_bad", {
name="Label",
-- Please note the coordinates are shoddily chosen here, the don't respect
-- the Documention System formspec boundaries at all, so this is just a guess.
@ -145,7 +151,7 @@ doc.new_entry("example3", "simple_bad", {
})
-- Just an entry with a label (good example)
doc.new_entry("example3", "simple_good", {
doc.add_entry("example3", "simple_good", {
name="Label",
--[[ This is the proper way to add widgets (this is also how you should do it in build_formspec):
Defining the coordinates relative to the Documentation System's boundaries. In this case,
@ -154,7 +160,7 @@ doc.new_entry("example3", "simple_good", {
})
-- Now let's get crazy with MULTIPLE formspec entries. How awesome is that?
doc.new_entry("example3", "multi", {
doc.add_entry("example3", "multi", {
name="Label",
-- Label, just like before
data = "label["..doc.FORMSPEC.ENTRY_START_X..","..doc.FORMSPEC.ENTRY_START_Y..";Just another label.]" ..
@ -167,7 +173,7 @@ doc.new_entry("example3", "multi", {
})
-- This entry will be interactive.
doc.new_entry("example3", "testbutton", {
doc.add_entry("example3", "testbutton", {
name="Event Button",
-- This button actually will be used for an event …
data = "button["..doc.FORMSPEC.ENTRY_START_X..","..doc.FORMSPEC.ENTRY_START_Y..";5,1;example_button;Event]",
@ -194,11 +200,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end)
-------------------------------------------------------------------------------
--[[ This category shows off the gallery widget ]]
--[[ This category demonstrates the use of the gallery widget. ]]
-- FIXME: Depends on Minetest Game
doc.new_category("example4", {
doc.add_category("example4", {
name="Example: Galleries",
build_formspec = function(data, playername)
-- The trick here is to include doc.widgets.gallery into the custom
-- build_formspec definition.
local formspec = ""
--[[ Mostly using default values, but we want an aspect ratio of
1:1 (square). ]]
@ -208,7 +216,7 @@ doc.new_category("example4", {
})
-- Several gallery entries
doc.new_entry("example4", "gallery2", {
doc.add_entry("example4", "gallery2", {
name="Gallery with 2 images",
-- The entry data will be also fed into `doc_widgets_gallery`
data = {
@ -217,7 +225,7 @@ doc.new_entry("example4", "gallery2", {
},
})
doc.new_entry("example4", "gallery3", {
doc.add_entry("example4", "gallery3", {
name="Gallery with 3 images",
data = {
{image="default_grass.png"},
@ -225,7 +233,10 @@ doc.new_entry("example4", "gallery3", {
{image="default_papyrus.png"}},
})
doc.new_entry("example4", "gallery4", {
--[[ The default gallery size is 3. But this gallery has 4 images.
The Documentation System automatically adds scroll buttons
if the number of images exceeds the gallery size ]]
doc.add_entry("example4", "gallery4", {
name="Gallery with 4 images",
data = {
{image="default_dirt.png"},
@ -235,7 +246,7 @@ doc.new_entry("example4", "gallery4", {
},
})
doc.new_entry("example4", "gallery5", {
doc.add_entry("example4", "gallery5", {
name="Gallery with 5 images",
data = {
{image="default_dirt.png"},
@ -246,7 +257,7 @@ doc.new_entry("example4", "gallery5", {
},
})
doc.new_entry("example4", "gallery6", {
doc.add_entry("example4", "gallery6", {
name="Gallery with 6 images",
data = {
{image="default_grass.png"},
@ -257,7 +268,7 @@ doc.new_entry("example4", "gallery6", {
{image="default_bronze_block.png"}},
})
doc.new_entry("example4", "gallery7", {
doc.add_entry("example4", "gallery7", {
name="Gallery with 7 item images",
data = {
-- You can use this syntax to display item images instead of normal textures

View File

@ -121,6 +121,6 @@ minetest.register_node("doc_example:node2", {
--[[ Register an alias to make sure the lookup tool still works.
If this is NOT done, the lookup tool will fail when it is
used on doc_example:node2. ]]
doc.add_entry_alias("nodes", "doc_example:node1", "doc_example:node2")
doc.add_entry_alias("nodes", "doc_example:node1", "nodes", "doc_example:node2")
-- Another example of this concept in action be seen in the mod “doc_identifier”.