Advertisement
SkyCrafter0

skimgeditor.lua

Apr 18th, 2021 (edited)
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.11 KB | None | 0 0
  1. --[[MIT License
  2.  
  3. Copyright (c) 2021 SkyCrafter0
  4.  
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11.  
  12. The above copyright notice and this permission notice shall be included in all
  13. copies or substantial portions of the Software.
  14.  
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. SOFTWARE.]]
  22.  
  23. -- Get all the shit for bein online
  24. local h,err = http.get("https://raw.githubusercontent.com/SkyTheCodeMaster/SkyDocs/fdf3d62fcbdaa39a957f7a074ebef95bff4a79a1/src/main/misc/sUtils.lua")
  25. if err then error("Something went wrong whilst downloading sUtils!") end
  26. local content = h.readAll() h.close()
  27. local sUtils = load(content,"=prewebquire-package","t",_ENV)()
  28. local button = sUtils.webquire("https://raw.githubusercontent.com/SkyTheCodeMaster/SkyDocs/ddec75606d183c743c9a92bd08d28b60f8caae3a/src/main/misc/button.lua")
  29. local paintutils = sUtils.webquire("https://skydocs.madefor.cc/scriptdata/paintutils.lua") -- paintutils is always online :D
  30.  
  31. --[[
  32.   Standard `.skimg` attributes tablelib
  33.   {
  34.     width = 26,
  35.     height = 20,
  36.     creator = "SkyCrafter0",
  37.     locked = false,
  38.    
  39.   }
  40. ]]
  41.  
  42. -- localize some APIs, make it faster to call them.
  43. local term = term
  44. local fs = fs
  45. local colours = colours
  46. local window = window
  47.  
  48. local data = {
  49.   bgColour = colours.black,
  50.   textColour = colours.white,
  51.   promptColour = colours.yellow,
  52.   blitToWord = {
  53.     ["0"] = "White",
  54.     ["1"] = "Orange",
  55.     ["2"] = "Magenta",
  56.     ["3"] = "Light Blue",
  57.     ["4"] = "Yellow",
  58.     ["5"] = "Lime",
  59.     ["6"] = "Pink",
  60.     ["7"] = "Grey",
  61.     ["8"] = "Light Grey",
  62.     ["9"] = "Cyan",
  63.     ["a"] = "Purple",
  64.     ["b"] = "Blue",
  65.     ["c"] = "Brown",
  66.     ["d"] = "Green",
  67.     ["e"] = "Red",
  68.     ["f"] = "Black",
  69.   }
  70. }
  71.  
  72. local assets = {
  73.   colours = {
  74.     attributes = {
  75.       width = 4,
  76.       height = 4,
  77.       creator = "SkyCrafter0",
  78.       locked = true,
  79.     },
  80.     data = {
  81.       {"+-FG-+-BG-+","88888888888","00000000000",1},
  82.       {"|    |    |","80000800008","00123001230",2},
  83.       {"|    |    |","80000800008","04567045670",3},
  84.       {"|    |    |","80000800008","089ab089ab0",4},
  85.       {"|    |    |","80000800008","0cdef0cdef0",5},
  86.       {"+----+----+","88888888888","00000000000",6}
  87.     }
  88.   },
  89.   col = {
  90.     "0123",
  91.     "4567",
  92.     "89ab",
  93.     "cdef",
  94.   },
  95.   resize = {
  96.     {"Resize the canvas?","000000000000000000","777777777777777777",1},
  97.     {"                  ","000000000000000000","777777777777777777",2},
  98.     {"New X Dimension:  ","000000000000000000","777777777777777777",3},
  99.     {"                  ","000000000000000000","777777777777777777",4},
  100.     {"New Y Dimension:  ","000000000000000000","777777777777777777",5},
  101.     {"                  ","                  ","777777777777777777",6},
  102.   },
  103.   fileMenu = {
  104.     {"Redraw","000000","777777",1},
  105.     {"Resize","000000","777777",2},
  106.     {"Save  ","000000","777777",3},
  107.     {"Exit  ","000000","777777",4},
  108.   },
  109.   characters = {
  110.     attributes = {
  111.       width = 8,
  112.       height = 8,
  113.       creator = "SkyCrafter0",
  114.       locked = true,
  115.     },
  116.     data = {
  117.       {"\0\1\2\3\4\5\6\7\8\9\10\11\12\13\14\15","0000000000000000","ffffffffffffffff",1},
  118.       {"\16\17\18\19\20\21\22\23\24\25\26\27\28\29\30\31","0000000000000000","ffffffffffffffff",2},
  119.       {"\32\33\34\35\36\37\38\39\40\41\42\43\44\45\46\47","0000000000000000","ffffffffffffffff",3},
  120.       {"\48\49\50\51\52\53\54\55\56\57\58\59\60\61\62\63","0000000000000000","ffffffffffffffff",4},
  121.       {"\64\65\66\67\68\69\70\71\72\73\74\75\76\77\78\79","0000000000000000","ffffffffffffffff",5},
  122.       {"\80\81\82\83\84\85\86\87\88\89\90\91\92\93\94\95","0000000000000000","ffffffffffffffff",6},
  123.       {"\96\97\98\99\100\101\102\103\104\105\106\107\108\109\110\111","0000000000000000","ffffffffffffffff",7},
  124.       {"\112\113\114\115\116\117\118\119\120\121\122\123\124\125\126\127","0000000000000000","ffffffffffffffff",8},
  125.       {"\128\129\130\131\132\133\134\135\136\137\138\139\140\141\142\143","0000000000000000","ffffffffffffffff",9},
  126.       {"\144\145\146\147\148\149\150\151\152\153\154\155\156\157\158\159","0000000000000000","ffffffffffffffff",10},
  127.       {"\160\161\162\163\164\165\166\167\168\169\170\171\172\173\174\175","0000000000000000","ffffffffffffffff",11},
  128.       {"\176\177\178\179\180\181\182\183\184\185\186\187\188\189\190\191","0000000000000000","ffffffffffffffff",12},
  129.       {"\192\193\194\195\196\197\198\199\200\201\202\203\204\205\206\207","0000000000000000","ffffffffffffffff",13},
  130.       {"\208\209\210\211\212\213\214\215\216\217\218\219\220\221\222\223","0000000000000000","ffffffffffffffff",14},
  131.       {"\224\225\226\227\228\229\230\231\232\233\234\235\236\237\238\239","0000000000000000","ffffffffffffffff",15},
  132.       {"\240\241\242\243\244\245\246\247\248\249\250\251\252\253\254\255","0000000000000000","ffffffffffffffff",16},
  133.     }
  134.   },
  135. }
  136.  
  137. local function pullEvent(filter)
  138.   local event = {os.pullEventRaw()}
  139.   if event[1] == "terminate" then
  140.     term.clear()
  141.     term.setCursorPos(1,1)
  142.     error("Program closed")
  143.   elseif event[1] == filter then
  144.     return table.unpack(event)
  145.   end
  146. end
  147.  
  148. local function promptPrint(str)
  149.   term.setTextColour(data.promptColour)
  150.   print(str)
  151.   term.setTextColour(data.textColour)
  152. end
  153.  
  154. local function boolX(bool)
  155.   if bool then return "X" else return " " end
  156. end
  157.  
  158. local tArgs = {...}
  159. local file = tArgs[1]
  160. if not file then error("\nUsage:\n" .. shell.getRunningProgram() .. " <file.skimg>") end
  161. local fileExtension = sUtils.split(fs.getName(file),".")[2]
  162. if fileExtension ~= "skimg" then error("File must be a \".skimg\" file!") end
  163.  
  164. term.setTextColour(data.textColour)
  165. term.setBackgroundColour(data.bgColour)
  166. term.clear()
  167.  
  168. -- if file doesn't exist, run through creating the file.
  169. if not fs.exists(tArgs[1]) then
  170.   promptPrint("File not found, do you want to create it?")
  171.   term.setTextColour(data.textColour)
  172.   local accept = sUtils.confirm()
  173.   if accept then
  174.     local x,y,name
  175.     promptPrint("How wide is the canvas? ")
  176.     x = sUtils.readNumber()
  177.     promptPrint("How tall is the canvas? ")
  178.     y = sUtils.readNumber()
  179.     promptPrint("Who is the creator of the image? ")
  180.     name = read()
  181.     x = x or 10
  182.     y = y or 10
  183.     name = name or "nil"
  184.     local canvas = sUtils.asset.skimg.generateDefaultSkimg(x,y,name,false)
  185.     sUtils.encfwrite(file,canvas)
  186.     term.clear()
  187.   end
  188. end
  189.  
  190. local image = sUtils.asset.load(file)
  191. local imageAttributes = image.attributes
  192. local canvasX,canvasY = imageAttributes.width,imageAttributes.height
  193. local ram = {
  194.   event = {},
  195.   activeChar = { -- this is the character in the canvas
  196.     x = 1,
  197.     y = 1,
  198.   },
  199.   char = { -- this is the character in the chars window
  200.     char = "\1"
  201.   },
  202.   col = {
  203.     fg = "0",
  204.     bg = "f",
  205.   },
  206.   menus = {
  207.     active ={
  208.       drag = false,
  209.       lock = false,
  210.     },
  211.     open = {
  212.       file = false,
  213.       canvas = false,
  214.     }
  215.   },
  216.   running = true,
  217. }
  218.  
  219. local function getCharacterInfo(x,y)
  220.   x = x or 1
  221.   y = y or 1
  222.   -- make sure that x/y is in canvas
  223.   if x > canvasX then x = canvasX end
  224.   if y > canvasY then y = canvasY end
  225.  
  226.   local char = image.data[y][1]:sub(x,x)
  227.   local fg = image.data[y][2]:sub(x,x)
  228.   local bg = image.data[y][3]:sub(x,x)
  229.   return {char,fg,bg}
  230. end
  231.  
  232. local function drawInfoFields()
  233.   local x = canvasX+14
  234.   term.setCursorPos(x,2)
  235.   term.blit("Selected Cell","4444444444444","fffffffffffff")
  236.   term.setCursorPos(x,3)
  237.   term.blit("X:","44","ff")
  238.   term.setCursorPos(x,4)
  239.   term.blit("Y:","44","ff")
  240.   term.setCursorPos(x,5)
  241.   term.blit("Char:","44444","fffff")
  242.   term.setCursorPos(x,6)
  243.   term.blit("FG:","444","fff")
  244.   term.setCursorPos(x,7)
  245.   term.blit("BG:","444","fff")
  246. end
  247.  
  248. local function drawInfoData(charX,y,char,fg,bg)
  249.   local x = canvasX+14
  250.   term.setCursorPos(x+3,3)
  251.   local strX = sUtils.cut(tostring(charX),3)
  252.   term.blit(strX,("0"):rep(strX:len()),("f"):rep(strX:len()))
  253.   term.setCursorPos(x+3,4)
  254.   local strY = sUtils.cut(tostring(y),3)
  255.   term.blit(strY,("0"):rep(strY:len()),("f"):rep(strY:len()))
  256.   term.setCursorPos(x+6,5)
  257.   term.blit(char,fg,bg)
  258.   term.setCursorPos(x+5,6)
  259.   local wordFG = data.blitToWord[fg]
  260.   term.blit(sUtils.cut(wordFG,10),"0000000000","ffffffffff")
  261.   term.setCursorPos(x+5,7)
  262.   local wordBG = data.blitToWord[bg]
  263.   term.blit(sUtils.cut(wordBG,10),"0000000000","ffffffffff")
  264. end
  265.  
  266. local wins = {}
  267. wins.borderWin = window.create(term.current(),1,2,canvasX+2,canvasY+2)
  268. wins.canvasWin = window.create(wins.borderWin,2,2,canvasX,canvasY)
  269. wins.colourWin = window.create(term.current(),canvasX+3,2,11,6)
  270. wins.charWin = window.create(term.current(),canvasX+2,8,18,18)
  271. wins.debugWin = window.create(term.current(),50,1,120,50,false)
  272. wins.resizeWin = window.create(term.current(),1,canvasY+10,18,6,false)
  273.  
  274. local function debugWrite(str)
  275.   wins.debugWin.write(str)
  276.   local x,y = wins.debugWin.getCursorPos()
  277.   if x >= 40 then wins.debugWin.clear() wins.debugWin.clear() wins.debugWin.setCursorPos(1,1) end
  278.   wins.debugWin.setCursorPos(1,y+1)
  279. end
  280.  
  281. -- draw the various borders around the windows
  282. paintutils.drawBox(1,1,canvasX+2,canvasY+2,colours.white,wins.borderWin)
  283. paintutils.drawBox(1,1,18,18,colours.white,wins.charWin)
  284.  
  285. sUtils.asset.drawSkimg(image,1,1,wins.canvasWin)
  286. sUtils.asset.drawSkimg(assets.colours,1,1,wins.colourWin)
  287. sUtils.asset.drawSkimg(assets.characters,2,2,wins.charWin)
  288. -- Draw the file menu buttons
  289. sUtils.asset.drawBlit(assets.fileMenu,canvasX+20,8)
  290.  
  291. drawInfoFields()
  292.  
  293. local function getPixel(tbl,x,y)
  294.   local charString = tbl[y][1]
  295.   local fgString = tbl[y][2]
  296.   local bgString = tbl[y][3]
  297.   local char = charString:sub(x,x)
  298.   local fg = fgString:sub(x,x)
  299.   local bg = bgString:sub(x,x)
  300.   return {char,fg,bg}
  301. end
  302.  
  303. local function getPixelSingle(tbl,x,y)
  304.   local charString = tbl[y]
  305.   local char = charString:sub(x,x)
  306.   return char
  307. end
  308.  
  309. local function setPixel(x,y,char,fg,bg)
  310.   char = char or ram.char.char
  311.   fg = fg or ram.col.fg
  312.   bg = bg or ram.col.bg
  313.   local blitLine = image.data[y]
  314.   local charLine = sUtils.splice(blitLine[1],x-1,char,true)
  315.   local fgLine = sUtils.splice(blitLine[2],x-1,fg,true)
  316.   local bgLine = sUtils.splice(blitLine[3],x-1,bg,true)
  317.   wins.canvasWin.setCursorPos(1,y)
  318.   term.blit(charLine,fgLine,bgLine)
  319.   image.data[y] = {charLine,fgLine,bgLine,y}
  320. end
  321.  
  322. local function drawChars(fg,bg)
  323.   local chars = assets.characters.data
  324.   for i=1,#chars do
  325.     chars[i][2] = fg:rep(16)
  326.     chars[i][3] = bg:rep(16)
  327.   end
  328.   sUtils.asset.drawBlit(chars,2,2,wins.charWin)
  329. end
  330.  
  331. local function setColour(arg)
  332.   local x,y
  333.   local event = ram.event
  334.   if arg then
  335.     x = event[3] - canvasX-3
  336.     y = event[4] - 2
  337.     debugWrite(tostring(x) .. " " .. tostring(y))
  338.     local char = getPixelSingle(assets.col,x,y)
  339.     ram.col.fg = char
  340.   end
  341.   if not arg then
  342.     x = event[3] - canvasX-8
  343.     y = event[4] - 2
  344.     debugWrite(tostring(x) .. " " .. tostring(y))
  345.     local char = getPixelSingle(assets.col,x,y)
  346.     ram.col.bg = char
  347.   end
  348.   drawChars(ram.col.fg,ram.col.bg)
  349. end
  350.  
  351. local function captureCanvas()
  352.   local x,y = wins.canvasWin.getSize()
  353.   local screenshot = {}
  354.   for i=1,y do
  355.     screenshot[i] = {wins.canvasWin.getLine(i)}
  356.     screenshot[i][4] = i
  357.   end
  358.   return screenshot
  359. end
  360.  
  361. local function save(location)
  362.   local path = location or tArgs[1]
  363.   local skimg = {
  364.     attributes = imageAttributes,
  365.     data = image.data,
  366.   }
  367.   --sUtils.encfwrite(path,skimg)
  368.   sUtils.encfwrite(path,skimg)
  369. end
  370.  
  371. local function changePixel()
  372.   ram.activeChar.x = ram.event[3]
  373.   ram.activeChar.y = ram.event[4]-2
  374.   local x,y = ram.activeChar.x,ram.activeChar.y
  375.   if ram.event[2] == 1 then
  376.     ram.activeChar.info = getCharacterInfo(ram.activeChar.x,ram.activeChar.y)
  377.     drawInfoData(ram.activeChar.x,ram.activeChar.y,ram.activeChar.info[1],ram.activeChar.info[2],ram.activeChar.info[3])
  378.     term.setCursorPos(ram.event[3],ram.event[4])
  379.     term.setCursorBlink(true)
  380.     setPixel(x,y)
  381.   elseif ram.event[2] == 2 then
  382.     ram.activeChar.info = getCharacterInfo(ram.activeChar.x-1,ram.activeChar.y)
  383.     drawInfoData(ram.activeChar.x-1,ram.activeChar.y,ram.activeChar.info[1],ram.activeChar.info[2],ram.activeChar.info[3])
  384.     term.setCursorPos(ram.event[3],ram.event[4])
  385.     term.setCursorBlink(true)
  386.   end
  387. end
  388.  
  389. local function setChar()
  390.   local x,y = ram.event[3]-canvasX-2,ram.event[4]-8
  391.   ram.char.char = getPixel(assets.characters.data,x,y)[1]
  392.   debugWrite(ram.char)
  393. end
  394.  
  395. local buttonIDs
  396. local function resizeCanvas()
  397.   -- Pop up a window over canvas/border win, also close file menu.
  398.   wins.resizeWin.setVisible(true)
  399.   sUtils.asset.drawBlit(assets.resize,1,1,wins.resizeWin)
  400.   wins.resizeWin.setCursorPos(1,2)
  401.   local accept = sUtils.confirm()
  402.   if not accept then
  403.     term.clear()
  404.     wins.resizeWin.setVisible(false)
  405.     wins.borderWin.redraw()
  406.     wins.charWin.redraw()
  407.     wins.canvasWin.redraw()
  408.     wins.colourWin.redraw()
  409.     drawInfoFields()
  410.     sUtils.asset.drawBlit(assets.fileMenu,canvasX+20,8)
  411.     paintutils.drawBox(1,1,canvasX+2,canvasY+2,colours.white,wins.borderWin)
  412.     paintutils.drawBox(1,1,18,18,colours.white,wins.charWin)
  413.     sUtils.asset.drawSkimg(image,1,1,wins.canvasWin)
  414.     sUtils.asset.drawSkimg(assets.colours,1,1,wins.colourWin)
  415.     sUtils.asset.drawSkimg(assets.characters,2,2,wins.charWin)
  416.     return
  417.   end
  418.   wins.resizeWin.setCursorPos(1,4)
  419.   local x = sUtils.readNumber()
  420.   wins.resizeWin.setCursorPos(1,6)
  421.   local y = sUtils.readNumber()
  422.  
  423.   -- If new canvas is smaller, delete some data
  424.   if x < canvasX then
  425.     for i=1,#image.data do
  426.       image.data[i][1] = sUtils.cut(image.data[i][1],x)
  427.       image.data[i][2] = sUtils.cut(image.data[i][2],x)
  428.       image.data[i][3] = sUtils.cut(image.data[i][3],x)
  429.     end
  430.   end
  431.   -- If new canvas is bigger, repeat some data
  432.   if x > canvasX then
  433.     for i=1,#image.data do
  434.       local length = image.data[i][1]:len()
  435.       local char = image.data[i][1]:sub(length,length)
  436.       local fg = image.data[i][2]:sub(length,length)
  437.       local bg = image.data[i][3]:sub(length,length)
  438.       image.data[i][1] = sUtils.cut(image.data[i][1],x,char)
  439.       image.data[i][2] = sUtils.cut(image.data[i][2],x,fg)
  440.       image.data[i][3] = sUtils.cut(image.data[i][3],x,bg)
  441.     end
  442.   end
  443.   -- If new canvas is shorter, delete some data
  444.   if y < canvasY then
  445.     for i=y+1,#image.data do
  446.       image.data[i] = nil
  447.     end
  448.   end
  449.   -- If new canvas is taller, repeat some data
  450.   if y > canvasY then
  451.     local repeatLine = image.data[#image.data]
  452.     for i=canvasY+1,y do
  453.       image.data[i] = repeatLine
  454.       image.data[i][4] = i
  455.     end
  456.   end
  457.   imageAttributes.width = x
  458.   imageAttributes.height = y
  459.   canvasX = imageAttributes.width
  460.   canvasY = imageAttributes.height
  461.  
  462.   local x,y = wins.borderWin.getPosition()
  463.   wins.borderWin.reposition(x,y,canvasX+2,canvasY+2)
  464.   local x,y = wins.canvasWin.getPosition()
  465.   wins.canvasWin.reposition(x,y,canvasX,canvasY)
  466.   wins.colourWin.reposition(canvasX+3,2,11,6)
  467.   wins.charWin.reposition(canvasX+2,8,18,18)
  468.  
  469.   -- Redraw ***ALL*** the stuffs. this is painful. why do i exist. this is a nightmare nightmare nightmare nightmare nightmare nightmare nightmare nightmare
  470.   term.clear()
  471.   wins.resizeWin.setVisible(false)
  472.   wins.borderWin.redraw()
  473.   wins.charWin.redraw()
  474.   wins.canvasWin.redraw()
  475.   wins.colourWin.redraw()
  476.   drawInfoFields()
  477.   sUtils.asset.drawBlit(assets.fileMenu,canvasX+20,8)
  478.   paintutils.drawBox(1,1,canvasX+2,canvasY+2,colours.white,wins.borderWin)
  479.   paintutils.drawBox(1,1,18,18,colours.white,wins.charWin)
  480.  
  481.   sUtils.asset.drawSkimg(image,1,1,wins.canvasWin)
  482.   sUtils.asset.drawSkimg(assets.colours,1,1,wins.colourWin)
  483.   sUtils.asset.drawSkimg(assets.characters,2,2,wins.charWin)
  484.  
  485.   -- Now the really complicated bit, reassigning the buttons... nightmare nightmare nightmare nightmare nightmare nightmare nightmare nightmare nightmare nightmare nightmare nightmare
  486.   button.edit(buttonIDs.canvas,nil,nil,canvasX,canvasY)
  487.   button.edit(buttonIDs.characters,canvasX+3)
  488.   button.edit(buttonIDs.colFG,canvasX+4)
  489.   button.edit(buttonIDs.colBG,canvasX+9)
  490.   button.edit(buttonIDs.redraw,canvasX+20)
  491.   button.edit(buttonIDs.resize,canvasX+20)
  492.   button.edit(buttonIDs.save,canvasX+20)
  493.   button.edit(buttonIDs.exit,canvasX+20)
  494.   return
  495. end
  496.  
  497. buttonIDs = {
  498.   canvas = button.newButton(2,3,canvasX,canvasY,changePixel),
  499.   characters = button.newButton(canvasX+3,9,16,16,setChar),
  500.   colFG = button.newButton(canvasX+4,3,4,4,function() setColour(true) end),
  501.   colBG = button.newButton(canvasX+9,3,4,4,function() setColour(false) end),
  502.   redraw = button.newButton(20,8,7,1,function() paintutils.drawBox(1,1,canvasX+2,canvasY+2,colours.white,wins.borderWin)sUtils.asset.drawSkimg(image,1,1,wins.canvasWin) end),
  503.   resize = button.newButton(canvasX+20,9,7,1,function() resizeCanvas() end),
  504.   save = button.newButton(  canvasX+20,10,7,1,function() save() end),
  505.   exit = button.newButton(  canvasX+20,11,7,1,function() ram.running = false end),
  506. }
  507.  
  508. term.setCursorPos(1,canvasY+4)
  509.  
  510. local function handleEvent(event)
  511.   ram.event = event
  512.   debugWrite(textutils.serialize(event))
  513.   if event[1] == "mouse_click" then
  514.     button.executeButtons(event)
  515.   elseif event[1] == "mouse_drag" then
  516.     button.executeButtons(event,true)
  517.   end
  518. end
  519.  
  520. local function main()
  521.   while ram.running do
  522.     handleEvent({os.pullEvent()})
  523.   end
  524.   term.clear()
  525.   term.setCursorPos(1,1)
  526.   term.setBackgroundColour(colours.black)
  527.   term.setTextColour(colours.white)
  528.   term.write("Closed.")
  529.   term.setCursorPos(1,2)
  530. end
  531.  
  532. parallel.waitForAny(main)--,handleMenus)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement