keybindings.lua 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. return {
  2. EditMode = {
  3. {
  4. "key:g:pressed",
  5. function()
  6. Sled.grid.show = not Sled.grid.show
  7. end
  8. },
  9. {
  10. "key:e:pressed",
  11. function()
  12. if Sled.state == "map" then
  13. if Sled.grid.tx and Sled.grid.ty then
  14. Sled.current_screen:focus_on(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
  15. end
  16. elseif Sled.state == "focused" then
  17. Sled.current_screen:unfocus()
  18. Sled.grid:reset()
  19. end
  20. end
  21. },
  22. {
  23. "key:w:pressed",
  24. function()
  25. local tile = Sled:tile(Sled.grid.tx, Sled.grid.ty-8):select()
  26. if Sled.state == "focused" then
  27. Sled.current_screen:focus_on(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
  28. end
  29. end
  30. },
  31. {
  32. "key:d:pressed",
  33. function()
  34. local tile = Sled:tile(Sled.grid.tx+8, Sled.grid.ty):select()
  35. if Sled.state == "focused" then
  36. Sled.current_screen:focus_on(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
  37. end
  38. end
  39. },
  40. {
  41. "key:a:pressed",
  42. function()
  43. local tile = Sled:tile(Sled.grid.tx-8, Sled.grid.ty):select()
  44. if Sled.state == "focused" then
  45. Sled.current_screen:focus_on(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
  46. end
  47. end
  48. },
  49. {
  50. "key:s:pressed",
  51. function()
  52. local tile = Sled:tile(Sled.grid.tx, Sled.grid.ty+8):select()
  53. if Sled.state == "focused" then
  54. Sled.current_screen:focus_on(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
  55. end
  56. end
  57. },
  58. {
  59. "key:c:pressed",
  60. function()
  61. if not Sled.grid.tx then return end
  62. Sled.current_screen:center(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
  63. end
  64. },
  65. {
  66. "key:f:pressed",
  67. function()
  68. Sled.config.fullscreen = not Sled.config.fullscreen
  69. _lw.setFullscreen(Sled.config.fullscreen)
  70. end
  71. },
  72. {
  73. "key:x:pressed",
  74. function()
  75. Sled.gui.command_bar:activate(true)
  76. end
  77. },
  78. {
  79. "mouse:1:down",
  80. function()
  81. if not Sled.current_layer then
  82. Sled.gui.command_bar:activate(true)
  83. Sled.gui.command_bar:print("no layers in map")
  84. return
  85. end
  86. if Sled.state == "map" then
  87. if not Sled:tile(Sled.cursor.x, Sled.cursor.y):is_in_map() then return end
  88. if _lk.isDown("lshift") then
  89. Sled:tile(Sled.cursor.x, Sled.cursor.y):paste()
  90. elseif _lk.isDown("lctrl") and Sled.current_marker then
  91. Sled:tile(Sled.cursor.x, Sled.cursor.y):paste_with_marker(Sled.current_marker)
  92. elseif _lk.isDown("lalt") and Sled.current_marker then
  93. Sled:tile(Sled.cursor.x, Sled.cursor.y):add_marker(Sled.current_marker)
  94. else
  95. Sled:tile(Sled.cursor.x, Sled.cursor.y):select()
  96. end
  97. elseif Sled.state == "focused" then
  98. local tx, ty = Sled.grid.tx, Sled.grid.ty
  99. local x, y = Sled.cursor.x - tx, Sled.cursor.y - ty
  100. if x < 0 or y < 0 or x >= Sled.tile_size or y >= Sled.tile_size then
  101. return
  102. end
  103. local r, g, b, a = Sled.gui.palette:get_current_color()
  104. Sled.tile_buffer:setPixel(x, y, r, g, b, a)
  105. Sled:tile(tx, ty):set_img_data()
  106. end
  107. Sled.cursor.old_dx, Sled.cursor.old_dy = Sled.cursor:get_delta()
  108. end
  109. },
  110. {
  111. "mouse:2:down",
  112. function()
  113. if Sled.state == "map" then
  114. if _lk.isDown("lalt") then
  115. if not Sled:tile(Sled.cursor.x, Sled.cursor.y):select() then return end
  116. Sled:tile(Sled.cursor:get_position()):remove_marker ()
  117. else
  118. local dx, dy = Sled.cursor.dx, Sled.cursor.dy
  119. local camera = Sled.current_screen.camera
  120. camera:translate(dx / camera:getScale(), dy / camera:getScale())
  121. end
  122. elseif Sled.state == "focused" then
  123. local tx, ty = Sled.grid.tx, Sled.grid.ty
  124. local x, y = Sled.cursor.x - tx, Sled.cursor.y - ty
  125. if x < 0 or y < 0 or x >= Sled.tile_size or y >= Sled.tile_size then
  126. return
  127. end
  128. Sled.tile_buffer:setPixel(x, y, 0,0,0,0)
  129. Sled:tile(tx, ty):set_img_data()
  130. end
  131. end
  132. },
  133. {
  134. "key:space:down",
  135. function()
  136. local dx, dy = Sled.cursor.dx, Sled.cursor.dy
  137. local camera = Sled.current_screen.camera
  138. camera:translate(dx / camera:getScale(), dy / camera:getScale())
  139. end
  140. }
  141. },
  142. CommandMode = {
  143. {
  144. "text::",
  145. function(k)
  146. Sled.gui.command_bar:add_char(k)
  147. end
  148. },
  149. {
  150. "key:tab:pressed",
  151. function()
  152. Sled.gui.command_bar:suggest()
  153. end
  154. },
  155. {
  156. "key:left:pressed",
  157. function()
  158. if Sled.gui.command_bar.active then
  159. if _lk.isDown("lctrl") then
  160. Sled.gui.command_bar:move_cursor_last_word(-1)
  161. else
  162. Sled.gui.command_bar:move_cursor(-1)
  163. end
  164. end
  165. end
  166. },
  167. {
  168. "key:right:pressed",
  169. function()
  170. if _lk.isDown("lctrl") then
  171. Sled.gui.command_bar:move_cursor_next_word(1)
  172. else
  173. Sled.gui.command_bar:move_cursor(1)
  174. end
  175. end
  176. },
  177. {
  178. "key:up:pressed",
  179. function()
  180. if Sled.gui.command_bar.active then
  181. Sled.gui.command_bar:go_up()
  182. end
  183. end
  184. },
  185. {
  186. "key:down:pressed",
  187. function()
  188. if Sled.gui.command_bar.active then
  189. Sled.gui.command_bar:go_down()
  190. end
  191. end
  192. },
  193. {
  194. "key:return:pressed",
  195. function()
  196. Sled.gui.command_bar:eval()
  197. end
  198. },
  199. {
  200. "key:backspace:pressed",
  201. function()
  202. Sled.gui.command_bar:del_char()
  203. end
  204. },
  205. {
  206. "key:escape:pressed",
  207. function()
  208. Sled.gui.command_bar:activate()
  209. end
  210. },
  211. {
  212. "mouse:1:down",
  213. function()
  214. if Sled.state == "map" then
  215. if _lk.isDown("lshift") then
  216. Sled:tile(Sled.cursor.x, Sled.cursor.y):paste()
  217. else
  218. Sled:tile(Sled.cursor.x, Sled.cursor.y):select()
  219. end
  220. elseif Sled.state == "focused" then
  221. if not Sled.cursor.is_on_canvas then return end
  222. local tx, ty = Sled.grid.tx, Sled.grid.ty
  223. local x, y = Sled.cursor.local_x - tx, Sled.cursor.local_y - ty
  224. if x < 0 or y < 0 or x >= Sled.tile_size or y >= Sled.tile_size then
  225. return
  226. end
  227. local r, g, b, a = Sled.gui.palette:get_current_color()
  228. Sled.tile_buffer:setPixel(x, y, r, g, b, a)
  229. Sled.tile(Sled.grid.tx, Sled.grid.ty):set_img_data()
  230. end
  231. end
  232. },
  233. {
  234. "mouse:2:down",
  235. function()
  236. local dx, dy = Sled.cursor.dx, Sled.cursor.dy
  237. local camera = Sled.current_screen.camera
  238. camera:translate(dx / camera:getScale(), dy / camera:getScale())
  239. end
  240. }
  241. }
  242. }