sorcery  Diff

Differences From Artifact [f535fa81e6]:

  • File cookbook.lua — part of check-in [72eebac4bc] at 2020-09-26 18:49:51 on branch trunk — add writing stand for editing codexes; add scissors, ink, erasure fluid, pens; touch up codex UI; add many recipe notes; add craft divination type for crafttools; defuckulate fucktarded crafttool impl; enhance table library with missing features like lua's table.unpack; many bug fixes and enhancements; blood for the blood god (user: lexi, size: 19056) [annotate] [blame] [check-ins using]

To Artifact [62888214aa]:

  • File cookbook.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: 19568) [annotate] [blame] [check-ins using]

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
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
...
356
357
358
359
360
361
362

363

364
365

366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
				    (restrict.mod   and module ~= restrict.mod)
				 or (restrict.group and (minetest.get_item_group(k, restrict.group) == 0))
			))) then names[#names + 1] = k end
		end
	end
	return names[math.random(#names)]
end end
local find_builtin = function(out)

	local rec = {}












	local i = minetest.get_craft_recipe(out)





	if i == nil or i.items == nil or #i.items == 0 then return nil end
	local w = (i.width == 0) and 3 or i.width


	-- for j=1,#i.items do
	for j,item in pairs(i.items) do
		local row = math.floor((j-1) / w)
		local col = (j-1) % w
		if i.items[j] then

			rec[1 + (row * 3) + col] = i.items[j]
		end
	end
	return rec

end
local function group_eval(i)
	if string.sub(i,1,6) == 'group:' then
		local g = string.sub(i,7)
		if constants.group_ids[g] then
			return constants.group_ids[g].cnitem,
			       constants.group_ids[g].caption
................................................................................
		name = 'Crafting Guide';
		node = 'xdecor:workbench';
		booksuf = 'Codex';
		w = 3, h = 3;
		chance = 2;
		slots = slot3x3;
		pick = pick_builtin('normal');
		find = find_builtin;
		props = props_builtin;
		apply_exclusions = true;
	};
	-- smelt = {
	-- 	w = 3, h = 3;
	-- 	slots = slot3x3;
	-- };
................................................................................
		name = 'Cooking Recipe';
		node = 'default:furnace';
		booksuf = 'Cookbook';
		w = 1, h = 1;
		chance = 3;
		slots = {{-0.2,0}};
		pick = pick_builtin('cooking');
		find = find_builtin;
		props = props_builtin;
		apply_exclusions = true;
	};
	infuse = {
		name = 'Infusion Recipe';
		node = 'sorcery:infuser';
		booksuf = 'Pharmacopeia';
................................................................................

	return recipe_kinds[kind].pick(restrict), kind
end

local render_recipe = function(kind,ingredients,result,notes_right)
	local k = recipe_kinds[kind]
	local t = ''

	for i=1,#k.slots do

		local x, y = k.slots[i][1], k.slots[i][2]
		if ingredients[i] and ingredients[i] ~= '' then

			local tt
			if k.indesc then tt = k.indesc(ingredients[i]) else tt = desc_builtin(ingredients[i]) end
			t = t .. string.format([[
				item_image[%f,%f;1,1;%s]
				tooltip[%f,%f;1,1;%s]
			]], x,y, minetest.formspec_escape(group_eval(ingredients[i])),
			    x,y, minetest.formspec_escape(tt))
		else
			if k.drawslots == nil or k.drawslots then
				t = string.format('box[%f,%f;0.1,0.1;#00000060]',x+0.45,y+0.45) .. t
			end
		end
	end
	local img, ot
	local props = k.props(result)
	if props.note then
		local nx, ny, nw, nh
		if notes_right then
			nx = 5.25 ny = 0
			nw = 4 nh = 3
		else
			nx = 0 ny = 3







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







 







|







 







|







 







>

>

<
>

|



|








<







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
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
377
378
379
380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
				    (restrict.mod   and module ~= restrict.mod)
				 or (restrict.group and (minetest.get_item_group(k, restrict.group) == 0))
			))) then names[#names + 1] = k end
		end
	end
	return names[math.random(#names)]
end end
local find_builtin = function(method,kind)
	return function(out)
		local rec = {}
		local crec = sorcery.lib.tbl.walk(minetest.registered_items[out],{'_sorcery','recipe','canonical',kind})
		local w=0, lst
		if crec then
			lst = {}
			for i,v in pairs(crec) do
				if #v > w then w = #v end
				for j,n in pairs(v) do
					lst[#lst+1] = n
				end
			end
		else
			-- WHY IS THIS INTERFACE SO CLUMSY
			local all,i = minetest.get_all_craft_recipes(out), nil
			for _,r in pairs(all) do
				if r.method == method and r.items and #r.items>0 then
					i = r break
				end
			end
			if i == nil or i.items == nil or #i.items == 0 then return nil end
			w = (i.width == 0) and 3 or i.width
			lst = i.items
		end
		-- for j=1,#i.items do
		for j,item in pairs(lst) do
			local row = math.floor((j-1) / w)
			local col = (j-1) % w

			if item then
				rec[1 + (row * 3) + col] = item
			end
		end
		return rec
	end
end
local function group_eval(i)
	if string.sub(i,1,6) == 'group:' then
		local g = string.sub(i,7)
		if constants.group_ids[g] then
			return constants.group_ids[g].cnitem,
			       constants.group_ids[g].caption
................................................................................
		name = 'Crafting Guide';
		node = 'xdecor:workbench';
		booksuf = 'Codex';
		w = 3, h = 3;
		chance = 2;
		slots = slot3x3;
		pick = pick_builtin('normal');
		find = find_builtin('normal','craft');
		props = props_builtin;
		apply_exclusions = true;
	};
	-- smelt = {
	-- 	w = 3, h = 3;
	-- 	slots = slot3x3;
	-- };
................................................................................
		name = 'Cooking Recipe';
		node = 'default:furnace';
		booksuf = 'Cookbook';
		w = 1, h = 1;
		chance = 3;
		slots = {{-0.2,0}};
		pick = pick_builtin('cooking');
		find = find_builtin('cooking','cook');
		props = props_builtin;
		apply_exclusions = true;
	};
	infuse = {
		name = 'Infusion Recipe';
		node = 'sorcery:infuser';
		booksuf = 'Pharmacopeia';
................................................................................

	return recipe_kinds[kind].pick(restrict), kind
end

local render_recipe = function(kind,ingredients,result,notes_right)
	local k = recipe_kinds[kind]
	local t = ''
	local props = k.props(result)
	for i=1,#k.slots do
		local ing = ingredients[i]
		local x, y = k.slots[i][1], k.slots[i][2]

		if ing and ing ~= '' then
			local tt
			if k.indesc then tt = k.indesc(ing) else tt = desc_builtin(ing) end
			t = t .. string.format([[
				item_image[%f,%f;1,1;%s]
				tooltip[%f,%f;1,1;%s]
			]], x,y, minetest.formspec_escape(group_eval(ing)),
			    x,y, minetest.formspec_escape(tt))
		else
			if k.drawslots == nil or k.drawslots then
				t = string.format('box[%f,%f;0.1,0.1;#00000060]',x+0.45,y+0.45) .. t
			end
		end
	end
	local img, ot

	if props.note then
		local nx, ny, nw, nh
		if notes_right then
			nx = 5.25 ny = 0
			nw = 4 nh = 3
		else
			nx = 0 ny = 3