watercrafts.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. local function crystal_ingot()
  2. local craft = {}
  3. local b0 = " "
  4. m1 = "default:mese_crystal"
  5. m2 = "ethereal:crystal_spike"
  6. m3 = "bucket:bucket_water"
  7. craft[1] = {m1, m2, m2}
  8. craft[2] = {m1, m3, b0}
  9. craft[3] = {b0, b0, b0}
  10. return craft
  11. end
  12. -- set m1row pattern
  13. local function m1row(m1, m2, m3, m4)
  14. local craft = {}
  15. local b0 = " "
  16. craft[1] = {m1, m1, m1}
  17. craft[2] = {m2, m3, m4}
  18. craft[3] = {b0, b0, b0}
  19. return craft
  20. end
  21. local function touch_response(dev, msg)
  22. if msg["key_enter_field"] == nil and msg["quit"] ~= nil then
  23. -- ignore the event when a player closes menu
  24. return
  25. end
  26. if msg["onoff"] ~= nil then
  27. mem.state = not mem.state
  28. if mem.state then
  29. digiline_send("lcd", "Ice machine started.")
  30. else
  31. digiline_send("lcd", "Ice machine stopped.")
  32. end
  33. elseif msg["key_enter_field"] == "vanilla" then
  34. local s1 = "farming:vanilla"
  35. local s2 = s1;
  36. local s3 = "farming:bottle_ethanol"
  37. local s4 = "bucket:bucket_water"
  38. digiline_send(dev, m1row(s1, s2, s3, s4))
  39. elseif msg["key_enter_field"] == "minty" then
  40. local s1 = "farming:mint_leaf"
  41. local s2 = "bucket:bucket_water"
  42. local s3 = "farming:juicer"
  43. local s4 = "vessels:drinking_glass"
  44. digiline_send(dev, m1row(s1, s2, s3, s4))
  45. elseif msg["key_enter_field"] == "soymilk" then
  46. local s1 = "farming:soy_beans"
  47. local s2 = "farming:vanilla_extract"
  48. local s3 = "bucket:bucket_water"
  49. local s4 = "vessels:drinking_glass"
  50. digiline_send(dev, m1row(s1, s2, s3, s4))
  51. elseif msg["key_enter_field"] == "crystalingot" then
  52. digiline_send(dev, crystal_ingot())
  53. end
  54. local quantity = msg[msg["key_enter_field"]]
  55. if tonumber(quantity) ~= nil then
  56. for i=1, quantity, 1 do
  57. digiline_send(dev, "single")
  58. end
  59. end
  60. end
  61. local function spawn_button(name, label, x, y)
  62. local btn_width = 3
  63. local btn_height = 1
  64. local button = {}
  65. button.command = "addbutton"
  66. button["X"] = x
  67. button["Y"] = y
  68. button["W"] = btn_width
  69. button["H"] = btn_height
  70. button["name"] = name
  71. button["label"] = label
  72. return button
  73. end
  74. local function spawn_field(name, label, x, y)
  75. local height = 1
  76. local width = 3
  77. local field = {}
  78. field.command = "addfield"
  79. field["X"] = x
  80. field["Y"] = y
  81. field["W"] = width
  82. field["H"] = height
  83. field["name"] = name
  84. field["label"] = label
  85. -- have 16 water buckets stored in autocrafter
  86. field["default"] = "16"
  87. return field
  88. end
  89. local function touch_init3(chnl, state)
  90. local reset = {}
  91. reset.command = "clear"
  92. digiline_send(chnl, reset)
  93. local guide = {}
  94. guide.command = "addlabel"
  95. guide["X"] = 2.5
  96. guide["Y"] = 0
  97. guide.label = "Press ENTER (or RETURN) key to place order."
  98. digiline_send(chnl, guide)
  99. local button = {}
  100. button.command = "addbutton"
  101. button["X"] = 0
  102. button["Y"] = 0.5
  103. button["W"] = 10
  104. button["H"] = 1
  105. button["name"] = "onoff"
  106. if state then
  107. button["label"] = "Stop Ice Machine"
  108. else
  109. button["label"] = "Start Ice Machine"
  110. end
  111. digiline_send(chnl, button)
  112. local offset_x = 1
  113. local offset_y = 1.5
  114. local choices = {}
  115. choices[1] = {name = "vanilla", label = "Vanilla Extract"}
  116. choices[2] = {name = "minty", label = "Mint Tea"}
  117. choices[3] = {name = "soymilk", label = "Soy Milk"}
  118. choices[4] = {name = "crystalingot", label = "Crystal Ingot"}
  119. for i, v in ipairs(choices) do
  120. local f = spawn_field(v.name, v.label,
  121. offset_x, i + offset_y)
  122. digiline_send(chnl, f)
  123. end
  124. end
  125. local function touch_init2(channel)
  126. local reset = {}
  127. reset.command = "clear"
  128. digiline_send(channel, reset)
  129. local choices = {}
  130. local c = {}
  131. c.name = "vanilla"; c.label = "Vanilla Extract"
  132. choices[1] = c
  133. c.name = "minty"; c.label = "Mint Tea"
  134. choices[2] = c
  135. for i, v in ipairs(choices) do
  136. local btn = spawn_button(v.name, v.label, x % 6, 0 + i)
  137. digiline_send(channel, btn)
  138. end
  139. end
  140. local function main()
  141. local CONST_T = 1
  142. local CONST_T_ICE = 5
  143. local ts = "ts" -- touchscreen
  144. local ac = "ac" -- autocrafter
  145. if event.type == "program" then
  146. mem.state = false
  147. mem.timer = 0
  148. touch_init3(ts, mem.state)
  149. elseif event.type == "digiline" and event.channel == ts then
  150. touch_response(ac, event.msg)
  151. touch_init3(ts, mem.state)
  152. end
  153. if event.type == "interrupt"
  154. or event.type == "program" then
  155. port.c = not port.c
  156. mem.timer = mem.timer + 1 % CONST_T_ICE;
  157. if mem.timer % CONST_T_ICE == 0 and mem.state then
  158. port.a = not port.a
  159. end
  160. interrupt(CONST_T)
  161. end
  162. end
  163. return main()