Differences From
Artifact [b6f042d41b]:
16 16 local cfg = function(str) return worldcfg('sorcery/' .. str) end
17 17 local selfname = minetest.get_current_modname()
18 18 local stage = function(s,...)
19 19 local f = sorcery.cfg(s .. '.lua')
20 20 if test(f) then return loadfile(f)(...) or true end
21 21 return false
22 22 end
23 +
24 + local function
25 + argjoin(arg, nxt, ...)
26 + if arg and not nxt then return tostring(arg) end
27 + if not arg then return "(nil)" end
28 + return tostring(arg) .. ' ' .. argjoin(nxt, ...)
29 + end
23 30
24 31 sorcery = {
25 32 self = selfname;
26 33 path = path;
27 34 load = function(name) get(name) end;
28 35 worldcfg = worldcfg, cfg = cfg;
29 36 stage = stage;
37 +
30 38 log = function(module,text)
31 39 if module then
32 40 minetest.log('info',string.format('[%s :: %s] %s',selfname,module,text))
33 41 else
34 42 minetest.log('info',string.format('[%s] %s',selfname,text))
35 43 end
36 44 end;
37 45 act = function(module,text)
38 46 minetest.log('action',string.format('[%s :: %s] %s',selfname,module,text))
47 + end;
48 + logger = function(module)
49 + local emit = function(lvl)
50 + return function(...)
51 + if module then
52 + minetest.log(lvl,string.format('[%s :: %s] %s',selfname,module,argjoin(...)))
53 + else
54 + minetest.log(lvl,string.format('[%s] %s',selfname,argjoin(...)))
55 + end
56 + end
57 + end
58 + return {
59 + log = emit('info');
60 + warn = emit('warning');
61 + err = emit('error');
62 + act = emit('action');
63 + }
39 64 end;
40 65 unit = function(ns,sfx,override)
41 66 local target
42 67 if ns then
43 68 sorcery[ns] = {}
44 69 target = sorcery[ns]
45 70 else target = sorcery end
................................................................................
46 71 if override == true then override = ''
47 72 elseif override then override = override .. '-' end
48 73 local loaded = {}
49 74 return function(lst)
50 75 for i,name in pairs(lst) do
51 76 if not loaded[name] then
52 77 loaded[name] = true
78 + local log = sorcery.logger(name)
53 79 local fpath = ((ns and ns..'/') or '')..name
54 80 local extra = cfg(string.format('%s%s-extra.lua', override,name))
55 81 local replace = cfg(string.format('%s%s.lua', override,name))
56 82 local default = get(fpath)
57 83 if override and test(replace) then
58 - sorcery.log(name,'loading local replacement for ' .. fpath .. ' from ' .. replace)
84 + log.info('loading local replacement for', fpath,'from', replace)
59 85 target[name] = loadfile(replace)(default)
60 86 else
61 87 target[name] = default
62 88 if override and test(extra) then
63 - sorcery.log(name,'loading local extras for ' .. fpath .. ' from ' .. extra)
89 + log.info('loading local extras for', fpath, 'from', extra)
64 90 local extbl = loadfile(extra)(default)
65 91 for k,v in pairs(extbl) do target[name][k] = v end
66 92 end
67 93 end
68 94 end
69 95 end
70 96 end
71 97 end;
72 98 }
99 +
100 + -- LEGACY INTERFACE
101 + sorcery.log = function(mod,...) return sorcery.logger(mod).info(...) end
102 + sorcery.act = function(mod,...) return sorcery.logger(mod).act(...) end
73 103 end
74 104
75 105 -- unfortunately we can't just iterate over the files
76 106 -- and load them automatically, as interdependencies
77 107 -- exist (especially with /lib) and we need to be very
78 108 -- careful about the order they're loaded in
79 109
................................................................................
119 149 end
120 150 end
121 151 end
122 152
123 153 sorcery.stage('startup',data)
124 154 for _,u in pairs {
125 155 'vfx'; 'attunement'; 'context'; 'itemclass'; 'spell';
126 - 'potions'; 'metal', 'gems'; 'leylines'; 'infuser';
156 + 'liquid'; 'potions'; 'metal', 'gems'; 'leylines'; 'infuser';
127 157 'altar'; 'wands'; 'tools', 'crafttools'; 'enchanter';
128 158 'harvester'; 'metallurgy-hot', 'metallurgy-cold';
129 159 'entities'; 'recipes'; 'coins'; 'interop';
130 160 'tnodes'; 'forcefield'; 'farcaster'; 'portal';
131 161 'cookbook', 'writing'; 'disassembly'; 'displacer';
132 162 'gravitator'; 'precipitator'; 'calendar', 'astrolabe';
133 - 'keypunch'; 'runeforge';
163 + 'keypunch'; 'runeforge'; 'keg';
134 164
135 165 'privs', 'admin';
136 166 } do sorcery.load(u) end
137 167 sorcery.stage('finalize')
138 168
139 169 sorcery.registry.defercheck()