Differences From
Artifact [330ca92ebf]:
- File
init.lua
— part of check-in
[3f6a913e4e]
at
2020-09-29 12:40:28
on branch trunk
— * remove former hacky registration system, replace with consistent and flexible API; rewrite metal/gem generation to take advantage of this new API; tweaks to init system to enable world-local tweaks to lore and sorcery behavior
* initial documentation commit
* initial steps towards calendar - add default date format, astrolabe; prepare infra for division/melding/transmutation spells, various tweaks and fixes
(user:
lexi,
size: 3736)
[annotate]
[blame]
[check-ins using]
1 1 do
2 2 local path = minetest.get_modpath('sorcery');
3 3 local get = function(unit)
4 4 return dofile(path .. '/' .. unit .. '.lua')
5 5 end
6 + local test = function(file) -- :/
7 + local hnd = io.open(file,'r')
8 + if hnd == nil then return false else
9 + hnd:close()
10 + return true
11 + end
12 + end
13 + local worldcfg = function(str)
14 + return minetest.get_worldpath() .. '/' .. str
15 + end
16 + local cfg = function(str) return worldcfg('sorcery/' .. str) end
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 +
6 24 sorcery = {
25 + self = selfname;
7 26 path = path;
8 27 load = function(name) get(name) end;
9 - unit = function(ns,sfx)
28 + worldcfg = worldcfg, cfg = cfg;
29 + stage = stage;
30 + log = function(module,text)
31 + if module then
32 + minetest.log('info',string.format('[%s :: %s] %s',selfname,module,text))
33 + else
34 + minetest.log('info',string.format('[%s] %s',selfname,text))
35 + end
36 + end;
37 + act = function(module,text)
38 + minetest.log('action',string.format('[%s :: %s] %s',selfname,module,text))
39 + end;
40 + unit = function(ns,sfx,override)
10 41 local target
11 42 if ns then
12 43 sorcery[ns] = {}
13 44 target = sorcery[ns]
14 45 else target = sorcery end
46 + if override == true then override = ''
47 + elseif override then override = override .. '-' end
48 + local loaded = {}
15 49 return function(lst)
16 - for i=1,#lst do
17 - target[lst[i]] = get(((ns and ns..'/') or '')..lst[i])
50 + for i,name in pairs(lst) do
51 + if not loaded[name] then
52 + loaded[name] = true
53 + local fpath = ((ns and ns..'/') or '')..name
54 + local extra = cfg(string.format('%s%s-extra.lua', override,name))
55 + local replace = cfg(string.format('%s%s.lua', override,name))
56 + local default = get(fpath)
57 + if override and test(replace) then
58 + sorcery.log(name,'loading local replacement for ' .. fpath .. ' from ' .. replace)
59 + target[name] = loadfile(replace)(default)
60 + else
61 + target[name] = default
62 + if override and test(extra) then
63 + sorcery.log(name,'loading local extras for ' .. fpath .. ' from ' .. extra)
64 + local extbl = loadfile(extra)(default)
65 + for k,v in pairs(extbl) do target[name][k] = v end
66 + end
67 + end
68 + end
18 69 end
19 70 end
20 71 end;
21 72 }
22 73 end
23 74
24 75 -- unfortunately we can't just iterate over the files
25 76 -- and load them automatically, as interdependencies
26 77 -- exist (especially with /lib) and we need to be very
27 78 -- careful about the order they're loaded in
28 79
29 -sorcery.unit('data') {'ui'}
80 +local data = sorcery.unit('data',nil,'lore')
81 +local root = sorcery.unit()
82 +sorcery.stage('bootstrap',data,root)
83 +
84 +data {'ui'}
30 85 sorcery.unit('lib') {
31 86 -- convenience
32 87 'str';
33 88 -- serialization
34 89 'marshal', 'json';
35 90 -- data structures
36 91 'tbl', 'class';
37 92 -- wrappers
38 93 'color', 'image', 'ui';
39 94 -- game
40 95 'node';
41 96 }
42 97
43 -sorcery.unit() { 'compat', 'matreg' }
44 -sorcery.unit('data') {
45 - 'compat';
46 - 'affinities'; 'gods';
47 - 'enchants', 'spells';
48 - 'gems', 'metals';
49 - 'potions', 'oils', 'greases',
50 - 'draughts', 'elixirs',
51 - 'philters', 'extracts';
52 - 'register';
53 -}
98 +sorcery.stage('worldbuilding',data,root)
99 +root {'compat','matreg'}
100 +if not sorcery.stage('loadlore', data, root) then
101 + data {
102 + 'compat';
103 + 'affinities'; 'gods';
104 + 'calendar', 'signs';
105 + 'enchants', 'spells';
106 + 'gems', 'metals';
107 + 'potions', 'oils', 'greases',
108 + 'draughts', 'elixirs',
109 + 'philters', 'extracts';
110 + }
111 +end
112 +
113 +sorcery.load('registration') do
114 + local exclude = {'compat','ui'}
115 + for k,v in pairs(sorcery.data) do
116 + if not sorcery.lib.tbl.has(exclude,k) then
117 + sorcery.registry.mk(k,v)
118 + end
119 + end
120 +end
54 121
122 +sorcery.stage('startup',data)
55 123 for _,u in pairs {
56 124 'attunement'; 'context'; 'itemclass'; 'potions';
57 125 'metal', 'gems'; 'leylines'; 'infuser'; 'altar';
58 126 'wands'; 'tools', 'crafttools'; 'enchanter';
59 127 'harvester'; 'metallurgy-hot', 'metallurgy-cold';
60 128 'entities'; 'recipes'; 'coins'; 'interop';
61 129 'tnodes'; 'forcefield'; 'farcaster'; 'portal';
62 130 'cookbook', 'writing'; 'disassembly'; 'displacer';
63 - 'gravitator';
131 + 'gravitator'; 'precipitator'; 'astrolabe';
64 132
65 133 'admin';
66 134 } do sorcery.load(u) end
135 +sorcery.stage('finalize')
67 136
137 +sorcery.registry.defercheck()