Split default snippets
[minetest_tt.git] / init.lua
blob134caae98a115ec7a8d93d5101fa4c1e95a9b615
1 local S = minetest.get_translator("tt")
3 tt = {}
4 tt.COLOR_DEFAULT = "#d0ffd0"
5 tt.COLOR_DANGER = "#ffff00"
6 tt.COLOR_GOOD = "#00ff00"
8 -- API
9 tt.registered_snippets = {}
11 tt.register_snippet = function(func)
12 table.insert(tt.registered_snippets, func)
13 end
15 -- Register core snippets
17 dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets_core.lua")
18 dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets_builtin.lua")
20 -- Apply item description updates
22 local function append_snippets()
23 for itemstring, def in pairs(minetest.registered_items) do
24 if itemstring ~= "" and itemstring ~= "air" and itemstring ~= "ignore" and itemstring ~= "unknown" and def ~= nil and def.description ~= nil and def.description ~= "" and def._tt_ignore ~= true then
25 local desc = def.description
26 local orig_desc = desc
27 local first = true
28 -- Apply snippets
29 for s=1, #tt.registered_snippets do
30 local str, snippet_color = tt.registered_snippets[s](itemstring)
31 if snippet_color == nil then
32 snippet_color = tt.COLOR_DEFAULT
33 elseif snippet_color == false then
34 snippet_color = false
35 end
36 if str then
37 if first then
38 first = false
39 else
40 desc = desc .. "\n"
41 end
42 if snippet_color then
43 desc = desc .. minetest.colorize(snippet_color, str)
44 else
45 desc = desc .. str
46 end
47 end
48 end
49 if desc ~= def.description then
50 minetest.override_item(itemstring, { description = desc, _tt_original_description = orig_desc })
51 end
52 end
53 end
54 end
56 minetest.register_on_mods_loaded(append_snippets)