@@ -14,20 +14,39 @@ return minetest.get_worldpath() .. '/' .. str end local cfg = function(str) return worldcfg('sorcery/' .. str) end local selfname = minetest.get_current_modname() - local stage = function(s,...) - local f = sorcery.cfg(s .. '.lua') - if test(f) then return loadfile(f)(...) or true end - return false - end - local function argjoin(arg, nxt, ...) if arg and not nxt then return tostring(arg) end if not arg then return "(nil)" end return tostring(arg) .. ' ' .. argjoin(nxt, ...) end + + local logger = function(module) + local emit = function(lvl) + return function(...) + if module then + minetest.log(lvl,string.format('[%s :: %s] %s',selfname,module,argjoin(...))) + else + minetest.log(lvl,string.format('[%s] %s',selfname,argjoin(...))) + end + end + end + return { + info = emit('info'); + warn = emit('warning'); + err = emit('error'); + act = emit('action'); + } + end; + + local stage = function(s,...) + logger().info('entering stage',s) + local f = sorcery.cfg(s .. '.lua') + if test(f) then return loadfile(f)(...) or true end + return false + end sorcery = { self = selfname; path = path; @@ -44,26 +63,12 @@ end; act = function(module,text) minetest.log('action',string.format('[%s :: %s] %s',selfname,module,text)) end; - logger = function(module) - local emit = function(lvl) - return function(...) - if module then - minetest.log(lvl,string.format('[%s :: %s] %s',selfname,module,argjoin(...))) - else - minetest.log(lvl,string.format('[%s] %s',selfname,argjoin(...))) - end - end - end - return { - log = emit('info'); - warn = emit('warning'); - err = emit('error'); - act = emit('action'); - } - end; + logger = logger; unit = function(ns,sfx,override) + if ns then logger('loader').info('opening unit',ns) end + local log = logger(ns and ('loader/'..ns)) local target if ns then sorcery[ns] = {} target = sorcery[ns] @@ -74,9 +79,9 @@ return function(lst) for i,name in pairs(lst) do if not loaded[name] then loaded[name] = true - local log = sorcery.logger(name) + log.info('installing component', name) local fpath = ((ns and ns..'/') or '')..name local extra = cfg(string.format('%s%s-extra.lua', override,name)) local replace = cfg(string.format('%s%s.lua', override,name)) local default = get(fpath) @@ -105,8 +110,12 @@ -- unfortunately we can't just iterate over the files -- and load them automatically, as interdependencies -- exist (especially with /lib) and we need to be very -- careful about the order they're loaded in + +local log = sorcery.logger() + +log.info('loading data') local data = sorcery.unit('data',nil,'lore') local root = sorcery.unit() sorcery.stage('bootstrap',data,root) @@ -132,9 +141,9 @@ 'compat'; 'affinities'; 'gods'; 'calendar', 'signs'; 'resonance'; - 'gems', 'metals'; + 'trees', 'gems', 'metals'; 'enchants', 'spells', 'runes'; 'potions', 'oils', 'greases', 'draughts', 'elixirs', 'philters', 'extracts'; @@ -147,23 +156,24 @@ if not sorcery.lib.tbl.has(exclude,k) then sorcery.registry.mk(k,v) end end + sorcery.registry.mk('residue',false) end sorcery.stage('startup',data) for _,u in pairs { - 'vfx'; 'attunement'; 'context'; 'itemclass'; 'spell'; - 'liquid'; 'potions'; 'metal', 'gems'; 'leylines'; 'infuser'; - 'altar'; 'wands'; 'tools', 'crafttools'; 'enchanter'; - 'harvester'; 'metallurgy-hot', 'metallurgy-cold'; + 'vfx'; 'context'; 'attunement'; 'itemclass'; 'craft'; 'spell'; + 'liquid'; 'tree'; 'potions'; 'metal', 'gems'; 'leylines'; + 'infuser'; 'altar'; 'wands'; 'tools', 'crafttools'; + 'enchanter'; 'harvester'; 'metallurgy-hot', 'metallurgy-cold'; 'entities'; 'recipes'; 'coins'; 'interop'; 'tnodes'; 'forcefield'; 'farcaster'; 'portal'; 'cookbook', 'writing'; 'disassembly'; 'displacer'; 'gravitator'; 'precipitator'; 'calendar', 'astrolabe'; - 'keypunch'; 'runeforge'; 'keg'; + 'keypunch'; 'runeforge'; 'keg'; 'tap'; 'privs', 'admin'; } do sorcery.load(u) end sorcery.stage('finalize') sorcery.registry.defercheck()