summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2016-12-08 19:18:59 +0100
committerWuzzy <almikes@aol.com>2016-12-08 19:18:59 +0100
commit0ed6eb4951eb31b2f3b48c70514bf787a57cece0 (patch)
treec29fd0c95a7d2c6b175fca5c95f103c4ee122515
parent989ec62153a840b46f93085541ae4498bc6cc624 (diff)
Support factoids for tools and craftitems. Yay!
-rw-r--r--API.md4
-rw-r--r--init.lua27
2 files changed, 24 insertions, 7 deletions
diff --git a/API.md b/API.md
index 078a8a5..2731710 100644
--- a/API.md
+++ b/API.md
@@ -222,8 +222,8 @@ Add a custom factoid (see above) for the specified category.
* `category_id`: The documentation category fow which the factoid applies:
* `"nodes"`: Blocks
- * `"tools"`: Tools and weapons (***Not yet supported***)
- * `"craftitems"`: Misc. items (***Not yet supported***)
+ * `"tools"`: Tools and weapons
+ * `"craftitems"`: Misc. items
* `factoid_type`: Rough categorization of the factoid's content. Controls
where in the text the factoid appears. Possible values:
* `"groups"`: Factoid appears near groups
diff --git a/init.lua b/init.lua
index f87f162..45121df 100644
--- a/init.lua
+++ b/init.lua
@@ -251,6 +251,23 @@ factoid_generators.nodes = {}
factoid_generators.tools = {}
factoid_generators.craftitems = {}
+--[[ Returns a list of all registered factoids for the specified category and type
+* category_id: Identifier of the Documentation System category in which the factoid appears
+* factoid_type: If set, oly returns factoid with a matching factoid_type.
+ If nil, all factoids for this category will be generated ]]
+local get_custom_factoids = function(category_id, factoid_type, data)
+ local ftable = factoid_generators[category_id]
+ local datastring = ""
+ -- Custom factoids are inserted here
+ for i=1,#ftable do
+ if factoid_type == nil or ftable[i].ftype == factoid_type then
+ datastring = datastring .. ftable[i].fgen(data.itemstring, data.def)
+ datastring = newline(datastring)
+ end
+ end
+ return datastring
+end
+
function doc.sub.items.register_factoid(category_id, factoid_type, factoid_generator)
local ftable = { fgen = factoid_generator, ftype = factoid_type }
if category_id == "nodes" then
@@ -562,11 +579,7 @@ doc.new_category("nodes", {
end
datastring = newline2(datastring)
- -- Custom factoids are inserted here
- for i=1,#factoid_generators.nodes do
- datastring = datastring .. factoid_generators.nodes[i].fgen(data.itemstring, data.def)
- datastring = newline(datastring)
- end
+ datastring = datastring .. get_custom_factoids("nodes", "groups", data)
datastring = newline2(datastring)
-- Show other “exposable” groups in quick list
@@ -797,7 +810,9 @@ doc.new_category("tools", {
datastring = newline(datastring)
datastring = datastring .. toolcaps_to_text(data.def.tool_capabilities)
+ datastring = newline2(datastring)
+ datastring = datastring .. get_custom_factoids("tools", "groups", data)
datastring = newline2(datastring)
-- Show other “exposable” groups
@@ -863,7 +878,9 @@ doc.new_category("craftitems", {
datastring = newline(datastring)
datastring = datastring .. toolcaps_to_text(data.def.tool_capabilities)
+ datastring = newline2(datastring)
+ datastring = datastring .. get_custom_factoids("craftitems", "groups", data)
datastring = newline2(datastring)
-- Show other “exposable” groups