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     78   				    (restrict.mod   and module ~= restrict.mod)
    79     79   				 or (restrict.group and (minetest.get_item_group(k, restrict.group) == 0))
    80     80   			))) then names[#names + 1] = k end
    81     81   		end
    82     82   	end
    83     83   	return names[math.random(#names)]
    84     84   end end
    85         -local find_builtin = function(out)
    86         -	local rec = {}
    87         -	local i = minetest.get_craft_recipe(out)
    88         -	if i == nil or i.items == nil or #i.items == 0 then return nil end
    89         -	local w = (i.width == 0) and 3 or i.width
    90         -	-- for j=1,#i.items do
    91         -	for j,item in pairs(i.items) do
    92         -		local row = math.floor((j-1) / w)
    93         -		local col = (j-1) % w
    94         -		if i.items[j] then
    95         -			rec[1 + (row * 3) + col] = i.items[j]
           85  +local find_builtin = function(method,kind)
           86  +	return function(out)
           87  +		local rec = {}
           88  +		local crec = sorcery.lib.tbl.walk(minetest.registered_items[out],{'_sorcery','recipe','canonical',kind})
           89  +		local w=0, lst
           90  +		if crec then
           91  +			lst = {}
           92  +			for i,v in pairs(crec) do
           93  +				if #v > w then w = #v end
           94  +				for j,n in pairs(v) do
           95  +					lst[#lst+1] = n
           96  +				end
           97  +			end
           98  +		else
           99  +			-- WHY IS THIS INTERFACE SO CLUMSY
          100  +			local all,i = minetest.get_all_craft_recipes(out), nil
          101  +			for _,r in pairs(all) do
          102  +				if r.method == method and r.items and #r.items>0 then
          103  +					i = r break
          104  +				end
          105  +			end
          106  +			if i == nil or i.items == nil or #i.items == 0 then return nil end
          107  +			w = (i.width == 0) and 3 or i.width
          108  +			lst = i.items
          109  +		end
          110  +		-- for j=1,#i.items do
          111  +		for j,item in pairs(lst) do
          112  +			local row = math.floor((j-1) / w)
          113  +			local col = (j-1) % w
          114  +			if item then
          115  +				rec[1 + (row * 3) + col] = item
          116  +			end
    96    117   		end
          118  +		return rec
    97    119   	end
    98         -	return rec
    99    120   end
   100    121   local function group_eval(i)
   101    122   	if string.sub(i,1,6) == 'group:' then
   102    123   		local g = string.sub(i,7)
   103    124   		if constants.group_ids[g] then
   104    125   			return constants.group_ids[g].cnitem,
   105    126   			       constants.group_ids[g].caption
................................................................................
   164    185   		name = 'Crafting Guide';
   165    186   		node = 'xdecor:workbench';
   166    187   		booksuf = 'Codex';
   167    188   		w = 3, h = 3;
   168    189   		chance = 2;
   169    190   		slots = slot3x3;
   170    191   		pick = pick_builtin('normal');
   171         -		find = find_builtin;
          192  +		find = find_builtin('normal','craft');
   172    193   		props = props_builtin;
   173    194   		apply_exclusions = true;
   174    195   	};
   175    196   	-- smelt = {
   176    197   	-- 	w = 3, h = 3;
   177    198   	-- 	slots = slot3x3;
   178    199   	-- };
................................................................................
   180    201   		name = 'Cooking Recipe';
   181    202   		node = 'default:furnace';
   182    203   		booksuf = 'Cookbook';
   183    204   		w = 1, h = 1;
   184    205   		chance = 3;
   185    206   		slots = {{-0.2,0}};
   186    207   		pick = pick_builtin('cooking');
   187         -		find = find_builtin;
          208  +		find = find_builtin('cooking','cook');
   188    209   		props = props_builtin;
   189    210   		apply_exclusions = true;
   190    211   	};
   191    212   	infuse = {
   192    213   		name = 'Infusion Recipe';
   193    214   		node = 'sorcery:infuser';
   194    215   		booksuf = 'Pharmacopeia';
................................................................................
   356    377   
   357    378   	return recipe_kinds[kind].pick(restrict), kind
   358    379   end
   359    380   
   360    381   local render_recipe = function(kind,ingredients,result,notes_right)
   361    382   	local k = recipe_kinds[kind]
   362    383   	local t = ''
          384  +	local props = k.props(result)
   363    385   	for i=1,#k.slots do
          386  +		local ing = ingredients[i]
   364    387   		local x, y = k.slots[i][1], k.slots[i][2]
   365         -		if ingredients[i] and ingredients[i] ~= '' then
          388  +		if ing and ing ~= '' then
   366    389   			local tt
   367         -			if k.indesc then tt = k.indesc(ingredients[i]) else tt = desc_builtin(ingredients[i]) end
          390  +			if k.indesc then tt = k.indesc(ing) else tt = desc_builtin(ing) end
   368    391   			t = t .. string.format([[
   369    392   				item_image[%f,%f;1,1;%s]
   370    393   				tooltip[%f,%f;1,1;%s]
   371         -			]], x,y, minetest.formspec_escape(group_eval(ingredients[i])),
          394  +			]], x,y, minetest.formspec_escape(group_eval(ing)),
   372    395   			    x,y, minetest.formspec_escape(tt))
   373    396   		else
   374    397   			if k.drawslots == nil or k.drawslots then
   375    398   				t = string.format('box[%f,%f;0.1,0.1;#00000060]',x+0.45,y+0.45) .. t
   376    399   			end
   377    400   		end
   378    401   	end
   379    402   	local img, ot
   380         -	local props = k.props(result)
   381    403   	if props.note then
   382    404   		local nx, ny, nw, nh
   383    405   		if notes_right then
   384    406   			nx = 5.25 ny = 0
   385    407   			nw = 4 nh = 3
   386    408   		else
   387    409   			nx = 0 ny = 3