Update pain2.lua

This commit is contained in:
LDDestroier 2020-04-14 04:24:59 -04:00 committed by GitHub
parent c2385693e7
commit 2e0c7b5da4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 121 additions and 47 deletions

168
pain2.lua
View File

@ -72,6 +72,11 @@ pain.control = {
holdDown = true, holdDown = true,
modifiers = {}, modifiers = {},
}, },
singleScroll = {
key = keys.tab,
holdDown = true,
modifiers = {},
},
resetScroll = { resetScroll = {
key = keys.a, key = keys.a,
holdDown = false, holdDown = false,
@ -106,9 +111,42 @@ pain.control = {
holdDown = false, holdDown = false,
modifiers = {}, modifiers = {},
}, },
shiftDotsRight = {
key = keys.right,
holdDown = false,
modifiers = {
[keys.shift] = true
}
},
shiftDotsLeft = {
key = keys.left,
holdDown = false,
modifiers = {
[keys.shift] = true
}
},
shiftDotsUp = {
key = keys.up,
holdDown = false,
modifiers = {
[keys.shift] = true
}
},
shiftDotsDown = {
key = keys.down,
holdDown = false,
modifiers = {
[keys.shift] = true
}
},
toggleLayerMenu = {
key = keys.l,
holdDown = false,
modifiers = {}
}
} }
local checkControl = function(name) local checkControl = function(name, forceHoldDown)
local modlist = { local modlist = {
keys.ctrl, keys.ctrl,
keys.shift, keys.shift,
@ -127,7 +165,11 @@ local checkControl = function(name)
end end
if pain.control[name].key then if pain.control[name].key then
if keysDown[pain.control[name].key] then if keysDown[pain.control[name].key] then
if pain.control[name].holdDown then local holdDown = pain.control[name].holdDown
if forceHoldDown ~= nil then
holdDown = forceHoldDown
end
if holdDown then
return true return true
else else
if not pain.controlHoldCheck[name] then if not pain.controlHoldCheck[name] then
@ -237,10 +279,11 @@ windont.default.alwaysRender = false
local scr_x, scr_y = term.getSize() local scr_x, scr_y = term.getSize()
pain.windows.toolPreview = windont.newWindow(1, 1, scr_x, scr_y, {textColor = "-", backColor = "-"}) pain.windows.toolPreview = windont.newWindow(1, 1, scr_x, scr_y, {textColor = "-", backColor = "-"})
pain.windows.menu = windont.newWindow(1, 1, scr_x, scr_y, {textColor = "-", backColor = "-"}) pain.windows.mainMenu = windont.newWindow(1, 1, scr_x, scr_y, {textColor = "-", backColor = "-"})
pain.windows.smallPreview = windont.newWindow(1, 1, scr_x, scr_y, {textColor = "-", backColor = "-"}) pain.windows.layerMenu = windont.newWindow(scr_x - 20, 1, 20, scr_y, {textColor = "-", backColor = "-"})
pain.windows.grid = windont.newWindow(1, 1, scr_x, scr_y, {textColor = "-", backColor = "-"}) pain.windows.smallPreview = windont.newWindow(1, 1, scr_x, scr_y, {textColor = "-", backColor = "-"})
pain.windows.grid = windont.newWindow(1, 1, scr_x, scr_y, {textColor = "-", backColor = "-"})
local function tableCopy(tbl) local function tableCopy(tbl)
local output = {} local output = {}
@ -270,13 +313,13 @@ end
pain.tickTimers = function() pain.tickTimers = function()
local done = {} local done = {}
for k,v in pairs(pain.timers) do for k,v in next, pain.timers do
pain.timers[k] = v - 1 pain.timers[k] = v - 1
if pain.timers[k] <= 0 then if pain.timers[k] <= 0 then
done[k] = true done[k] = true
end end
end end
for k,v in pairs(done) do for k,v in next, done do
pain.timers[k] = nil pain.timers[k] = nil
end end
return done return done
@ -335,29 +378,13 @@ local getDotsInLine = function( startX, startY, endX, endY )
end end
pain.manip.touchDot = function(canvas, x, y) pain.manip.touchDot = function(canvas, x, y)
if false then for c = 1, 3 do
if (x > canvas.meta.width or y > canvas.meta.height) and (x >= 1 and y >= 1) then canvas.meta.buffer[c][y] = canvas.meta.buffer[c][y] or {}
canvas.meta.width = x for xx = 1, x do
canvas.meta.height = y canvas.meta.buffer[c][y][xx] = canvas.meta.buffer[c][y][xx] or "-"
canvas.meta.buffer = canvas.meta.newBuffer(
x,
y,
" ",
"-",
"-",
canvas.meta.buffer
)
end end
return true
else
for c = 1, 3 do
canvas.meta.buffer[c][y] = canvas.meta.buffer[c][y] or {}
for xx = 1, x do
canvas.meta.buffer[c][y][xx] = canvas.meta.buffer[c][y][xx] or "-"
end
end
return true
end end
return true
end end
pain.manip.setDot = function(canvas, x, y, char, text, back) pain.manip.setDot = function(canvas, x, y, char, text, back)
@ -386,6 +413,19 @@ pain.manip.changePainColor = function(mode, amount, doLoop)
pain.color[mode] = hexColors:sub(sNum, sNum) pain.color[mode] = hexColors:sub(sNum, sNum)
end end
pain.manip.shiftDots = function(canvas, xDist, yDist)
local output = {{}, {}, {}}
for c = 1, 3 do
for y,vy in next, canvas.meta.buffer[c] do
output[c][y + yDist] = {}
for x,vx in next, vy do
output[c][y + yDist][x + xDist] = vx
end
end
end
canvas.meta.buffer = output
end
local whitespace = { local whitespace = {
["\009"] = true, ["\009"] = true,
["\010"] = true, ["\010"] = true,
@ -428,9 +468,9 @@ tools.pencil = {
oldY or (my - (canvas.meta.y - 1)), oldY or (my - (canvas.meta.y - 1)),
mx - (canvas.meta.x - 1), mx - (canvas.meta.x - 1),
my - (canvas.meta.y - 1), my - (canvas.meta.y - 1),
mode == 1 and pain.color.char or " ", mode == 1 and pain.color.char or nil, -- " ",
mode == 1 and pain.color.text or "-", mode == 1 and pain.color.text or nil, -- "-",
mode == 1 and pain.color.back or "-" mode == 1 and pain.color.back or nil -- "-"
) )
end end
while miceDown[mode] do while miceDown[mode] do
@ -463,9 +503,9 @@ tools.line = {
initY, initY,
mx - (canvas.meta.x - 1), mx - (canvas.meta.x - 1),
my - (canvas.meta.y - 1), my - (canvas.meta.y - 1),
mode == 1 and pain.color.char or " ", mode == 1 and pain.color.char or nil, --" ",
mode == 1 and pain.color.text or "-", mode == 1 and pain.color.text or nil, -- "-",
mode == 1 and pain.color.back or "-" mode == 1 and pain.color.back or nil -- "-"
) )
end end
end end
@ -583,16 +623,28 @@ local drawGrid = function(canvas)
end end
end end
local makeMenu = function() local copyCanvasBuffer = function(buffer, x1, y1, x2, y2)
local output = {{}, {}, {}}
for c = 1, 3 do
for y = y1, y2 do
output[c][y] = {}
if buffer[c][y] then
for x = x1, x2 do
output[c][y][x] = buffer[c][y][x]
end
end
end
end
return output
end end
local main = function() local main = function()
local render = function(canvasList) local render = function(canvasList)
drawGrid(canvasList[1]) drawGrid(canvasList[1])
local rList = { local rList = {
pain.windows.menu, -- pain.windows.mainMenu,
pain.windows.smallPreview, -- pain.windows.layerMenu,
-- pain.windows.smallPreview,
pain.windows.toolPreview, pain.windows.toolPreview,
} }
for i = 1, #canvasList do for i = 1, #canvasList do
@ -623,14 +675,18 @@ local main = function()
showToolPreview = false -- if true, will render the tool preview INSTEAD of the current canvas showToolPreview = false -- if true, will render the tool preview INSTEAD of the current canvas
} }
local isToolGood = false
local resume = function(newEvent) local resume = function(newEvent)
if cTool.coroutine then if cTool.coroutine then
if (cTool.lastEvent == (newEvent or evt[1])) or (not cTool.lastEvent) then if (cTool.lastEvent == (newEvent or evt[1])) or (not cTool.lastEvent) then
cTool.doQuickResume = false cTool.doQuickResume = false
if cTool.showToolPreview then if cTool.showToolPreview then
pain.windows.toolPreview.meta.buffer = tableCopy(canvas.meta.buffer) pain.windows.toolPreview.meta.buffer = copyCanvasBuffer(
canvas.meta.buffer,
-canvas.meta.x,
-canvas.meta.y,
-canvas.meta.x + scr_x + 1,
-canvas.meta.y + scr_y + 1
)
pain.windows.toolPreview.meta.x = canvas.meta.x pain.windows.toolPreview.meta.x = canvas.meta.x
pain.windows.toolPreview.meta.y = canvas.meta.y pain.windows.toolPreview.meta.y = canvas.meta.y
pain.windows.toolPreview.meta.width = canvas.meta.width pain.windows.toolPreview.meta.width = canvas.meta.width
@ -671,28 +727,46 @@ local main = function()
mainTimer = os.startTimer(0.05) mainTimer = os.startTimer(0.05)
tCompleted = pain.tickTimers() -- get list of completed pain timers tCompleted = pain.tickTimers() -- get list of completed pain timers
canvas = pain.image[pain.layer] -- 'canvas' is a term object, you smarmy cunt canvas = pain.image[pain.layer] -- 'canvas' is a term object, you smarmy cunt
for k,v in pairs(keysDown) do keysDown[k] = v + 1 end for k,v in next, keysDown do keysDown[k] = v + 1 end
local singleScroll = checkControl("singleScroll")
if checkControl("quit") then -- why did I call myself a cunt if checkControl("quit") then -- why did I call myself a cunt
pain.running = false pain.running = false
end end
if checkControl("scrollRight") then if checkControl("scrollRight", not singleScroll) then
canvas.meta.x = canvas.meta.x - 1 canvas.meta.x = canvas.meta.x - 1
end end
if checkControl("scrollLeft") then if checkControl("scrollLeft", not singleScroll) then
canvas.meta.x = canvas.meta.x + 1 canvas.meta.x = canvas.meta.x + 1
end end
if checkControl("scrollDown") then if checkControl("scrollDown", not singleScroll) then
canvas.meta.y = canvas.meta.y - 1 canvas.meta.y = canvas.meta.y - 1
end end
if checkControl("scrollUp") then if checkControl("scrollUp", not singleScroll) then
canvas.meta.y = canvas.meta.y + 1 canvas.meta.y = canvas.meta.y + 1
end end
if checkControl("shiftDotsRight") then
pain.manip.shiftDots(canvas, 1, 0)
end
if checkControl("shiftDotsLeft") then
pain.manip.shiftDots(canvas, -1, 0)
end
if checkControl("shiftDotsUp") then
pain.manip.shiftDots(canvas, 0, -1)
end
if checkControl("shiftDotsDown") then
pain.manip.shiftDots(canvas, 0, 1)
end
if checkControl("resetScroll") then if checkControl("resetScroll") then
canvas.meta.x = 1 canvas.meta.x = 1
canvas.meta.y = 1 canvas.meta.y = 1