123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- return {
- EditMode = {
- {
- "key:g:pressed",
- function()
- Sled.grid.show = not Sled.grid.show
- end
- },
- {
- "key:e:pressed",
- function()
- if Sled.state == "map" then
- if Sled.grid.tx and Sled.grid.ty then
- Sled.current_screen:focus_on(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
-
- end
- elseif Sled.state == "focused" then
- Sled.current_screen:unfocus()
- Sled.grid:reset()
- end
- end
- },
- {
- "key:w:pressed",
- function()
- local tile = Sled:tile(Sled.grid.tx, Sled.grid.ty-8):select()
- if Sled.state == "focused" then
- Sled.current_screen:focus_on(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
- end
- end
- },
- {
- "key:d:pressed",
- function()
- local tile = Sled:tile(Sled.grid.tx+8, Sled.grid.ty):select()
- if Sled.state == "focused" then
- Sled.current_screen:focus_on(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
- end
- end
- },
- {
- "key:a:pressed",
- function()
- local tile = Sled:tile(Sled.grid.tx-8, Sled.grid.ty):select()
- if Sled.state == "focused" then
- Sled.current_screen:focus_on(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
- end
- end
- },
- {
- "key:s:pressed",
- function()
- local tile = Sled:tile(Sled.grid.tx, Sled.grid.ty+8):select()
- if Sled.state == "focused" then
- Sled.current_screen:focus_on(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
- end
- end
- },
- {
- "key:c:pressed",
- function()
- if not Sled.grid.tx then return end
- Sled.current_screen:center(Sled.grid.tx, Sled.grid.ty, Sled.tile_size, Sled.tile_size)
- end
- },
- {
- "key:f:pressed",
- function()
- Sled.config.fullscreen = not Sled.config.fullscreen
- _lw.setFullscreen(Sled.config.fullscreen)
- end
- },
- {
- "key:x:pressed",
- function()
- Sled.gui.command_bar:activate(true)
- end
- },
- {
- "mouse:1:down",
- function()
- if not Sled.current_layer then
- Sled.gui.command_bar:activate(true)
- Sled.gui.command_bar:print("no layers in map")
- return
- end
- if Sled.state == "map" then
- if not Sled:tile(Sled.cursor.x, Sled.cursor.y):is_in_map() then return end
- if _lk.isDown("lshift") then
- Sled:tile(Sled.cursor.x, Sled.cursor.y):paste()
- elseif _lk.isDown("lctrl") and Sled.current_marker then
- Sled:tile(Sled.cursor.x, Sled.cursor.y):paste_with_marker(Sled.current_marker)
- elseif _lk.isDown("lalt") and Sled.current_marker then
- Sled:tile(Sled.cursor.x, Sled.cursor.y):add_marker(Sled.current_marker)
- else
- Sled:tile(Sled.cursor.x, Sled.cursor.y):select()
- end
- elseif Sled.state == "focused" then
- local tx, ty = Sled.grid.tx, Sled.grid.ty
- local x, y = Sled.cursor.x - tx, Sled.cursor.y - ty
- if x < 0 or y < 0 or x >= Sled.tile_size or y >= Sled.tile_size then
- return
- end
- local r, g, b, a = Sled.gui.palette:get_current_color()
- Sled.tile_buffer:setPixel(x, y, r, g, b, a)
- Sled:tile(tx, ty):set_img_data()
- end
- Sled.cursor.old_dx, Sled.cursor.old_dy = Sled.cursor:get_delta()
- end
- },
- {
- "mouse:2:down",
- function()
- if Sled.state == "map" then
- if _lk.isDown("lalt") then
- if not Sled:tile(Sled.cursor.x, Sled.cursor.y):select() then return end
- Sled:tile(Sled.cursor:get_position()):remove_marker ()
- else
- local dx, dy = Sled.cursor.dx, Sled.cursor.dy
- local camera = Sled.current_screen.camera
- camera:translate(dx / camera:getScale(), dy / camera:getScale())
- end
- elseif Sled.state == "focused" then
- local tx, ty = Sled.grid.tx, Sled.grid.ty
- local x, y = Sled.cursor.x - tx, Sled.cursor.y - ty
- if x < 0 or y < 0 or x >= Sled.tile_size or y >= Sled.tile_size then
- return
- end
- Sled.tile_buffer:setPixel(x, y, 0,0,0,0)
- Sled:tile(tx, ty):set_img_data()
- end
- end
- },
- {
- "key:space:down",
- function()
- local dx, dy = Sled.cursor.dx, Sled.cursor.dy
- local camera = Sled.current_screen.camera
- camera:translate(dx / camera:getScale(), dy / camera:getScale())
- end
- }
- },
- CommandMode = {
- {
- "text::",
- function(k)
- Sled.gui.command_bar:add_char(k)
- end
- },
- {
- "key:tab:pressed",
- function()
- Sled.gui.command_bar:suggest()
- end
- },
- {
- "key:left:pressed",
- function()
- if Sled.gui.command_bar.active then
- if _lk.isDown("lctrl") then
- Sled.gui.command_bar:move_cursor_last_word(-1)
- else
- Sled.gui.command_bar:move_cursor(-1)
- end
- end
- end
- },
- {
- "key:right:pressed",
- function()
- if _lk.isDown("lctrl") then
- Sled.gui.command_bar:move_cursor_next_word(1)
- else
- Sled.gui.command_bar:move_cursor(1)
- end
- end
- },
- {
- "key:up:pressed",
- function()
- if Sled.gui.command_bar.active then
- Sled.gui.command_bar:go_up()
- end
- end
- },
- {
- "key:down:pressed",
- function()
- if Sled.gui.command_bar.active then
- Sled.gui.command_bar:go_down()
- end
- end
- },
- {
- "key:return:pressed",
- function()
- Sled.gui.command_bar:eval()
- end
- },
- {
- "key:backspace:pressed",
- function()
- Sled.gui.command_bar:del_char()
- end
- },
- {
- "key:escape:pressed",
- function()
- Sled.gui.command_bar:activate()
- end
- },
- {
- "mouse:1:down",
- function()
- if Sled.state == "map" then
- if _lk.isDown("lshift") then
- Sled:tile(Sled.cursor.x, Sled.cursor.y):paste()
- else
- Sled:tile(Sled.cursor.x, Sled.cursor.y):select()
- end
- elseif Sled.state == "focused" then
- if not Sled.cursor.is_on_canvas then return end
- local tx, ty = Sled.grid.tx, Sled.grid.ty
- local x, y = Sled.cursor.local_x - tx, Sled.cursor.local_y - ty
- if x < 0 or y < 0 or x >= Sled.tile_size or y >= Sled.tile_size then
- return
- end
- local r, g, b, a = Sled.gui.palette:get_current_color()
- Sled.tile_buffer:setPixel(x, y, r, g, b, a)
- Sled.tile(Sled.grid.tx, Sled.grid.ty):set_img_data()
- end
- end
- },
- {
- "mouse:2:down",
- function()
- local dx, dy = Sled.cursor.dx, Sled.cursor.dy
- local camera = Sled.current_screen.camera
- camera:translate(dx / camera:getScale(), dy / camera:getScale())
- end
- }
- }
- }
|