sorcery  Diff

Differences From Artifact [330ca92ebf]:

To Artifact [f5b9efd3d5]:

  • 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
2
3
4
5


















6

7
8












9
10
11
12
13
14



15
16



17















18
19
20
21
22
23
24
25
26
27
28
29




30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


45
46

47
48
49
50
51
52
53

54










55
56
57
58
59
60
61
62
63
64
65
66

67

do
	local path = minetest.get_modpath('sorcery');
	local get = function(unit)
		return dofile(path .. '/' .. unit .. '.lua')
	end


















	sorcery = {

		path = path;
		load = function(name) get(name) end;












		unit = function(ns,sfx)
			local target
			if ns then
				sorcery[ns] = {}
				target = sorcery[ns]
			else target = sorcery end



			return function(lst)
				for i=1,#lst do



					target[lst[i]] = get(((ns and ns..'/') or '')..lst[i])















				end
			end
		end;
	}
end

-- 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

sorcery.unit('data') {'ui'}




sorcery.unit('lib') {
	-- convenience
	'str';
	-- serialization
	'marshal', 'json';
	-- data structures
	'tbl', 'class';
	-- wrappers
	'color', 'image', 'ui';
	-- game
	'node';
}

sorcery.unit() { 'compat', 'matreg' }
sorcery.unit('data') {


	'compat';
	'affinities'; 'gods';

	'enchants', 'spells';
	'gems', 'metals';
	'potions', 'oils', 'greases',
		'draughts', 'elixirs',
		'philters', 'extracts';
	'register';
}












for _,u in pairs {
	'attunement'; 'context'; 'itemclass'; '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';

	'admin';
} do sorcery.load(u) end








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>


>
>
>
>
>
>
>
>
>
>
>
>
|





>
>
>

<
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>











|
>
>
>
>













|
|
>
>
|
|
>
|
|
|
|
|
<
|
>

>
>
>
>
>
>
>
>
>
>








|



>

>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
do
	local path = minetest.get_modpath('sorcery');
	local get = function(unit)
		return dofile(path .. '/' .. unit .. '.lua')
	end
	local test = function(file) -- :/
		local hnd = io.open(file,'r')
		if hnd == nil then return false else
			hnd:close()
			return true
		end
	end
	local worldcfg = function(str)
		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

	sorcery = {
		self = selfname;
		path = path;
		load = function(name) get(name) end;
		worldcfg = worldcfg, cfg = cfg;
		stage = stage;
		log = function(module,text)
			if module then
				minetest.log('info',string.format('[%s :: %s] %s',selfname,module,text))
			else
				minetest.log('info',string.format('[%s] %s',selfname,text))
			end
		end;
		act = function(module,text)
			minetest.log('action',string.format('[%s :: %s] %s',selfname,module,text))
		end;
		unit = function(ns,sfx,override)
			local target
			if ns then
				sorcery[ns] = {}
				target = sorcery[ns]
			else target = sorcery end
			if override == true then override = ''
				elseif override then override = override .. '-' end
			local loaded = {}
			return function(lst)

				for i,name in pairs(lst) do
					if not loaded[name] then
						loaded[name] = true
						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)
						if override and test(replace) then
							sorcery.log(name,'loading local replacement for ' .. fpath .. ' from ' .. replace)
							target[name] = loadfile(replace)(default)
						else
							target[name] = default
							if override and test(extra) then
								sorcery.log(name,'loading local extras for ' .. fpath .. ' from ' .. extra)
								local extbl = loadfile(extra)(default)
								for k,v in pairs(extbl) do target[name][k] = v end
							end
						end
					end
				end
			end
		end;
	}
end

-- 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 data = sorcery.unit('data',nil,'lore')
local root = sorcery.unit()
sorcery.stage('bootstrap',data,root)

data {'ui'}
sorcery.unit('lib') {
	-- convenience
	'str';
	-- serialization
	'marshal', 'json';
	-- data structures
	'tbl', 'class';
	-- wrappers
	'color', 'image', 'ui';
	-- game
	'node';
}

sorcery.stage('worldbuilding',data,root)
root {'compat','matreg'}
if not sorcery.stage('loadlore', data, root) then
	data {
		'compat';
		'affinities'; 'gods';
		'calendar', 'signs';
		'enchants', 'spells';
		'gems', 'metals';
		'potions', 'oils', 'greases',
			'draughts', 'elixirs',
			'philters', 'extracts';

	}
end

sorcery.load('registration') do
	local exclude = {'compat','ui'}
	for k,v in pairs(sorcery.data) do
		if not sorcery.lib.tbl.has(exclude,k) then
			sorcery.registry.mk(k,v)
		end
	end
end

sorcery.stage('startup',data)
for _,u in pairs {
	'attunement'; 'context'; 'itemclass'; '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'; 'astrolabe';

	'admin';
} do sorcery.load(u) end
sorcery.stage('finalize')

sorcery.registry.defercheck()