sorcery  Diff

Differences From Artifact [8803c503c6]:

To Artifact [58ff591804]:


    11     11   		end
    12     12   	end
    13     13   	local worldcfg = function(str)
    14     14   		return minetest.get_worldpath() .. '/' .. str
    15     15   	end
    16     16   	local cfg = function(str) return worldcfg('sorcery/' .. str) end
    17     17   	local selfname = minetest.get_current_modname()
    18         -	local stage = function(s,...)
    19         -		local f = sorcery.cfg(s .. '.lua')
    20         -		if test(f) then return loadfile(f)(...) or true end
    21         -		return false
    22         -	end
    23         -
    24     18   	local function
    25     19   	argjoin(arg, nxt, ...)
    26     20   		if arg and not nxt then return tostring(arg) end
    27     21   		if not arg then return "(nil)" end
    28     22   		return tostring(arg) .. ' ' .. argjoin(nxt, ...)
    29     23   	end
           24  +
           25  +	local logger = function(module)
           26  +		local emit = function(lvl)
           27  +			return function(...)
           28  +				if module then
           29  +					minetest.log(lvl,string.format('[%s :: %s] %s',selfname,module,argjoin(...)))
           30  +				else
           31  +					minetest.log(lvl,string.format('[%s] %s',selfname,argjoin(...)))
           32  +				end
           33  +			end
           34  +		end
           35  +		return {
           36  +			info = emit('info');
           37  +			warn = emit('warning');
           38  +			err = emit('error');
           39  +			act = emit('action');
           40  +		}
           41  +	end;
           42  +
           43  +	local stage = function(s,...)
           44  +		logger().info('entering stage',s)
           45  +		local f = sorcery.cfg(s .. '.lua')
           46  +		if test(f) then return loadfile(f)(...) or true end
           47  +		return false
           48  +	end
    30     49   
    31     50   	sorcery = {
    32     51   		self = selfname;
    33     52   		path = path;
    34     53   		load = function(name) get(name) end;
    35     54   		worldcfg = worldcfg, cfg = cfg;
    36     55   		stage = stage;
................................................................................
    41     60   			else
    42     61   				minetest.log('info',string.format('[%s] %s',selfname,text))
    43     62   			end
    44     63   		end;
    45     64   		act = function(module,text)
    46     65   			minetest.log('action',string.format('[%s :: %s] %s',selfname,module,text))
    47     66   		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         -			}
    64         -		end;
           67  +		logger = logger;
    65     68   		unit = function(ns,sfx,override)
           69  +			if ns then logger('loader').info('opening unit',ns) end
           70  +			local log = logger(ns and ('loader/'..ns))
    66     71   			local target
    67     72   			if ns then
    68     73   				sorcery[ns] = {}
    69     74   				target = sorcery[ns]
    70     75   			else target = sorcery end
    71     76   			if override == true then override = ''
    72     77   				elseif override then override = override .. '-' end
    73     78   			local loaded = {}
    74     79   			return function(lst)
    75     80   				for i,name in pairs(lst) do
    76     81   					if not loaded[name] then
    77     82   						loaded[name] = true
    78         -						local log = sorcery.logger(name)
           83  +						log.info('installing component', name)
    79     84   						local fpath = ((ns and ns..'/') or '')..name
    80     85   						local extra = cfg(string.format('%s%s-extra.lua', override,name))
    81     86   						local replace = cfg(string.format('%s%s.lua', override,name))
    82     87   						local default = get(fpath)
    83     88   						if override and test(replace) then
    84     89   							log.info('loading local replacement for', fpath,'from', replace)
    85     90   							target[name] = loadfile(replace)(default)
................................................................................
   102    107   	sorcery.act = function(mod,...) return sorcery.logger(mod).act(...) end
   103    108   end
   104    109   
   105    110   -- unfortunately we can't just iterate over the files
   106    111   -- and load them automatically, as interdependencies
   107    112   -- exist (especially with /lib) and we need to be very
   108    113   -- careful about the order they're loaded in
          114  +
          115  +local log = sorcery.logger()
          116  +
          117  +log.info('loading data')
   109    118   
   110    119   local data = sorcery.unit('data',nil,'lore')
   111    120   local root = sorcery.unit()
   112    121   sorcery.stage('bootstrap',data,root)
   113    122   
   114    123   data {'ui'}
   115    124   sorcery.unit('lib') {
................................................................................
   129    138   root {'compat','matreg'}
   130    139   if not sorcery.stage('loadlore', data, root) then
   131    140   	data {
   132    141   		'compat';
   133    142   		'affinities'; 'gods';
   134    143   		'calendar', 'signs';
   135    144   		'resonance';
   136         -		'gems', 'metals';
          145  +		'trees', 'gems', 'metals';
   137    146   		'enchants', 'spells', 'runes';
   138    147   		'potions', 'oils', 'greases',
   139    148   			'draughts', 'elixirs',
   140    149   			'philters', 'extracts';
   141    150   	}
   142    151   end
   143    152   
................................................................................
   144    153   sorcery.load('registration') do
   145    154   	local exclude = {'compat','ui'}
   146    155   	for k,v in pairs(sorcery.data) do
   147    156   		if not sorcery.lib.tbl.has(exclude,k) then
   148    157   			sorcery.registry.mk(k,v)
   149    158   		end
   150    159   	end
          160  +	sorcery.registry.mk('residue',false)
   151    161   end
   152    162   
   153    163   sorcery.stage('startup',data)
   154    164   for _,u in pairs {
   155         -	'vfx'; 'attunement'; 'context'; 'itemclass'; 'spell';
   156         -	'liquid'; 'potions'; 'metal', 'gems'; 'leylines'; 'infuser';
   157         -	'altar'; 'wands'; 'tools', 'crafttools'; 'enchanter';
   158         -	'harvester'; 'metallurgy-hot', 'metallurgy-cold';
          165  +	'vfx'; 'context'; 'attunement'; 'itemclass'; 'craft'; 'spell';
          166  +	'liquid'; 'tree'; 'potions'; 'metal', 'gems'; 'leylines';
          167  +	'infuser'; 'altar'; 'wands'; 'tools', 'crafttools';
          168  +	'enchanter'; 'harvester'; 'metallurgy-hot', 'metallurgy-cold';
   159    169   	'entities'; 'recipes'; 'coins'; 'interop';
   160    170   	'tnodes'; 'forcefield'; 'farcaster'; 'portal';
   161    171   	'cookbook', 'writing'; 'disassembly'; 'displacer';
   162    172   	'gravitator'; 'precipitator'; 'calendar', 'astrolabe';
   163         -	'keypunch'; 'runeforge'; 'keg';
          173  +	'keypunch'; 'runeforge'; 'keg'; 'tap';
   164    174   
   165    175   	'privs', 'admin';
   166    176   } do sorcery.load(u) end
   167    177   sorcery.stage('finalize')
   168    178   
   169    179   sorcery.registry.defercheck()