Differences From
Artifact [89adffa44b]:
- 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]
31 31 vessel = { caption = 'Any Bottle', cnitem = 'vessels:glass_bottle' };
32 32 flower = { caption = 'Any Flower', cnitem = 'flowers:rose' };
33 33 mushroom = { caption = 'Any Mushroom', cnitem = 'flowers:mushroom_brown' };
34 34 water_bucket = { caption = 'Water Bucket', cnitem = 'bucket:bucket_water' };
35 35 sorcery_ley_cable = { caption = 'Cable', cnitem = 'sorcery:cable_vidrium' };
36 36 };
37 37 }
38 +sorcery.cookbook.constants = constants
38 39
39 40 local slot3x3 = {
40 41 {0,0}, {1,0}, {2,0};
41 42 {0,1}, {1,1}, {2,1};
42 43 {0,2}, {1,2}, {2,2};
43 44 }
44 45 local props_builtin = function(item)
................................................................................
82 83 return names[math.random(#names)]
83 84 end end
84 85 local find_builtin = function(out)
85 86 local rec = {}
86 87 local i = minetest.get_craft_recipe(out)
87 88 if i == nil or i.items == nil or #i.items == 0 then return nil end
88 89 local w = (i.width == 0) and 3 or i.width
89 - for j=1,#i.items do
90 + -- for j=1,#i.items do
91 + for j,item in pairs(i.items) do
90 92 local row = math.floor((j-1) / w)
91 93 local col = (j-1) % w
92 94 if i.items[j] then
93 95 rec[1 + (row * 3) + col] = i.items[j]
94 96 end
95 97 end
96 98 return rec
................................................................................
157 159 end
158 160 end;
159 161 }
160 162 sorcery.cookbook.classes = {
161 163 craft = {
162 164 name = 'Crafting Guide';
163 165 node = 'xdecor:workbench';
164 - booksuf = 'Manual';
166 + booksuf = 'Codex';
165 167 w = 3, h = 3;
166 168 chance = 2;
167 169 slots = slot3x3;
168 170 pick = pick_builtin('normal');
169 171 find = find_builtin;
170 - desc = desc_builtin;
171 172 props = props_builtin;
172 173 apply_exclusions = true;
173 174 };
174 175 -- smelt = {
175 176 -- w = 3, h = 3;
176 177 -- slots = slot3x3;
177 178 -- };
................................................................................
234 235 w = 1, h = 2;
235 236 pick = function(restrict)
236 237 cache:populate_grindables()
237 238 local i = cache.grindables[math.random(#cache.grindables)]
238 239 local pd = sorcery.itemclass.get(i, 'grindable')
239 240 return pd.powder
240 241 end;
241 - desc = desc_builtin;
242 242 props = props_builtin;
243 243 slots = {
244 244 {0,1},
245 245 {0,0};
246 246 };
247 247 find = function(out)
248 248 cache:populate_grindables()
................................................................................
377 377 end
378 378 end
379 379 local img, ot
380 380 local props = k.props(result)
381 381 if props.note then
382 382 local nx, ny, nw, nh
383 383 if notes_right then
384 - nx = 5 ny = 0
385 - nw = 3 nh = 3
384 + nx = 5.25 ny = 0
385 + nw = 4 nh = 3
386 386 else
387 387 nx = 0 ny = 3
388 388 nw = 4 nh = 1
389 389 end
390 390 t = t .. string.format([[
391 - textarea[%f,%f;%f,%f;;;%s]
391 + hypertext[%f,%f;%f,%f;note;<global valign=middle halign=justify size=20>%s]
392 392 ]], nx,ny,nw,nh, minetest.formspec_escape(props.note))
393 393 end
394 394 if k.icon then img = k.icon(result) end
395 395 if k.outdesc then ot = k.outdesc(result) else ot = desc_builtin(result) end
396 396 -- image[%f,%f;1,1;gui_furnace_arrow_bg.png^[transformR270]
397 397 return t .. string.format([[
398 398 item_image[%f,%f;1,1;%s]tooltip[%f,%f;1,1;%s]
................................................................................
468 468 type = 'shapeless';
469 469 recipe = {
470 470 'sorcery:cookbook';
471 471 'default:book';
472 472 };
473 473 output = 'sorcery:cookbook';
474 474 };
475 +
476 +-- erase cookbooks in the usual way
477 +minetest.register_craft {
478 + type = 'shapeless';
479 + recipe = {
480 + 'sorcery:cookbook';
481 + 'bucket:bucket_water';
482 + };
483 + output = 'default:book';
484 + replacements = {
485 + {'bucket:bucket_water','bucket:bucket_empty'};
486 + };
487 +};
475 488
476 489 local m = sorcery.lib.marshal
477 490 local encbook, decbook = m.transcoder {
478 491 pages = m.g.array(8, m.g.struct {
479 492 kind = m.t.str;
480 493 name = m.t.str;
481 494 })
................................................................................
483 496
484 497 local bookprops = function(stack)
485 498 local meta = stack:get_meta()
486 499 if meta:contains('cookbook') then
487 500 return decbook(sorcery.lib.str.meta_dearmor(meta:get_string('cookbook'),true))
488 501 else return {pages={}} end
489 502 end
503 +
504 +sorcery.cookbook.get = bookprops
505 +sorcery.cookbook.set = function(stack,props)
506 + local meta = stack:get_meta()
507 + meta:set_string('cookbook', sorcery.lib.str.meta_armor(encbook(props),true))
508 +end
509 +
510 +sorcery.cookbook.defaults = {
511 + indesc = desc_builtin;
512 + outdesc = desc_builtin;
513 + title = desc_builtin;
514 + props = props_builtin;
515 + pick = pick_builtin;
516 + find = find_builtin;
517 +}
518 +
519 +sorcery.cookbook.recfn = function(class,fn)
520 + local c = sorcery.cookbook.classes[class]
521 + if c[fn] then return c[fn] end
522 + return sorcery.cookbook.defaults[fn]
523 +end
490 524
491 525 local bookform_ctx = {}
492 526 local bookform = function(stack,user)
493 527 bookform_ctx[user:get_player_name()] = user:get_wield_index()
494 528
495 529 local meta = stack:get_meta()
496 530 local book = bookprops(stack)
................................................................................
498 532 local curpage = meta:contains("pagenr") and meta:get_int("pagenr") or 1
499 533
500 534 local pgofs = (curpage - 1) * constants.recipes_per_cookbook_page
501 535 local form = string.format([[
502 536 formspec_version[3]
503 537 size[10,12]real_coordinates[true]
504 538 box[0,0;10,1;#580C39FF]label[0.4,0.5;%s]
505 - button_exit[3,11;4,1;quit;Page %u/%u]
539 + style[pgind;border=false]
540 + style[pgind:hovered;content_offset=0,0]
541 + button[3,11;4,1;pgind;Page %u/%u]
506 542 ]], minetest.formspec_escape(meta:get_string('description')),
507 543 curpage, pagect)
544 + -- using an extremely dishonorable trick to fake centered text
508 545
509 546 if curpage > 1 then form = form .. 'button[0,11;3,1;pageback;< Back]' end
510 547 if curpage < pagect then form = form .. 'button[7,11;3,1;pagenext;Next >]' end
511 548
512 549 local coords = {
513 - {2,1.3};
514 - {2,4.5};
515 - {2,7.7};
550 + {0.85,1.3};
551 + {0.85,4.5};
552 + {0.85,7.7};
516 553 -- {0,1.3}, {4, 1.3};
517 554 -- {0,4.7}, {4, 4.7};
518 555 -- {0,8.1}, {4, 8.1};
519 556 }
520 557 for i=pgofs,(pgofs + constants.recipes_per_cookbook_page-1) do
521 558 local maxw, maxh = 3, 2
522 559 if not book.pages[i+1] then break end