Move core snippets to snippets.lua
[minetest_tt.git] / init.lua
blobe36e3d104ba4c4e482d4ee1ba16e53f4198748b4
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.lua")
19 -- Apply item description updates
21 local function append_snippets()
22 for itemstring, def in pairs(minetest.registered_items) do
23 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
24 local desc = def.description
25 local orig_desc = desc
26 local first = true
27 -- Apply snippets
28 for s=1, #tt.registered_snippets do
29 local str, snippet_color = tt.registered_snippets[s](itemstring)
30 if snippet_color == nil then
31 snippet_color = tt.COLOR_DEFAULT
32 elseif snippet_color == false then
33 snippet_color = false
34 end
35 if str then
36 if first then
37 first = false
38 else
39 desc = desc .. "\n"
40 end
41 if snippet_color then
42 desc = desc .. minetest.colorize(snippet_color, str)
43 else
44 desc = desc .. str
45 end
46 end
47 end
48 if desc ~= def.description then
49 minetest.override_item(itemstring, { description = desc, _tt_original_description = orig_desc })
50 end
51 end
52 end
53 end
55 minetest.register_on_mods_loaded(append_snippets)