Untangle hard dependencies on rp_default
[Pixture/pixture_revival.git] / mods / tt / init.lua
bloba79bf27b59e680ca11bfaef341c06cfc6c4187f9
1 tt = {}
2 tt.COLOR_DEFAULT = "#d0ffd0"
3 tt.COLOR_DANGER = "#ffff00"
4 tt.COLOR_GOOD = "#00ff00"
6 -- API
7 tt.registered_snippets = {}
9 tt.register_snippet = function(func)
10 table.insert(tt.registered_snippets, func)
11 end
13 dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets.lua")
15 -- Apply item description updates
17 local function append_snippets()
18 for itemstring, def in pairs(minetest.registered_items) do
19 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
20 local desc = def.description
21 local orig_desc = desc
22 local first = true
23 -- Apply snippets
24 for s=1, #tt.registered_snippets do
25 local str, snippet_color = tt.registered_snippets[s](itemstring)
26 if snippet_color == nil then
27 snippet_color = tt.COLOR_DEFAULT
28 elseif snippet_color == false then
29 snippet_color = false
30 end
31 if str then
32 if first then
33 first = false
34 end
35 desc = desc .. "\n"
36 if snippet_color then
37 desc = desc .. minetest.colorize(snippet_color, str)
38 else
39 desc = desc .. str
40 end
41 end
42 end
43 if desc ~= def.description then
44 minetest.override_item(itemstring, { description = desc, _tt_original_description = orig_desc })
45 end
46 end
47 end
48 end
50 minetest.register_on_mods_loaded(append_snippets)