254 lines
8.7 KiB
Lua
254 lines
8.7 KiB
Lua
local function iterBoardLine(start, step)
|
|
local step = step or 1
|
|
local i = start
|
|
local n = 0
|
|
return function()
|
|
i = i + step
|
|
n = n + 1
|
|
if n > 9 then return end
|
|
if i > 9 then i = 1 end
|
|
if i < 1 then i = 9 end
|
|
return i
|
|
end
|
|
end
|
|
|
|
function love.keypressed2(key, scancode)
|
|
if key == "escape" or key == "q" then
|
|
love.event.quit()
|
|
elseif key == "right" or key == "l" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
for x in iterBoardLine(cursor.x) do
|
|
if board[1][cursor.y][x] == 0 then
|
|
cursor.x = x
|
|
break
|
|
end
|
|
end
|
|
else
|
|
cursor.x = cursor.x + 1
|
|
if cursor.x > 9 then cursor.x = 1 end
|
|
end
|
|
elseif key == "left" or key == "h" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
for x in iterBoardLine(cursor.x, -1) do
|
|
if board[1][cursor.y][x] == 0 then
|
|
cursor.x = x
|
|
break
|
|
end
|
|
end
|
|
else
|
|
cursor.x = cursor.x - 1
|
|
if cursor.x < 1 then cursor.x = 9 end
|
|
end
|
|
elseif key == "down" or key == "j" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
for y in iterBoardLine(cursor.y) do
|
|
if board[1][y][cursor.x] == 0 then
|
|
cursor.y = y
|
|
break
|
|
end
|
|
end
|
|
else
|
|
cursor.y = cursor.y + 1
|
|
if cursor.y > 9 then cursor.y = 1 end
|
|
end
|
|
elseif key == "up" or key == "k" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
for y in iterBoardLine(cursor.y, -1) do
|
|
if board[1][y][cursor.x] == 0 then
|
|
cursor.y = y
|
|
break
|
|
end
|
|
end
|
|
else
|
|
cursor.y = cursor.y - 1
|
|
if cursor.y < 1 then cursor.y = 9 end
|
|
end
|
|
elseif key == "1" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
board[#board][cursor.y][cursor.x] = 1
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
smallNumbersVal[cursor.x][cursor.y][1] = not smallNumbersVal[cursor.x][cursor.y][1]
|
|
end
|
|
end
|
|
elseif key == "2" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
board[#board][cursor.y][cursor.x] = 2
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
smallNumbersVal[cursor.x][cursor.y][2] = not smallNumbersVal[cursor.x][cursor.y][2]
|
|
end
|
|
end
|
|
elseif key == "3" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
board[#board][cursor.y][cursor.x] = 3
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
smallNumbersVal[cursor.x][cursor.y][3] = not smallNumbersVal[cursor.x][cursor.y][3]
|
|
end
|
|
end
|
|
elseif key == "4" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
board[#board][cursor.y][cursor.x] = 4
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
smallNumbersVal[cursor.x][cursor.y][4] = not smallNumbersVal[cursor.x][cursor.y][4]
|
|
end
|
|
end
|
|
elseif key == "5" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
board[#board][cursor.y][cursor.x] = 5
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
smallNumbersVal[cursor.x][cursor.y][5] = not smallNumbersVal[cursor.x][cursor.y][5]
|
|
end
|
|
end
|
|
elseif key == "6" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
board[#board][cursor.y][cursor.x] = 6
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
smallNumbersVal[cursor.x][cursor.y][6] = not smallNumbersVal[cursor.x][cursor.y][6]
|
|
end
|
|
end
|
|
elseif key == "7" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
board[#board][cursor.y][cursor.x] = 7
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
smallNumbersVal[cursor.x][cursor.y][7] = not smallNumbersVal[cursor.x][cursor.y][7]
|
|
end
|
|
end
|
|
elseif key == "8" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
board[#board][cursor.y][cursor.x] = 8
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
smallNumbersVal[cursor.x][cursor.y][8] = not smallNumbersVal[cursor.x][cursor.y][8]
|
|
end
|
|
end
|
|
elseif key == "9" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
board[#board][cursor.y][cursor.x] = 9
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
smallNumbersVal[cursor.x][cursor.y][9] = not smallNumbersVal[cursor.x][cursor.y][9]
|
|
end
|
|
end
|
|
elseif key == "delete" or key == "0" then
|
|
if love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift') then
|
|
board[#board][cursor.y][cursor.x] = 0
|
|
elseif board[#board][cursor.y][cursor.x] ~= 0 then
|
|
board[#board][cursor.y][cursor.x] = 0
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
for i = 1, 9 do
|
|
smallNumbersVal[cursor.x][cursor.y][i] = false
|
|
end
|
|
end
|
|
end
|
|
elseif key == "return" or key == "tab" then
|
|
cursor.isSmall = not cursor.isSmall
|
|
end
|
|
end
|
|
|
|
function handleRight(shift)
|
|
if shift then
|
|
for x in iterBoardLine(cursor.x) do
|
|
if board[1][cursor.y][x] == 0 then
|
|
cursor.x = x
|
|
break
|
|
end
|
|
end
|
|
else
|
|
cursor.x = cursor.x + 1
|
|
if cursor.x > 9 then cursor.x = 1 end
|
|
end
|
|
end
|
|
|
|
function handleLeft(shift)
|
|
if shift then
|
|
for x in iterBoardLine(cursor.x, -1) do
|
|
if board[1][cursor.y][x] == 0 then
|
|
cursor.x = x
|
|
break
|
|
end
|
|
end
|
|
else
|
|
cursor.x = cursor.x - 1
|
|
if cursor.x < 1 then cursor.x = 9 end
|
|
end
|
|
end
|
|
|
|
function handleDown(shift)
|
|
if shift then
|
|
for y in iterBoardLine(cursor.y) do
|
|
if board[1][y][cursor.x] == 0 then
|
|
cursor.y = y
|
|
break
|
|
end
|
|
end
|
|
else
|
|
cursor.y = cursor.y + 1
|
|
if cursor.y > 9 then cursor.y = 1 end
|
|
end
|
|
end
|
|
|
|
function handleUp(shift)
|
|
if shift then
|
|
for y in iterBoardLine(cursor.y, -1) do
|
|
if board[1][y][cursor.x] == 0 then
|
|
cursor.y = y
|
|
break
|
|
end
|
|
end
|
|
else
|
|
cursor.y = cursor.y - 1
|
|
if cursor.y < 1 then cursor.y = 9 end
|
|
end
|
|
end
|
|
|
|
function love.keypressed(key, scancode)
|
|
local shift = love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift')
|
|
if key == "escape" or key == "q" then
|
|
love.event.quit()
|
|
elseif key == "right" or key == "l" then
|
|
handleRight(shift)
|
|
elseif key == "left" or key == "h" then
|
|
handleLeft(shift)
|
|
elseif key == "down" or key == "j" then
|
|
handleDown(shift)
|
|
elseif key == "up" or key == "k" then
|
|
handleUp(shift)
|
|
elseif board[1][cursor.y][cursor.x] == 0 then
|
|
local n = tonumber(key) or -1
|
|
if n > 0 and n < 10 then
|
|
if shift or cursor.editMode then
|
|
board[#board][cursor.y][cursor.x] = 0
|
|
cursor.editMode = true
|
|
smallNumbersVal[cursor.x][cursor.y][n] = not smallNumbersVal[cursor.x][cursor.y][n]
|
|
else
|
|
-- for i = 1, 9 do
|
|
-- smallNumbersVal[cursor.x][cursor.y][i] = false
|
|
-- end
|
|
board[#board][cursor.y][cursor.x] = n
|
|
end
|
|
elseif key == "delete" or key == "0" then
|
|
if board[#board][cursor.y][cursor.x] ~= 0 then
|
|
board[#board][cursor.y][cursor.x] = 0
|
|
else
|
|
if board[1][cursor.y][cursor.x] == 0 then
|
|
for i = 1, 9 do
|
|
smallNumbersVal[cursor.x][cursor.y][i] = false
|
|
end
|
|
end
|
|
end
|
|
elseif key == "tab" then
|
|
if cursor.editMode == false and board[#board][cursor.y][cursor.x] ~= 0 then
|
|
board[#board][cursor.y][cursor.x] = 0
|
|
end
|
|
cursor.editMode = not cursor.editMode
|
|
end
|
|
end
|
|
end
|