You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

85 lines
2.0 KiB

  1. --
  2. -- formspeclib pre-baked objects
  3. --
  4. -- Making formspecs even more fun!
  5. --
  6. --
  7. -- formspeclib:player_inventory - The current player's inventory
  8. --
  9. -- Syntax: x, y
  10. --
  11. formspeclib.register_object('formspeclib:player_inventory', function(obj, safe_mode)
  12. if type(obj.y) ~= 'number' then return false end
  13. return {{
  14. type = 'inventory',
  15. x = obj.x,
  16. y = obj.y,
  17. width = 8,
  18. height = 1,
  19. location = 'current_player',
  20. name = 'main',
  21. shift_click = true,
  22. },
  23. {
  24. type = 'inventory',
  25. x = obj.x,
  26. y = obj.y + 1.23,
  27. width = 8,
  28. height = 3,
  29. location = 'current_player',
  30. name = 'main',
  31. start_at = 8,
  32. }}
  33. end)
  34. --
  35. -- formspeclib:node_inventory - The current node's inventory
  36. --
  37. -- Syntax: x, y, width(?), height(?), name(?)
  38. --
  39. formspeclib.register_object('formspeclib:node_inventory', function(obj, safe_mode)
  40. return {{
  41. type = 'inventory',
  42. x = obj.x,
  43. y = obj.y,
  44. width = obj.width or 8,
  45. height = obj.height or 4,
  46. location = 'context',
  47. name = obj.name or 'main',
  48. shift_click = true,
  49. }}
  50. end)
  51. --
  52. -- formspeclib:chest - Most useful with chest touchscreens.
  53. --
  54. -- Syntax: x(?), y(?), width(?), height(?)
  55. --
  56. formspeclib.register_object('formspeclib:chest', function(obj, safe_mode)
  57. local r = not obj.x and not obj.y
  58. if type(obj.x) ~= 'number' then obj.x = 0 end
  59. if type(obj.y) ~= 'number' then obj.y = 0 end
  60. if type(obj.width) ~= 'number' then obj.width = 8 end
  61. if type(obj.height) ~= 'number' then obj.height = 4 end
  62. return {
  63. width = r and obj.width,
  64. height = r and obj.height + 5,
  65. {
  66. type = 'formspeclib:node_inventory',
  67. x = obj.x,
  68. y = obj.y + 0.3,
  69. width = obj.width,
  70. height = obj.height,
  71. name = obj.name,
  72. },
  73. {
  74. type = 'formspeclib:player_inventory',
  75. x = obj.x + (obj.width / 2) - 4,
  76. y = obj.y + obj.height + 0.82,
  77. },
  78. }
  79. end)