Use new doc syntax to add entries and categories

master
Wuzzy 2016-12-28 15:48:27 +01:00
parent c752876077
commit 3a27442228
1 changed files with 30 additions and 21 deletions

51
doc.lua
View File

@ -9,7 +9,7 @@ function used in category definitions. ]]
-- Let's start with a very simple text-based category. -- Let's start with a very simple text-based category.
-- This category only contains simple text. -- This category only contains simple text.
doc.new_category("example1", { doc.add_category("example1", {
-- This name is for humans and mandatory -- This name is for humans and mandatory
name = "Example: Text", name = "Example: Text",
-- This category uses a preset formspec builder for simple text -- This category uses a preset formspec builder for simple text
@ -18,8 +18,14 @@ doc.new_category("example1", {
to the user ]] to the user ]]
}) })
doc.add_category("sexample", {
name = "Example: Empty",
})
-- Entries for the aforementioned category. We add 2 entries. -- 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. -- This is for the entry title in the user interface, it's mandatory.
name = "Text example", name = "Text example",
-- For this category, the entry data is simply the text to be displayed -- 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 -- We will use this entry in doc_identifier.lua
doc.new_entry("example1", "entity", { doc.add_entry("example1", "entity", {
name = "Entity entry", 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.", 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,7 +43,7 @@ doc.new_entry("example1", "entity", {
--[[ Category with hidden entry. --[[ Category with hidden entry.
This is a category like the one before, but this time, we add a hidden entry. This is a category like the one before, but this time, we add a hidden entry.
]] ]]
doc.new_category("example_hide", { doc.add_category("example_hide", {
name = "Example: Hidden entry", name = "Example: Hidden entry",
build_formspec = doc.entry_builders.text build_formspec = doc.entry_builders.text
}) })
@ -45,7 +51,7 @@ doc.new_category("example_hide", {
-- This entry will start hidden. The user will not see it until it gets -- 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 -- 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. -- 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", name = "Hidden Entry",
hidden = true, hidden = true,
data = "This entry is hidden.", data = "This entry is hidden.",
@ -70,7 +76,7 @@ reveal entries. ;-) ]]
--[[ A simple category with 3 entries: Cities. --[[ A simple category with 3 entries: Cities.
Now we're getting somewhere! This time, we define a custom build_formspec Now we're getting somewhere! This time, we define a custom build_formspec
function to display entry data dynamically. ]] function to display entry data dynamically. ]]
doc.new_category("example2", { doc.add_category("example2", {
name = "Example: Cities", name = "Example: Cities",
description = "Example category: Quick information about the cities of the world", description = "Example category: Quick information about the cities of the world",
--[[ This is a manual formspec builder: This will parse the entry data and --[[ This is a manual formspec builder: This will parse the entry data and
@ -94,7 +100,7 @@ doc.new_category("example2", {
end, end,
}) })
doc.new_entry("example2", "london", { doc.add_entry("example2", "london", {
name="London", name="London",
-- Reminder: This data is put into the previous build_formspec function -- Reminder: This data is put into the previous build_formspec function
data = { data = {
@ -102,14 +108,14 @@ doc.new_entry("example2", "london", {
population = 8538689, population = 8538689,
}, },
}) })
doc.new_entry("example2", "shanghai", { doc.add_entry("example2", "shanghai", {
name="Shanghai", name="Shanghai",
data = { data = {
description = "Shanghai lies in China and is one of the biggest cities in the world.", description = "Shanghai lies in China and is one of the biggest cities in the world.",
population = 23019148, population = 23019148,
}, },
}) })
doc.new_entry("example2", "tripoli", { doc.add_entry("example2", "tripoli", {
name="Tripoli", name="Tripoli",
data = { data = {
description = "Tripoli is the capital of Lybia.", 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 --[[ Formspec category: This category shows how you can add widgets in entries
and even interact with them ]] and even interact with them ]]
doc.new_category("example3", { doc.add_category("example3", {
name="Example: Formspec", name="Example: Formspec",
description="Example category for manual free-form formspec entries", description="Example category for manual free-form formspec entries",
--[[ This is a built-in formspec builder. In this case, the entry data --[[ 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) -- Just an entry with a label (BAD example)
doc.new_entry("example3", "simple_bad", { doc.add_entry("example3", "simple_bad", {
name="Label", name="Label",
-- Please note the coordinates are shoddily chosen here, the don't respect -- 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. -- 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) -- Just an entry with a label (good example)
doc.new_entry("example3", "simple_good", { doc.add_entry("example3", "simple_good", {
name="Label", name="Label",
--[[ This is the proper way to add widgets (this is also how you should do it in build_formspec): --[[ 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, 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? -- 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", name="Label",
-- Label, just like before -- Label, just like before
data = "label["..doc.FORMSPEC.ENTRY_START_X..","..doc.FORMSPEC.ENTRY_START_Y..";Just another label.]" .. 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. -- This entry will be interactive.
doc.new_entry("example3", "testbutton", { doc.add_entry("example3", "testbutton", {
name="Event Button", name="Event Button",
-- This button actually will be used for an event … -- 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]", data = "button["..doc.FORMSPEC.ENTRY_START_X..","..doc.FORMSPEC.ENTRY_START_Y..";5,1;example_button;Event]",
@ -196,7 +202,7 @@ end)
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
--[[ This category demonstrates the use of the gallery widget. ]] --[[ This category demonstrates the use of the gallery widget. ]]
-- FIXME: Depends on Minetest Game -- FIXME: Depends on Minetest Game
doc.new_category("example4", { doc.add_category("example4", {
name="Example: Galleries", name="Example: Galleries",
build_formspec = function(data, playername) build_formspec = function(data, playername)
-- The trick here is to include doc.widgets.gallery into the custom -- The trick here is to include doc.widgets.gallery into the custom
@ -210,7 +216,7 @@ doc.new_category("example4", {
}) })
-- Several gallery entries -- Several gallery entries
doc.new_entry("example4", "gallery2", { doc.add_entry("example4", "gallery2", {
name="Gallery with 2 images", name="Gallery with 2 images",
-- The entry data will be also fed into `doc_widgets_gallery` -- The entry data will be also fed into `doc_widgets_gallery`
data = { data = {
@ -219,7 +225,7 @@ doc.new_entry("example4", "gallery2", {
}, },
}) })
doc.new_entry("example4", "gallery3", { doc.add_entry("example4", "gallery3", {
name="Gallery with 3 images", name="Gallery with 3 images",
data = { data = {
{image="default_grass.png"}, {image="default_grass.png"},
@ -227,7 +233,10 @@ doc.new_entry("example4", "gallery3", {
{image="default_papyrus.png"}}, {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", name="Gallery with 4 images",
data = { data = {
{image="default_dirt.png"}, {image="default_dirt.png"},
@ -237,7 +246,7 @@ doc.new_entry("example4", "gallery4", {
}, },
}) })
doc.new_entry("example4", "gallery5", { doc.add_entry("example4", "gallery5", {
name="Gallery with 5 images", name="Gallery with 5 images",
data = { data = {
{image="default_dirt.png"}, {image="default_dirt.png"},
@ -248,7 +257,7 @@ doc.new_entry("example4", "gallery5", {
}, },
}) })
doc.new_entry("example4", "gallery6", { doc.add_entry("example4", "gallery6", {
name="Gallery with 6 images", name="Gallery with 6 images",
data = { data = {
{image="default_grass.png"}, {image="default_grass.png"},
@ -259,7 +268,7 @@ doc.new_entry("example4", "gallery6", {
{image="default_bronze_block.png"}}, {image="default_bronze_block.png"}},
}) })
doc.new_entry("example4", "gallery7", { doc.add_entry("example4", "gallery7", {
name="Gallery with 7 item images", name="Gallery with 7 item images",
data = { data = {
-- You can use this syntax to display item images instead of normal textures -- You can use this syntax to display item images instead of normal textures