Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inputTable = {
- Logs = {
- [ "Desktop1.log" ] = "[1:19.937].[Desktop1]:Error: NewInteract.lua:240: bad argument: table expected, got nil\
- [1:23.196].[Desktop1]:Error: NewInteract.lua:266: bad argument: table expected, got nil\
- [2:0.564].[Desktop1]:Error: Main.lua:59: attempt to call nil\
- [2:14.59].[Desktop1]:Error: Main.lua:58: attempt to call nil\
- [2:22.897].[Desktop1]:Error: Main.lua:60: attempt to call nil\
- [3:0.392].[Desktop1]:Error: Main.lua:63: attempt to call nil\
- [3:1.288].[Desktop1]:Error: Main.lua:63: attempt to call nil\
- [3:2.773].[Desktop1]:Error: NewInteract.lua:316: Invalid redirect target\
- [3:3.907].[Desktop1]:Error: Main.lua:69: attempt to call nil\
- [4:4.75].[Desktop1]:Error: Main.lua:70: attempt to index ? (a nil value)\
- [4:7.729].[Desktop1]:Error: NewInteract.lua:710: attempt to perform arithmetic __add on number and nil\
- [4:17.287].[Desktop1]:Error: Main.lua:90: attempt to concatenate string and table\
- [12:13.78].[Desktop1]:Error: Kernel.lua:116: attempt to index ? (a nil value)\
- [12:14.271].[Desktop1]:Error: Kernel.lua:116: attempt to index ? (a nil value)\
- [12:16.966].[Desktop1]:Error: Kernel.lua:116: attempt to index ? (a nil value)\
- [13:9.149].[Desktop1]:Error: Sandbox.lua:19: attempt to call nil\
- [15:17.764].[Desktop1]:Error: Kernel.lua:118: attempt to call nil\
- [15:20.064].[Desktop1]:Error: Kernel.lua:118: attempt to call nil\
- [15:21.409].[Desktop1]:Error: Kernel.lua:118: attempt to call nil\
- [16:1.498].[Desktop1]:Error: Kernel.lua:118: attempt to call nil\
- [16:2.398].[Desktop1]:Error: Kernel.lua:118: attempt to call nil",
- [ "Sandbox.log" ] = "[16:22.159]:FileX1\
- [17:3.7]:FileX1\
- [17:9.873]:FileX1\
- [17:12.003]:FileX\
- [17:13.086]:FileX\
- [17:17.765]:Edit\
- [17:19.83]:FileX\
- [17:19.904]:edit\
- [18:1.495]:FileX",
- [ "edit1.log" ] = "[17:19.905].[edit1]:Error: Main.lua:61: attempt to index ? (a nil value)",
- [ "SandboxPath.log" ] = "[17:9.875]:OmniOS/Programs/FileX1.app/\
- [17:12.005]:OmniOS/Programs/FileX.app/\
- [17:12.072]:OmniOS/Programs/FileX.app/\
- [17:12.092]:OmniOS/Programs/FileX.app//Data\
- [17:12.11]:OmniOS/Programs/FileX.app/\
- [17:12.841]:OmniOS/Programs/FileX.app/\
- [17:13.091]:OmniOS/Programs/FileX.app/\
- [17:17.81]:OmniOS/Programs/Edit.app/OmniOS/Data/here\
- [17:19.831]:OmniOS/Programs/FileX.app/\
- [17:19.905]:OmniOS/Programs/edit.app//permission.data\
- [18:1.496]:OmniOS/Programs/FileX.app/",
- [ "Aware1.log" ] = "[15:8.569].[Aware1]:Error: Main.lua:38: attempt to index ? (a nil value)",
- [ "Calculator.log" ] = "[3:0.392]:bios:366: [string \"Main.layout\"]:48: unexpected symbol\
- [3:1.288]:bios:366: [string \"Main.layout\"]:59: '}' expected (to close '{' at line 2)\
- [11:1.347]:atan(\
- [11:1.385]:1\
- [11:1.411]:2\
- [12:12.198]:2\
- [12:12.223]:+",
- [ "System.log" ] = "[15:20.028]:Launching task Desktop. By kernel\
- [15:20.064]:Opening app FileX\
- [15:20.064]:Opening app FileX: retrieved permissions.\
- [15:20.064]:Opening app FileX: about to launch task.\
- [15:20.064]:Launching task FileX. By kernel\
- [15:20.064]:Launching task FileX1: adding environment. By kernel\
- [15:21.381]:Launching task Desktop. By kernel\
- [15:21.409]:Opening app FileX\
- [15:21.409]:Opening app FileX: retrieved permissions.\
- [15:21.409]:Opening app FileX: about to launch task.\
- [15:21.409]:Launching task FileX. By kernel\
- [15:21.409]:Launching task FileX1: adding environment. By kernel\
- [16:1.466]:Launching task Desktop. By kernel\
- [16:1.498]:Opening app FileX\
- [16:1.498]:Opening app FileX: retrieved permissions.\
- [16:1.498]:Opening app FileX: about to launch task.\
- [16:1.498]:Launching task FileX. By kernel\
- [16:1.498]:Launching task FileX1: adding environment. By kernel\
- [16:2.373]:Launching task Desktop. By kernel\
- [16:2.398]:Opening app Edit\
- [16:2.398]:Opening app Edit: retrieved permissions.\
- [16:2.398]:Opening app Edit: about to launch task.\
- [16:2.398]:Launching task Edit. By kernel\
- [16:2.398]:Launching task Edit1: adding environment. By kernel\
- [16:3.636]:Launching task Desktop. By kernel\
- [16:3.682]:Opening app FileX\
- [16:3.682]:Opening app FileX: retrieved permissions.\
- [16:3.682]:Opening app FileX: about to launch task.\
- [16:3.682]:Launching task FileX. By kernel\
- [16:3.682]:Launching task FileX1: adding environment. By kernel\
- [16:3.683]:Opening app FileX: launched task.\
- [16:22.128]:Launching task Desktop. By kernel\
- [16:22.159]:Opening app FileX\
- [16:22.159]:Opening app FileX: retrieved permissions.\
- [16:22.159]:Opening app FileX: about to launch task.\
- [16:22.159]:Launching task FileX. By kernel\
- [16:22.159]:Launching task FileX1: adding environment. By kernel\
- [16:22.161]:Opening app FileX: launched task.\
- [17:3.7]:Opening app FileX\
- [17:3.7]:Opening app FileX: retrieved permissions.\
- [17:3.7]:Opening app FileX: about to launch task.\
- [17:3.7]:Launching task FileX. By kernel\
- [17:3.7]:Launching task FileX1: adding environment. By kernel\
- [17:3.701]:Opening app FileX: launched task.\
- [17:9.84]:Launching task Desktop. By kernel\
- [17:9.872]:Opening app FileX\
- [17:9.872]:Opening app FileX: retrieved permissions.\
- [17:9.872]:Opening app FileX: about to launch task.\
- [17:9.873]:Launching task FileX. By kernel\
- [17:9.873]:Launching task FileX1: adding environment. By kernel\
- [17:9.875]:Opening app FileX: launched task.\
- [17:11.972]:Launching task Desktop. By kernel\
- [17:12.002]:Opening app FileX\
- [17:12.002]:Opening app FileX: retrieved permissions.\
- [17:12.003]:Opening app FileX: about to launch task.\
- [17:12.003]:Launching task FileX. By kernel\
- [17:12.003]:Launching task FileX1: adding environment. By kernel\
- [17:12.005]:Opening app FileX: launched task.\
- [17:12.864]:Opening app BetterPaint\
- [17:12.864]:Opening app BetterPaint: retrieved permissions.\
- [17:12.865]:Opening app BetterPaint: about to launch task.\
- [17:12.865]:Launching task BetterPaint. By kernel\
- [17:12.868]:Opening app BetterPaint: launched task.\
- [17:13.086]:Opening app FileX\
- [17:13.086]:Opening app FileX: retrieved permissions.\
- [17:13.086]:Opening app FileX: about to launch task.\
- [17:13.086]:Launching task FileX. By kernel\
- [17:13.086]:Launching task FileX2: adding environment. By kernel\
- [17:13.092]:Opening app FileX: launched task.\
- [17:13.196]:Opening app BetterPaint\
- [17:13.196]:Opening app BetterPaint: retrieved permissions.\
- [17:13.196]:Opening app BetterPaint: about to launch task.\
- [17:13.196]:Launching task BetterPaint. By kernel\
- [17:13.199]:Opening app BetterPaint: launched task.\
- [17:17.737]:Launching task Desktop. By kernel\
- [17:17.765]:Opening app Edit\
- [17:17.765]:Opening app Edit: retrieved permissions.\
- [17:17.765]:Opening app Edit: about to launch task.\
- [17:17.765]:Launching task Edit. By kernel\
- [17:17.765]:Launching task Edit1: adding environment. By kernel\
- [17:17.766]:Opening app Edit: launched task.\
- [17:19.83]:Opening app FileX\
- [17:19.83]:Opening app FileX: retrieved permissions.\
- [17:19.83]:Opening app FileX: about to launch task.\
- [17:19.83]:Launching task FileX. By kernel\
- [17:19.83]:Launching task FileX1: adding environment. By kernel\
- [17:19.831]:Opening app FileX: launched task.\
- [17:19.904]:Opening app edit\
- [17:19.904]:Opening app edit: retrieved permissions.\
- [17:19.904]:Opening app edit: about to launch task.\
- [17:19.904]:Launching task edit. By kernel\
- [17:19.904]:Launching task edit1: adding environment. By kernel\
- [17:19.905]:Opening app edit: launched task.\
- [18:1.411]:Launching task Desktop. By kernel\
- [18:1.495]:Opening app FileX\
- [18:1.495]:Opening app FileX: retrieved permissions.\
- [18:1.495]:Opening app FileX: about to launch task.\
- [18:1.495]:Launching task FileX. By kernel\
- [18:1.495]:Launching task FileX1: adding environment. By kernel\
- [18:1.496]:Opening app FileX: launched task.",
- [ "Error.log" ] = "[1:19.937].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [1:23.196].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [2:0.565].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [2:14.592].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [2:22.897].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [3:0.393].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [3:1.289].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [3:2.773].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [3:3.907].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [4:4.637].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [4:4.75].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [4:7.729].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [4:9.837].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [4:17.288].[Missing]: Kernel.lua:104: attempt to index ? (a nil value)\
- [12:13.78].[Missing]: Kernel.lua:105: attempt to index ? (a nil value)\
- [12:14.271].[Missing]: Kernel.lua:105: attempt to index ? (a nil value)\
- [12:16.966].[Missing]: Kernel.lua:105: attempt to index ? (a nil value)\
- [13:9.15].[Missing]: Kernel.lua:105: attempt to index ? (a nil value)\
- [15:17.764].[Missing]: 199\
- [15:20.064].[Missing]: 194\
- [15:21.411].[Missing]: 194\
- [16:1.499].[Missing]: 198\
- [16:2.399].[Missing]: 194",
- [ "FileX1.log" ] = "[1:12.644].[FileX1]:Error: Main.lua:756: attempt to index ? (a nil value)\
- [15:10.283].[FileX1]:Error: Main.lua:756: attempt to index ? (a nil value)\
- [15:15.363].[FileX1]:Error: Main.lua:756: attempt to index ? (a nil value)\
- [16:3.683].[FileX1]:Error: Main.lua:-1: Not a directory\
- [16:22.161].[FileX1]:Error: Main.lua:397: Not a directory\
- [17:3.701].[FileX1]:Error: Main.lua:-1: Not a directory\
- [17:9.875].[FileX1]:Error: Main.lua:397: Not a directory",
- },
- [ "README.md" ] = "# TheOS\
- GitHub repository of TheOS",
- [ "BIOS.lua" ] = "--[[\
- BIOS by Creator\
- for OmniOS\
- ]]--\
- \
- term.redirect(term.native())\
- \
- --Variables--\
- local gui = {}\
- local OS = {}\
- local timeLeft = 5\
- local currentOS = 1\
- local defaultOS = \"\"\
- local toBoot = 0\
- local layout = [[\
- +-----------------------------------------+\
- | Current selection: |\
- | |\
- +-----------------------------------------+\
- | Available OSes: |\
- | |\
- | |\
- | |\
- | |\
- | |\
- | |\
- +-----------------------------------------+\
- | S: Settings |\
- +-----------------------------------------+\
- | Time left: |\
- +-----------------------------------------+\
- ]]\
- --Functions\
- function gui.clear()\
- term.setBackgroundColor(colors.blue)\
- term.setTextColor(colors.white)\
- term.setCursorPos(1,2)\
- term.clear()\
- end\
- \
- function gui.drawMain()\
- gui.clear()\
- term.setCursorPos(1,3)\
- print(layout)\
- term.setCursorPos(8,4)\
- term.write(OS[currentOS][1])\
- for i = 1, #OS do\
- term.setCursorPos(8,i+6)\
- term.write(i..\") \"..OS[i][1])\
- end\
- term.setCursorPos(19,16)\
- term.write(timeLeft)\
- end\
- \
- local function loadOS()\
- return dofile(\"OmniOS/BIOS/List\")\
- end\
- \
- local function loadDefault()\
- return dofile(\"OmniOS/BIOS/default\")\
- end\
- \
- local function findCurrent()\
- for i, v in pairs(OS) do\
- if defaultOS == v[1] then\
- return i\
- end\
- end\
- error(\"The OS you are searching does not exist!\")\
- end\
- \
- --Code\
- OS = loadOS()\
- defaultOS = loadDefault()\
- currentOS = findCurrent()\
- while true do \
- gui.drawMain()\
- local timerID = os.startTimer(1)\
- local event = {os.pullEvent()}\
- if timeLeft == 0 then\
- toBoot = currentOS\
- break\
- end\
- if event[1] == \"key\" then\
- os.cancelTimer(timerID)\
- if 2 <= event[2] and event[2] <= 11 then\
- event[2] = event[2] == 11 and 0 or event[2] - 1\
- if OS[event[2]] then\
- toBoot = event[2]\
- break\
- end\
- elseif event[2] == keys.up then\
- currentOS = currentOS - 1\
- currentOS = currentOS == 0 and #OS or currentOS\
- elseif event[2] == keys.down then\
- currentOS = currentOS + 1\
- currentOS = currentOS == #OS + 1 and 1 or currentOS\
- elseif event[2] == keys.enter then\
- toBoot = currentOS\
- break\
- end\
- elseif event[1] == \"timer\" and event[2] == timerID then\
- timeLeft = timeLeft - 1\
- end\
- end\
- \
- if OS[toBoot][1] == \"CraftOS\" then\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.yellow)\
- term.clear()\
- term.setCursorPos(1,1)\
- print(\"CraftOS 1.7\")\
- else\
- dofile(OS[toBoot][2])\
- end",
- Media = {
- Boot = {
- [ "Boot_Logo.nfp" ] = "d d eeeeeeeee\
- dd d ddde ee \
- d dddddde eeeee\
- d d dd e e e\
- dddd ddddeeeeeeeee",
- [ "Boot_Hide.nfp" ] = "000000000000000000000000000\
- 000000000000000000000000000\
- 000000000000000000000000000\
- 000000000000000000000000000\
- 000000000000000000000000000\
- 000000000000000000000000000\
- 000000000000000000000000000\
- 000000000000000000000000000",
- },
- },
- int = " term.clear()\
- gui = Interact.Initialize()\
- button = gui.Button.new( {\
- name = \"Hi\",\
- label = \"hello\",\
- xPos = 2,\
- yPos = 5,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 7,\
- yLength = 3,\
- returnValue = \"hi\",\
- xTextPos = 2,\
- yTextPos = 2,\
- onRightClick = function() print(\"wow\") sleep(3) end,\
- onLeftClick = function() os.shutdown() end,\
- })\
- button:draw()\
- \
- os.pullEvent()",
- BIOS = {
- default = "return \"OmniOS\"",
- List = " return {\
- { \"OmniOS\",\"OmniOS/Core/Boot.lua\" },\
- {\"CraftOS\",\"shell\"},\
- }",
- },
- CodeIDontNeedNow = {
- toggles = " ToggleTable = {\
- test = {\
- name = \"beu\",\
- state = false,\
- xPos = 7,\
- yPos = 8,\
- trueColor = colors.green,\
- falseColor = colors.red,\
- trueText = \"T\",\
- falseText = \"F\",\
- selectedBg = colors.gray,\
- notSelectedBg = colors.black,\
- returnValue = \"yyy\",\
- }\
- }",
- [ "Installer.lua" ] = "args = {...}\
- local sPath = args[1]\
- local filesystem = {}\
- \
- local function readFile(path)\
- local file = fs.open(path,\"r\")\
- local variable = file.readAll()\
- file.close()\
- return variable\
- end\
- \
- filesystem = textutils.unserialize(readFile(sPath))\
- \
- \
- local function writeFile(path,content)\
- local file = fs.open(path,\"w\")\
- file.write(content)\
- file.close()\
- end\
- \
- function writeDown(input,dir)\
- for i,v in pairs(input) do\
- if type(v) == \"table\" then\
- writeDown(v,dir..\"/\"..i)\
- elseif type(v) == \"string\" then\
- writeFile(dir..\"/\"..i,v)\
- end\
- end\
- end\
- writeDown(filesystem,\"TheOS\")",
- },
- wow = "function test()\
- pritn(\"hello\") --# will error\
- end\
- \
- local ok, res = coroutine.resume( coroutine.create( test ) )\
- \
- print( tostring(ok) .. \":\" .. res )",
- Core = {
- [ "LoadAPIs.lua" ] = "--Code--\
- local apis = fs.list(\"OmniOS/API/\")\
- local dirs = {}\
- function loadAPI( _sPath )\
- local sName = fs.getName( _sPath )\
- local tEnv = {}\
- setmetatable( tEnv, { __index = _G } )\
- local fnAPI, err = loadfile( _sPath )\
- if fnAPI then\
- setfenv( fnAPI, tEnv )\
- local ok, err = pcall( fnAPI )\
- if not ok then\
- printError( err )\
- return false\
- end\
- else\
- printError( err )\
- return false\
- end\
- \
- local tAPI = {}\
- for k,v in pairs( tEnv ) do\
- tAPI[k] = v\
- end\
- \
- _G[sName:match(\"[^%.]+\")] = tAPI \
- return true\
- end\
- for i,v in pairs(apis) do\
- if fs.isDir(\"OmniOS/API/\"..v) then\
- dirs[i] = true\
- end\
- end\
- for i,v in pairs(dirs) do\
- apis[i] = nil\
- end\
- for i,v in pairs(apis) do\
- loadAPI(\"OmniOS/API/\"..v)\
- term.setTextColor(colors.black)\
- print(v)\
- end\
- os.pullEvent()",
- [ "Boot.lua" ] = "--OmniOS: Boot--\
- --by Creator--\
- \
- --Variables--\
- local tasks = 2\
- local finishedTasks = 0\
- term.redirect(term.native())\
- local w,h = term.getSize()\
- local textutilsserialize = textutils.serialize\
- local textutilsunserialize = textutils.unserialize\
- local APIlist = {}\
- local oldPullEvent = os.pullEvent\
- local whichLang = nil\
- local lang = {}\
- local oldFs = {}\
- local logo = paintutils.loadImage(\"OmniOS/Media/Boot/Boot_Logo.nfp\")\
- local hideLogo = paintutils.loadImage(\"OmniOS/Media/Boot/Boot_Hide.nfp\")\
- local logoWide = 18\
- --Functions--\
- \
- local function nPrint(text)\
- finishedTasks = finishedTasks + 1\
- local txt = \"OmniOS by Creator\"\
- term.setBackgroundColor(colors.white)\
- term.setTextColor(colors.lightGray)\
- term.clear()\
- term.setCursorPos(math.floor((w-#txt)/2),math.floor(h/2)-1)\
- term.write(txt)\
- term.setTextColor(colors.gray)\
- term.setCursorPos(math.floor((w-#text)/2),math.floor(h/2))\
- term.write(text)\
- paintutils.drawImage(logo,math.floor((w-logoWide)/2),math.floor(h/2)+3)\
- paintutils.drawImage(hideLogo,math.floor((w-logoWide)/2)+math.ceil((finishedTasks/tasks)*logoWide),math.floor(h/2)+3)\
- sleep(.2)\
- end\
- \
- --Code--\
- \
- term.setTextColor(colors.white)\
- term.setBackgroundColor(colors.white)\
- term.clear()\
- term.setCursorPos(1,1)\
- \
- --Load language file--\
- langFile = fs.open(\"OmniOS/Settings/Language/CurrentLang\",\"r\")\
- whichLang = langFile.readAll()\
- langFile.close()\
- \
- langFile = fs.open(\"OmniOS/Languages/Boot_\"..whichLang..\".lang\",\"r\")\
- lang = textutilsunserialize(langFile.readAll())\
- langFile.close()\
- \
- --Load APIs--\
- nPrint(lang[3])\
- dofile(\"OmniOS/Core/LoadAPIs.lua\")\
- nPrint(lang[4])\
- \
- --Overwrite os.pullEventFunctions--\
- --oldPullEvent = os.pullEvent\
- --os.pullEvent = os.pullEventRaw\
- \
- --Go to next\
- function goOn()\
- local login, err = loadfile(\"OmniOS/Core/Login.lua\")\
- if err then print(err) log.log(\"Error\",err) os.pullEvent() end\
- --login()\
- local kernel, err= loadfile(\"OmniOS/Core/Kernel.lua\")\
- if err then print(err) os.pullEvent() log.log(\"Error\",err) end\
- local desktop,err = loadfile(\"OmniOS/Programs/Desktop.app/Main.lua\")\
- if err then print(err) os.pullEvent() log.log(\"Error\",err) end\
- kernel(\"Desktop\",\"Desktop\",desktop,\"user\")\
- end\
- \
- ok, err = pcall(goOn)\
- \
- if not ok then\
- pcall(shell.run(\"OmniOS/Core/Crash.lua \"..err))\
- end",
- [ "Login.lua" ] = "--Variables--\
- local notLogin = true\
- local w,h = term.getSize()\
- term.redirect(term.native())\
- local user = nil\
- local pass = nil\
- \
- --Code--\
- --Startup script--\
- term.setBackgroundColor(colors.white)\
- term.clear()\
- term.setCursorPos(1,1)\
- term.setTextColor(colors.black)\
- \
- --GUI\
- gui.resetButtons()\
- gui.resetKeys()\
- gui.cPrint(\"Login\",colors.black,nil,math.floor((w-5)/2),3)\
- --gui.cPrint(\"Username: >\",colors.gray,nil,3,6)\
- gui.cPrint(\"Password: >\",colors.gray,nil,3,8)\
- --gui.addField(15,6,20,1,\"userField\")\
- --paintutils.drawFilledBox(15,6,35,6,colors.lightGray)\
- gui.addField(15,8,20,1,\"passField\")\
- paintutils.drawFilledBox(15,8,35,8,colors.lightGray)\
- gui.addKey(keys.enter,\"Enter\")\
- gui.drawButton(15,10,8,3,colors.green,2,2,\"Ready!\",colors.black,\"ready\")\
- \
- --Main Loop--\
- while notLogin do\
- --Script\
- local result = gui.detectButtonOrKeyHit()\
- if result[1] == \"userField\" then\
- paintutils.drawFilledBox(15,6,35,6,colors.lightGray)\
- term.setCursorPos(15,6)\
- term.setTextColor(colors.black)\
- user = read()\
- elseif result[1] == \"passField\" then\
- paintutils.drawFilledBox(15,8,35,8,colors.lightGray)\
- term.setCursorPos(15,8)\
- term.setTextColor(colors.black)\
- pass = read(\"*\")\
- elseif result[1] == \"Enter\" or result[1] == \"ready\" then\
- if user == nil or pass == nil then\
- else\
- paintutils.drawFilledBox(15,15,35,15,colors.lightGray)\
- local realPass\
- ok = pcall( function()\
- f = fs.open(\"TheOS/Settings/Users/Admin\",\"r\")\
- realPass = f.readAll()\
- f.close()\
- end )\
- if realPass == Sha.sha256(pass) then\
- notLogin = false\
- end\
- if ok == false or notLogin then\
- gui.cPrint(\"Wrong username or password!\",colors.red,colors.white,13,15)\
- end\
- end\
- end\
- end",
- [ "Crash.lua" ] = "os.pullEvent = os.pullEventRaw\
- tArgs = {...}\
- \
- err = \"\"\
- \
- term.redirect(term.native())\
- term.setBackgroundColor(colors.blue)\
- term.clear()\
- term.setTextColor(colors.white)\
- term.setCursorPos(2,4)\
- term.write(\"TheOS has crashed :(\")\
- term.setCursorPos(2,6)\
- print(\"Click anywhere to restart the system, if the\\n problem persists send the error message\\n to Creator on the CC forums or to\\n TheOnlyCreator on GitHub.\")\
- term.setCursorPos(2,11)\
- term.write(\"Error message: \")\
- term.setCursorPos(4,13)\
- for i,v in pairs(tArgs) do\
- err = err..\" \"..v\
- end\
- print(err)\
- log.log(\"Error\",err,\"Missing\")\
- os.pullEvent(\"mouse_click\")\
- --os.reboot()",
- [ "Kernel.lua" ] = "--[[\
- TheOS Kernel\
- by Creator\
- for TheOS &\
- you to learn\
- from it! (Yeah learn, rather become dumber)\
- theoriginalbit\
- also gets credit for \
- his safePairs function.\
- Lots of thanks to BombBloke too for \
- finalizing and bug fixing it.\
- ]]--\
- \
- local logMessage = \"\"\
- local history = {}\
- local w,h = term.getSize()\
- local currTerm, routines, activeRoutine, eventBuffer = term.current(), {}, \"\", {}\
- local eventFilter = {[\"key\"] = true, [\"mouse_click\"] = true, [\"monitor_touch\"] = true, [\"paste\"] = true,\
- [\"char\"] = true, [\"terminate\"] = true, [\"mouse_scroll\"] = true, [\"mouse_drag\"] = true}\
- \
- local function safePairs(t)\
- local keys = {}\
- for k,v in pairs(t) do\
- keys[#keys+1] = k\
- end\
- local i = 0\
- return function()\
- i = i + 1\
- return keys[i], t[keys[i]]\
- end\
- end\
- \
- local function drawClosed()\
- paintutils.drawLine(w,1,w,h,colors.black)\
- term.setTextColor(colors.white)\
- term.setBackgroundColor(colors.black)\
- term.setCursorPos(w,h/2+2)\
- term.write(\"<\")\
- end\
- \
- local function drawOpen()\
- term.setCursorBlink(false)\
- paintutils.drawFilledBox(w-15,1,w,h,colors.black)\
- local xVsProcess, curr = {}, 1\
- term.setTextColor(colors.white)\
- for i,v in pairs(routines) do\
- paintutils.drawLine(w-15,curr*2,w,curr*2,i == activeRoutine and colours.blue or colours.black)\
- paintutils.drawLine(w-15,curr*2+1,w,curr*2+1,i == activeRoutine and colours.blue or colours.black)\
- term.setBackgroundColour(i == activeRoutine and colours.blue or colours.black)\
- term.setCursorPos(w-14,curr*2)\
- term.write(\"x \"..v.title)\
- term.setCursorPos(w-12,curr*2+1)\
- term.write(coroutine.status(v.routine))\
- xVsProcess[curr*2] = i\
- curr = curr + 1\
- end\
- --print(activeRoutine)\
- --for i,v in pairs(history) do\
- -- print(i..\" \"..v)\
- --end\
- \
- while true do\
- local evnt = {os.pullEventRaw()}\
- if evnt[1] == \"mouse_click\" then\
- if w-12 <= evnt[3] and evnt[3] <= w then\
- if xVsProcess[evnt[4]] then\
- routines[activeRoutine].window.setVisible( false )\
- activeRoutine = xVsProcess[evnt[4]]\
- routines[activeRoutine].window.setVisible(true)\
- history[#history+1] = activeRoutine\
- return\
- end\
- elseif w-14 == evnt[3] then\
- if xVsProcess[evnt[4]] and xVsProcess[evnt[4]] ~= \"Desktop1\" then\
- if activeRoutine == xVsProcess[evnt[4]] then\
- --history[#history] = nil\
- --for i,v in pairs(history) do\
- -- if xVsProcess[evnt[4]] == v then\
- -- table.remove(history,i)\
- -- end\
- --activeRoutine = history[#history]\
- activeRoutine = \"Desktop1\"\
- routines[activeRoutine].window.setVisible(true)\
- end\
- routines[xVsProcess[evnt[4]]] = nil\
- return\
- end\
- else return end\
- else eventBuffer[#eventBuffer+1] = evnt end\
- end\
- end\
- \
- local function checkIfDead(routine)\
- if coroutine.status(routines[routine].routine) == \"dead\" then\
- routines[routine] = nil\
- if routine == activeRoutine then\
- --history[#history] = nil\
- --[[for i,v in pairs(history) do\
- if routine == v then\
- table.remove(history,i)\
- end\
- end\
- activeRoutine = history[#history]]--\
- activeRoutine = \"Desktop1\"\
- routines[activeRoutine].window.setVisible(true)\
- end\
- return true\
- else return false end\
- end\
- \
- function newRoutine(name,title,func,permission,...)\
- log.log(\"System\",\"Launching task \"..name..\". By kernel\")\
- local oldName = name\
- local tries = 1\
- while routines[name .. tries] do tries = tries + 1 end\
- name = name .. tries\
- if permission == \"userTest\" then\
- log.log(\"System\",\"Launching task \"..name..\": adding environment. By kernel\")\
- local env = Sandbox.newEnv(oldName)\
- --log.log(\"SandboxOutput\",textutils.serialize(env))\
- setfenv(func,env)\
- end\
- \
- routines[name] = {\
- [\"title\"] = title,\
- [\"permission\"] = permission,\
- [\"path\"] = path,\
- [\"routine\"] = coroutine.create(func),\
- [\"window\"] = OmniWindow.create(currTerm,1,1,w-1,h,true),\
- [\"filter\"] = \"\",\
- }\
- \
- --Run it!\
- if routines[activeRoutine] then routines[activeRoutine].window.setVisible(false) end\
- activeRoutine = name\
- term.redirect(routines[activeRoutine].window)\
- routines[activeRoutine].window.setVisible(true)\
- logMessage, routines[activeRoutine].filter = coroutine.resume(routines[activeRoutine].routine,...)\
- if not logMessage then\
- log.log(activeRoutine,\"Error: \"..tostring(routines[activeRoutine].filter),activeRoutine)\
- end\
- term.redirect(currTerm)\
- checkIfDead(activeRoutine)\
- history[#history+1] = activeRoutine\
- end\
- \
- function getPermission(program)\
- return routines[program].permission or \"Not a valid program\"\
- end\
- \
- drawClosed()\
- \
- newRoutine(...)\
- \
- while true do\
- local event = #eventBuffer == 0 and {os.pullEventRaw()} or table.remove(eventBuffer,1)\
- if (event[1] == \"mouse_click\" or event[1] == \"monitor_touch\") and event[3] == w then\
- drawOpen()\
- drawClosed()\
- routines[activeRoutine].window.redraw()\
- elseif eventFilter[event[1]] then\
- if routines[activeRoutine].filter == nil or routines[activeRoutine].filter == \"\" or routines[activeRoutine].filter == event[1] then\
- term.redirect(routines[activeRoutine].window)\
- logMessage, routines[activeRoutine].filter = coroutine.resume(routines[activeRoutine].routine,unpack(event))\
- if not logMessage then\
- log.log(activeRoutine,\"Error: \"..tostring(routines[activeRoutine].filter),activeRoutine)\
- end\
- term.redirect(currTerm)\
- checkIfDead(activeRoutine)\
- end\
- else\
- for i,v in safePairs(routines) do\
- term.redirect(routines[i].window)\
- logMessage, routines[i].filter = coroutine.resume(routines[i].routine,unpack(event))\
- if not logMessage then\
- log.log(i,\"Error: \"..tostring(routines[i].filter),i)\
- end\
- term.redirect(currTerm)\
- checkIfDead(i)\
- end\
- end\
- end",
- },
- [ ".gitignore" ] = "*.log",
- Data = {
- [ ".toGitHub" ] = "",
- wow = "really",
- heyBro = "",
- wut = "",
- here = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 1,\
- \" \",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 1,\
- \" \",\
- 1,\
- },\
- },\
- [ 5 ] = {},\
- }",
- where = "error('This is an image, not a program!')\
- {\
- [ 11 ] = {\
- [ 9 ] = {\
- 32768,\
- \" \",\
- 1,\
- },\
- },\
- }",
- },
- API = {
- [ "OmniWindow.lua" ] = "\
- function create( parent, nX, nY, nWidth, nHeight, bStartVisible )\
- \
- if type( parent ) ~= \"table\" or\
- type( nX ) ~= \"number\" or\
- type( nY ) ~= \"number\" or\
- type( nWidth ) ~= \"number\" or\
- type( nHeight ) ~= \"number\" or\
- (bStartVisible ~= nil and type( bStartVisible ) ~= \"boolean\") then\
- error( \"Expected object, number, number, number, number, [boolean]\", 2 )\
- end\
- \
- if parent == term then\
- error( \"term is not a recommended window parent, try term.current() instead\", 2 )\
- end\
- \
- -- Setup\
- local bVisible = (bStartVisible ~= false)\
- local nCursorX = 1\
- local nCursorY = 1\
- local bCursorBlink = false\
- local nTextColor = colors.white\
- local nBackgroundColor = colors.black\
- local sEmpty = string.rep( \" \", nWidth )\
- local tLines = {}\
- do\
- local tEmpty = { { sEmpty, nTextColor, nBackgroundColor } }\
- for y=1,nHeight do\
- tLines[y] = tEmpty\
- end\
- end\
- \
- -- Helper functions\
- local function updateCursorPos()\
- if nCursorX >= 1 and nCursorY >= 1 and\
- nCursorX <= nWidth and nCursorY <= nHeight then\
- parent.setCursorPos( nX + nCursorX - 1, nY + nCursorY - 1 )\
- else\
- parent.setCursorPos( 0, 0 )\
- end\
- end\
- \
- local function updateCursorBlink()\
- parent.setCursorBlink( bCursorBlink )\
- end\
- \
- local function updateCursorColor()\
- parent.setTextColor( nTextColor )\
- end\
- \
- local function redrawLine( n )\
- parent.setCursorPos( nX, nY + n - 1 )\
- local tLine = tLines[ n ]\
- for m=1,#tLine do\
- local tBit = tLine[ m ]\
- parent.setTextColor( tBit[2] )\
- parent.setBackgroundColor( tBit[3] )\
- parent.write( tBit[1] )\
- end\
- end\
- \
- local function lineLen( tLine )\
- local nLength = 0\
- for n=1,#tLine do\
- nLength = nLength + string.len( tLine[n][1] )\
- end\
- return nLength\
- end\
- \
- local function lineSub( tLine, nStart, nEnd )\
- --assert( math.floor(nStart) == nStart )\
- --assert( math.floor(nEnd) == nEnd )\
- --assert( nStart >= 1 )\
- --assert( nEnd >= nStart )\
- --assert( nEnd <= lineLen( tLine ) )\
- local tSubLine = {}\
- local nBitStart = 1\
- for n=1,#tLine do\
- local tBit = tLine[n]\
- local sBit = tBit[1]\
- local nBitEnd = nBitStart + string.len( sBit ) - 1\
- if nBitEnd >= nStart and nBitStart <= nEnd then\
- if nBitStart >= nStart and nBitEnd <= nEnd then\
- -- Include bit wholesale\
- table.insert( tSubLine, tBit )\
- --assert( lineLen( tSubLine ) == (math.min(nEnd, nBitEnd) - nStart + 1) )\
- elseif nBitStart < nStart and nBitEnd <= nEnd then\
- -- Include end of bit\
- table.insert( tSubLine, {\
- string.sub( sBit, nStart - nBitStart + 1 ),\
- tBit[2], tBit[3]\
- } )\
- --assert( lineLen( tSubLine ) == (math.min(nEnd, nBitEnd) - nStart + 1) )\
- elseif nBitStart >= nStart and nBitEnd > nEnd then\
- -- Include beginning of bit\
- table.insert( tSubLine, {\
- string.sub( sBit, 1, nEnd - nBitStart + 1 ),\
- tBit[2], tBit[3]\
- } )\
- --assert( lineLen( tSubLine ) == (math.min(nEnd, nBitEnd) - nStart + 1) )\
- else\
- -- Include middle of bit\
- table.insert( tSubLine, {\
- string.sub( sBit, nStart - nBitStart + 1, nEnd - nBitStart + 1 ),\
- tBit[2], tBit[3]\
- } )\
- --assert( lineLen( tSubLine ) == (math.min(nEnd, nBitEnd) - nStart + 1) )\
- end\
- end\
- nBitStart = nBitEnd + 1\
- end\
- --assert( lineLen( tSubLine ) == (nEnd - nStart + 1) )\
- return tSubLine\
- end\
- \
- local function lineJoin( tLine1, tLine2 )\
- local tNewLine = {}\
- if tLine1[#tLine1][2] == tLine2[1][2] and\
- tLine1[#tLine1][3] == tLine2[1][3] then\
- -- Merge middle bits\
- for n=1,#tLine1-1 do\
- table.insert( tNewLine, tLine1[n] )\
- end\
- table.insert( tNewLine, {\
- tLine1[#tLine1][1] .. tLine2[1][1],\
- tLine2[1][2], tLine2[1][3]\
- } )\
- for n=2,#tLine2 do\
- table.insert( tNewLine, tLine2[n] )\
- end\
- --assert( lineLen( tNewLine ) == lineLen(tLine1) + lineLen(tLine2) )\
- else\
- -- Just concatenate\
- for n=1,#tLine1 do\
- table.insert( tNewLine, tLine1[n] )\
- end\
- for n=1,#tLine2 do\
- table.insert( tNewLine, tLine2[n] )\
- end\
- --assert( lineLen( tNewLine ) == lineLen(tLine1) + lineLen(tLine2) )\
- end\
- return tNewLine\
- end\
- \
- local function redraw()\
- for n=1,nHeight do\
- redrawLine( n )\
- end\
- end\
- \
- local window = {}\
- \
- -- Terminal implementation\
- function window.write( sText )\
- local nLen = string.len( sText )\
- local nStart = nCursorX\
- local nEnd = nStart + nLen - 1\
- if nCursorY >= 1 and nCursorY <= nHeight then\
- -- Work out where to put new line\
- --assert( math.floor(nStart) == nStart )\
- --assert( math.floor(nEnd) == nEnd )\
- if nStart <= nWidth and nEnd >= 1 then\
- -- Construct new line\
- local tLine = tLines[ nCursorY ]\
- if nStart == 1 and nEnd == nWidth then\
- -- Exactly replace line\
- tLine = {\
- { sText, nTextColor, nBackgroundColor }\
- }\
- --assert( lineLen( tLine ) == nWidth )\
- elseif nStart <= 1 and nEnd >= nWidth then\
- -- Overwrite line with subset\
- tLine = {\
- { string.sub( sText, 1 - nStart + 1, nWidth - nStart + 1 ), nTextColor, nBackgroundColor }\
- }\
- --assert( lineLen( tLine ) == nWidth )\
- elseif nStart <= 1 then\
- -- Overwrite beginning of line\
- tLine = lineJoin(\
- { { string.sub( sText, 1 - nStart + 1 ), nTextColor, nBackgroundColor } },\
- lineSub( tLine, nEnd + 1, nWidth )\
- )\
- --assert( lineLen( tLine ) == nWidth )\
- elseif nEnd >= nWidth then\
- -- Overwrite end of line\
- tLine = lineJoin(\
- lineSub( tLine, 1, nStart - 1 ),\
- { { string.sub( sText, 1, nWidth - nStart + 1 ), nTextColor, nBackgroundColor } }\
- )\
- --assert( lineLen( tLine ) == nWidth )\
- else\
- -- Overwrite middle of line\
- tLine = lineJoin(\
- lineJoin(\
- lineSub( tLine, 1, nStart - 1 ),\
- { { sText, nTextColor, nBackgroundColor } }\
- ),\
- lineSub( tLine, nEnd + 1, nWidth )\
- )\
- --assert( lineLen( tLine ) == nWidth )\
- end\
- \
- -- Store and redraw new line\
- tLines[ nCursorY ] = tLine\
- if bVisible then\
- redrawLine( nCursorY )\
- end\
- end\
- end\
- \
- -- Move and redraw cursor\
- nCursorX = nEnd + 1\
- if bVisible then\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- \
- function window.clear()\
- local tEmpty = { { sEmpty, nTextColor, nBackgroundColor } }\
- for y=1,nHeight do\
- tLines[y] = tEmpty\
- end\
- if bVisible then\
- redraw()\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- \
- function window.clearLine()\
- if nCursorY >= 1 and nCursorY <= nHeight then\
- tLines[ nCursorY ] = { { sEmpty, nTextColor, nBackgroundColor } }\
- if bVisible then\
- redrawLine( nCursorY )\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- end\
- \
- function window.getCursorPos()\
- return nCursorX, nCursorY\
- end\
- \
- function window.setCursorPos( x, y )\
- nCursorX = math.floor( x )\
- nCursorY = math.floor( y )\
- if bVisible then\
- updateCursorPos()\
- end\
- end\
- \
- function window.setCursorBlink( blink )\
- bCursorBlink = blink\
- if bVisible then\
- updateCursorBlink()\
- end\
- end\
- \
- function window.isColor()\
- return parent.isColor()\
- end\
- \
- function window.isColour()\
- return parent.isColor()\
- end\
- \
- local function setTextColor( color )\
- if not parent.isColor() then\
- if color ~= colors.white and color ~= colors.black then\
- error( \"Colour not supported\", 3 )\
- end\
- end\
- nTextColor = color\
- if bVisible then\
- updateCursorColor()\
- end\
- end\
- \
- function window.setTextColor( color )\
- setTextColor( color )\
- end\
- \
- function window.setTextColour( color )\
- setTextColor( color )\
- end\
- \
- local function setBackgroundColor( color )\
- if not parent.isColor() then\
- if color ~= colors.white and color ~= colors.black then\
- error( \"Colour not supported\", 3 )\
- end\
- end\
- nBackgroundColor = color\
- end\
- \
- function window.setBackgroundColor( color )\
- setBackgroundColor( color )\
- end\
- \
- function window.setBackgroundColour( color )\
- setBackgroundColor( color )\
- end\
- \
- function window.getSize()\
- return nWidth, nHeight\
- end\
- \
- function window.scroll( n )\
- if n ~= 0 then\
- local tNewLines = {}\
- local tEmpty = { { sEmpty, nTextColor, nBackgroundColor } }\
- for newY=1,nHeight do\
- local y = newY + n\
- if y >= 1 and y <= nHeight then\
- tNewLines[newY] = tLines[y]\
- else\
- tNewLines[newY] = tEmpty\
- end\
- end\
- tLines = tNewLines\
- if bVisible then\
- redraw()\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- end\
- \
- -- Other functions\
- function window.setVisible( bVis )\
- if bVisible ~= bVis then\
- bVisible = bVis\
- if bVisible then\
- window.redraw()\
- end\
- end\
- end\
- \
- function window.redraw()\
- if bVisible then\
- redraw()\
- updateCursorBlink()\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- \
- function window.restoreCursor()\
- if bVisible then\
- updateCursorBlink()\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- \
- function window.getPosition()\
- return nX, nY\
- end\
- \
- function window.reposition( nNewX, nNewY, nNewWidth, nNewHeight )\
- nX = nNewX\
- nY = nNewY\
- if nNewWidth and nNewHeight then\
- sEmpty = string.rep( \" \", nNewWidth )\
- local tNewLines = {}\
- local tEmpty = { { sEmpty, nTextColor, nBackgroundColor } }\
- for y=1,nNewHeight do\
- if y > nHeight then\
- tNewLines[y] = tEmpty\
- else\
- if nNewWidth == nWidth then\
- tNewLines[y] = tLines[y]\
- elseif nNewWidth < nWidth then\
- tNewLines[y] = lineSub( tLines[y], 1, nNewWidth )\
- else\
- tNewLines[y] = lineJoin( tLines[y], { { string.sub( sEmpty, nWidth + 1, nNewWidth ), nTextColor, nBackgroundColor } } )\
- end\
- end\
- end\
- nWidth = nNewWidth\
- nHeight = nNewHeight\
- tLines = tNewLines\
- end\
- if bVisible then\
- window.redraw()\
- end\
- end\
- \
- function window.getBuffer()\
- return tLines\
- end\
- \
- function window.setBuffer(tNewBuffer)\
- tLines = tNewBuffer\
- end\
- \
- if bVisible then\
- window.redraw()\
- end\
- return window\
- end",
- [ "Interact.lua" ] = "--[[\
- Interact API in ComputerCraft\
- by Creator\
- Complete rewrite in OOP\
- ]]--\
- \
- --Variables\
- local textutilsserialize = textutils.serialize\
- local textutilsunserialize = textutils.unserialize\
- local KeyCodes = {\
- [ 2 ] = 1 ,\
- [ 3 ] = 2,\
- [ 4 ] = 3,\
- [ 5 ] = 4,\
- [ 6 ] = 5,\
- [ 7 ] = 6,\
- [ 8 ] = 7,\
- [ 9 ] = 8,\
- [ 10 ] = 9,\
- [ 11 ] = 0,\
- [ 12 ] = \"-\",\
- [ 13 ] = \"=\",\
- [ 14 ] = \"Backspace\",\
- [ 15 ] = \"Tab\",\
- [ 16 ] = \"q\",\
- [ 17 ] = \"w\",\
- [ 18 ] = \"e\",\
- [ 19 ] = \"r\",\
- [ 20 ] = \"t\",\
- [ 21 ] = \"y\",\
- [ 22 ] = \"u\",\
- [ 23 ] = \"i\",\
- [ 24 ] = \"o\",\
- [ 25 ] = \"p\",\
- [ 26 ] = \"LeftBracket\",\
- [ 27 ] = \"RightBracket\",\
- [ 28 ] = \"Enter\",\
- [ 29 ] = \"LeftControl\",\
- [ 30 ] = \"a\",\
- [ 31 ] = \"s\",\
- [ 32 ] = \"d\",\
- [ 33 ] = \"f\",\
- [ 34 ] = \"g\",\
- [ 35 ] = \"h\",\
- [ 36 ] = \"j\",\
- [ 37 ] = \"k\",\
- [ 38 ] = \"l\",\
- [ 39 ] = \";\",\
- [ 40 ] = \"\\'\",\
- [ 41 ] = \"`\",\
- [ 42 ] = \"LeftShift\",\
- [ 43 ] = \"Backslash\",\
- [ 44 ] = \"z\",\
- [ 45 ] = \"x\",\
- [ 46 ] = \"c\",\
- [ 47 ] = \"v\",\
- [ 48 ] = \"b\",\
- [ 49 ] = \"n\",\
- [ 50 ] = \"m\",\
- [ 51 ] = \",\",\
- [ 52 ] = \".\",\
- [ 53 ] = \"/\",\
- [ 54 ] = \"RightShift\",\
- [ 55 ] = \"*\",\
- [ 56 ] = \"LeftAlt\",\
- [ 57 ] = \" \",\
- [ 58 ] = \"CapsLock\",\
- [ 59 ] = \"F1\",\
- [ 60 ] = \"F2\",\
- [ 61 ] = \"F3\",\
- [ 62 ] = \"F4\",\
- [ 63 ] = \"F5\",\
- [ 64 ] = \"F6\",\
- [ 65 ] = \"F7\",\
- [ 66 ] = \"F8\",\
- [ 67 ] = \"F9\",\
- [ 68 ] = \"F10\",\
- [ 69 ] = \"NumberLock\",\
- [ 70 ] = \"ScrollLock\",\
- [ 71 ] = \"NumPAd7\",\
- [ 72 ] = \"NumPAd8\",\
- [ 73 ] = \"NumPAd9\",\
- [ 74 ] = \"Substract\",\
- [ 75 ] = \"NumPAd4\",\
- [ 76 ] = \"NumPAd5\",\
- [ 77 ] = \"NumPAd6\",\
- [ 78 ] = \"Add\",\
- [ 79 ] = \"NumPAd1\",\
- [ 80 ] = \"NumPAd2\",\
- [ 81 ] = \"NumPAd3\",\
- [ 82 ] = \"NumPAd0\",\
- [ 83 ] = \"Decimal\",\
- [ 87 ] = \"F11\",\
- [ 88 ] = \"F12\",\
- [ 100] = \"F13\",\
- [ 101] = \"F14\",\
- [ 102] = \"F15\",\
- [ 103] = \"F16\",\
- [ 104] = \"F17\",\
- [ 105] = \"F18\",\
- [ 112] = \"Kana\",\
- [ 113] = \"F19\",\
- [ 121] = \"Convert\",\
- [ 123] = \"Noconvert\",\
- [ 125] = \"Yen\",\
- [ 141] = \"NumPadEquals\",\
- [ 144] = \"^\",\
- [ 145] = \"@\",\
- [ 146] = \":\",\
- [ 147] = \"_\",\
- [ 148] = \"Kanji\",\
- [ 149] = \"Stop\",\
- [ 150] = \"Ax\",\
- [ 151] = \"Unlabeled\",\
- [ 156] = \"NumPadEnter\",\
- [ 157] = \"RightControl\",\
- [ 157] = \"Section\",\
- [ 179] = \"NumPadComma\",\
- [ 181] = \"Dvide\",\
- [ 183] = \"Sysrq\",\
- [ 184] = \"RightAlt\",\
- [ 196] = \"Function\",\
- [ 197] = \"Pause\",\
- [ 199] = \"Home\",\
- [ 200] = \"Up\",\
- [ 201] = \"PageUp\",\
- [ 203] = \"Left\",\
- [ 205] = \"Right\",\
- [ 207] = \"End\",\
- [ 208] = \"Down\",\
- [ 209] = \"PageDown\",\
- [ 210] = \"Insert\",\
- [ 211] = \"Delete\",\
- }\
- \
- --Class declarations--\
- local Button = {}\
- local Layout = {}\
- local Toggle = {}\
- local BackgroundColor = {}\
- local ColorField = {}\
- local BetterPaint = {}\
- local Text = {}\
- local TextBox = {}\
- local Key = {}\
- \
- function loadObjects(self)\
- local output = {}\
- output.Button = {}\
- output.Toggle = {}\
- output.ColorField = {}\
- output.BetterPaint = {}\
- output.Text = {}\
- output.TextBox = {}\
- output.Key = {}\
- output.Layout = {}\
- for o,v in pairs(output) do\
- if self[o] == nil then\
- self[o] = {}\
- end\
- end\
- for i,v in pairs(self.Button) do\
- output.Button[i] = Button.new(self.Button[i])\
- end\
- for i,v in pairs(self.Toggle) do\
- output.Toggle[i] = Toggle.new(self.Toggle[i])\
- end\
- for i,v in pairs(self.ColorField) do\
- output.ColorField[i] = ColorField.new(self.ColorField[i])\
- end\
- for i,v in pairs(self.BetterPaint) do\
- output.BetterPaint[i] = BetterPaint.new(self.BetterPaint[i])\
- end\
- for i,v in pairs(self.Text) do\
- output.Text[i] = Text.new(self.Text[i])\
- end\
- for i,v in pairs(self.TextBox) do\
- output.TextBox[i] = TextBox.new(self.TextBox[i])\
- end\
- for i,v in pairs(self.Key) do\
- output.Key[i] = Key.new(self.Key[i])\
- end\
- for i,v in pairs(self.Layout) do\
- output.Layout[i] = Layout.new(self.Layout[i])\
- end\
- output.BackgroundColor = self.BackgroundColor or 1\
- output.nilClick = self.nilClick or false\
- return output\
- end\
- \
- function loadLayout(input,output)\
- for i,v in pairs(input.Button) do\
- output:addButton(input.Button[i])\
- end\
- for i,v in pairs(input.Toggle) do\
- output:addToggle(input.Toggle[i])\
- end\
- for i,v in pairs(input.ColorField) do\
- output:addColorField(input.ColorField[i])\
- end\
- for i,v in pairs(input.BetterPaint) do\
- output:addBetterPaint(input.BetterPaint[i])\
- end\
- for i,v in pairs(input.Text) do\
- output:addText(input.Text[i])\
- end\
- for i,v in pairs(input.TextBox) do\
- output:addTextBox(input.TextBox[i])\
- end\
- for i,v in pairs(input.Key) do\
- output:addKey(input.Key[i])\
- end\
- for i,v in pairs(input.Layout) do\
- output:addLayout(input.Layout[i])\
- end\
- output.BackgroundColor = input.BackgroundColor\
- output.nilClick = input.nilClick\
- end\
- \
- --Class Layout--\
- --Layout initialization function--\
- Layout.new = function(input)\
- local self = {}\
- setmetatable(self,{__index = Layout})\
- self.Button = {}\
- self.Toggle = {}\
- self.ColorField = {}\
- self.BetterPaint = {}\
- self.Text = {}\
- self.TextBox = {}\
- self.Key = {}\
- self.Window = {}\
- self.BackgroundColor = 1\
- self.xPos = input.xPos or 1\
- self.yPos = input.yPos or 1\
- self.xLength = input.xLength or 51\
- self.yLength = input.yLength or 19\
- self.nilClick = input.nilClick or false\
- self.windowBuffer = Screen.new(term.current(),self.xPos,self.yPos,self.xLength,self.yLength)\
- return self\
- end\
- \
- --Add element function--\
- Layout.addButton = function(self,_elementData)\
- self.Button[_elementData.name] = _elementData\
- end\
- \
- Layout.addToggle = function(self,_elementData)\
- self.Toggle[_elementData.name] = _elementData\
- end\
- \
- Layout.addBackgroundColor = function(self,_elementData)\
- self.BackgroundColor = _elementData.color\
- end\
- \
- Layout.addColorField = function(self,_elementData)\
- self.ColorField[_elementData.name] = _elementData\
- end\
- \
- Layout.addBetterPaint = function(self,_elementData)\
- self.BetterPaint[_elementData.name] = _elementData\
- end\
- \
- Layout.addText = function(self,_elementData)\
- self.Text[_elementData.name] = _elementData\
- end\
- \
- Layout.addTextBox = function(self,_elementData)\
- self.TextBox[_elementData.name] = _elementData\
- end\
- \
- Layout.addKey = function(self,_elementData)\
- self.Key[_elementData.name] = _elementData\
- end\
- \
- Layout.addLayout = function(self,_elementData)\
- loadLayout(self.Layout[_elementData.name],_elementData)\
- end\
- \
- Layout.draw = function(self,xPlus,yPlus)\
- xPlus = xPlus or 0\
- yPlus = yPlus or 0\
- local oldTerm= term.current()\
- term.redirect(self.windowBuffer)\
- local buttonFunctions = {}\
- local toggleFunctions = {}\
- local colorFieldFunctions = {}\
- local betterPaintFunctions = {}\
- local textFunctions = {}\
- local textBoxFunctions = {}\
- local layoutFunctions = {}\
- setmetatable(buttonFunctions,{__index = Button})\
- setmetatable(toggleFunctions,{__index = Toggle})\
- setmetatable(colorFieldFunctions,{__index = ColorField})\
- setmetatable(betterPaintFunctions,{__index = BetterPaint})\
- setmetatable(textFunctions,{__index = Text})\
- setmetatable(textBoxFunctions,{__index = TextBox})\
- setmetatable(layoutFunctions,{__index = Layout})\
- paintutils.drawFilledBox(1,1,self.xLength,self.yLength,self.BackgroundColor)\
- for i,v in pairs(self.ColorField) do\
- colorFieldFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.Button) do\
- buttonFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.BetterPaint) do\
- betterPaintFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.Toggle) do\
- toggleFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.Text) do\
- textFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.TextBox) do\
- textBoxFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- term.redirect(oldTerm)\
- end\
- \
- --Class Button--\
- --Button initialization function\
- Button.new = function(input)\
- local self = {}\
- setmetatable(self,{__index = Button})\
- self.name = input.name\
- self.label = input.label\
- self.xPos = input.xPos\
- self.yPos = input.yPos\
- self.fgColor = input.fgColor\
- self.bgColor = input.bgColor\
- self.xLength = input.xLength\
- self.yLength = input.yLength\
- self.returnValue = input.returnValue\
- self.xTextPos = input.xTextPos\
- self.yTextPos = input.yTextPos\
- self.onRightClick = input.onRightClick or nil\
- self.onLeftClick = input.onLeftClick or nil\
- return self\
- end\
- \
- --Draw function\
- Button.draw = function(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- \
- self.finalX = finalX\
- self.finalY = finalY\
- local newText\
- if #self.label > self.xLength then\
- newText = string.sub(self.label,1,self.xLength)\
- else\
- newText = self.label\
- end\
- paintutils.drawFilledBox(finalX,finalY,finalX+self.xLength-1,finalY+self.yLength-1,self.bgColor)\
- term.setTextColor(self.fgColor)\
- term.setCursorPos(finalX+self.xTextPos-1,finalY+self.yTextPos-1)\
- term.write(newText)\
- end\
- \
- --Return function--\
- Button.returnData = function(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- --Sample Input table--\
- example = [[\
- example = {\
- name = \"quickSettings\",\
- label = \">\",\
- xPos = 1,\
- yPos = 3,\
- xLength = 1,\
- yLength = 6,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = colors.blue,\
- bgColor = colors.lightGray,\
- returnValue = \"quickSettings\",\
- },\
- ]]\
- \
- --Class Toggle--\
- --Initialize Toggle Object--\
- Toggle.new = function(input)\
- local self = {}\
- setmetatable(self,{__index = Toggle})\
- self.name = input.name or \"randomName\"\
- self.state = input.state or true\
- self.xPos = input.xPos or 1\
- self.yPos = input.yPos or 1\
- self.trueColor = input.trueColor or colors.green\
- self.falseColor = input.falseColor or colors.red\
- self.trueText = input.trueText or \"T\"\
- self.falseText = input.falseText or \"F\"\
- self.selectedBg = input.selectedBg or colors.gray\
- self.notSelectedBg = input.notSelectedBg or colors.lightGray\
- self.returnValue = input.returnValue or \"mmmmmmm\"\
- self.moveX = input.moveX or false\
- self.moveY = input.moveY or false\
- self.onRightClick = input.onRightClick or nil\
- self.onLeftClick = input.onLeftClick or nil\
- return self\
- end\
- \
- function Toggle.draw(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- self.finalX = finalX\
- self.finalY = finalY\
- term.setCursorPos(finalX,finalY)\
- if self.state == false then\
- term.setBackgroundColor(self.notSelectedBg)\
- term.setTextColor(self.trueColor)\
- term.write(string.sub(self.trueText,1,1))\
- term.setBackgroundColor(self.selectedBg)\
- term.setTextColor(self.falseColor)\
- term.write(\" \"..string.sub(self.falseText,1,1)..\" \")\
- elseif self.state == true then\
- term.setBackgroundColor(self.selectedBg)\
- term.setTextColor(self.trueColor)\
- term.write(\" \"..string.sub(self.trueText,1,1)..\" \")\
- term.setBackgroundColor(self.notSelectedBg)\
- term.setTextColor(self.falseColor)\
- term.write(string.sub(self.falseText,1,1))\
- end\
- end\
- \
- function Toggle.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- function Toggle.toggle(self)\
- if self.state == true then\
- self.state = false\
- else\
- self.state = true\
- end\
- end\
- \
- function Toggle.getState(self)\
- return self.state\
- end\
- \
- --BackgroundColor Class--\
- function BackgroundColor.new(input)\
- local self = {}\
- setmetatable(self,{__index = BackgroundColor})\
- self.color = input.color\
- return self\
- end\
- \
- function BackgroundColor.setColor(self,color)\
- self.color = color\
- end\
- \
- function BackgroundColor.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- --ColorField Class--\
- function ColorField.new(input)\
- local self = {}\
- setmetatable(self,{__index = ColorField})\
- self.name = input.name\
- self.xPos = input.xPos\
- self.yPos = input.yPos\
- self.xLength = input.xLength\
- self.yLength = input.yLength\
- self.color = input.color\
- self.moveX = input.moveX or false\
- self.moveY = input.moveY or false\
- return self\
- end\
- \
- function ColorField.draw(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- self.finalX = finalX\
- self.finalY = finalY\
- term.setTextColor(colors.black)\
- paintutils.drawFilledBox(finalX,finalY,finalX+self.xLength-1,finalY+self.yLength-1,self.color)\
- end\
- \
- function ColorField.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- --BetterPaint Class--\
- function BetterPaint.new(input)\
- local self = {}\
- setmetatable(self,{__index = BetterPaint})\
- self.xPos = input.xPos\
- self.yPos = input.yPos\
- self.name = input.name\
- self.path = input.path\
- self.xLength = input.xLength\
- self.yLength = input.yLength\
- self.returnValue = input.returnValue\
- self.label = input.label\
- self.labelBg = input.labelBg\
- self.labelFg = input.labelFg\
- self.moveX = input.moveX or false\
- self.moveY = input.moveY or false\
- self.onRightClick = input.onRightClick or nil\
- self.onLeftClick = input.onLeftClick or nil\
- return self\
- end\
- \
- function BetterPaint.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- function BetterPaint.draw(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- self.finalX = finalX\
- self.finalY = finalY\
- paint.drawImage(self.path,finalX,finalY)\
- term.setCursorPos(finalX,finalY+self.yLength)\
- term.setTextColor(self.labelFg)\
- term.setBackgroundColor(self.labelBg)\
- term.write(self.label)\
- end\
- \
- --Text Class--\
- function Text.new(input)\
- local self = {}\
- setmetatable(self,{__index = Text})\
- self.name = input.name\
- self.text = input.text\
- self.xPos = input.xPos\
- self.yPos = input.yPos\
- self.bgColor = input.bgColor\
- self.fgColor = input.fgColor\
- return self\
- end\
- \
- function Text.draw(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- self.finalX = finalX\
- self.finalY = finalY\
- term.setCursorPos(finalX,finalY)\
- term.setTextColor(self.fgColor)\
- term.setBackgroundColor(self.bgColor)\
- term.write(self.text)\
- end\
- \
- function Text.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- --TextBox Class \
- \
- function TextBox.new(input)\
- local self = {}\
- setmetatable(self,{__index = TextBox})\
- self.name = input.name\
- self.helpText = input.helpText\
- self.xPos = input.xPos\
- self.yPos = input.yPos\
- self.xLength = input.xLength\
- self.yLength = input.yLength\
- self.bgColor = input.bgColor\
- self.fgColor = input.fgColor\
- self.helpFgColor = input.helpFgColor\
- self.charLimit = input.charLimit\
- self.moveX = input.moveX or false\
- self.moveY = input.moveY or false\
- self.text = \"\"\
- self.returnValue = input.returnValue\
- self.confidential = input.confidential or false\
- return self\
- end\
- \
- function TextBox.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- function TextBox.draw(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- self.finalX = finalX\
- self.finalY = finalY\
- paintutils.drawFilledBox(finalX,finalY,finalX+self.xLength-1,finalY+self.yLength-1,self.bgColor)\
- term.setBackgroundColor(self.bgColor)\
- term.setCursorPos(self.finalX,self.finalY)\
- if self.text == \"\" or self.confidential then\
- term.setTextColor(self.helpFgColor)\
- term.write(self.helpText)\
- else\
- term.setTextColor(self.fgColor)\
- term.write(self.text)\
- end\
- end\
- \
- function TextBox.read(self,_sReplaceChar, _tHistory)\
- paintutils.drawFilledBox(self.finalX,self.finalY,self.finalX+self.xLength-1,self.finalY+self.yLength-1,self.bgColor)\
- term.setTextColor(self.fgColor)\
- term.setCursorPos(self.finalX,self.finalY)\
- return read()\
- end\
- \
- --Key Class\
- function Key.new(input)\
- local self = {}\
- setmetatable(self,{__index = TextBox})\
- self.name = input.name\
- self.key = input.key\
- self.onPress = input.onPress or nil\
- return self\
- end\
- \
- function Key.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- local function localEventHandler(self,event, p1, p2, p3, p4, p5, p6)\
- local toAddX = self.xPos - 1\
- local toAddY = self.yPos - 1\
- while true do\
- if event == \"mouse_click\" then\
- for i,v in pairs(self.Button) do\
- if v.finalX + toAddX <= p2 and p2 <= v.finalX + v.xLength-1 + toAddX and v.finalY + toAddY <= p3 and p3 <= v.finalY + v.yLength-1 + toAddY then\
- if p1 == 1 then\
- if v.onLeftClick then \
- v.onLeftClick()\
- end\
- elseif p1 == 2 then\
- if v.onRightClick then\
- v.onRightClick()\
- end\
- end\
- return {\"Button\",tostring(v.returnValue),p1,p2,p3}\
- end\
- end\
- for i,v in pairs(self.Toggle) do\
- if v.finalX + toAddX <= p2 and p2 <= v.finalX + 3 + toAddX and v.finalY + toAddY == p3 then\
- return {\"Toggle\",tostring(v.returnValue),p1,p2,p3}\
- end\
- end\
- for i,v in pairs(self.BetterPaint) do \
- if v.finalX + toAddX <= p2 and p2 <= v.finalX + v.xLength-1 + toAddX and v.finalY + toAddY <= p3 and p3 <= v.finalY + v.yLength-1 + toAddY then\
- return {\"Button\",tostring(v.returnValue),p1,p2,p3}\
- end\
- end\
- for i,v in pairs(self.TextBox) do \
- if v.finalX + toAddX <= p2 and p2 <= v.finalX + v.xLength-1 + toAddX and v.finalY + toAddY <= p3 and p3 <= v.finalY + v.yLength-1 + toAddY then\
- return {\"TextBox\",tostring(v.returnValue),p1,p2,p3}\
- end\
- end\
- if self.nilClick then\
- if not (self.xPos <= p2 and p2 <= self.xPos+self.xLength-1 and self.yPos <= p3 and p3 <= self.yPos+self.yLength-1) then\
- return {\"Nil\",\"Nil\",p1,p2,p3}\
- end\
- end\
- elseif event == \"key\" then\
- local pressedKey = p1\
- for i,v in pairs(self.Key) do\
- if v.key == KeyCodes[pressedKey] then\
- if v.onPress then\
- v.onPress()\
- else\
- return {\"Key\",KeyCodes[pressedKey],pressedKey}\
- end\
- end\
- \
- end\
- elseif event == \"monitor_touch\" then\
- os.queueEvent(\"mouse_click\", p1, p2, p3, p4, p5, p6)\
- end\
- end\
- end\
- \
- --Event handler function--\
- eventHandler = function(self)\
- local tEvent = {os.pullEvent()}\
- return localEventHandler(self,unpack(tEvent))\
- end\
- \
- --Load Function--\
- function Initialize()\
- local toReturn = {}\
- toReturn.Button = Button\
- toReturn.Layout = Layout\
- toReturn.Toggle = Toggle\
- toReturn.BackgroundColor = BackgroundColor\
- toReturn.ColorField = ColorField\
- toReturn.BetterPaint = BetterPaint\
- toReturn.Text = Text\
- toReturn.TextBox = TextBox\
- toReturn.Key = Key\
- toReturn.eventHandler = eventHandler\
- toReturn.loadObjects = loadObjects\
- toReturn.loadLayout = loadLayout\
- return toReturn\
- end",
- [ "paint.lua" ] = "transparentIcon = \"-\"\
- args = {...}\
- tX, tY = term.getSize()\
- \
- function import(source,dest)\
- init()\
- if fs.exists(source) == false then\
- print(\"File \"..source..\" doesnt exists!\")\
- error()\
- elseif not dest then\
- print(\"Provide an output file.\")\
- error()\
- elseif fs.exists(dest) == true then\
- print(\"File \"..dest..\" already exists!\")\
- error()\
- end\
- --if mode == \"import\" then\
- h = fs.open(source,\"r\")\
- lines = {}\
- count = 0\
- repeat\
- count = count + 1\
- lines[count] = h.readLine(count) \
- until lines[count] == nil\
- h.close()\
- data = {}\
- if not painted then\
- painted = {}\
- end\
- for i=1,#lines do\
- data[i] = {}\
- string.gsub(lines[i],\".\",function(char) table.insert(data[i],char) end)\
- end\
- x=0\
- y=0\
- for i=1,#data do\
- y = y + 1\
- x = 0\
- for a=1,#data[i] do\
- x = x + 1\
- if not painted[x] then\
- painted[x] = {}\
- end\
- if not painted[x][y] then\
- painted[x][y] = {}\
- end\
- rawColor = data[i][x]\
- if rawColor == \"0\" then\
- colorLoaded = colors.white\
- elseif rawColor == \"1\" then\
- colorLoaded = colors.orange\
- elseif rawColor == \"2\" then\
- colorLoaded = colors.magenta\
- elseif rawColor == \"3\" then\
- colorLoaded = colors.lightBlue\
- elseif rawColor == \"4\" then\
- colorLoaded = colors.yellow\
- elseif rawColor == \"5\" then\
- colorLoaded = colors.lime\
- elseif rawColor == \"6\" then\
- colorLoaded = colors.pink\
- elseif rawColor == \"7\" then\
- colorLoaded = colors.gray\
- elseif rawColor == \"8\" then\
- colorLoaded = colors.lightGray\
- elseif rawColor == \"9\" then\
- colorLoaded = colors.cyan\
- elseif rawColor == \"a\" then\
- colorLoaded = colors.purple\
- elseif rawColor == \"b\" then\
- colorLoaded = colors.blue\
- elseif rawColor == \"c\" then\
- colorLaoded = colors.brown\
- elseif rawColor == \"d\" then\
- colorLoaded = colors.green\
- elseif rawColor == \"e\" then\
- colorLoaded = colors.red\
- elseif rawColor == \"f\" then\
- colorLoaded = colors.black\
- elseif rawColor == \" \" then\
- -- Do nothing, allow it\
- else\
- error(\"File: \\\"\"..source..\"\\\" has an incorrect format!\")\
- end\
- if rawColor ~= \" \" then\
- painted[x][y] = {colorLoaded,\" \",colorLoaded} \
- else\
- painted[x][y] = nil\
- end\
- end\
- end\
- --end\
- args[1] = dest\
- save()\
- end\
- \
- \
- function drawImage(file,xSet,ySet,redirection)\
- init()\
- lastImage = file\
- lastX = xSet\
- lastY = ySet\
- lastRedirection = redirection\
- if redirection then\
- current = term.current()\
- term.redirect(redirection)\
- end\
- drawData(xSet,ySet,file)\
- if redirection then\
- term.redirect(current)\
- end\
- end\
- \
- function overWrite(textSet,xSet,ySet,colorSet)\
- init()\
- exists = true\
- if not lastImage then\
- error(\"Use drawImage first!\")\
- end\
- if not writeBuffer then\
- writeBuffer = {}\
- end\
- if not writeBuffer[lastImage] then\
- writeBuffer[lastImage] = {}\
- end\
- plusPos = 0\
- for char in string.gmatch(textSet,\".\") do\
- if not writeBuffer[lastImage][xSet+plusPos] then\
- writeBuffer[lastImage][xSet+plusPos] = {}\
- end\
- if not writeBuffer[lastImage][xSet+plusPos][ySet] then\
- writeBuffer[lastImage][xSet+plusPos][ySet] = {colors.black,\" \",colors.white}\
- end\
- writeBuffer[lastImage][xSet+plusPos][ySet][2] = char\
- writeBuffer[lastImage][xSet+plusPos][ySet][3] = colorSet\
- plusPos = plusPos + 1 \
- end\
- drawImage(lastImage,lastX,lastY,lastRedirection)\
- end\
- \
- function init()\
- function eventHandler()\
- while true do\
- event = {os.pullEvent()}\
- if event[1] == \"key\" then\
- if event[2] == keys.leftCtrl or event[2] == 157 then\
- menuStatus = not menuStatus\
- writeMenuBar(menuStatus)\
- end\
- if menuStatus == true then\
- if event[2] == keys.right or event[2] == keys.left then\
- if menuItemSelected == 1 then\
- menuItemSelected = 2\
- else\
- menuItemSelected = 1\
- end\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.enter then\
- if menuItemSelected == 1 then\
- save()\
- writeMenuBar(false)\
- else\
- term.setTextColor(colors.yellow)\
- term.setBackgroundColor(colors.black)\
- term.clear()\
- term.setCursorPos(1,1)\
- error()\
- end\
- end\
- else \
- if event[2] == keys.right then\
- drawData(offSetX-1,offSetY)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.left then\
- drawData(offSetX+1,offSetY)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.up then\
- drawData(offSetX,offSetY+1)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.down then\
- drawData(offSetX,offSetY-1)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- end\
- end\
- end\
- if event[1] == \"mouse_click\" or event[1] == \"mouse_drag\" then\
- if event[3] > 2 and event[4] ~= tY then\
- insertItem(event[3],event[4],event[2])\
- elseif event[4] < 18 and event[4] > 1 then\
- if event[3] == 1 then\
- bgSelected = 2^(event[4]-2)\
- elseif event[3] == 2 then\
- tSelected = 2^(event[4]-2)\
- end\
- drawMenu()\
- elseif event[4] == tY - 1 and event[3] == 1 then\
- setLetter()\
- drawData(offSetX,offSetY)\
- drawMenu()\
- elseif event[3] == tX and event[4] == tY and menuStatus == false then\
- writeHelp()\
- end\
- end\
- if event[1] == \"char\" then\
- textSelected = string.sub(event[2],1,1)\
- drawMenu()\
- end\
- --drawData(offSetX,offSetY)\
- end\
- end\
- \
- function writeHelp()\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.green)\
- term.clear()\
- term.setCursorPos(1,1)\
- term.write(\"Help:\")\
- term.setTextColor(colors.white)\
- term.setCursorPos(1,3)\
- print(\"Usage:\")\
- term.setTextColor(colors.lightGray)\
- print(\" Select color: Click on the color on the left\")\
- print(\" Change draw char: Press a key on the keyboard\")\
- print(\" Change transparent icon: Click on the icon's char in the menu\")\
- print(\" Change text color: Click on a color in the menu on the right side\")\
- print(\" Change background color: Click on a color in the menu on the left side\")\
- term.setTextColor(colors.white)\
- print()\
- print(\"Controls:\")\
- term.setTextColor(colors.lightGray)\
- print(\" Arrow keys to pan\")\
- print(\" Left mouse button to select and draw\")\
- print(\" Right mouse button to delete\")\
- print(\" Ctrl to open menu\")\
- print()\
- term.setTextColor(colors.white)\
- term.write(\"Click a mouse button to exit.\")\
- term.setTextColor(colors.orange)\
- term.setCursorPos(tX-9,1)\
- term.write(\"API help >\")\
- event = {os.pullEvent(\"mouse_click\")}\
- if event[3] > tX-10 and event[4] == 1 then\
- drawAPIhelp()\
- end\
- drawData(offSetX,offSetY)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- end\
- \
- function drawAPIhelp()\
- term.clear()\
- term.setCursorPos(1,1)\
- term.setTextColor(colors.orange)\
- print(\"API help menu:\")\
- term.setTextColor(colors.white)\
- print(\"Drawing an image: \")\
- term.setTextColor(colors.lightGray)\
- print(shell.getRunningProgram(),\".drawImage(<file name>,<x pos>,<y pos>,[redirection object])\")\
- print()\
- term.setTextColor(colors.white)\
- print(\"Overlaying text on the last image:\")\
- term.setTextColor(colors.lightGray)\
- print(shell.getRunningProgram(),\".overWrite(<Text>,<x pos>,<y pos>,<text color>)\")\
- print()\
- term.setTextColor(colors.white)\
- print(\"Convert a paintutils file to betterpaint file:\")\
- term.setTextColor(colors.lightGray)\
- print(shell.getRunningProgram(),\".import(<source>,<destination>)\")\
- term.setTextColor(colors.red)\
- print()\
- print(\"Overwriting text will only work AFTER drawing an image!\")\
- term.setTextColor(colors.white)\
- print()\
- print(\"Example:\")\
- term.setTextColor(colors.lightGray)\
- print(\"os.loadAPI(\\\"\",shell.getRunningProgram(),\"\\\")\")\
- print(shell.getRunningProgram(),\".drawImage(\\\"myPicture\\\",1,1)\")\
- term.write((shell.getRunningProgram()..\".overWrite(\\\"Hello!\\\",2,3,colors.orange)\"))\
- os.pullEvent(\"mouse_click\")\
- end\
- \
- function setLetter()\
- term.setBackgroundColor(colors.red)\
- term.setTextColor(colors.black)\
- for i=1,4 do\
- term.setCursorPos(tX/2-11,(tY/2-4)+i)\
- term.write(\" \")\
- end\
- term.setCursorPos(tX/2-10,tY/2-2)\
- term.write(\"Change transparancy\")\
- term.setCursorPos(tX/2-10,tY/2-1)\
- term.write(\"character to: (key)\")\
- event = {os.pullEvent(\"char\")}\
- transparentIcon = event[2]\
- end\
- \
- function insertItem(xPos,yPos,modeSet)\
- if saved == true then\
- saved = false\
- writeMenuBar(false)\
- end\
- --bgSelected\
- --tSelected\
- --textSelected\
- if not painted then\
- painted = {}\
- end\
- if not painted[xPos-offSetX] then\
- painted[xPos-offSetX] = {}\
- end\
- if modeSet == 1 then\
- if not textSelected then\
- textSelected = \" \"\
- end\
- TMPtextSelected = textSelected\
- painted[xPos-offSetX][yPos-offSetY] = {bgSelected,textSelected,tSelected}\
- term.setBackgroundColor(bgSelected)\
- term.setTextColor(tSelected)\
- else\
- TMPtextSelected = transparentIcon\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.gray)\
- painted[xPos-offSetX][yPos-offSetY] = nil\
- end\
- term.setCursorPos(xPos,yPos)\
- term.write(TMPtextSelected)\
- end\
- \
- --if #args ~= 1 then\
- -- print(\"Usage: \"..shell.getRunningProgram()..\" <path>\")\
- -- return\
- --end\
- \
- if args[1] and fs.exists(args[1]) == true then\
- buff = fs.open(args[1],\"r\")\
- previousData = buff.readAll()\
- buff.close()\
- processed = string.sub(previousData,43)\
- painted = textutils.unserialize(processed)\
- else\
- painted = {}\
- end\
- \
- function save()\
- file = fs.open(args[1],\"w\")\
- file.write(\"error('This is an image, not a program!')\\n\"..textutils.serialize(painted))\
- file.close()\
- saved = true\
- end\
- \
- function drawData(xStart, yStart, file)\
- offSetX = xStart\
- offSetY = yStart\
- if not file then\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.gray)\
- transparentLine = \"\"\
- for x=1,tX-2 do\
- transparentLine = transparentIcon..transparentLine\
- end\
- for y=1,tY-1 do\
- term.setCursorPos(3,y)\
- term.write(transparentLine)\
- end\
- else\
- if fs.exists(file) == false then\
- error(\"File given doesnt exists! file name: \"..file)\
- else\
- local fileD = fs.open(file,\"r\")\
- raw = fileD.readAll()\
- --ignoreL = string.len(fileD.readLine(1))\
- processed = string.sub(raw,43)\
- --term.redirect(term.native())\
- -- textutils.pagedPrint(processed)\
- painted = textutils.unserialize(processed)\
- fileD.close()\
- end\
- end\
- if not painted then\
- painted = {}\
- end\
- paintedF = painted\
- count = 0\
- repeat ---------\
- count = count + 1\
- for xPos,v in pairs(paintedF) do\
- for yPos in pairs (paintedF[xPos]) do\
- overWrite = true\
- if not lastImage or not writeBuffer or not writeBuffer[lastImage] then\
- overWrite = false\
- end\
- if overWrite == true then\
- if not writeBuffer[lastImage][xPos] then\
- overWrite = false\
- end\
- end\
- if overWrite == true then\
- if not writeBuffer[lastImage][xPos][yPos] then\
- overWrite = false\
- end\
- end\
- if overWrite == false then\
- bgColor = paintedF[xPos][yPos][1]\
- text = paintedF[xPos][yPos][2]\
- tColor = paintedF[xPos][yPos][3]\
- else\
- if painted and painted[xPos] and painted[xPos][yPos] and painted[xPos][yPos][1] then\
- bgColor = painted[xPos][yPos][1]\
- else\
- bgColor = colors.black\
- end\
- --if not bgColor then\
- -- bgColor = colors.black\
- --end\
- text = writeBuffer[lastImage][xPos][yPos][2]\
- tColor = writeBuffer[lastImage][xPos][yPos][3]\
- end\
- if not tColor then\
- tColor = colors.white\
- end\
- if not text then\
- text = \" \"\
- end\
- term.setCursorPos(xPos+xStart,yPos+yStart)\
- term.setBackgroundColor(bgColor)\
- term.setTextColor(tColor)\
- term.write(text)\
- end\
- end\
- if count == 1 and writeBuffer and lastImage then\
- paintedF = writeBuffer[lastImage]\
- elseif count == 1 and not lastImage or not writeBuffer then\
- count = 2\
- end\
- until count == 2\
- term.setCursorPos(1,tY)\
- end\
- \
- function drawMenu()\
- term.setCursorPos(1,1)\
- term.setTextColor(colors.white)\
- if not bgSelected then\
- bgSelected = colors.black\
- elseif bgSelected == colors.white then\
- term.setTextColor(colors.black)\
- end\
- if not tSelected then\
- tSelected = colors.white\
- elseif tSelected == colors.white then\
- term.setTextColor(colors.black)\
- end\
- if not textSelected then\
- textSelected = \" \"\
- end\
- term.setBackgroundColor(bgSelected)\
- term.write(\"B\")\
- term.setBackgroundColor(tSelected)\
- term.write(\"T\")\
- for i=1,16 do\
- i=i-1\
- term.setCursorPos(1,i+2)\
- term.setBackgroundColor(2^i)\
- term.write(\" \")\
- end\
- term.setCursorPos(1,18)\
- term.setBackgroundColor(colors.black)\
- if not textSelected then\
- textSelected = \" \"\
- elseif string.len(textSelected) > 1 then\
- textSelected = string.sub(textSelected,1,1)\
- end\
- term.setTextColor(colors.gray)\
- term.setBackgroundColor(colors.black)\
- term.write(transparentIcon)\
- term.setTextColor(tSelected)\
- term.setBackgroundColor(bgSelected)\
- term.write(textSelected)\
- end\
- \
- function writeMenuBar(booly)\
- menuStatus = booly\
- term.setBackgroundColor(colors.black)\
- if booly == true then\
- term.setCursorPos(1,tY)\
- term.clearLine()\
- if not menuItemSelected then\
- menuItemSelected = 1\
- end\
- term.setTextColor(colors.white)\
- term.write(\" Save Exit \")\
- term.setCursorPos(6*menuItemSelected-5,tY)\
- term.setTextColor(colors.yellow)\
- term.write(\"[\")\
- term.setCursorPos(6*menuItemSelected,tY)\
- term.write(\"]\")\
- elseif booly == false then\
- term.setCursorPos(1,tY)\
- term.setTextColor(colors.yellow)\
- term.clearLine()\
- if saved == true then\
- term.write(\"Saved to \"..args[1])\
- else\
- term.write(\"Press Ctrl to access menu\")\
- end\
- term.setCursorPos(tX,tY)\
- term.setTextColor(colors.lightGray)\
- term.write(\"?\")\
- end\
- end\
- end\
- \
- if args[1] == \"import\" then -- or args[1] == \"export\" then\
- init()\
- mode = args[1]\
- source = args[2]\
- destination = args[3]\
- if not args[2] then\
- print(\"Usage: \"..shell.getRunningProgram()..\" \"..mode..\" <source> <destination>\")\
- error()\
- end\
- import(source,destination)\
- if mode == \"import\" then\
- print(\"File imported.\")\
- error()\
- end\
- elseif #args > 0 then\
- init()\
- menuStatus = false\
- saved = false\
- writeMenuBar(menuStatus)\
- menuItemSelected = 1\
- drawData(3,0)\
- drawMenu()\
- eventHandler()\
- end",
- [ "Sha.lua" ] = "local MOD = 2^32\
- local MODM = MOD-1\
- \
- local function memoize(f)\
- local mt = {}\
- local t = setmetatable({}, mt)\
- function mt:__index(k)\
- local v = f(k)\
- t[k] = v\
- return v\
- end\
- return t\
- end\
- \
- local function make_bitop_uncached(t, m)\
- local function bitop(a, b)\
- local res,p = 0,1\
- while a ~= 0 and b ~= 0 do\
- local am, bm = a % m, b % m\
- res = res + t[am][bm] * p\
- a = (a - am) / m\
- b = (b - bm) / m\
- p = p*m\
- end\
- res = res + (a + b) * p\
- return res\
- end\
- return bitop\
- end\
- \
- local function make_bitop(t)\
- local op1 = make_bitop_uncached(t,2^1)\
- local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)\
- return make_bitop_uncached(op2, 2 ^ (t.n or 1))\
- end\
- \
- local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})\
- \
- local function bxor(a, b, c, ...)\
- local z = nil\
- if b then\
- a = a % MOD\
- b = b % MOD\
- z = bxor1(a, b)\
- if c then z = bxor(z, c, ...) end\
- return z\
- elseif a then return a % MOD\
- else return 0 end\
- end\
- \
- local function band(a, b, c, ...)\
- local z\
- if b then\
- a = a % MOD\
- b = b % MOD\
- z = ((a + b) - bxor1(a,b)) / 2\
- if c then z = bit32_band(z, c, ...) end\
- return z\
- elseif a then return a % MOD\
- else return MODM end\
- end\
- \
- local function bnot(x) return (-1 - x) % MOD end\
- \
- local function rshift1(a, disp)\
- if disp < 0 then return lshift(a,-disp) end\
- return math.floor(a % 2 ^ 32 / 2 ^ disp)\
- end\
- \
- local function rshift(x, disp)\
- if disp > 31 or disp < -31 then return 0 end\
- return rshift1(x % MOD, disp)\
- end\
- \
- local function lshift(a, disp)\
- if disp < 0 then return rshift(a,-disp) end\
- return (a * 2 ^ disp) % 2 ^ 32\
- end\
- \
- local function rrotate(x, disp)\
- x = x % MOD\
- disp = disp % 32\
- local low = band(x, 2 ^ disp - 1)\
- return rshift(x, disp) + lshift(low, 32 - disp)\
- end\
- \
- local k = {\
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,\
- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,\
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,\
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,\
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,\
- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,\
- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\
- }\
- \
- local function str2hexa(s)\
- return (string.gsub(s, \".\", function(c) return string.format(\"%02x\", string.byte(c)) end))\
- end\
- \
- local function num2s(l, n)\
- local s = \"\"\
- for i = 1, n do\
- local rem = l % 256\
- s = string.char(rem) .. s\
- l = (l - rem) / 256\
- end\
- return s\
- end\
- \
- local function s232num(s, i)\
- local n = 0\
- for i = i, i + 3 do n = n*256 + string.byte(s, i) end\
- return n\
- end\
- \
- local function preproc(msg, len)\
- local extra = 64 - ((len + 9) % 64)\
- len = num2s(8 * len, 8)\
- msg = msg .. \"\\128\" .. string.rep(\"\\0\", extra) .. len\
- assert(#msg % 64 == 0)\
- return msg\
- end\
- \
- local function initH256(H)\
- H[1] = 0x6a09e667\
- H[2] = 0xbb67ae85\
- H[3] = 0x3c6ef372\
- H[4] = 0xa54ff53a\
- H[5] = 0x510e527f\
- H[6] = 0x9b05688c\
- H[7] = 0x1f83d9ab\
- H[8] = 0x5be0cd19\
- return H\
- end\
- \
- local function digestblock(msg, i, H)\
- local w = {}\
- for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end\
- for j = 17, 64 do\
- local v = w[j - 15]\
- local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))\
- v = w[j - 2]\
- w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))\
- end\
- \
- local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]\
- for i = 1, 64 do\
- local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))\
- local maj = bxor(band(a, b), band(a, c), band(b, c))\
- local t2 = s0 + maj\
- local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))\
- local ch = bxor (band(e, f), band(bnot(e), g))\
- local t1 = h + s1 + ch + k[i] + w[i]\
- h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2\
- end\
- \
- H[1] = band(H[1] + a)\
- H[2] = band(H[2] + b)\
- H[3] = band(H[3] + c)\
- H[4] = band(H[4] + d)\
- H[5] = band(H[5] + e)\
- H[6] = band(H[6] + f)\
- H[7] = band(H[7] + g)\
- H[8] = band(H[8] + h)\
- end\
- \
- function sha256(msg)\
- msg = preproc(msg, #msg)\
- local H = initH256({})\
- for i = 1, #msg, 64 do digestblock(msg, i, H) end\
- return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..\
- num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))\
- end",
- [ "OmniOS.lua" ] = "version = \"alpha\"\
- tag = \"15w16a\"\
- loadAPI = function(_sPath)\
- local sName = fs.getName( _sPath )\
- local tEnv = {}\
- setmetatable( tEnv, { __index = _G } )\
- local fnAPI, err = loadfile( _sPath )\
- if fnAPI then\
- setfenv( fnAPI, tEnv )\
- local ok, err = pcall( fnAPI )\
- if not ok then\
- printError( err )\
- return false\
- end\
- else\
- printError( err )\
- return false\
- end\
- \
- local tAPI = {}\
- for k,v in pairs( tEnv ) do\
- tAPI[k] = v\
- end\
- \
- _G[sName:match(\"[^%.]+\")] = tAPI \
- return true\
- end\
- \
- requireAPI = function(_sPath)\
- local sName = fs.getName( _sPath )\
- local tEnv = {}\
- setmetatable( tEnv, { __index = _G } )\
- local fnAPI, err = loadfile( _sPath )\
- if fnAPI then\
- setfenv( fnAPI, tEnv )\
- local ok, err = pcall( fnAPI )\
- if not ok then\
- printError( err )\
- return false\
- end\
- else\
- printError( err )\
- return false\
- end\
- \
- local tAPI = {}\
- for k,v in pairs( tEnv ) do\
- tAPI[k] = v\
- end\
- return tAPI \
- end",
- [ "Sandbox.lua" ] = "--[[\
- Sandbox \
- environment\
- by Creator\
- for TheOS\
- ]]--\
- \
- --Variables--\
- local oldGetfenv = getfenv\
- local oldLoadfile = loadfile\
- local globalName = \"\"\
- \
- --Functions--\
- \
- function newEnv(name)\
- globalName = name\
- log.log(\"Sandbox\",globalName)\
- return {\
- redstone = redstone,\
- gps = gps,\
- _VERSION = _VERSION,\
- keys = keys,\
- printError = printError,\
- peripheral = peripheral,\
- assert = assert,\
- getfenv = function(a)\
- if type(a) == \"number\" then\
- oldGetfenv(1)\
- elseif type(a) == \"function\" then\
- oldGetfenv(a)\
- else\
- error(\"Expected function or number, got \"..type(a))\
- end end,\
- bit = bit,\
- rawset = rawset,\
- tonumber = tonumber,\
- loadstring = function(str) local func = loadstring(str) setfenv(func,getfenv(1))end,\
- error = error,\
- tostring = tostring,\
- type = type,\
- coroutine = { \
- create = coroutine.create,\
- resume = coroutine.resume,\
- running = coroutine.running,\
- status = coroutine.status,\
- wrap = coroutine.wrap,\
- },\
- disk = disk,\
- window = window,\
- next = next,\
- unpack = unpack,\
- colours = colours,\
- pcall = pcall,\
- sleep = sleep,\
- loadfile = function(a) \
- local func = oldLoadfile(a)\
- setfenv(func,getfenv(1))\
- end,\
- math = math,\
- pairs = pairs,\
- fs = {\
- combine = fs.combine,\
- isReadOnly = function(path) log.log(\"SandboxPath\",\"OmniOS/Programs/\"..globalName..\".app/\"..path) return fs.isReadOnly(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- getSize = function(path) return fs.getSize(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- move = function(path1,path2) return fs.move(\"OmniOS/Programs/\"..globalName..\".app/\"..path1,\"OmniOS/Programs/\"..globalName..\".app/\"..path2) end,\
- exists = function(path) return fs.exists(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- copy = function(path1,path2) return fs.copy(\"OmniOS/Programs/\"..globalName..\".app/\"..path1,\"OmniOS/Programs/\"..globalName..\".app/\"..path2) end,\
- getFreeSpace = function(path) return fs.getFreeSpace(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- makeDir = function(path) return fs.makeDir(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- find = function(path) return fs.find(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- getDir = fs.getDir,\
- delete = function(path) return fs.delete(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- open = function(path,...) return fs.open(\"OmniOS/Programs/\"..globalName..\".app/\"..path,...) end,\
- list = function(path) log.log(\"SandboxPath\",\"OmniOS/Programs/\"..globalName..\".app/\"..path) return fs.list(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- getDrive = function(path) return fs.getDrive(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- getName = fs.getName,\
- isDir = function(path) return fs.isDir(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- },\
- rawget = rawget,\
- _G = envToReturn,\
- __inext = __inext,\
- read = read,\
- rednet = rednet,\
- ipairs = ipairs,\
- xpcall = xpcall,\
- os = os,\
- help = help,\
- io = io,\
- rawequal = rawequal,\
- setfenv = setfenv,\
- rs = rs,\
- http = http,\
- write = write,\
- string = string,\
- setmetatable = setmetatable,\
- print = print,\
- getmetatable = getmetatable,\
- table = table,\
- parallel = parallel,\
- dofile = function(path) dofile(\"OmniOS/Programs/\"..globalName..\".app/\"..path) end,\
- textutils = textutils,\
- term = term,\
- colors = colors,\
- vector = vectors,\
- select = select,\
- paintutils = paintutils,\
- System = System,\
- OmniOS = OmniOS,\
- log = log,\
- }\
- end",
- [ "OldSandbox.lua" ] = "--[[\
- Sandbox \
- environment\
- by Creator\
- for TheOS\
- ]]--\
- \
- --Variables--\
- local oldGetfenv = getfenv\
- local oldLoadfile = loadfile\
- --Functions--\
- \
- function newEnv(permission)\
- if permission == \"admin\" then\
- return \"global\"\
- else\
- return \"custom\" , customEnv()\
- end\
- end\
- \
- local function makeDir(path)\
- local parentPath = \"\"\
- local buffer = {}\
- for token in string.gmatch(path,\"[^/]+\") do\
- buffer[#buffer+1] = token\
- end\
- for i=1,#buffer-1 do\
- parentPath = parentPath..\"/\"..buffer[i]\
- end\
- local _,permission = isReadOnly(parentPath)\
- if permission == \"admin\" then\
- error(\"Operation not allowed, you have no power here...\",2)\
- elseif permission == \"user\" then\
- \
- elseif permission == \"public\" then\
- fs.makeDir(path)\
- end\
- end\
- \
- local function copy(a,b)\
- local function readFile(path)\
- local file = fs.open(path,\"r\")\
- local variable = file.readAll()\
- file.close()\
- return variable\
- end\
- \
- local function writeFile(path,content)\
- local file = fs.open(path,\"w\")\
- file.write(content)\
- file.close()\
- end\
- \
- if fs.isDir(a) then\
- local function explore(dir)\
- local buffer = {}\
- local sBuffer = fs.list(dir)\
- for i,v in pairs(sBuffer) do\
- sleep(0.05)\
- if fs.isDir(dir..\"/\"..v) then\
- buffer[v] = explore(dir..\"/\"..v)\
- else\
- buffer[v] = readFile(dir..\"/\"..v)\
- end\
- end\
- return buffer\
- end\
- filesystem = explore(\"TheOS\")\
- \
- function writeDown(input,dir)\
- for i,v in pairs(input) do\
- if type(v) == \"table\" then\
- writeDown(v,dir..\"/\"..i)\
- elseif type(v) == \"string\" then\
- writeFile(dir..\"/\"..i,v)\
- end\
- end\
- end\
- writeDown(explore(a),b)\
- else\
- writeFile(b,readFile(a))\
- end\
- end\
- \
- local function isReadOnly(path)\
- if fs.isDir(path) then\
- if \
- \
- else\
- \
- end\
- end\
- \
- local function customEnv()\
- return {\
- redstone = redstone,\
- gps = gps,\
- _VERSION = _VERSION,\
- keys = keys,\
- printError = printError,\
- peripheral = peripheral,\
- assert = assert,\
- getfenv = function(a)\
- if type(a) == \"number\" then\
- oldGetfenv(1)\
- elseif type(a) == \"function\" then\
- oldGetfenv(a)\
- else\
- error(\"Expected function or number, got \"..type(a))\
- end,\
- bit = bit,\
- rawset = rawset,\
- tonumber = tonumber,\
- loadstring = function(str) local func = loadstring(str) setfenv(func,getfenv(1))end,\
- error = error,\
- tostring = tostring,\
- type = type,\
- coroutine = { \
- create = coroutine.create,\
- resume = coroutine.resume,\
- running = coroutine.running,\
- status = coroutine.status,\
- wrap = coroutine.wrap,\
- },\
- disk = disk,\
- window = window,\
- next = next,\
- unpack = unpack,\
- colours = colours,\
- pcall = pcall,\
- sleep = sleep,\
- loadfile = function(a) \
- local func = oldLoadfile(a)\
- setfenv(func,getfenv(1))\
- end,\
- math = math,\
- pairs = pairs,\
- fs = {\
- combine = fs.combine,\
- isReadOnly = isReadOnly,\
- getSize = fs.getSize,\
- move = function(a,b)\
- copy(a,b)\
- fs.delete(a)\
- end,\
- exists = fs.exists,\
- copy = copy(a,b)\
- getFreeSpace = fs.getFreeSpace,\
- makeDir = makeDir,\
- find = fs.find,\
- getDir = fs.getDir,\
- delete = \
- open\
- list\
- getDrive\
- getName\
- isDir\
- },\
- rawget = rawget\
- _G \
- __inext \
- read \
- rednet \
- ipairs \
- xpcall \
- os \
- help \
- io \
- rawequal \
- setfenv \
- rs \
- http \
- write \
- string \
- setmetatable \
- print \
- getmetatable \
- table \
- parallel \
- dofile \
- textutils \
- term \
- colors \
- vector \
- select \
- paintutils \
- },\
- end",
- [ "System.lua" ] = "--[[\
- System API\
- for \
- TheOS\
- by Creator\
- ]]--\
- \
- function reboot()\
- os.reboot()\
- end\
- \
- function newTask(name,title,...)\
- log.log(\"System\",\"Opening app \"..name)\
- local mainPath = \"OmniOS/Programs/\"..name..\".app/Main.lua\"\
- local permissionPath = \"OmniOS/Programs/\"..name..\".app/permission.data\"\
- local file = fs.open(permissionPath,\"r\")\
- local permission = file.readAll and file.readAll() or \"user\"\
- file.close()\
- log.log(\"System\",\"Opening app \"..name..\": retrieved permissions.\")\
- if fs.exists(mainPath) then\
- local func, err = loadfile(mainPath)\
- if func then\
- log.log(\"System\",\"Opening app \"..name..\": about to launch task.\")\
- newRoutine(name,title,func,permission,...)\
- log.log(\"System\",\"Opening app \"..name..\": launched task.\")\
- end\
- end\
- return false\
- end\
- \
- function getPerimssion(program)\
- return getPerimssion(program)\
- end",
- [ "NewInteract.lua" ] = "--[[\
- Interact API in ComputerCraft\
- by Creator\
- Complete rewrite in OOP\
- ]]--\
- \
- --Variables\
- local textutilsserialize = textutils.serialize\
- local textutilsunserialize = textutils.unserialize\
- local KeyCodes = {\
- [ 2 ] = 1 ,\
- [ 3 ] = 2,\
- [ 4 ] = 3,\
- [ 5 ] = 4,\
- [ 6 ] = 5,\
- [ 7 ] = 6,\
- [ 8 ] = 7,\
- [ 9 ] = 8,\
- [ 10 ] = 9,\
- [ 11 ] = 0,\
- [ 12 ] = \"-\",\
- [ 13 ] = \"=\",\
- [ 14 ] = \"Backspace\",\
- [ 15 ] = \"Tab\",\
- [ 16 ] = \"q\",\
- [ 17 ] = \"w\",\
- [ 18 ] = \"e\",\
- [ 19 ] = \"r\",\
- [ 20 ] = \"t\",\
- [ 21 ] = \"y\",\
- [ 22 ] = \"u\",\
- [ 23 ] = \"i\",\
- [ 24 ] = \"o\",\
- [ 25 ] = \"p\",\
- [ 26 ] = \"LeftBracket\",\
- [ 27 ] = \"RightBracket\",\
- [ 28 ] = \"Enter\",\
- [ 29 ] = \"LeftControl\",\
- [ 30 ] = \"a\",\
- [ 31 ] = \"s\",\
- [ 32 ] = \"d\",\
- [ 33 ] = \"f\",\
- [ 34 ] = \"g\",\
- [ 35 ] = \"h\",\
- [ 36 ] = \"j\",\
- [ 37 ] = \"k\",\
- [ 38 ] = \"l\",\
- [ 39 ] = \";\",\
- [ 40 ] = \"\\'\",\
- [ 41 ] = \"`\",\
- [ 42 ] = \"LeftShift\",\
- [ 43 ] = \"Backslash\",\
- [ 44 ] = \"z\",\
- [ 45 ] = \"x\",\
- [ 46 ] = \"c\",\
- [ 47 ] = \"v\",\
- [ 48 ] = \"b\",\
- [ 49 ] = \"n\",\
- [ 50 ] = \"m\",\
- [ 51 ] = \",\",\
- [ 52 ] = \".\",\
- [ 53 ] = \"/\",\
- [ 54 ] = \"RightShift\",\
- [ 55 ] = \"*\",\
- [ 56 ] = \"LeftAlt\",\
- [ 57 ] = \" \",\
- [ 58 ] = \"CapsLock\",\
- [ 59 ] = \"F1\",\
- [ 60 ] = \"F2\",\
- [ 61 ] = \"F3\",\
- [ 62 ] = \"F4\",\
- [ 63 ] = \"F5\",\
- [ 64 ] = \"F6\",\
- [ 65 ] = \"F7\",\
- [ 66 ] = \"F8\",\
- [ 67 ] = \"F9\",\
- [ 68 ] = \"F10\",\
- [ 69 ] = \"NumberLock\",\
- [ 70 ] = \"ScrollLock\",\
- [ 71 ] = \"NumPAd7\",\
- [ 72 ] = \"NumPAd8\",\
- [ 73 ] = \"NumPAd9\",\
- [ 74 ] = \"Substract\",\
- [ 75 ] = \"NumPAd4\",\
- [ 76 ] = \"NumPAd5\",\
- [ 77 ] = \"NumPAd6\",\
- [ 78 ] = \"Add\",\
- [ 79 ] = \"NumPAd1\",\
- [ 80 ] = \"NumPAd2\",\
- [ 81 ] = \"NumPAd3\",\
- [ 82 ] = \"NumPAd0\",\
- [ 83 ] = \"Decimal\",\
- [ 87 ] = \"F11\",\
- [ 88 ] = \"F12\",\
- [ 100] = \"F13\",\
- [ 101] = \"F14\",\
- [ 102] = \"F15\",\
- [ 103] = \"F16\",\
- [ 104] = \"F17\",\
- [ 105] = \"F18\",\
- [ 112] = \"Kana\",\
- [ 113] = \"F19\",\
- [ 121] = \"Convert\",\
- [ 123] = \"Noconvert\",\
- [ 125] = \"Yen\",\
- [ 141] = \"NumPadEquals\",\
- [ 144] = \"^\",\
- [ 145] = \"@\",\
- [ 146] = \":\",\
- [ 147] = \"_\",\
- [ 148] = \"Kanji\",\
- [ 149] = \"Stop\",\
- [ 150] = \"Ax\",\
- [ 151] = \"Unlabeled\",\
- [ 156] = \"NumPadEnter\",\
- [ 157] = \"RightControl\",\
- [ 157] = \"Section\",\
- [ 179] = \"NumPadComma\",\
- [ 181] = \"Dvide\",\
- [ 183] = \"Sysrq\",\
- [ 184] = \"RightAlt\",\
- [ 196] = \"Function\",\
- [ 197] = \"Pause\",\
- [ 199] = \"Home\",\
- [ 200] = \"Up\",\
- [ 201] = \"PageUp\",\
- [ 203] = \"Left\",\
- [ 205] = \"Right\",\
- [ 207] = \"End\",\
- [ 208] = \"Down\",\
- [ 209] = \"PageDown\",\
- [ 210] = \"Insert\",\
- [ 211] = \"Delete\",\
- }\
- \
- --Class declarations--\
- local Button = {}\
- local Layout = {}\
- local Toggle = {}\
- local BackgroundColor = {}\
- local ColorField = {}\
- local BetterPaint = {}\
- local Text = {}\
- local TextBox = {}\
- local Key = {}\
- \
- function loadObjects(self)\
- local output = {}\
- output.Button = {}\
- output.Toggle = {}\
- output.ColorField = {}\
- output.BetterPaint = {}\
- output.Text = {}\
- output.TextBox = {}\
- output.Key = {}\
- output.Layout = {}\
- for o,v in pairs(output) do\
- if self[o] == nil then\
- self[o] = {}\
- end\
- end\
- for i,v in pairs(self.Button) do\
- output.Button[i] = Button.new(self.Button[i])\
- end\
- for i,v in pairs(self.Toggle) do\
- output.Toggle[i] = Toggle.new(self.Toggle[i])\
- end\
- for i,v in pairs(self.ColorField) do\
- output.ColorField[i] = ColorField.new(self.ColorField[i])\
- end\
- for i,v in pairs(self.BetterPaint) do\
- output.BetterPaint[i] = BetterPaint.new(self.BetterPaint[i])\
- end\
- for i,v in pairs(self.Text) do\
- output.Text[i] = Text.new(self.Text[i])\
- end\
- for i,v in pairs(self.TextBox) do\
- output.TextBox[i] = TextBox.new(self.TextBox[i])\
- end\
- for i,v in pairs(self.Key) do\
- output.Key[i] = Key.new(self.Key[i])\
- end\
- for i,v in pairs(self.Layout) do\
- output.Layout[i] = Layout.new(self.Layout[i])\
- end\
- output.BackgroundColor = self.BackgroundColor or 1\
- output.nilClick = self.nilClick or false\
- return output\
- end\
- \
- function loadLayout(input,output)\
- for i,v in pairs(input.Button) do\
- output:addButton(input.Button[i])\
- end\
- for i,v in pairs(input.Toggle) do\
- output:addToggle(input.Toggle[i])\
- end\
- for i,v in pairs(input.ColorField) do\
- output:addColorField(input.ColorField[i])\
- end\
- for i,v in pairs(input.BetterPaint) do\
- output:addBetterPaint(input.BetterPaint[i])\
- end\
- for i,v in pairs(input.Text) do\
- output:addText(input.Text[i])\
- end\
- for i,v in pairs(input.TextBox) do\
- output:addTextBox(input.TextBox[i])\
- end\
- for i,v in pairs(input.Key) do\
- output:addKey(input.Key[i])\
- end\
- for i,v in pairs(input.Layout) do\
- output:addLayout(input.Layout[i])\
- end\
- output.BackgroundColor = input.BackgroundColor\
- output.nilClick = input.nilClick\
- end\
- \
- --Class Layout--\
- --Layout initialization function--\
- Layout.new = function(input)\
- local self = {}\
- setmetatable(self,{__index = Layout})\
- self.Button = {}\
- self.Toggle = {}\
- self.ColorField = {}\
- self.BetterPaint = {}\
- self.Text = {}\
- self.TextBox = {}\
- self.Key = {}\
- self.Layout = {}\
- for i,v in pairs(self) do\
- if input[i] == nil then\
- input[i] = {}\
- end\
- end\
- self.BackgroundColor = 1\
- self.xPos = input.xPos or 1\
- self.yPos = input.yPos or 1\
- self.xLength = input.xLength or 51\
- self.yLength = input.yLength or 19\
- self.nilClick = input.nilClick or false\
- self.window = Screen.new(term.current(),self.xPos,self.yPos,self.xLength,self.yLength)\
- for i,v in pairs(input.Button) do\
- self:addButton(input.Button[i])\
- end\
- for i,v in pairs(input.Toggle) do\
- self:addToggle(input.Toggle[i])\
- end\
- for i,v in pairs(input.ColorField) do\
- self:addColorField(input.ColorField[i])\
- end\
- for i,v in pairs(input.BetterPaint) do\
- self:addBetterPaint(input.BetterPaint[i])\
- end\
- for i,v in pairs(input.Text) do\
- self:addText(input.Text[i])\
- end\
- for i,v in pairs(input.TextBox) do\
- self:addTextBox(input.TextBox[i])\
- end\
- for i,v in pairs(input.Key) do\
- self:addKey(input.Key[i])\
- end\
- for i,v in pairs(input.Layout) do\
- self:addLayout(input.Layout[i])\
- end\
- self.BackgroundColor = input.BackgroundColor\
- self.nilClick = input.nilClick\
- return self\
- end\
- \
- --Add element function--\
- Layout.addButton = function(self,_elementData)\
- setmetatable(_elementData,{__index = Button})\
- self.Button[_elementData.name] = _elementData\
- end\
- \
- Layout.addToggle = function(self,_elementData)\
- setmetatable(_elementData,{__index = Toggle})\
- self.Toggle[_elementData.name] = _elementData\
- end\
- \
- Layout.addBackgroundColor = function(self,_elementData)\
- self.BackgroundColor = _elementData.color\
- end\
- \
- Layout.addColorField = function(self,_elementData)\
- setmetatable(_elementData,{__index = ColorField})\
- self.ColorField[_elementData.name] = _elementData\
- end\
- \
- Layout.addBetterPaint = function(self,_elementData)\
- setmetatable(_elementData,{__index = BetterPaint})\
- self.BetterPaint[_elementData.name] = _elementData\
- end\
- \
- Layout.addText = function(self,_elementData)\
- setmetatable(_elementData,{__index = Text})\
- self.Text[_elementData.name] = _elementData\
- end\
- \
- Layout.addTextBox = function(self,_elementData)\
- setmetatable(_elementData,{__index = TextBox})\
- self.TextBox[_elementData.name] = _elementData\
- end\
- \
- Layout.addKey = function(self,_elementData)\
- setmetatable(_elementData,{__index = Key})\
- self.Key[_elementData.name] = _elementData\
- end\
- \
- Layout.addLayout = function(self,_elementData)\
- self.Layout[_elementData.name] = Layout.new(_elementData)\
- end\
- \
- Layout.draw = function(self,xPlus,yPlus)\
- xPlus = xPlus or 0\
- yPlus = yPlus or 0\
- self.finalX = xPlus\
- self.finalY = yPlus\
- local oldTerm = term.current()\
- term.redirect(self.window)\
- local buttonFunctions = {}\
- local toggleFunctions = {}\
- local colorFieldFunctions = {}\
- local betterPaintFunctions = {}\
- local textFunctions = {}\
- local textBoxFunctions = {}\
- local layoutFunctions = {}\
- setmetatable(buttonFunctions,{__index = Button})\
- setmetatable(toggleFunctions,{__index = Toggle})\
- setmetatable(colorFieldFunctions,{__index = ColorField})\
- setmetatable(betterPaintFunctions,{__index = BetterPaint})\
- setmetatable(textFunctions,{__index = Text})\
- setmetatable(textBoxFunctions,{__index = TextBox})\
- setmetatable(layoutFunctions,{__index = Layout})\
- paintutils.drawFilledBox(1,1,self.xLength,self.yLength,self.BackgroundColor)\
- for i,v in pairs(self.ColorField) do\
- colorFieldFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.Button) do\
- buttonFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.BetterPaint) do\
- betterPaintFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.Toggle) do\
- toggleFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.Text) do\
- textFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.TextBox) do\
- textBoxFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- for i,v in pairs(self.Layout) do\
- layoutFunctions.draw(v,self.xPos-1+xPlus,self.yPos-1+yPlus)\
- end\
- term.redirect(oldTerm)\
- end\
- \
- --Class Button--\
- --Button initialization function\
- Button.new = function(input)\
- local self = {}\
- setmetatable(self,{__index = Button})\
- self.name = input.name\
- self.label = input.label\
- self.xPos = input.xPos\
- self.yPos = input.yPos\
- self.fgColor = input.fgColor\
- self.bgColor = input.bgColor\
- self.xLength = input.xLength\
- self.yLength = input.yLength\
- self.returnValue = input.returnValue\
- self.xTextPos = input.xTextPos\
- self.yTextPos = input.yTextPos\
- self.onRightClick = input.onRightClick or nil\
- self.onLeftClick = input.onLeftClick or nil\
- return self\
- end\
- \
- --Draw function\
- Button.draw = function(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- \
- self.finalX = finalX\
- self.finalY = finalY\
- local newText\
- if #self.label > self.xLength then\
- newText = string.sub(self.label,1,self.xLength)\
- else\
- newText = self.label\
- end\
- paintutils.drawFilledBox(finalX,finalY,finalX+self.xLength-1,finalY+self.yLength-1,self.bgColor)\
- term.setTextColor(self.fgColor)\
- term.setCursorPos(finalX+self.xTextPos-1,finalY+self.yTextPos-1)\
- term.write(newText)\
- end\
- \
- --Return function--\
- Button.returnData = function(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- --Sample Input table--\
- example = [[\
- example = {\
- name = \"quickSettings\",\
- label = \">\",\
- xPos = 1,\
- yPos = 3,\
- xLength = 1,\
- yLength = 6,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = colors.blue,\
- bgColor = colors.lightGray,\
- returnValue = \"quickSettings\",\
- },\
- ]]\
- \
- --Class Toggle--\
- --Initialize Toggle Object--\
- Toggle.new = function(input)\
- local self = {}\
- setmetatable(self,{__index = Toggle})\
- self.name = input.name or \"randomName\"\
- self.state = input.state or true\
- self.xPos = input.xPos or 1\
- self.yPos = input.yPos or 1\
- self.trueColor = input.trueColor or colors.green\
- self.falseColor = input.falseColor or colors.red\
- self.trueText = input.trueText or \"T\"\
- self.falseText = input.falseText or \"F\"\
- self.selectedBg = input.selectedBg or colors.gray\
- self.notSelectedBg = input.notSelectedBg or colors.lightGray\
- self.returnValue = input.returnValue or \"mmmmmmm\"\
- self.moveX = input.moveX or false\
- self.moveY = input.moveY or false\
- self.onRightClick = input.onRightClick or nil\
- self.onLeftClick = input.onLeftClick or nil\
- return self\
- end\
- \
- function Toggle.draw(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- self.finalX = finalX\
- self.finalY = finalY\
- term.setCursorPos(finalX,finalY)\
- if self.state == false then\
- term.setBackgroundColor(self.notSelectedBg)\
- term.setTextColor(self.trueColor)\
- term.write(string.sub(self.trueText,1,1))\
- term.setBackgroundColor(self.selectedBg)\
- term.setTextColor(self.falseColor)\
- term.write(\" \"..string.sub(self.falseText,1,1)..\" \")\
- elseif self.state == true then\
- term.setBackgroundColor(self.selectedBg)\
- term.setTextColor(self.trueColor)\
- term.write(\" \"..string.sub(self.trueText,1,1)..\" \")\
- term.setBackgroundColor(self.notSelectedBg)\
- term.setTextColor(self.falseColor)\
- term.write(string.sub(self.falseText,1,1))\
- end\
- end\
- \
- function Toggle.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- function Toggle.toggle(self)\
- if self.state == true then\
- self.state = false\
- else\
- self.state = true\
- end\
- end\
- \
- function Toggle.getState(self)\
- return self.state\
- end\
- \
- --BackgroundColor Class--\
- function BackgroundColor.new(input)\
- local self = {}\
- setmetatable(self,{__index = BackgroundColor})\
- self.color = input.color\
- return self\
- end\
- \
- function BackgroundColor.setColor(self,color)\
- self.color = color\
- end\
- \
- function BackgroundColor.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- --ColorField Class--\
- function ColorField.new(input)\
- local self = {}\
- setmetatable(self,{__index = ColorField})\
- self.name = input.name\
- self.xPos = input.xPos\
- self.yPos = input.yPos\
- self.xLength = input.xLength\
- self.yLength = input.yLength\
- self.color = input.color\
- self.moveX = input.moveX or false\
- self.moveY = input.moveY or false\
- return self\
- end\
- \
- function ColorField.draw(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- self.finalX = finalX\
- self.finalY = finalY\
- term.setTextColor(colors.black)\
- paintutils.drawFilledBox(finalX,finalY,finalX+self.xLength-1,finalY+self.yLength-1,self.color)\
- end\
- \
- function ColorField.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- --BetterPaint Class--\
- function BetterPaint.new(input)\
- local self = {}\
- setmetatable(self,{__index = BetterPaint})\
- self.xPos = input.xPos\
- self.yPos = input.yPos\
- self.name = input.name\
- self.path = input.path\
- self.xLength = input.xLength\
- self.yLength = input.yLength\
- self.returnValue = input.returnValue\
- self.label = input.label\
- self.labelBg = input.labelBg\
- self.labelFg = input.labelFg\
- self.moveX = input.moveX or false\
- self.moveY = input.moveY or false\
- self.onRightClick = input.onRightClick or nil\
- self.onLeftClick = input.onLeftClick or nil\
- return self\
- end\
- \
- function BetterPaint.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- function BetterPaint.draw(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- self.finalX = finalX\
- self.finalY = finalY\
- paint.drawImage(self.path,finalX,finalY)\
- term.setCursorPos(finalX,finalY+self.yLength)\
- term.setTextColor(self.labelFg)\
- term.setBackgroundColor(self.labelBg)\
- term.write(self.label)\
- end\
- \
- --Text Class--\
- function Text.new(input)\
- local self = {}\
- setmetatable(self,{__index = Text})\
- self.name = input.name\
- self.text = input.text\
- self.xPos = input.xPos\
- self.yPos = input.yPos\
- self.bgColor = input.bgColor\
- self.fgColor = input.fgColor\
- return self\
- end\
- \
- function Text.draw(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- self.finalX = finalX\
- self.finalY = finalY\
- term.setCursorPos(finalX,finalY)\
- term.setTextColor(self.fgColor)\
- term.setBackgroundColor(self.bgColor)\
- term.write(self.text)\
- end\
- \
- function Text.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- --TextBox Class \
- \
- function TextBox.new(input)\
- local self = {}\
- setmetatable(self,{__index = TextBox})\
- self.name = input.name\
- self.helpText = input.helpText\
- self.xPos = input.xPos\
- self.yPos = input.yPos\
- self.xLength = input.xLength\
- self.yLength = input.yLength\
- self.bgColor = input.bgColor\
- self.fgColor = input.fgColor\
- self.helpFgColor = input.helpFgColor\
- self.charLimit = input.charLimit\
- self.moveX = input.moveX or false\
- self.moveY = input.moveY or false\
- self.text = \"\"\
- self.returnValue = input.returnValue\
- self.confidential = input.confidential or false\
- return self\
- end\
- \
- function TextBox.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- function TextBox.draw(self,addX,addY)\
- addX = addX or 0\
- addY = addY or 0\
- local finalX = self.xPos + addX\
- local finalY = self.yPos + addY\
- self.finalX = finalX\
- self.finalY = finalY\
- paintutils.drawFilledBox(finalX,finalY,finalX+self.xLength-1,finalY+self.yLength-1,self.bgColor)\
- term.setBackgroundColor(self.bgColor)\
- term.setCursorPos(self.finalX,self.finalY)\
- if self.text == \"\" or self.confidential then\
- term.setTextColor(self.helpFgColor)\
- term.write(self.helpText)\
- else\
- term.setTextColor(self.fgColor)\
- term.write(self.text)\
- end\
- end\
- \
- function TextBox.read(self,_sReplaceChar, _tHistory)\
- paintutils.drawFilledBox(self.finalX,self.finalY,self.finalX+self.xLength-1,self.finalY+self.yLength-1,self.bgColor)\
- term.setTextColor(self.fgColor)\
- term.setCursorPos(self.finalX,self.finalY)\
- return read()\
- end\
- \
- --Key Class\
- function Key.new(input)\
- local self = {}\
- setmetatable(self,{__index = TextBox})\
- self.name = input.name\
- self.key = input.key\
- self.onPress = input.onPress or nil\
- return self\
- end\
- \
- function Key.returnData(self)\
- local toReturn = {}\
- for i,v in pairs(self) do\
- toReturn[i] = v\
- end\
- return toReturn\
- end\
- \
- local function localEventHandler(self,toAddX, toAddY, event, p1, p2, p3, p4, p5, p6)\
- while true do\
- if event == \"mouse_click\" then\
- for i,v in pairs(self.Button) do\
- if v.finalX + toAddX <= p2 and p2 <= v.finalX + v.xLength-1 + toAddX and v.finalY + toAddY <= p3 and p3 <= v.finalY + v.yLength-1 + toAddY then\
- if p1 == 1 then\
- if v.onLeftClick then \
- v.onLeftClick()\
- end\
- elseif p1 == 2 then\
- if v.onRightClick then\
- v.onRightClick()\
- end\
- end\
- return {\"Button\",tostring(v.returnValue),p1,p2,p3}\
- end\
- end\
- for i,v in pairs(self.Toggle) do\
- if v.finalX + toAddX <= p2 and p2 <= v.finalX + 3 + toAddX and v.finalY + toAddY == p3 then\
- return {\"Toggle\",tostring(v.returnValue),p1,p2,p3}\
- end\
- end\
- for i,v in pairs(self.BetterPaint) do \
- if v.finalX + toAddX <= p2 and p2 <= v.finalX + v.xLength-1 + toAddX and v.finalY + toAddY <= p3 and p3 <= v.finalY + v.yLength-1 + toAddY then\
- return {\"Button\",tostring(v.returnValue),p1,p2,p3}\
- end\
- end\
- for i,v in pairs(self.TextBox) do \
- if v.finalX + toAddX <= p2 and p2 <= v.finalX + v.xLength-1 + toAddX and v.finalY + toAddY <= p3 and p3 <= v.finalY + v.yLength-1 + toAddY then\
- return {\"TextBox\",tostring(v.returnValue),p1,p2,p3}\
- end\
- end\
- for i,v in pairs(self.Layout) do \
- if v.finalX + toAddX <= p2 and p2 <= v.finalX + v.xLength-1 + toAddX and v.finalY + toAddY <= p3 and p3 <= v.finalY + v.yLength-1 + toAddY then\
- local toReturn = localEventHandler(v,v.finalX-1,v.finalY-1, event, p1, p2, p3, p4, p5, p6)\
- return {toReturn[1],toReturn[2],p1,p2,p3}\
- end\
- end\
- if self.nilClick then\
- if not (self.xPos <= p2 and p2 <= self.xPos+self.xLength-1 and self.yPos <= p3 and p3 <= self.yPos+self.yLength-1) then\
- return {\"Nil\",\"Nil\",p1,p2,p3}\
- end\
- end\
- elseif event == \"key\" then\
- local pressedKey = p1\
- for i,v in pairs(self.Key) do\
- if v.key == KeyCodes[pressedKey] then\
- if v.onPress then\
- v.onPress()\
- else\
- return {\"Key\",KeyCodes[pressedKey],pressedKey}\
- end\
- end\
- \
- end\
- elseif event == \"monitor_touch\" then\
- os.queueEvent(\"mouse_click\", p1, p2, p3, p4, p5, p6)\
- end\
- end\
- end\
- \
- --Event handler function--\
- eventHandler = function(self)\
- \
- return localEventHandler(self,self.xPos-1,self.yPos-1,os.pullEvent())\
- end\
- \
- --Load Function--\
- function Initialize()\
- local toReturn = {}\
- toReturn.Button = Button\
- toReturn.Layout = Layout\
- toReturn.Toggle = Toggle\
- toReturn.BackgroundColor = BackgroundColor\
- toReturn.ColorField = ColorField\
- toReturn.BetterPaint = BetterPaint\
- toReturn.Text = Text\
- toReturn.TextBox = TextBox\
- toReturn.Key = Key\
- toReturn.eventHandler = eventHandler\
- toReturn.loadObjects = loadObjects\
- toReturn.loadLayout = loadLayout\
- return toReturn\
- end",
- [ "gui.lua" ] = "--[[\
- GUI API in ComputerCraft\
- by Creator\
- Complete rewrite in OOP\
- ]]--\
- \
- --Button Class--\
- \
- Button = {}\
- \
- newButton = function(_name,_label,_xPos,_yPos,_xLength,_yLength,_fgColor,_bgColor,_returnValue)\
- local self = {}\
- setmetatable(self,{__index = Button})\
- self.name = _name\
- self.label = _label\
- self.xPos = _xPos\
- self.yPos = _yPos\
- self.fgColor = _fgColor\
- self.bgColor = _bgColor\
- self.xLength = _xLength\
- self.yLength = _yLength\
- self.returnValue = _returnValue\
- return self\
- end\
- \
- Button.draw = function(self)\
- --term.setBackgroundColor(self.bgColor)\
- paintutils.drawFilledBox(self.xPos,self.yPos,self.xLength-1,self.yLength-1,self.bgColor)\
- \
- end\
- \
- --Variables--\
- --Functions--\
- \
- function addKey(key,returnValue)\
- keysMain[#keysMain+1] = {key,returnValue}\
- end\
- \
- function resetKeys()\
- keysMain = {}\
- end\
- \
- local function localAddField(minX,minY,maxX,maxY,returnV)\
- buttonsMain[#buttonsMain+1] = {minX,minY,minX+maxX-1,minY+maxY-1,returnV}\
- end\
- \
- function addField(minX,minY,maxX,maxY,returnV)\
- if not pcall(localAddField,minX,minY,maxX,maxY,returnV) then\
- print([[\
- Usage:\
- As an argument pass a table structured like this:\
- {\
- xPos,\
- yPos,\
- wide,\
- height,\
- returnValue,\
- }\
- ]])\
- end\
- end\
- \
- local function localDrawButton(xPos,yPos,wide,height,colorOfButton,inButtonXPosOfLabel,inButtonYPosOfLabel,label,textColor,returnValue)\
- if colorOfButton ~= nil then\
- paintutils.drawFilledBox(xPos,yPos,xPos+wide-1,yPos+height-1,colorOfButton)\
- end\
- term.setTextColor(textColor)\
- term.setCursorPos(xPos+inButtonXPosOfLabel-1,yPos+inButtonYPosOfLabel-1)\
- local textToPrint = string.sub(label,1,xPos+wide-inButtonXPosOfLabel)\
- term.write(textToPrint)\
- buttonsMain[#buttonsMain+1] = {xPos,yPos,xPos+wide-1,yPos+height-1,returnValue}\
- end\
- \
- function drawButton(xPos,yPos,wide,height,colorOfButton,inButtonXPosOfLabel,inButtonYPosOfLabel,label,textColor,returnValue)\
- if not pcall(localDrawButton,xPos,yPos,wide,height,colorOfButton,inButtonXPosOfLabel,inButtonYPosOfLabel,label,textColor,returnValue) then\
- print([[\
- Usage:\
- As an argument pass a table structured like this:\
- {\
- xPos,\
- yPos,\
- wide,\
- height,\
- colorOfButton,\
- inButtonXPosOfLabel,\
- inButtonYPosOfLabel,\
- label,\
- textColor,\
- returnValue,\
- }\
- You can have the option to not use the background color.\
- You can do this by simply setting color of button to nil.\
- ]])\
- end\
- end\
- \
- function detectButtonOrKeyHit()\
- while true do\
- local event, button, x, y\
- repeat\
- event, button, x, y = os.pullEvent()\
- until (event == \"mouse_click\" and buttonsMain ~= nil) or (event == \"key\" and keysMain ~= nil)\
- if event == \"mouse_click\" then\
- for i,v in pairs(buttonsMain) do\
- if v[1] <= x and x <= v[3] and v[2] <= y and y <= v[4] then\
- return {v[5], button, x, y}\
- end\
- end\
- elseif event == \"key\" then\
- for i,v in pairs(keysMain) do\
- if button == v[1] then\
- return {v[2]}\
- end\
- end\
- end\
- end\
- end\
- \
- function resetButtons()\
- buttonsMain = {}\
- end\
- \
- local function localCPrint(txt,color,bgColor,xPos,yPos,maxL)\
- if not maxL == nil then\
- txt = string.sub(txt,1,maxL)\
- end\
- term.setTextColor(color)\
- if bgColor ~= nil then\
- term.setBackgroundColor(bgColor)\
- end\
- term.setCursorPos(xPos,yPos)\
- term.write(txt)\
- end\
- \
- function cPrint(txt,color,bgColor,xPos,yPos,maxL)\
- if not pcall(localCPrint,txt,color,bgColor,xPos,yPos,maxL) then\
- print([[\
- Usage:\
- Arguments are as follws:\
- {\
- Text to print\
- Text color\
- Background color\
- xPos\
- yPos\
- Maximal lenght of the string\
- }\
- Maximal lenght of the string can be left \"nil\" with qoutes\
- ]])\
- end\
- end",
- [ "log.lua" ] = "--[[\
- Log API\
- by Creator\
- for TheOS\
- ]]--\
- \
- function log(destination,message,app)\
- local finalMsg = \"[\"..os.day()..\":\"..os.time()..\"]\"\
- if app then\
- finalMsg = finalMsg..\".[\"..tostring(app)..\"]:\"..tostring(message)\
- else\
- finalMsg = finalMsg..\":\"..tostring(message)\
- end\
- local m = fs.open(\"OmniOS/Logs/\"..destination..\".log\",\"a\")\
- m.write(finalMsg..\"\\n\")\
- m.close()\
- end",
- [ "Screen.lua" ] = "function new( parent, nX, nY, nWidth, nHeight)\
- \
- if type( parent ) ~= \"table\" then error( \"Expected object\",2 ) end\
- if type( nX ) ~= \"number\" then error( \"Expected number1\", 2 ) end\
- if type( nY ) ~= \"number\" then error( \"Expected number2\", 2 ) end\
- if type( nWidth ) ~= \"number\" then error( \"Expected number3\", 2 ) end\
- if type( nHeight ) ~= \"number\" then error( \"Expected number4\", 2 ) end\
- \
- if parent == term then\
- parent = term.current()\
- end\
- \
- -- Setup\
- local nCursorX = 1\
- local nCursorY = 1\
- \
- -- Helper functions\
- local function updateCursorPos()\
- if nCursorX >= 1 and nCursorY >= 1 and\
- nCursorX <= nWidth and nCursorY <= nHeight then\
- parent.setCursorPos( nX + nCursorX - 1, nY + nCursorY - 1 )\
- else\
- parent.setCursorPos( 0, 0 )\
- end\
- end\
- \
- local window = {}\
- \
- -- Terminal implementation\
- function window.write( sText )\
- local nLen = sText:len()\
- updateCursorPos()\
- for i = 1, nLen do\
- if nCursorX <= nWidth and nCursorY <= nHeight then\
- parent.write(sText:sub(i,i))\
- nCursorX = nCursorX + 1\
- end\
- end\
- end\
- \
- local function clearLine()\
- for i=1,nWidth do\
- parent.write(\" \")\
- nCursorX = nCursorX + 1\
- end\
- end\
- \
- function window.clear()\
- for m=1, nHeight do\
- updateCursorPos()\
- clearLine()\
- nCursorY = nCursorY + 1\
- end\
- end\
- \
- function window.clearLine()\
- clearLine()\
- end\
- \
- function window.getCursorPos()\
- return nCursorX, nCursorY\
- end\
- \
- function window.setCursorPos( x, y )\
- nCursorX = math.floor( x )\
- nCursorY = math.floor( y )\
- updateCursorPos()\
- end\
- \
- function window.setCursorBlink( blink )\
- parent.setCursorBlink(blink)\
- end\
- \
- function window.isColor()\
- return parent.isColor()\
- end\
- \
- function window.isColour()\
- return parent.isColor()\
- end\
- \
- local function setTextColor( color )\
- if not parent.isColor() then\
- if color ~= colors.white and color ~= colors.black then\
- error( \"Colour not supported\", 3 )\
- end\
- end\
- parent.setTextColour(color)\
- end\
- \
- function window.setTextColor( color )\
- setTextColor( color )\
- end\
- \
- function window.setTextColour( color )\
- setTextColor( color )\
- end\
- \
- local function setBackgroundColor( color )\
- if not parent.isColor() then\
- if color ~= colors.white and color ~= colors.black then\
- error( \"Colour not supported\", 3 )\
- end\
- end\
- parent.setBackgroundColor(color)\
- end\
- \
- function window.setBackgroundColor( color )\
- setBackgroundColor( color )\
- end\
- \
- function window.setBackgroundColour( color )\
- setBackgroundColor( color )\
- end\
- \
- function window.getSize()\
- return nWidth, nHeight\
- end\
- \
- function window.scroll( n )\
- print(\"Fuck you! No freaking buffer.\")\
- end\
- \
- return window\
- end",
- },
- Programs = {
- [ "Desktop.app" ] = {
- [ "permission.data" ] = "",
- [ "Main.luaBlah.lua" ] = "--[[\
- Desktop in ComputerCraft\
- by Creator\
- for OmniOS\
- ]]--\
- --Variables--\
- local textutilsserialize = textutils.serialize\
- local textutilsunserialize = textutils.unserialize\
- local w,h = term.getSize()\
- local Settings = {}\
- local result = {}\
- local Main = {}\
- local QuickSettings = {}\
- local MatchingColors = {}\
- local gui = {}\
- local mainLayout = {}\
- local quickSettingsLayout = {}\
- local mainLayoutTable = {}\
- local quickSettingsLayoutTable = {}\
- local paths = {}\
- local scroll = 0\
- local programPath = \"OmniOS/Programs/Desktop.app/Data/\"\
- \
- --Functions--\
- local function readFile(_path)\
- local file = fs.open(_path,\"r\")\
- local data = file.readAll()\
- file.close()\
- return data\
- end\
- \
- local function split(str,sep)\
- local buffer = {}\
- for token in str:gmatch(sep) do\
- buffer[#buffer+1] = token\
- end\
- return buffer\
- end\
- \
- local function loadShortcuts()\
- local buffer = readFile(programPath..\"Shortcuts\")\
- local sBuffer = textutilsunserialize(buffer)\
- local nBuffer = {}\
- paths = {}\
- for i,v in pairs(sBuffer) do\
- nBuffer[v.name] = {\
- xPos = 2+(6*(v.xPos-1)),\
- yPos = 1+(5*(v.yPos-1)),\
- name = v.name,\
- path = v.path..\".ico\",\
- yLength = 4,\
- xLength = 3,\
- returnValue = v.name,\
- label = string.sub(v.name,1,5),\
- labelFg = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- labelBg = Settings.bgColor,\
- moveY = true,\
- }\
- paths[v.name] = v.path\
- end\
- Main.BetterPaint = nBuffer\
- end\
- \
- local function loadObjects()\
- --Object table--\
- Main.Button = {\
- quickSettings = {\
- name = \"quickSettings\",\
- label = \"^\",\
- xPos = 1,\
- yPos = h,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- bgColor = Settings.bgColor,\
- returnValue = \"quickSettings\",\
- },\
- windowPlus = {\
- name = \"windowPlus\",\
- label = \">\",\
- xPos = w,\
- yPos = 1,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- bgColor = Settings.bgColor,\
- returnValue = \"windowPlus\",\
- },\
- windowMinus = {\
- name = \"windowMinus\",\
- label = \"<\",\
- xPos = 1,\
- yPos = 1,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- bgColor = Settings.bgColor,\
- returnValue = \"windowMinus\",\
- },\
- }\
- QuickSettings.Button = {\
- Right = {\
- name = \"Right\",\
- label = \">\",\
- xPos = w-1,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- bgColor = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- returnValue = \"Right\",\
- },\
- Left = {\
- name = \"Left\",\
- label = \"<\",\
- xPos = 2,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- bgColor = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- returnValue = \"Left\",\
- },\
- Green = {\
- name = \"Green\",\
- label = \" \",\
- xPos = 31,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.green,\
- returnValue = \"color:green\",\
- },\
- Lime = {\
- name = \"Lime\",\
- label = \" \",\
- xPos = 31,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.lime,\
- returnValue = \"color:lime\",\
- },\
- Brown = {\
- name = \"Brown\",\
- label = \" \",\
- xPos = 32,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.brown,\
- returnValue = \"color:brown\",\
- },\
- Purple = {\
- name = \"Purple\",\
- label = \" \",\
- xPos = 32,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.purple,\
- returnValue = \"color:purple\",\
- },\
- Blue = {\
- name = \"Blue\",\
- label = \" \",\
- xPos = 33,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.blue,\
- returnValue = \"color:blue\",\
- },\
- lightBlue = {\
- name = \"lightBlue\",\
- label = \" \",\
- xPos = 33,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.lightBlue,\
- returnValue = \"color:lightBlue\",\
- },\
- Yellow = {\
- name = \"Yellow\",\
- label = \" \",\
- xPos = 34,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.yellow,\
- returnValue = \"color:yellow\",\
- },\
- Cyan = {\
- name = \"Cyan\",\
- label = \" \",\
- xPos = 34,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.cyan,\
- returnValue = \"color:cyan\",\
- },\
- Orange = {\
- name = \"Orange\",\
- label = \" \",\
- xPos = 35,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.orange,\
- returnValue = \"color:orange\",\
- },\
- Pink = {\
- name = \"Pink\",\
- label = \" \",\
- xPos = 35,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.pink,\
- returnValue = \"color:pink\",\
- },\
- Red = {\
- name = \"Red\",\
- label = \" \",\
- xPos = 36,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.red,\
- returnValue = \"color:red\",\
- },\
- Magenta = {\
- name = \"Magenta\",\
- label = \" \",\
- xPos = 36,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.magenta,\
- returnValue = \"color:magenta\",\
- },\
- White = {\
- name = \"White\",\
- label = \" \",\
- xPos = 37,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.white,\
- returnValue = \"color:white\",\
- },\
- lightGray = {\
- name = \"lightGray\",\
- label = \" \",\
- xPos = 37,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.lightGray,\
- returnValue = \"color:lightGray\",\
- },\
- Black = {\
- name = \"Black\",\
- label = \" \",\
- xPos = 38,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.black,\
- returnValue = \"color:black\",\
- },\
- Gray = {\
- name = \"Gray\",\
- label = \" \",\
- xPos = 38,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.gray,\
- returnValue = \"color:gray\",\
- },\
- RefreshColor = {\
- name = \"RefreshColor\",\
- label = \"Refresh\",\
- xPos = 40,\
- yPos = 3,\
- xLength = 9,\
- yLength = 5,\
- xTextPos = 2,\
- yTextPos = 3,\
- fgColor = 1,\
- bgColor = colors.gray,\
- returnValue = \"Refresh\",\
- },\
- }\
- \
- QuickSettings.BetterPaint = {\
- Restart = {\
- xPos = 4,\
- yPos = 2,\
- name = \"Restart\",\
- path = programPath..\"QuickSettings/restart.ico\",\
- yLength = 6,\
- xLength = 7,\
- returnValue = \"reboot\",\
- label = \"Restart\",\
- labelFg = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- labelBg = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- },\
- Shutdown = {\
- xPos = 22,\
- yPos = 2,\
- name = \"Shutdown\",\
- path = programPath..\"QuickSettings/shutdown.ico\",\
- yLength = 6,\
- xLength = 7,\
- returnValue = \"shutdown\",\
- label = \"Shutdown\",\
- labelFg = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- labelBg = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- },\
- Settings = {\
- xPos = 13,\
- yPos = 2,\
- name = \"Settings\",\
- path = programPath..\"QuickSettings/settings.ico\",\
- yLength = 6,\
- xLength = 7,\
- returnValue = \"settings\",\
- label = \"Settings\",\
- labelFg = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- labelBg = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- },\
- }\
- \
- QuickSettings.Text = {\
- Label = {\
- name = \"Label\",\
- text = \"QuickSettings\",\
- xPos = w/2-6,\
- yPos = 1,\
- bgColor = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- fgColor = Settings.bgColor,\
- },\
- }\
- QuickSettings.Key = {\
- R = {\
- name = \"R\",\
- key = \"r\",\
- onPress = function() os.reboot() end,\
- },\
- S = {\
- name = \"S\",\
- key = \"s\",\
- onPress = function() os.shutdown() end,\
- },\
- LeftAlt = {\
- name = \"LeftAlt\",\
- key = \"LeftAlt\",\
- onPress = function() System.newTask(\"Settings\",\"Settings\") end,\
- },\
- }\
- loadShortcuts()\
- \
- end\
- \
- local function loadGUI()\
- --Initializing GUI components\
- gui = Interact:Initialize()\
- mainLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- quickSettingsLayout = gui.Layout.new({xPos = 1,yPos = h-7, xLength = w,yLength = 7})\
- mainLayoutTable = {}\
- quickSettingsLayoutTable = {}\
- end\
- \
- local function InitializeGUI()\
- loadObjects()\
- --Main--\
- mainLayoutTable = {}\
- mainLayoutTable = gui.loadObjects(Main)\
- mainLayoutTable.mainBgColor = gui.BackgroundColor.new({color = Settings.bgColor})\
- \
- --QuickSettings--\
- quickSettingsLayoutTable = {}\
- quickSettingsLayoutTable.Text = {}\
- quickSettingsLayoutTable = gui.loadObjects(QuickSettings)\
- quickSettingsLayoutTable.quickSettingsBgColor = gui.BackgroundColor.new({color = MatchingColors[Settings.bgColor][\"quickSettings\"]})\
- \
- --Initializing structures--\
- --Main--\
- for i,v in pairs(mainLayoutTable.Button) do\
- mainLayout:addButton(mainLayoutTable.Button[i]:returnData())\
- end\
- for i,v in pairs(mainLayoutTable.BetterPaint) do\
- mainLayout:addBetterPaint(mainLayoutTable.BetterPaint[i]:returnData())\
- end\
- mainLayout:addBackgroundColor(mainLayoutTable.mainBgColor:returnData())\
- \
- --QuickSettings--\
- for i,v in pairs(quickSettingsLayoutTable.Button) do\
- quickSettingsLayout:addButton(quickSettingsLayoutTable.Button[i]:returnData())\
- end\
- quickSettingsLayout:addBackgroundColor(quickSettingsLayoutTable.quickSettingsBgColor:returnData())\
- quickSettingsLayout:addBetterPaint(quickSettingsLayoutTable.BetterPaint.Restart)\
- quickSettingsLayout:addBetterPaint(quickSettingsLayoutTable.BetterPaint.Shutdown)\
- quickSettingsLayout:addBetterPaint(quickSettingsLayoutTable.BetterPaint.Settings)\
- quickSettingsLayout:addKey(quickSettingsLayoutTable.Key.R:returnData())\
- quickSettingsLayout:addKey(quickSettingsLayoutTable.Key.S:returnData())\
- quickSettingsLayout:addKey(quickSettingsLayoutTable.Key.LeftAlt:returnData())\
- end\
- \
- local function changeColor(color)\
- Settings.bgColor = colors[color] or colors.green\
- local f = fs.open(programPath..\"Settings\",\"w\")\
- f.write(textutilsserialize(Settings))\
- f.close()\
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- loadObjects()\
- InitializeGUI()\
- end\
- \
- --Loading settings--\
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- \
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- \
- \
- \
- loadObjects()\
- loadGUI()\
- InitializeGUI()\
- \
- \
- --Code--\
- while true do\
- mainLayout:draw(0,scroll)\
- local result = gui.eventHandler(mainLayout)\
- if result[1] == \"Button\" then\
- if result[2] == \"quickSettings\" then\
- quickSettingsLayout:draw()\
- local notClose = true\
- while notClose do\
- local answer = gui.eventHandler(quickSettingsLayout)\
- if answer[1] == \"Button\" then\
- if answer[2] == \"reboot\" then\
- os.reboot()\
- elseif answer[2] == \"shutdown\" then\
- os.shutdown()\
- elseif answer[2] == \"Close\" then\
- notClose = false\
- elseif answer[2] == \"settings\" then\
- System.newTask(\"Settings\",\"Settings\")\
- notClose = false\
- elseif answer[2] == \"Refresh\" then\
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- loadObjects()\
- InitializeGUI()\
- notClose = false\
- else\
- local buffer = split(answer[2],\"[^:]+\")\
- changeColor(buffer[2])\
- notClose = false\
- end\
- elseif answer[1] == \"Nil\" then\
- if answer[2] == \"Nil\" then\
- notClose = false\
- end\
- end\
- end\
- elseif result[2] == \"windowPlus\" then\
- scroll = scroll - 51\
- elseif result[2] == \"windowMinus\" then\
- scroll = scroll + 51\
- else\
- System.newTask(result[2],result[2])\
- end\
- end\
- end",
- [ "Main.lua" ] = "--[[\
- Desktop in ComputerCraft\
- by Creator\
- for OmniOS\
- ]]--\
- --Variables--\
- local textutilsserialize = textutils.serialize\
- local textutilsunserialize = textutils.unserialize\
- local w,h = term.getSize()\
- local Settings = {}\
- local result = {}\
- local Main = {}\
- local QuickSettings = {}\
- local MatchingColors = {}\
- local gui = {}\
- local mainLayout = {}\
- local quickSettingsLayout = {}\
- local mainLayoutTable = {}\
- local quickSettingsLayoutTable = {}\
- local paths = {}\
- local scroll = 0\
- local programPath = \"OmniOS/Programs/Desktop.app/Data/\"\
- \
- --Functions--\
- local function readFile(_path)\
- local file = fs.open(_path,\"r\")\
- local data = file.readAll()\
- file.close()\
- return data\
- end\
- \
- local function split(str,sep)\
- local buffer = {}\
- for token in str:gmatch(sep) do\
- buffer[#buffer+1] = token\
- end\
- return buffer\
- end\
- \
- local function loadShortcuts()\
- local buffer = readFile(programPath..\"Shortcuts\")\
- local sBuffer = textutilsunserialize(buffer)\
- local nBuffer = {}\
- paths = {}\
- for i,v in pairs(sBuffer) do\
- nBuffer[v.name] = {\
- xPos = 2+(6*(v.xPos-1)),\
- yPos = 1+(5*(v.yPos-1)),\
- name = v.name,\
- path = v.path..\".ico\",\
- yLength = 4,\
- xLength = 3,\
- returnValue = v.name,\
- label = string.sub(v.name,1,5),\
- labelFg = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- labelBg = Settings.bgColor,\
- moveY = true,\
- }\
- paths[v.name] = v.path\
- end\
- Main.BetterPaint = nBuffer\
- end\
- \
- local function loadObjects()\
- --Object table--\
- Main.Button = {\
- quickSettings = {\
- name = \"quickSettings\",\
- label = \"^\",\
- xPos = 1,\
- yPos = h,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- bgColor = Settings.bgColor,\
- returnValue = \"quickSettings\",\
- },\
- windowPlus = {\
- name = \"windowPlus\",\
- label = \">\",\
- xPos = w,\
- yPos = 1,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- bgColor = Settings.bgColor,\
- returnValue = \"windowPlus\",\
- },\
- windowMinus = {\
- name = \"windowMinus\",\
- label = \"<\",\
- xPos = 1,\
- yPos = 1,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- bgColor = Settings.bgColor,\
- returnValue = \"windowMinus\",\
- },\
- }\
- Main.Layout = {\
- QuickSettings\
- }\
- QuickSettings.Button = {\
- Right = {\
- name = \"Right\",\
- label = \">\",\
- xPos = w-1,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- bgColor = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- returnValue = \"Right\",\
- },\
- Left = {\
- name = \"Left\",\
- label = \"<\",\
- xPos = 2,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- bgColor = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- returnValue = \"Left\",\
- },\
- Green = {\
- name = \"Green\",\
- label = \" \",\
- xPos = 31,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.green,\
- returnValue = \"color:green\",\
- },\
- Lime = {\
- name = \"Lime\",\
- label = \" \",\
- xPos = 31,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.lime,\
- returnValue = \"color:lime\",\
- },\
- Brown = {\
- name = \"Brown\",\
- label = \" \",\
- xPos = 32,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.brown,\
- returnValue = \"color:brown\",\
- },\
- Purple = {\
- name = \"Purple\",\
- label = \" \",\
- xPos = 32,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.purple,\
- returnValue = \"color:purple\",\
- },\
- Blue = {\
- name = \"Blue\",\
- label = \" \",\
- xPos = 33,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.blue,\
- returnValue = \"color:blue\",\
- },\
- lightBlue = {\
- name = \"lightBlue\",\
- label = \" \",\
- xPos = 33,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.lightBlue,\
- returnValue = \"color:lightBlue\",\
- },\
- Yellow = {\
- name = \"Yellow\",\
- label = \" \",\
- xPos = 34,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.yellow,\
- returnValue = \"color:yellow\",\
- },\
- Cyan = {\
- name = \"Cyan\",\
- label = \" \",\
- xPos = 34,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.cyan,\
- returnValue = \"color:cyan\",\
- },\
- Orange = {\
- name = \"Orange\",\
- label = \" \",\
- xPos = 35,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.orange,\
- returnValue = \"color:orange\",\
- },\
- Pink = {\
- name = \"Pink\",\
- label = \" \",\
- xPos = 35,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.pink,\
- returnValue = \"color:pink\",\
- },\
- Red = {\
- name = \"Red\",\
- label = \" \",\
- xPos = 36,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.red,\
- returnValue = \"color:red\",\
- },\
- Magenta = {\
- name = \"Magenta\",\
- label = \" \",\
- xPos = 36,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.magenta,\
- returnValue = \"color:magenta\",\
- },\
- White = {\
- name = \"White\",\
- label = \" \",\
- xPos = 37,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.white,\
- returnValue = \"color:white\",\
- },\
- lightGray = {\
- name = \"lightGray\",\
- label = \" \",\
- xPos = 37,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.lightGray,\
- returnValue = \"color:lightGray\",\
- },\
- Black = {\
- name = \"Black\",\
- label = \" \",\
- xPos = 38,\
- yPos = 6,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.black,\
- returnValue = \"color:black\",\
- },\
- Gray = {\
- name = \"Gray\",\
- label = \" \",\
- xPos = 38,\
- yPos = 7,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.gray,\
- returnValue = \"color:gray\",\
- },\
- RefreshColor = {\
- name = \"RefreshColor\",\
- label = \"Refresh\",\
- xPos = 40,\
- yPos = 3,\
- xLength = 9,\
- yLength = 5,\
- xTextPos = 2,\
- yTextPos = 3,\
- fgColor = 1,\
- bgColor = colors.gray,\
- returnValue = \"Refresh\",\
- },\
- }\
- \
- QuickSettings.BetterPaint = {\
- Restart = {\
- xPos = 4,\
- yPos = 2,\
- name = \"Restart\",\
- path = programPath..\"QuickSettings/restart.ico\",\
- yLength = 6,\
- xLength = 7,\
- returnValue = \"reboot\",\
- label = \"Restart\",\
- labelFg = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- labelBg = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- },\
- Shutdown = {\
- xPos = 22,\
- yPos = 2,\
- name = \"Shutdown\",\
- path = programPath..\"QuickSettings/shutdown.ico\",\
- yLength = 6,\
- xLength = 7,\
- returnValue = \"shutdown\",\
- label = \"Shutdown\",\
- labelFg = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- labelBg = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- },\
- Settings = {\
- xPos = 13,\
- yPos = 2,\
- name = \"Settings\",\
- path = programPath..\"QuickSettings/settings.ico\",\
- yLength = 6,\
- xLength = 7,\
- returnValue = \"settings\",\
- label = \"Settings\",\
- labelFg = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- labelBg = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- },\
- }\
- \
- QuickSettings.Text = {\
- Label = {\
- name = \"Label\",\
- text = \"QuickSettings\",\
- xPos = w/2-6,\
- yPos = 1,\
- bgColor = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- fgColor = Settings.bgColor,\
- },\
- }\
- QuickSettings.Key = {\
- R = {\
- name = \"R\",\
- key = \"r\",\
- onPress = function() os.reboot() end,\
- },\
- S = {\
- name = \"S\",\
- key = \"s\",\
- onPress = function() os.shutdown() end,\
- },\
- LeftAlt = {\
- name = \"LeftAlt\",\
- key = \"LeftAlt\",\
- onPress = function() System.newTask(\"Settings\",\"Settings\") end,\
- },\
- }\
- \
- loadShortcuts()\
- \
- end\
- \
- local function loadGUI()\
- --Initializing GUI components\
- gui = Interact.Initialize()\
- mainLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- quickSettingsLayout = gui.Layout.new({xPos = 1,yPos = h-7,xLength = w,yLength = h, nilClick = true})\
- mainLayoutTable = {}\
- quickSettingsLayoutTable = {}\
- end\
- \
- local function InitializeGUI()\
- loadObjects()\
- --Main--\
- mainLayoutTable = {}\
- mainLayoutTable = gui.loadObjects(Main)\
- mainLayoutTable.mainBgColor = gui.BackgroundColor.new({color = Settings.bgColor})\
- \
- --QuickSettings--\
- quickSettingsLayoutTable = {}\
- quickSettingsLayoutTable.Text = {}\
- quickSettingsLayoutTable = gui.loadObjects(QuickSettings)\
- quickSettingsLayoutTable.quickSettingsBgColor = gui.BackgroundColor.new({color = MatchingColors[Settings.bgColor][\"quickSettings\"]})\
- \
- --Initializing structures--\
- --Main--\
- for i,v in pairs(mainLayoutTable.Button) do\
- mainLayout:addButton(mainLayoutTable.Button[i]:returnData())\
- end\
- for i,v in pairs(mainLayoutTable.BetterPaint) do\
- mainLayout:addBetterPaint(mainLayoutTable.BetterPaint[i]:returnData())\
- end\
- mainLayout:addBackgroundColor(mainLayoutTable.mainBgColor:returnData())\
- \
- --QuickSettings--\
- for i,v in pairs(quickSettingsLayoutTable.Button) do\
- quickSettingsLayout:addButton(quickSettingsLayoutTable.Button[i]:returnData())\
- end\
- quickSettingsLayout:addBackgroundColor(quickSettingsLayoutTable.quickSettingsBgColor:returnData())\
- quickSettingsLayout:addBetterPaint(quickSettingsLayoutTable.BetterPaint.Restart)\
- quickSettingsLayout:addBetterPaint(quickSettingsLayoutTable.BetterPaint.Shutdown)\
- quickSettingsLayout:addBetterPaint(quickSettingsLayoutTable.BetterPaint.Settings)\
- quickSettingsLayout:addKey(quickSettingsLayoutTable.Key.R:returnData())\
- quickSettingsLayout:addKey(quickSettingsLayoutTable.Key.S:returnData())\
- quickSettingsLayout:addKey(quickSettingsLayoutTable.Key.LeftAlt:returnData())\
- end\
- \
- local function changeColor(color)\
- Settings.bgColor = colors[color] or colors.green\
- local f = fs.open(programPath..\"Settings\",\"w\")\
- f.write(textutilsserialize(Settings))\
- f.close()\
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- loadObjects()\
- InitializeGUI()\
- end\
- \
- --Loading settings--\
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- \
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- \
- \
- \
- loadObjects()\
- loadGUI()\
- InitializeGUI()\
- \
- \
- --Code--\
- while true do\
- mainLayout:draw(0,scroll)\
- local result = gui.eventHandler(mainLayout)\
- if result[1] == \"Button\" then\
- if result[2] == \"quickSettings\" then\
- quickSettingsLayout:draw()\
- local notClose = true\
- while notClose do\
- local answer = gui.eventHandler(quickSettingsLayout)\
- if answer[1] == \"Button\" then\
- if answer[2] == \"reboot\" then\
- os.reboot()\
- elseif answer[2] == \"shutdown\" then\
- os.shutdown()\
- elseif answer[2] == \"Close\" then\
- notClose = false\
- elseif answer[2] == \"settings\" then\
- System.newTask(\"Settings\",\"Settings\")\
- notClose = false\
- elseif answer[2] == \"Refresh\" then\
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- loadObjects()\
- InitializeGUI()\
- notClose = false\
- else\
- local buffer = split(answer[2],\"[^:]+\")\
- changeColor(buffer[2])\
- notClose = false\
- end\
- elseif answer[1] == \"Nil\" then\
- if answer[2] == \"Nil\" then\
- notClose = false\
- end\
- end\
- end\
- elseif result[2] == \"windowPlus\" then\
- scroll = scroll - 51\
- elseif result[2] == \"windowMinus\" then\
- scroll = scroll + 51\
- else\
- System.newTask(result[2],result[2])\
- end\
- end\
- end",
- Data = {
- Settings = "{\
- bgColor = 1024,\
- }",
- QuickSettings = {
- [ "restart.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- },\
- {\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- },\
- {\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- },\
- {\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- },\
- [ 10 ] = {},\
- }",
- [ "settings.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- },\
- }",
- [ "shutdown.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- },\
- {\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- },\
- [ 0 ] = {\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- },\
- }",
- },
- MatchingColors = "{\
- [ 8192 ] = {\
- name = \"green\",\
- quickSettings = 32,\
- mainButtons = 1,\
- },\
- [ 4096 ] = {\
- name = \"brown\",\
- quickSettings = 2,\
- mainButtons = 1,\
- },\
- [ 32768 ] = {\
- name = \"black\",\
- quickSettings = 128,\
- mainButtons = 1,\
- },\
- [ 64 ] = {\
- name = \"pink\",\
- quickSettings = 16384,\
- mainButtons = 1,\
- },\
- [ 16 ] = {\
- name = \"yellow\",\
- quickSettings = 1,\
- mainButtons = 32768,\
- },\
- [ 2 ] = {\
- name = \"orange\",\
- quickSettings = 4096,\
- mainButtons = 1,\
- },\
- [ 4 ] = {\
- name = \"magenta\",\
- quickSettings = 1024,\
- mainButtons = 1,\
- },\
- [ 1024 ] = {\
- name = \"purple\",\
- quickSettings = 4,\
- mainButtons = 1,\
- },\
- [ 512 ] = {\
- name = \"cyan\",\
- quickSettings = 8,\
- mainButtons = 1,\
- },\
- [ 16384 ] = {\
- name = \"red\",\
- quickSettings = 64,\
- mainButtons = 1,\
- },\
- [ 1 ] = {\
- name = \"white\",\
- quickSettings = 128,\
- mainButtons = 32768,\
- },\
- [ 8 ] = {\
- name = \"lightBlue\",\
- quickSettings = 2048,\
- mainButtons = 32768,\
- },\
- [ 256 ] = {\
- name = \"lightGray\",\
- quickSettings = 1,\
- mainButtons = 1,\
- },\
- [ 128 ] = {\
- name = \"gray\",\
- quickSettings = 256,\
- mainButtons = 1,\
- },\
- [ 32 ] = {\
- name = \"lime\",\
- quickSettings = 8192,\
- mainButtons = 1,\
- },\
- [ 2048 ] = {\
- name = \"blue\",\
- quickSettings = 8,\
- mainButtons = 1,\
- },\
- }",
- MatchingColorsT = "green 8192\
- brown 4096\
- black 32768\
- pink 64\
- yellow 16\
- orange 2\
- magenta 4\
- purple 1024\
- cyan 512\
- red 16384\
- white 1\
- lightBlue 8\
- lightGray 256\
- gray 128\
- lime 32\
- blue 2048",
- Shortcuts = "{\
- {\
- xPos = 7,\
- yPos = 3,\
- path = \"OmniOS/Programs/FileX.app/FileX\",\
- name = \"FileX\",\
- },\
- {\
- xPos = 2,\
- yPos = 1,\
- path = \"OmniOS/Programs/nPaintPro.app/nPaintPro\",\
- name = \"nPaintPro\"\
- },\
- {\
- xPos = 2,\
- yPos = 3,\
- path = \"OmniOS/Programs/Aware.app/Aware\",\
- name = \"Aware\"\
- },\
- {\
- xPos = 3,\
- yPos = 1,\
- path = \"OmniOS/Programs/BetterPaint.app/BetterPaint\",\
- name = \"BetterPaint\"\
- },\
- {\
- xPos = 2,\
- yPos = 2,\
- path = \"OmniOS/Programs/Edit.app/Edit\",\
- name = \"Edit\"\
- },\
- {\
- xPos = 3,\
- yPos = 2,\
- path = \"OmniOS/Programs/Shell.app/Shell\",\
- name = \"Shell\"\
- },\
- {\
- xPos = 1,\
- yPos = 1,\
- path = \"OmniOS/Programs/Calculator.app/Calculator\",\
- name = \"Calculator\"\
- },\
- }",
- Layouts = {
- [ "Main.layout" ] = "local function loadShortcuts()\
- local buffer = readFile(programPath..\"Shortcuts\")\
- local sBuffer = textutilsunserialize(buffer)\
- local nBuffer = {}\
- paths = {}\
- for i,v in pairs(sBuffer) do\
- nBuffer[v.name] = {\
- xPos = 2+(6*(v.xPos-1)),\
- yPos = 1+(5*(v.yPos-1)),\
- name = v.name,\
- path = v.path..\".ico\",\
- yLength = 4,\
- xLength = 3,\
- returnValue = v.name,\
- label = string.sub(v.name,1,5),\
- labelFg = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- labelBg = Settings.bgColor,\
- moveY = true,\
- }\
- paths[v.name] = v.path\
- end\
- Main.BetterPaint = nBuffer\
- end\
- \
- Main.Button = {\
- quickSettings = {\
- name = \"quickSettings\",\
- label = \"^\",\
- xPos = 1,\
- yPos = h,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- bgColor = Settings.bgColor,\
- returnValue = \"quickSettings\",\
- },\
- windowPlus = {\
- name = \"windowPlus\",\
- label = \">\",\
- xPos = w,\
- yPos = 1,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- bgColor = Settings.bgColor,\
- returnValue = \"windowPlus\",\
- },\
- windowMinus = {\
- name = \"windowMinus\",\
- label = \"<\",\
- xPos = 1,\
- yPos = 1,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- bgColor = Settings.bgColor,\
- returnValue = \"windowMinus\",\
- },\
- }",
- },
- },
- },
- [ "Aware.app" ] = {
- [ "permission.data" ] = "user",
- [ "Aware.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 2,\
- \"_\",\
- 1,\
- },\
- {\
- 2,\
- \"U\",\
- 1,\
- },\
- {\
- 2,\
- \"_\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"_\",\
- 1,\
- },\
- {\
- 2,\
- \"U\",\
- 1,\
- },\
- {\
- 2,\
- \"_\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \" \",\
- 1,\
- },\
- {\
- 2,\
- \" \",\
- 1,\
- },\
- {\
- 2,\
- \"/\",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 1,\
- },\
- {\
- 2,\
- \"\\\\\",\
- 1,\
- },\
- },\
- }",
- Data = {
- UselessWords = "what\
- is\
- the\
- it",
- Commands = "{\
- shutdown = \"os.shutdown()\",\
- reboot = \"os.reboot()\",\
- time = \"print(\\\"The time is \\\"..textutils.formatTime(os.time()))\",\
- hi = \"redirect(\\\"hello\\\")\",\
- hello = \"randomElement(wordSet(\\\"Greetings\\\"))\",\
- exit = \"error(\\\"Thanks for using this thingy thingy!\\\")\",\
- shutup = \"redirect(\\\"exit\\\")\",\
- }",
- [ "Aware.layout" ] = "--[[\
- The Aware Project\
- by Creator\
- for TheOS\
- ]]--\
- \
- local layout = {}\
- \
- layout.",
- },
- [ "Main.lua" ] = "--[[\
- The Aware Project\
- by Creator\
- for TheOS\
- ]]--\
- --[[\
- First I am doing the mechanics of the program, afterwards I will do the GUI\
- ]]--\
- \
- --GUI\
- --if _G.Interact == nil then os.loadAPI(\"TheOS/API/Interact\") end\
- --local gui = Interact.Initialize()\
- \
- --Variables--\
- local input = {}\
- local Commands = {}\
- local path = \"TheOS/Programs/Aware.app/\"\
- local UselessWords = {}\
- --Functions--\
- \
- function split(str,sep)\
- local buffer = {}\
- for token in str:gmatch(sep) do\
- buffer[#buffer+1] = token\
- end\
- return buffer\
- end\
- \
- function getData()\
- local var = http.get(\"https://raw.githubusercontent.com/TheOnlyCreator/Aware/master/Test/Test\")\
- print(var.readAll())\
- os.pullEvent()\
- error()\
- end\
- \
- local function readFile(_path)\
- local file = fs.open(_path,\"r\")\
- local data = file.readAll()\
- file.close()\
- return data\
- end\
- \
- function filter(input)\
- local buffer = {}\
- for i,v in pairs(input) do\
- if UselessWords[v] == true then\
- buffer[#buffer+1] = i\
- end\
- end\
- for i,v in pairs(buffer) do\
- input[i] = nil\
- end\
- buffer = {}\
- for i,v in pairs(input) do\
- local sBuffer = {}\
- local f = \"\"\
- for token in string.gmatch(v,\"[%a]+\") do\
- sBuffer[#sBuffer+1] = token\
- end\
- for i,v in pairs(sBuffer) do\
- f = f..v\
- end\
- buffer[#buffer+1] = f\
- end\
- return buffer\
- end\
- \
- function redirect(word)\
- word = string.lower(word)\
- oneWordCommand(word)\
- end\
- \
- function wordSet(arg)\
- local fromWeb = http.get(\"https://raw.githubusercontent.com/CodingRevolution/Aware/master/WordSets/\"..arg)\
- local buffer = fromWeb.readAll()\
- return split(buffer,\"[^\\n]+\")\
- end\
- \
- function randomElement(input)\
- local element\
- local buffer = {}\
- for i,v in pairs(input) do\
- buffer[#buffer+1] = i\
- end\
- local rnd = buffer[math.random(1,#buffer)]\
- return input[rnd]\
- end\
- \
- function oneWordCommand(word)\
- if Commands[word] ~= nil then\
- local func = loadstring(Commands[word])\
- setfenv(func, getfenv())\
- func()\
- else\
- local firstLetter = string.sub(word,1,1)\
- print(firstLetter)\
- print(word)\
- local fromWeb = http.get(\"https://raw.githubusercontent.com/CodingRevolution/Aware/master/Actions/\"..firstLetter)\
- local buffer = fromWeb.readAll()\
- local tableFromWeb = textutils.unserialize(buffer)\
- print(tableFromWeb[word])\
- local func = loadstring(tableFromWeb[word])\
- setfenv(func, getfenv())\
- func()\
- end\
- end\
- \
- function main()\
- print(\"I am listening...\")\
- local buffer = read()\
- input = split(buffer,\"[^%s]+\")\
- for i,v in pairs(input) do\
- input[i] = string.lower(v)\
- end\
- if #input == 1 then\
- oneWordCommand(input[1])\
- else\
- oneWordCommand(filter(input)[1])\
- end\
- end\
- \
- \
- --Code--\
- local buffer = readFile(path..\"Commands\")\
- Commands = textutils.unserialize(buffer)\
- \
- local buffer = readFile(path..\"UselessWords\")\
- buffer = split(buffer,\"[^\\n]+\")\
- for i,v in pairs(buffer) do\
- UselessWords[v] = true\
- end\
- \
- term.setCursorPos(1,1)\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.white)\
- term.clear()\
- \
- while true do\
- main()\
- end",
- },
- [ "Settings.app" ] = {
- [ "permission.data" ] = "admin",
- [ "Settings.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- }",
- [ "Main.lua" ] = "--[[\
- Settings app\
- by Creator\
- for OmniOS\
- ]]--\
- \
- --variables--\
- local w,h = term.getSize()\
- local MainLayoutTable = {}\
- local path = \"OmniOS/Programs/Settings.app/Data/\"\
- \
- --functions--\
- local loadLayout = function(sPath,...)\
- local func = loadfile(sPath,...)\
- return func()\
- end\
- \
- local function changeColor(color)\
- local f = fs.open(\"OmniOS/Programs/Desktop.app/Data/Settings\",\"r\")\
- local Settings = textutils.unserialize(f.readAll())\
- print(f.readAll())\
- f.close()\
- Settings.bgColor = colors[color] or colors.green\
- local f = fs.open(\"OmniOS/Programs/Desktop.app/Data/Settings\",\"w\")\
- f.write(textutils.serialize(Settings))\
- f.close()\
- end\
- \
- local function split(str,sep)\
- local buffer = {}\
- for token in str:gmatch(sep) do\
- buffer[#buffer+1] = token\
- end\
- return buffer\
- end\
- \
- local function drawPrograms()\
- local tRawPrograms = fs.list(\"OmniOS/Programs\")\
- local tPrograms = {}\
- for i,v in pairs(tRawPrograms) do\
- tPrograms[#tPrograms+1] = string.match(v,\"[^.]+\")\
- end\
- local SelectLayout = gui.Layout.new({xPos = 1,\
- yPos = h-#tPrograms,\
- xLength = 15,\
- yLength = #tPrograms})\
- SelectLayoutTable = gui.loadObjects(loadLayout(path..\"Layouts/Select.layout\",tPrograms))\
- gui.loadLayout(SelectLayoutTable,SelectLayout)\
- SelectLayout:addBackgroundColor({color = colors.white})\
- SelectLayout:draw()\
- SelectLayoutEvent = gui.eventHandler(SelectLayout)\
- end\
- \
- --Code--\
- os.loadAPI(\"OmniOS/API/Interact\")\
- local gui = Interact.Initialize()\
- \
- --Layouts--\
- local MainLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- local DesktopLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- local SecurityLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- local ShortcutsLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- \
- --MainLayout--\
- local MainLayoutTable = gui.loadObjects(loadLayout(path..\"Layouts/Main.layout\"))\
- gui.loadLayout(MainLayoutTable,MainLayout)\
- MainLayout:addBackgroundColor({color = colors.white})\
- \
- --Desktop Layout--\
- local DesktopLayoutTable = gui.loadObjects(loadLayout(path..\"Layouts/Desktop.layout\"))\
- gui.loadLayout(DesktopLayoutTable,DesktopLayout)\
- DesktopLayout:addBackgroundColor({color = colors.white})\
- \
- --SecurityLayout--\
- local SecurityLayoutTable = gui.loadObjects(loadLayout(path..\"Layouts/Security.layout\"))\
- gui.loadLayout(SecurityLayoutTable,SecurityLayout)\
- SecurityLayout:addBackgroundColor({color = colors.white})\
- \
- --Desktop Shortcuts Layout\
- local ShortcutsLayoutTable = gui.loadObjects(loadLayout(path..\"Layouts/Shortcuts.layout\"))\
- gui.loadLayout(ShortcutsLayoutTable,ShortcutsLayout)\
- ShortcutsLayout:addBackgroundColor({color = colors.white})\
- \
- --Select Layout\
- local SelectLayoutTable = {}\
- \
- \
- while true do\
- MainLayout:draw()\
- local MainLayoutEvent = gui.eventHandler(MainLayout)\
- if MainLayoutEvent[1] == \"Button\" then\
- if MainLayoutEvent[2] == \"Desktop\" then\
- local notClose = true\
- while notClose do\
- DesktopLayout:draw()\
- DesktopLayoutEvent = gui.eventHandler(DesktopLayout)\
- if DesktopLayoutEvent[1] == \"Button\" then\
- if DesktopLayoutEvent[2] == \"Done\" then\
- notClose = false\
- elseif DesktopLayoutEvent[2] == \"Shortcuts\" then\
- while true do\
- ShortcutsLayout:draw()\
- ShortcutsLayoutEvent = gui.eventHandler(ShortcutsLayout)\
- if ShortcutsLayoutEvent[1] == \"Button\" then\
- if ShortcutsLayoutEvent[2] == \"Add\" then\
- drawPrograms()\
- elseif ShortcutsLayoutEvent[2] == \"Done\" then\
- break\
- end\
- elseif ShortcutsLayoutEvent[1] == \"BeterPaint\" then\
- \
- end\
- end\
- notClose = false\
- else\
- local buffer = split(DesktopLayoutEvent[2],\"[^:]+\")\
- print(DesktopLayoutEvent[2])\
- changeColor(buffer[2])\
- end\
- end\
- end\
- elseif MainLayoutEvent[2] == \"Security\" then\
- local notClose = true\
- while notClose do\
- SecurityLayout:draw()\
- SecurityLayoutEvent = gui.eventHandler(SecurityLayout)\
- if SecurityLayoutEvent[1] == \"TextBox\" then\
- if SecurityLayoutEvent[2] == \"Password\" then\
- local newPass = SecurityLayout.TextBox.Password:read()\
- local file = fs.open(\"OmniOS/Settings/Users/Admin\",\"w\")\
- file.write(Sha.sha256(newPass))\
- file.close()\
- end\
- elseif SecurityLayoutEvent[1] == \"Button\" then\
- if SecurityLayoutEvent[2] == \"Done\" then\
- notClose = false\
- end\
- end\
- end\
- elseif MainLayoutEvent[2] == \"Close\" then\
- break\
- end\
- end\
- end",
- Data = {
- Layouts = {
- [ "Shortcuts.layout" ] = "local w,h = term.getSize()\
- local programPath = \"OmniOS/Programs/Desktop.app/Data/\"\
- \
- MainTable = {\
- Button = {\
- Done = {\
- name = \"Done\",\
- label = \"Done\",\
- xPos = w-3,\
- yPos = h,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 4,\
- yLength = 1,\
- returnValue = \"Done\",\
- xTextPos = 1,\
- yTextPos = 1,\
- },\
- Add = {\
- name = \"Add\",\
- label = \"+\",\
- xPos = 1,\
- yPos = h,\
- fgColor = colors.black,\
- bgColor = colors.white,\
- xLength = 11,\
- yLength = 3,\
- returnValue = \"Add\",\
- xTextPos = 1,\
- yTextPos = 1,\
- },\
- },\
- }\
- \
- local function readFile(_path)\
- local file = fs.open(_path,\"r\")\
- local data = file.readAll()\
- file.close()\
- return data\
- end\
- \
- local function loadShortcuts()\
- local buffer = readFile(programPath..\"Shortcuts\")\
- local sBuffer = textutils.unserialize(buffer)\
- local nBuffer = {}\
- paths = {}\
- for i,v in pairs(sBuffer) do\
- nBuffer[v.name] = {\
- xPos = 2+(6*(v.xPos-1)),\
- yPos = 1+(5*(v.yPos-1)),\
- name = v.name,\
- path = v.path..\".ico\",\
- yLength = 4,\
- xLength = 3,\
- returnValue = v.name,\
- label = string.sub(v.name,1,5),\
- labelFg = colors.black,\
- labelBg = colors.white,\
- moveY = true,\
- }\
- paths[v.name] = v.path\
- end\
- MainTable.BetterPaint = nBuffer\
- end\
- \
- loadShortcuts()\
- \
- return MainTable",
- [ "Select.layout" ] = "local tArgs = {...}\
- local w,h = term.getSize()\
- local tReturnTable = {\
- Button = {},\
- Text = {\
- Title = {\
- name = \"Title\",\
- text = \"Select\",\
- xPos = 1,\
- yPos = 1,\
- bgColor = colors.gray,\
- fgColor = colors.white,\
- },\
- }\
- }",
- [ "Desktop.layout" ] = "local w,h = term.getSize()\
- MainTable = {\
- ColorField = {\
- Top = {\
- name = \"Top\",\
- xPos = 1,\
- yPos = 1,\
- xLength = w,\
- yLength = 3,\
- color = colors.orange,\
- \
- },\
- },\
- Button = {\
- Done = {\
- name = \"Done\",\
- label = \"Done\",\
- xPos = w-6,\
- yPos = h-3,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 6,\
- yLength = 3,\
- returnValue = \"Done\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Shortcuts = {\
- name = \"Shortcuts\",\
- label = \"Shortcuts\",\
- xPos = 3,\
- yPos = h-3,\
- fgColor = colors.white,\
- bgColor = colors.cyan,\
- xLength = 11,\
- yLength = 3,\
- returnValue = \"Shortcuts\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Green = {\
- name = \"Green\",\
- label = \" \",\
- xPos = w-3,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.green,\
- returnValue = \"color:green\",\
- },\
- Lime = {\
- name = \"Lime\",\
- label = \" \",\
- xPos = w-4,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.lime,\
- returnValue = \"color:lime\",\
- },\
- Brown = {\
- name = \"Brown\",\
- label = \" \",\
- xPos = w-5,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.brown,\
- returnValue = \"color:brown\",\
- },\
- Purple = {\
- name = \"Purple\",\
- label = \" \",\
- xPos = w-6,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.purple,\
- returnValue = \"color:purple\",\
- },\
- Blue = {\
- name = \"Blue\",\
- label = \" \",\
- xPos = w-7,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.blue,\
- returnValue = \"color:blue\",\
- },\
- lightBlue = {\
- name = \"lightBlue\",\
- label = \" \",\
- xPos = w-8,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.lightBlue,\
- returnValue = \"color:lightBlue\",\
- },\
- Yellow = {\
- name = \"Yellow\",\
- label = \" \",\
- xPos = w-9,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.yellow,\
- returnValue = \"color:yellow\",\
- },\
- Cyan = {\
- name = \"Cyan\",\
- label = \" \",\
- xPos = w-10,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.cyan,\
- returnValue = \"color:cyan\",\
- },\
- Orange = {\
- name = \"Orange\",\
- label = \" \",\
- xPos = w-11,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.orange,\
- returnValue = \"color:orange\",\
- },\
- Pink = {\
- name = \"Pink\",\
- label = \" \",\
- xPos = w-12,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.pink,\
- returnValue = \"color:pink\",\
- },\
- Red = {\
- name = \"Red\",\
- label = \" \",\
- xPos = w-13,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.red,\
- returnValue = \"color:red\",\
- },\
- Magenta = {\
- name = \"Magenta\",\
- label = \" \",\
- xPos = w-14,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.magenta,\
- returnValue = \"color:magenta\",\
- },\
- White = {\
- name = \"White\",\
- label = \" \",\
- xPos = w-15,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.white,\
- returnValue = \"color:white\",\
- },\
- lightGray = {\
- name = \"lightGray\",\
- label = \" \",\
- xPos = w-16,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.lightGray,\
- returnValue = \"color:lightGray\",\
- },\
- Black = {\
- name = \"Black\",\
- label = \" \",\
- xPos = w-17,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.black,\
- returnValue = \"color:black\",\
- },\
- Gray = {\
- name = \"Gray\",\
- label = \" \",\
- xPos = w-18,\
- yPos = 5,\
- xLength = 1,\
- yLength = 1,\
- xTextPos = 1,\
- yTextPos = 1,\
- fgColor = 1,\
- bgColor = colors.gray,\
- returnValue = \"color:gray\",\
- },\
- },\
- Text = {\
- Color = {\
- name = \"Color\",\
- text = \"Desktop Color\",\
- xPos = 3,\
- yPos = 5,\
- bgColor = colors.white,\
- fgColor = colors.black,\
- },\
- Title = {\
- name = \"Title\",\
- text = \"Settings/Desktop\",\
- xPos = 2,\
- yPos = 2,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- },\
- },\
- }\
- return MainTable",
- [ "Security.layout" ] = "local w,h = term.getSize()\
- MainTable = {\
- ColorField = {\
- Top = {\
- name = \"Top\",\
- xPos = 1,\
- yPos = 1,\
- xLength = w,\
- yLength = 3,\
- color = colors.orange,\
- \
- },\
- },\
- Text = {\
- Title = {\
- name = \"Title\",\
- text = \"Settings/Security\",\
- xPos = 2,\
- yPos = 2,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- },\
- Password = {\
- name = \"Password\",\
- text = \"Password\",\
- xPos = 2,\
- yPos = 5,\
- fgColor = colors.black,\
- bgColor = colors.white,\
- },\
- },\
- TextBox = {\
- Password = {\
- name = \"Password\",\
- helpText = \"Change password...\",\
- xPos = 20,\
- yPos = 5,\
- xLength = 30,\
- yLength = 1,\
- bgColor = colors.lightGray,\
- fgColor = colors.black,\
- helpFgColor = colors.gray,\
- charLimit = 4,\
- confidential = true,\
- returnValue = \"Password\",\
- }\
- },\
- Button = {\
- Done = {\
- name = \"Done\",\
- label = \"Done\",\
- xPos = w-6,\
- yPos = h-3,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 6,\
- yLength = 3,\
- returnValue = \"Done\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- },\
- }\
- return MainTable",
- [ "Main.layout" ] = "local w,h = term.getSize()\
- MainTable = {\
- ColorField = {\
- Top = {\
- name = \"Top\",\
- xPos = 1,\
- yPos = 1,\
- xLength = w,\
- yLength = 3,\
- color = colors.orange,\
- },\
- },\
- Button = {\
- Desktop = {\
- name = \"Desktop\",\
- label = \"Desktop\",\
- xPos = 2,\
- yPos = 5,\
- fgColor = colors.white,\
- bgColor = colors.blue,\
- xLength = 11,\
- yLength = 3,\
- returnValue = \"Desktop\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Security = {\
- name = \"Security\",\
- label = \"Security\",\
- xPos = 2,\
- yPos = 9,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 11,\
- yLength = 3,\
- returnValue = \"Security\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Close = {\
- name = \"Close\",\
- label = \"x\",\
- xPos = w-2,\
- yPos = 2,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 1,\
- yLength = 1,\
- returnValue = \"Close\",\
- xTextPos = 1,\
- yTextPos = 1,\
- },\
- },\
- Text = {\
- Title = {\
- name = \"Title\",\
- text = \"TheOS Settings\",\
- xPos = 2,\
- yPos = 2,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- },\
- },\
- }\
- return MainTable",
- },
- },
- },
- [ "Test.app" ] = {
- [ "Main.lua" ] = "local tArgs = {...}\
- while true do\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.white)\
- term.clear()\
- term.setCursorPos(1,1)\
- print(\"Protocol is initializng...\")\
- if System then \
- print(\"System API has been loaded..\")\
- print(\"The available methods are:\")\
- for i,v in pairs(System) do\
- print(\" - \"..i)\
- end\
- print(\"Done\")\
- else\
- print(\"System API has not been loaded..\")\
- end\
- print(tArgs[1])\
- os.pullEvent()\
- System.newTask(\"Edit\",\"Edit\",\"TheOS_15w14b\")\
- end",
- },
- [ "Shell.app" ] = {
- [ "Main.lua" ] = "--[[\
- Modified version of Shell\
- ]]--\
- \
- local multishell = multishell\
- local parentShell = shell\
- local parentTerm = term.current()\
- \
- if multishell then\
- multishell.setTitle( multishell.getCurrent(), \"shell\" )\
- end\
- \
- local bExit = false\
- local sDir = (parentShell and parentShell.dir()) or \"\"\
- local sPath = (parentShell and parentShell.path()) or \".:/rom/programs\"\
- local tAliases = (parentShell and parentShell.aliases()) or {}\
- local tProgramStack = {}\
- \
- local shell = {}\
- local tEnv = {\
- [ \"shell\" ] = shell,\
- [ \"multishell\" ] = multishell,\
- }\
- \
- -- Colours\
- local promptColour, textColour, bgColour\
- if term.isColour() then\
- promptColour = colours.yellow\
- textColour = colours.white\
- bgColour = colours.black\
- else\
- promptColour = colours.white\
- textColour = colours.white\
- bgColour = colours.black\
- end\
- \
- term.setBackgroundColor(bgColour)\
- term.clear()\
- \
- local function run( _sCommand, ... )\
- local sPath = shell.resolveProgram( _sCommand )\
- if sPath ~= nil then\
- tProgramStack[#tProgramStack + 1] = sPath\
- if multishell then\
- multishell.setTitle( multishell.getCurrent(), fs.getName( sPath ) )\
- end\
- local result = os.run( tEnv, sPath, ... )\
- tProgramStack[#tProgramStack] = nil\
- if multishell then\
- if #tProgramStack > 0 then\
- multishell.setTitle( multishell.getCurrent(), fs.getName( tProgramStack[#tProgramStack] ) )\
- else\
- multishell.setTitle( multishell.getCurrent(), \"shell\" )\
- end\
- end\
- return result\
- else\
- printError( \"No such program\" )\
- return false\
- end\
- end\
- \
- local function tokenise( ... )\
- local sLine = table.concat( { ... }, \" \" )\
- local tWords = {}\
- local bQuoted = false\
- for match in string.gmatch( sLine .. \"\\\"\", \"(.-)\\\"\" ) do\
- if bQuoted then\
- table.insert( tWords, match )\
- else\
- for m in string.gmatch( match, \"[^ \\t]+\" ) do\
- table.insert( tWords, m )\
- end\
- end\
- bQuoted = not bQuoted\
- end\
- return tWords\
- end\
- \
- -- Install shell API\
- function shell.run( ... )\
- local tWords = tokenise( ... )\
- local sCommand = tWords[1]\
- if sCommand then\
- return run( sCommand, unpack( tWords, 2 ) )\
- end\
- return false\
- end\
- \
- function shell.exit()\
- bExit = true\
- end\
- \
- function shell.dir()\
- return sDir\
- end\
- \
- function shell.setDir( _sDir )\
- sDir = _sDir\
- end\
- \
- function shell.path()\
- return sPath\
- end\
- \
- function shell.setPath( _sPath )\
- sPath = _sPath\
- end\
- \
- function shell.resolve( _sPath )\
- local sStartChar = string.sub( _sPath, 1, 1 )\
- if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
- return fs.combine( \"\", _sPath )\
- else\
- return fs.combine( sDir, _sPath )\
- end\
- end\
- \
- function shell.resolveProgram( _sCommand )\
- -- Substitute aliases firsts\
- if tAliases[ _sCommand ] ~= nil then\
- _sCommand = tAliases[ _sCommand ]\
- end\
- \
- -- If the path is a global path, use it directly\
- local sStartChar = string.sub( _sCommand, 1, 1 )\
- if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
- local sPath = fs.combine( \"\", _sCommand )\
- if fs.exists( sPath ) and not fs.isDir( sPath ) then\
- return sPath\
- end\
- return nil\
- end\
- \
- -- Otherwise, look on the path variable\
- for sPath in string.gmatch(sPath, \"[^:]+\") do\
- sPath = fs.combine( shell.resolve( sPath ), _sCommand )\
- if fs.exists( sPath ) and not fs.isDir( sPath ) then\
- return sPath\
- end\
- end\
- \
- -- Not found\
- return nil\
- end\
- \
- function shell.programs( _bIncludeHidden )\
- local tItems = {}\
- \
- -- Add programs from the path\
- for sPath in string.gmatch(sPath, \"[^:]+\") do\
- sPath = shell.resolve( sPath )\
- if fs.isDir( sPath ) then\
- local tList = fs.list( sPath )\
- for n,sFile in pairs( tList ) do\
- if not fs.isDir( fs.combine( sPath, sFile ) ) and\
- (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= \".\") then\
- tItems[ sFile ] = true\
- end\
- end\
- end\
- end \
- \
- -- Sort and return\
- local tItemList = {}\
- for sItem, b in pairs( tItems ) do\
- table.insert( tItemList, sItem )\
- end\
- table.sort( tItemList )\
- return tItemList\
- end\
- \
- if multishell then\
- function shell.openTab( ... )\
- local tWords = tokenise( ... )\
- local sCommand = tWords[1]\
- if sCommand then\
- local sPath = shell.resolveProgram( sCommand )\
- if sPath == \"rom/programs/shell\" then\
- return multishell.launch( tEnv, sPath, unpack( tWords, 2 ) )\
- elseif sPath ~= nil then\
- return multishell.launch( tEnv, \"rom/programs/shell\", sPath, unpack( tWords, 2 ) )\
- else\
- printError( \"No such program\" )\
- end\
- end\
- end\
- \
- function shell.switchTab( nID )\
- multishell.setFocus( nID )\
- end\
- end\
- \
- local tArgs = { ... }\
- if #tArgs > 0 then\
- -- \"shell x y z\"\
- -- Run the program specified on the commandline\
- shell.run( ... )\
- \
- else\
- -- \"shell\"\
- -- Print the header\
- term.setBackgroundColor( bgColour )\
- term.setTextColour( promptColour )\
- print( os.version() )\
- term.setTextColour( textColour )\
- \
- -- Read commands and execute them\
- local tCommandHistory = {}\
- while not bExit do\
- term.redirect( parentTerm )\
- term.setBackgroundColor( bgColour )\
- term.setTextColour( promptColour )\
- write( shell.dir() .. \"> \" )\
- term.setTextColour( textColour )\
- \
- local sLine = read( nil, tCommandHistory )\
- table.insert( tCommandHistory, sLine )\
- shell.run( sLine )\
- end\
- end",
- [ "permission.data" ] = "user",
- [ "Shell.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 32768,\
- \"_\",\
- 1,\
- },\
- {\
- 32768,\
- \" \",\
- 128,\
- },\
- {\
- 32768,\
- \" \",\
- 128,\
- },\
- },\
- {\
- {\
- 32768,\
- \" \",\
- 16,\
- },\
- {\
- 32768,\
- \" \",\
- 128,\
- },\
- {\
- 32768,\
- \" \",\
- 128,\
- },\
- },\
- {\
- {\
- 32768,\
- \" \",\
- 16,\
- },\
- {\
- 32768,\
- \" \",\
- 128,\
- },\
- {\
- 32768,\
- \" \",\
- 128,\
- },\
- },\
- [ 0 ] = {\
- {\
- 32768,\
- \">\",\
- 16,\
- },\
- {\
- 32768,\
- \" \",\
- 128,\
- },\
- {\
- 32768,\
- \" \",\
- 128,\
- },\
- },\
- }",
- },
- [ "FileX.app" ] = {
- [ "permission.data" ] = "userTest",
- [ "Main.lua" ] = "--------------FileX v1.2-------------\
- ---------------Program---------------\
- --------------by Creator-------------\
- \
- --Variables--\
- term.current(term.native())\
- local copyPath = \"\"\
- local copyHelp = \"\"\
- local textutilsserialize = textutils.serialize\
- local textutilsunserialize = textutils.unserialize\
- local w, h = term.getSize()\
- local folderMenu = {\
- term.current(),\
- 16,\
- \"Folder Options\",\
- colors.white,\
- colors.blue,\
- colors.black,\
- colors.lightGray,\
- {\
- {\
- \"Open\",\
- \"open\",\
- },\
- {\
- \"Delete\",\
- \"delete\",\
- },\
- {\
- \"Rename\",\
- \"rename\",\
- },\
- {\
- \"Move\",\
- \"move\",\
- },\
- {\
- \"Copy\",\
- \"copy\",\
- },\
- {\
- \"Cancel\",\
- \"cancel\",\
- },\
- },\
- }\
- local fileMenu = {\
- term.current(),\
- 16,\
- \"File Options\",\
- colors.white,\
- colors.blue,\
- colors.black,\
- colors.lightGray,\
- {\
- {\
- \"Open\",\
- \"open\",\
- },\
- {\
- \"Delete\",\
- \"delete\",\
- },\
- {\
- \"Rename\",\
- \"rename\",\
- },\
- {\
- \"Move\",\
- \"move\",\
- },\
- {\
- \"Cancel\",\
- \"cancel\",\
- },\
- {\
- \"Run\",\
- \"run\",\
- },\
- {\
- \"Copy\",\
- \"copy\",\
- },\
- {\
- \"Open with\",\
- \"openWith\",\
- },\
- },\
- }\
- local nilMenu = {\
- term.current(),\
- 16,\
- \"Options\",\
- colors.white,\
- colors.blue,\
- colors.black,\
- colors.lightGray,\
- {\
- {\
- \"Make a folder\",\
- \"makeFolder\",\
- },\
- {\
- \"Make a file\",\
- \"makeFile\",\
- },\
- {\
- \"Cancel\",\
- \"cancel\",\
- },\
- },\
- }\
- local newFolderWindow = {\
- term.current(),\
- math.floor((w-32)/2),\
- math.floor((h-8)/2),\
- 32,\
- 8,\
- true,\
- \"New folder name\",\
- colors.white,\
- colors.blue,\
- \"Write the name of%the new folder.\",\
- colors.black,\
- colors.lightGray,\
- colors.white,\
- colors.black,\
- }\
- local newFileWindow = {\
- term.current(),\
- math.floor((w-32)/2),\
- math.floor((h-8)/2),\
- 32,\
- 8,\
- true,\
- \"New file name\",\
- colors.white,\
- colors.blue,\
- \"Write the name of%the new file.\",\
- colors.black,\
- colors.lightGray,\
- colors.white,\
- colors.black,\
- }\
- local upFileWindow = {\
- term.current(),\
- math.floor((w-32)/2),\
- math.floor((h-8)/2),\
- 32,\
- 8,\
- true,\
- \"File path\",\
- colors.white,\
- colors.blue,\
- \"Write the path of%the file.\",\
- colors.black,\
- colors.lightGray,\
- colors.white,\
- colors.black,\
- }\
- local moveFolderWindow = {\
- term.current(),\
- math.floor((w-32)/2),\
- math.floor((h-8)/2),\
- 32,\
- 8,\
- true,\
- \"New folder path\",\
- colors.white,\
- colors.blue,\
- \"Write the name of%the new folder path.\",\
- colors.black,\
- colors.lightGray,\
- colors.white,\
- colors.black,\
- }\
- local bgColor = colors.black\
- local txtColor = colors.white\
- local domain = {}\
- local currDir = \"\"\
- local files = {}\
- local Buttons = {\
- {\
- 2,\
- 2,\
- 9,\
- 1,\
- \" Refresh \",\
- colors.white,\
- colors.green,\
- \"refresh\"\
- },\
- {\
- 13,\
- 2,\
- 4,\
- 1,\
- \" Up \",\
- colors.white,\
- colors.green,\
- \"up\"\
- },\
- {\
- 19,\
- 2,\
- 7,\
- 1,\
- \" Paste \",\
- colors.white,\
- colors.green,\
- \"paste\"\
- },\
- }\
- local folderIcon = {{2,2,2,2,16,16,16,16,},{2,2,2,2,2,2,2,2,},{2,2,2,2,2,2,2,2,},{2,2,2,2,2,2,2,2,},}\
- local fileIcon = {{8192,8192,8192,8192,8192,8192,8192,8192,},{8192,8192,8192,8192,8192,8192,8192,8192,},{8192,8192,8192,8192,8192,8192,8192,8192,},{8192,8192,8192,8192,8192,8192,8192,8192,},}\
- local scroll = 0\
- local globalButtonList = {}\
- local notEnded = true\
- local fileExtensions = {\
- nfp = \"nPaintPro\",\
- nfa = \"nPaintPro\",\
- txt = \"Edit\",\
- exe = \"Shell\",\
- lua = \"Shell\",\
- ico = \"BetterPaint\",\
- }\
- \
- --Functions--\
- \
- local function detectButtonHit(buttonsToTest)\
- local event, button, x, y\
- repeat\
- event, button, x, y = os.pullEvent()\
- until event == \"mouse_click\" or event == \"key\"\
- if event == \"mouse_click\" then\
- for i,v in pairs(buttonsToTest) do\
- if v[1] <= x and x <= v[3] and v[2] <= y and y <= v[4] then\
- return {v[5], button, x, y}\
- end\
- end\
- elseif event == \"key\" then\
- return {\"key:\"..tostring(button)}\
- end\
- return {\"pong\"}\
- end\
- \
- local function mkStrShort(str,lenght,n)\
- local bufferTable = {}\
- local toReturnTable = {}\
- local lenghtN = tonumber(lenght)\
- if lenghtN == nil then return false end\
- for i = 0,n-1 do \
- bufferTable[i+1] = string.sub(tostring(str),(i*lenghtN)+1,(i*lenghtN)+lenghtN)\
- end\
- for i,v in pairs(bufferTable) do\
- if v ~= nil then\
- toReturnTable[#toReturnTable+1] = v\
- end\
- end\
- return toReturnTable\
- end\
- \
- local function clear(bgColorArg)\
- term.setBackgroundColor(bgColorArg or bgColor)\
- term.setTextColor(txtColor)\
- term.setCursorPos(1,1)\
- term.clear()\
- globalButtonList = {}\
- end\
- \
- local function dropDownMenu(tableInput,clearBg,x,y)\
- term.setCursorPos(1,1)\
- if clearBg ~= false then\
- clear(colors.cyan)\
- end\
- globalButtonList = {}\
- local nTable = {}\
- local dropDownMenuWindow = window.create(tableInput[1],x,y,tableInput[2],#tableInput[8]+1,true)\
- dropDownMenuWindow.setTextColor(tableInput[4])\
- dropDownMenuWindow.setBackgroundColor(tableInput[5])\
- dropDownMenuWindow.setCursorPos(1,1)\
- dropDownMenuWindow.clearLine()\
- dropDownMenuWindow.write(tableInput[3])\
- dropDownMenuWindow.setTextColor(tableInput[6])\
- dropDownMenuWindow.setBackgroundColor(tableInput[7])\
- for i = 1 , #tableInput[8] do\
- dropDownMenuWindow.setCursorPos(1,i+1)\
- dropDownMenuWindow.clearLine()\
- dropDownMenuWindow.write(tableInput[8][i][1])\
- globalButtonList[#globalButtonList+1] = {x+1,y+i,x+tableInput[2],y+i,tableInput[8][i][2]}\
- end\
- local result\
- repeat\
- result = detectButtonHit(globalButtonList)\
- until result[1] ~= \"pong\"\
- return result[1]\
- end\
- \
- local function dialogBox(tableInput,clearBg)\
- if clearBg ~= false then\
- clear(colors.cyan)\
- end\
- local nTable = {}\
- dialogBoxWindow = window.create(\
- tableInput[1],\
- tableInput[2],\
- tableInput[3],\
- tableInput[4],\
- tableInput[5])\
- dialogBoxWindow.setBackgroundColor(tableInput[9])\
- dialogBoxWindow.setCursorPos(2,1)\
- dialogBoxWindow.clearLine()\
- dialogBoxWindow.setTextColor(tableInput[8])\
- dialogBoxWindow.write(tableInput[7])\
- dialogBoxWindow.setCursorPos(1,2)\
- dialogBoxWindow.setBackgroundColor(tableInput[12])\
- for i = 2 , tableInput[5] do\
- dialogBoxWindow.setCursorPos(1,i)\
- dialogBoxWindow.clearLine()\
- end\
- dialogBoxWindow.setCursorPos(1,2)\
- dialogBoxWindow.setTextColor(tableInput[11])\
- for token in string.gmatch(tableInput[10],\"[^%%]+\") do\
- nTable[#nTable+1] = token\
- end\
- for i,v in pairs(nTable) do\
- dialogBoxWindow.setCursorPos(2,1+i)\
- dialogBoxWindow.write(v)\
- end\
- local totalLenght = 0\
- globalButtonList = {}\
- for i,v in pairs(tableInput[13]) do\
- dialogBoxWindow.setCursorPos(2+totalLenght,tableInput[5]-1)\
- dialogBoxWindow.setTextColor(v[2])\
- dialogBoxWindow.setBackgroundColor(v[3])\
- local toWrite = \" \"..v[1]..\" \"\
- dialogBoxWindow.write(toWrite)\
- if globalButtonList == nil then\
- globalButtonList = {{tableInput[2]+1+totalLenght,tableInput[3] + tableInput[5]-2,tableInput[2]+totalLenght + #toWrite,tableInput[3] + tableInput[5]-1,v[4]}}\
- else\
- globalButtonList[#globalButtonList+1] = {tableInput[2]+1+totalLenght,tableInput[3] + tableInput[5]-2,tableInput[2]+totalLenght + #toWrite,tableInput[3] + tableInput[5]-1,v[4]}\
- end\
- totalLenght = #toWrite + totalLenght + 2\
- end\
- local repeatIt = true\
- while repeatIt == true do\
- local unparsedResult = detectButtonHit(globalButtonList)\
- result = unparsedResult[1]\
- if result ~= \"pong\" then\
- repeatIt = false\
- end\
- end\
- return result\
- end\
- \
- local function textBox(tableInput,secret,clearBg)\
- if clearBg ~= false then\
- clear(colors.cyan)\
- end\
- local nTable = {}\
- textBoxWindow = window.create(tableInput[1],tableInput[2],tableInput[3],tableInput[4],tableInput[5])\
- textBoxWindow.setCursorPos(2,1)\
- textBoxWindow.setBackgroundColor(tableInput[9])\
- textBoxWindow.clearLine()\
- textBoxWindow.setTextColor(tableInput[8])\
- textBoxWindow.write(tableInput[7])\
- textBoxWindow.setCursorPos(1,2)\
- textBoxWindow.setBackgroundColor(tableInput[12])\
- for i = 2 , tableInput[5] do\
- textBoxWindow.setCursorPos(1,i)\
- textBoxWindow.clearLine()\
- end\
- textBoxWindow.setTextColor(tableInput[11])\
- for token in string.gmatch(tableInput[10],\"[^%%]+\") do\
- nTable[#nTable+1] = token\
- end\
- for i,v in pairs(nTable) do\
- textBoxWindow.setCursorPos(2,1+i)\
- textBoxWindow.write(v)\
- end\
- textBoxWindow.setTextColor(tableInput[13])\
- textBoxWindow.setBackgroundColor(tableInput[14])\
- textBoxWindow.setCursorPos(2,tableInput[5]-1)\
- textBoxWindow.clearLine()\
- textBoxWindow.setCursorPos(2,tableInput[5]-1)\
- textBoxWindow.setTextColor(tableInput[13])\
- textBoxWindow.setBackgroundColor(tableInput[14])\
- if secret then\
- return read(\"*\")\
- else\
- return read()\
- end\
- end\
- \
- local function refresh(dir)\
- local bufferFiles = {}\
- for i,v in pairs(fs.list(dir)) do\
- if fs.isDir(currDir..\"/\"..v) then\
- bufferFiles[#bufferFiles+1] = {v,\"folder\"}\
- else\
- bufferFiles[#bufferFiles+1] = {v,\"file\"}\
- end\
- end\
- return bufferFiles\
- end\
- \
- local function drawOptions(tableInputDrawOptions)\
- for i,v in pairs(tableInputDrawOptions) do\
- term.setCursorPos(v[1],v[2])\
- paintutils.drawFilledBox(v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,v[7])\
- term.setCursorPos(v[1],v[2])\
- term.setTextColor(v[6])\
- term.write(v[5])\
- if globalButtonList == nil then\
- globalButtonList = {{v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,\"button:\"..v[8]}}\
- else\
- globalButtonList[#globalButtonList+1] = {v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,\"button:\"..v[8]}\
- end\
- end\
- end\
- \
- local function drawFiles(filesToDisplay)\
- local numItemsX = math.floor((w-1)/10)\
- numItemsY = math.ceil(#filesToDisplay/numItemsX)\
- local currFile = 1\
- for i = 0 , numItemsY-1 do\
- for k = 0 , numItemsX - 1 do\
- if currFile > #filesToDisplay then\
- break\
- else\
- term.setTextColor(colors.black)\
- if filesToDisplay[currFile][2] == \"file\" then\
- paintutils.drawImage(fileIcon,(k*10)+2,(i*5)+4-scroll)\
- for l,m in pairs(mkStrShort(filesToDisplay[currFile][1],6,3)) do \
- term.setCursorPos((k*10)+3,(i*5)+4+l-scroll)\
- term.write(m)\
- end\
- if ((i*5)+4-scroll) < 4 then\
- if ((i*5)+7-scroll) >= 4 then\
- if globalButtonList == nil then\
- globalButtonList = {{((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),\"file:\"..filesToDisplay[currFile][1]}}\
- else\
- globalButtonList[#globalButtonList+1] = {((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),\"file:\"..filesToDisplay[currFile][1]}\
- end\
- end\
- else\
- if globalButtonList == nil then\
- globalButtonList = {{((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),\"file:\"..filesToDisplay[currFile][1]}}\
- else\
- globalButtonList[#globalButtonList+1] = {((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),\"file:\"..filesToDisplay[currFile][1]}\
- end\
- end\
- elseif filesToDisplay[currFile][2] == \"folder\" then\
- paintutils.drawImage(folderIcon,(k*10)+2,(i*5)+4-scroll)\
- for l,m in pairs(mkStrShort(filesToDisplay[currFile][1],6,3)) do \
- term.setCursorPos((k*10)+3,(i*5)+4+l-scroll)\
- term.write(m)\
- end\
- if ((i*5)+4-scroll) < 4 then\
- if ((i*5)+7-scroll) >= 4 then\
- if globalButtonList == nil then\
- globalButtonList = {{((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),\"folder:\"..filesToDisplay[currFile][1]}}\
- else\
- globalButtonList[#globalButtonList+1] = {((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),\"folder:\"..filesToDisplay[currFile][1]}\
- end\
- end\
- else\
- if globalButtonList == nil then\
- globalButtonList = {{((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),\"folder:\"..filesToDisplay[currFile][1]}}\
- else\
- globalButtonList[#globalButtonList+1] = {((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),\"folder:\"..filesToDisplay[currFile][1]}\
- end\
- end\
- end\
- currFile = currFile + 1\
- end\
- end\
- end\
- end\
- \
- local function drawSideBar()\
- local lenghtSideBar = h-4\
- if numItemsY ~= 0 then\
- lenghtSideBar = math.ceil(((h-5)*(h-5))/(numItemsY*5))\
- end\
- paintutils.drawLine(w,3,w,3+lenghtSideBar,colors.green)\
- term.setBackgroundColor(colors.blue)\
- term.setCursorPos(w,3)\
- term.write(\"^\")\
- term.setCursorPos(w,h-1)\
- term.write(\"v\")\
- if globalButtonList == nil then\
- globalButtonList = {{w,3,w,3,\"button:scrollUp\"}}\
- else\
- globalButtonList[#globalButtonList+1] = {w,3,w,3,\"button:scrollUp\"}\
- end\
- if globalButtonList == nil then\
- globalButtonList = {{w,h-1,w,h-1,\"button:scrollDown\"}}\
- else\
- globalButtonList[#globalButtonList+1] = {w,h-1,w,h-1,\"button:scrollDown\"}\
- end\
- end\
- \
- local function program(extension)\
- if fileExtensions[extension] ~= nil then\
- return fileExtensions[extension]\
- else\
- return \"edit\"\
- end\
- end\
- \
- local function main(filesToDisplay,buttonsToDisplay)\
- clear(colors.white)\
- drawFiles(filesToDisplay)\
- drawSideBar()\
- term.setBackgroundColor(colors.orange)\
- for i = 1,2 do\
- term.setCursorPos(1,i)\
- term.clearLine()\
- end\
- term.setCursorPos(1,1)\
- term.setTextColor(colors.black)\
- term.write(\"Creator\\'s FileX v1.0\")\
- term.setCursorPos(w,1)\
- term.setBackgroundColor(colors.magenta)\
- term.write(\"X\")\
- if globalButtonList == nil then\
- globalButtonList = {{w,1,w,1,\"button:x\"}}\
- else\
- globalButtonList[#globalButtonList+1] = {w,1,w,1,\"button:x\"}\
- end\
- if globalButtonList == nil then\
- globalButtonList = {{1,3,w,h,\"nil:nil\"}}\
- else\
- globalButtonList[#globalButtonList+1] = {1,4,w,h,\"nil:nil\"}\
- end\
- drawOptions(buttonsToDisplay)\
- if globalButtonList == nil then\
- globalButtonList = {{1,1,w,3,\"nil:nilnil\"}}\
- else\
- globalButtonList[#globalButtonList+1] = {1,1,w,3,\"nil:nilnil\"}\
- end\
- term.setCursorPos(1,h)\
- term.setBackgroundColor(colors.orange)\
- term.clearLine()\
- term.setTextColor(colors.black)\
- term.write(currDir)\
- term.setCursorPos(1,1)\
- local detectedButtonUnparsedTable = detectButtonHit(globalButtonList)\
- local detectedButtonUnparsed = detectedButtonUnparsedTable[1]\
- local button = detectedButtonUnparsedTable[2]\
- local detectedButtonParsedTable = {}\
- for token in string.gmatch(detectedButtonUnparsed,\"[^:]+\") do\
- detectedButtonParsedTable[#detectedButtonParsedTable + 1] = token\
- end\
- local action = detectedButtonParsedTable[2]\
- if detectedButtonParsedTable[1] == \"button\" then\
- if action == \"x\" then\
- term.setBackgroundColor(colors.black)\
- clear()\
- print(\"Thank you for using Creator\\'s FTPclient. More coming soon...\\nSpecial thanks to:\\nNitrogenFingers for nPaintPro\")\
- notEnded = false\
- elseif action == \"up\" then\
- scroll = 0\
- if currDir == \"/\" then\
- else\
- local currDirBuffer = {}\
- for token in string.gmatch(currDir,\"(/[^/]+)\") do\
- currDirBuffer[#currDirBuffer + 1] = token\
- end\
- currDir = \"\"\
- if #currDirBuffer == 1 then\
- currDir = \"\"\
- else\
- for i = 1, #currDirBuffer-1 do\
- if i == 1 then\
- currDir = currDirBuffer[1]\
- else\
- currDir = currDir..currDirBuffer[i]\
- end\
- end\
- end\
- files = refresh(currDir)\
- end\
- elseif action == \"refresh\" then\
- files = refresh(currDir)\
- elseif action == \"scrollUp\" then\
- scroll = scroll - 1\
- if scroll < 0 then\
- scroll = 0\
- end\
- elseif action == \"scrollDown\" then\
- scroll = scroll + 1\
- if scroll > numItemsY*6 - h then\
- scroll = scroll - 1\
- end\
- elseif action == \"paste\" then\
- term.setCursorPos(1,1)\
- print(pathToCopy)\
- print(currDir)\
- print(copyHelp)\
- sleep(3)\
- fs.copy(copyPath,currDir..\"/\"..copyHelp)\
- files = refresh(currDir)\
- \
- end\
- elseif detectedButtonParsedTable[1] == \"key\" then\
- if tonumber(action) == keys.up then\
- scroll = scroll - 1\
- if scroll < 0 then\
- scroll = 0\
- end\
- elseif tonumber(action) == keys.down then\
- scroll = scroll + 1\
- if scroll > numItemsY*6 - h then\
- scroll = scroll - 1\
- end\
- end\
- elseif detectedButtonParsedTable[1] == \"folder\" then\
- if button == 1 then\
- currDir = currDir..\"/\"..action\
- files = refresh(currDir)\
- scroll = 0\
- elseif button == 2 then\
- local result = dropDownMenu(folderMenu,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4])\
- if result == \"open\" then\
- currDir = currDir..\"/\"..action\
- files = refresh(currDir)\
- scroll = 0\
- elseif result == \"copy\" then\
- pathToCopy = currDir..action\
- elseif result == \"delete\" then\
- fs.delete(currDir..\"/\"..action)\
- files = refresh(currDir)\
- elseif result == \"rename\" then\
- local answ = textBox(newFolderWindow,false,false)\
- fs.move(currDir..\"/\"..action,currDir..\"/\"..answ)\
- files = refresh(currDir)\
- elseif result == \"move\" then\
- local answ = textBox(moveFolderWindow,false,false)\
- if string.sub(answ,1,1) ~= \"/\" then\
- answ = \"/\"..answ\
- end\
- fs.move(currDir..\"/\"..action,answ)\
- files = refresh(currDir)\
- elseif result == \"copy\" then\
- copyPath = currDir..\"/\"..action\
- copyHelp = action\
- end\
- end\
- elseif detectedButtonParsedTable[1] == \"file\" then\
- if button == 1 then\
- local fileExtension\
- for token in string.gmatch(action,\"[^%.]+\") do\
- fileExtension = token\
- end\
- if fileExtension == action then\
- fileExtension = \"txt\"\
- end\
- programT = program(fileExtension)\
- --shell.run(progsDir..\"/\"..programT..\" \"..currDir..\"/\"..action)\
- System.newTask(programT,programT,currDir..\"/\"..action)\
- elseif button == 2 then\
- local result = dropDownMenu(fileMenu,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4])\
- if result == \"open\" then\
- local fileExtension\
- for token in string.gmatch(action,\"[^%.]+\") do\
- fileExtension = token\
- end\
- if fileExtension == action then\
- fileExtension = \"txt\"\
- end\
- programT = program(fileExtension)\
- System.newTask(programT,programT, currDir..\"/\"..action)\
- elseif result == \"delete\" then\
- fs.delete(currDir..\"/\"..action)\
- files = refresh(currDir)\
- elseif result == \"rename\" then\
- local answ = textBox(newFolderWindow,false,false)\
- fs.move(currDir..\"/\"..action,currDir..\"/\"..answ)\
- files = refresh(currDir)\
- elseif result == \"move\" then\
- local answ = textBox(moveFolderWindow,false,false)\
- if string.sub(answ,1,1) ~= \"/\" then\
- answ = \"/\"..answ\
- end\
- fs.move(currDir..\"/\"..action,answ)\
- files = refresh(currDir)\
- elseif result == \"run\" then\
- shell.run(progsDir..\"/shell \"..currDir..\"/\"..action)\
- elseif result == \"openWith\" then\
- local possibleExtensions = {}\
- for i,v in pairs(fileExtensions) do\
- local alreadyRegistered = false\
- for m,k in pairs(possibleExtensions) do\
- if v == k then\
- alreadyRegistered = true\
- end\
- end\
- if not alreadyRegistered then\
- possibleExtensions[#possibleExtensions+1] = v\
- end\
- end\
- local openWith = {\
- term.current(),\
- 16,\
- \"Open with:\",\
- colors.white,\
- colors.blue,\
- colors.black,\
- colors.lightGray,\
- {}\
- }\
- for i,v in pairs(possibleExtensions) do\
- openWith[8][#openWith[8]+1] = {v,v}\
- end\
- openWith[8][#openWith[8]+1] = {\"Cancel\",\"cancel\"}\
- globalButtonList = {}\
- result = dropDownMenu(openWith,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4]+6)\
- System.newTask(result,result,currDir..\"/\"..action)\
- elseif result == \"copy\" then\
- copyPath = currDir..\"/\"..action\
- copyHelp = action\
- end\
- end\
- elseif detectedButtonParsedTable[1] == \"nil\" then\
- if button == 2 then\
- if action == \"nil\" then\
- local result = dropDownMenu(nilMenu,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4])\
- if result == \"makeFolder\" then\
- local answ = textBox(newFolderWindow,false,false)\
- fs.makeDir(currDir..\"/\"..answ)\
- files = refresh(currDir)\
- scroll = 0\
- elseif result == \"makeFile\" then\
- local answ = textBox(newFileWindow,false,false)\
- f = fs.open(currDir..\"/\"..answ,\"w\")\
- f.close()\
- files = refresh(currDir)\
- scroll = 0\
- end\
- end\
- end\
- end\
- end\
- \
- --Code--\
- \
- clear()\
- files = refresh(currDir)\
- while notEnded do\
- main(files,Buttons)\
- end\
- shell.setDir(currDir)",
- Data = {
- shell = "local path = \"\"\
- local args = \"\"\
- local tArgs = {...}\
- for i,v in pairs(tArgs) do \
- if i == 1 then\
- path = v\
- else\
- args = args..\" \"..v\
- end\
- end\
- pcall(shell.run,path..\" \"..args)",
- nPaintPro = "--[[\
- NPaintPro\
- By NitrogenFingers\
- ]]--\
- \
- --The screen size\
- local w,h = term.getSize()\
- --Whether or not the program is currently waiting on user input\
- local inMenu = false\
- --Whether or not a drop down menu is active\
- local inDropDown = false\
- --Whether or not animation tools are enabled (use -a to turn them on)\
- local animated = false\
- --Whether or not \"blueprint\" display mode is on\
- local blueprint = false\
- --Whether or not the \"layer\" display is on\
- local layerDisplay = false\
- --Whether or not the \"direction\" display is on\
- local printDirection = false\
- --The tool/mode npaintpro is currently in. Default is \"paint\"\
- --For a list of modes, check out the help file\
- local state = \"paint\"\
- --Whether or not the program is presently running\
- local isRunning = true\
- --The rednet address of the 3D printer, if one has been attached\
- local printer = nil\
- \
- --The list of every frame, containing every image in the picture/animation\
- --Note: nfp files always have the picture at frame 1\
- local frames = { }\
- --How many frames are currently in the given animation.\
- local frameCount = 1\
- --The Colour Picker column\
- local column = {}\
- --The currently selected left and right colours\
- local lSel,rSel = colours.white,nil\
- --The amount of scrolling on the X and Y axis\
- local sx,sy = 0,0\
- --The alpha channel colour\
- --Change this to change default canvas colour\
- local alphaC = colours.yellow\
- --The currently selected frame. Default is 1\
- local sFrame = 1\
- --The contents of the image buffer- contains contents, width and height\
- local buffer = nil\
- --The position, width and height of the selection rectangle\
- local selectrect = nil\
- \
- --The currently calculated required materials\
- local requiredMaterials = {}\
- --Whether or not required materials are being displayed in the pallette\
- local requirementsDisplayed = false\
- --A list of the rednet ID's all in-range printers located\
- local printerList = { }\
- --A list of the names of all in-range printers located. Same as the printerList in reference\
- local printerNames = { }\
- --The selected printer\
- local selectedPrinter = 1\
- --The X,Y,Z and facing of the printer\
- local px,py,pz,pfx,pfz = 0,0,0,0,0\
- --The form of layering used\
- local layering = \"up\"\
- \
- --The animation state of the selection rectangle and image buffer \
- local rectblink = 0\
- --The ID for the timer\
- local recttimer = nil\
- --The radius of the brush tool\
- local brushsize = 3\
- --Whether or not \"record\" mode is activated (animation mode only)\
- local record = false\
- --The time between each frame when in play mode (animation mode only)\
- local animtime = 0.3\
- \
- --A list of hexidecimal conversions from numbers to hex digits\
- local hexnums = { [10] = \"a\", [11] = \"b\", [12] = \"c\", [13] = \"d\", [14] = \"e\" , [15] = \"f\" }\
- --The NPaintPro logo (divine, isn't it?)\
- local logo = {\
- \"fcc 3 339\";\
- \" fcc 9333 33\";\
- \" fcc 933 333 33\";\
- \" fcc 933 33 33\";\
- \" fcc 933 33 33\";\
- \" c88 333 93333\";\
- \" 888 333 9333\";\
- \" 333 3 333 939\";\
- }\
- --The Layer Up and Layer Forward printing icons\
- local layerUpIcon = {\
- \"0000000\";\
- \"0088880\";\
- \"0888870\";\
- \"07777f0\";\
- \"0ffff00\";\
- \"0000000\";\
- }\
- local layerForwardIcon = {\
- \"0000000\";\
- \"000fff0\";\
- \"00777f0\";\
- \"0888700\";\
- \"0888000\";\
- \"0000000\";\
- }\
- --The available menu options in the ctrl menu\
- local mChoices = {\"Save\",\"Exit\"}\
- --The available modes from the dropdown menu- tables indicate submenus (include a name!)\
- local ddModes = { { \"paint\", \"brush\", \"pippette\", \"flood\", \"move\", \"clear\", \"select\", name = \"painting\" }, { \"alpha to left\", \"alpha to right\", \"blueprint on\", \"layers on\", name = \"display\" }, \"help\", { \"print\", \"save\", \"exit\", name = \"file\" }, name = \"menu\" }\
- --The available modes from the selection right-click menu\
- local srModes = { \"cut\", \"copy\", \"paste\", \"clear\", \"hide\", name = \"selection\" }\
- --The list of available help topics for each mode 127\
- local helpTopics = {\
- [1] = {\
- name = \"Paint Mode\",\
- key = nil,\
- animonly = false,\
- message = \"The default mode for NPaintPro, for painting pixels.\"\
- ..\" Controls here that are not overridden will apply for all other modes. Leaving a mode by selecting that mode \"\
- ..\" again will always send the user back to paint mode.\",\
- controls = {\
- { \"Arrow keys\", \"Scroll the canvas\" },\
- { \"Left Click\", \"Paint/select left colour\" },\
- { \"Right Click\", \"Paint/select right colour\" },\
- { \"Z Key\", \"Clear image on screen\" },\
- { \"Tab Key\", \"Hide selection rectangle if visible\" },\
- { \"Q Key\", \"Set alpha mask to left colour\" },\
- { \"W Key\", \"Set alpha mask to right colour\" },\
- { \"Number Keys\", \"Swich between frames 1-9\" },\
- { \"</> keys\", \"Move to the next/last frame\" },\
- { \"R Key\", \"Removes every frame after the current frame\"}\
- }\
- },\
- [2] = {\
- name = \"Brush Mode\",\
- key = \"b\",\
- animonly = false,\
- message = \"Brush mode allows painting a circular area of variable diameter rather than a single pixel, working in \"..\
- \"the exact same way as paint mode in all other regards.\",\
- controls = {\
- { \"Left Click\", \"Paints a brush blob with the left colour\" },\
- { \"Right Click\", \"Paints a brush blob with the right colour\" },\
- { \"Number Keys\", \"Changes the radius of the brush blob from 2-9\" }\
- }\
- },\
- [3] = {\
- name = \"Pippette Mode\",\
- key = \"p\",\
- animonly = false,\
- message = \"Pippette mode allows the user to click the canvas and set the colour clicked to the left or right \"..\
- \"selected colour, for later painting.\",\
- controls = {\
- { \"Left Click\", \"Sets clicked colour to the left selected colour\" },\
- { \"Right Click\", \"Sets clicked colour to the right selected colour\" }\
- }\
- },\
- [4] = {\
- name = \"Move Mode\",\
- key = \"m\",\
- animonly = false,\
- message = \"Mode mode allows the moving of the entire image on the screen. This is especially useful for justifying\"..\
- \" the image to the top-left for animations or game assets.\",\
- controls = {\
- { \"Left/Right Click\", \"Moves top-left corner of image to selected square\" },\
- { \"Arrow keys\", \"Moves image one pixel in any direction\" }\
- }\
- },\
- [5] = {\
- name = \"Flood Mode (NYI)\",\
- key = \"f\",\
- animonly = false,\
- message = \"Flood mode allows the changing of an area of a given colour to that of the selected colour. \"..\
- \"The tool uses a flood4 algorithm and will not fill diagonally. Transparency cannot be flood filled.\",\
- controls = {\
- { \"Left Click\", \"Flood fills selected area to left colour\" },\
- { \"Right Click\", \"Flood fills selected area to right colour\" }\
- }\
- },\
- [6] = {\
- name = \"Select Mode\",\
- key = \"s\",\
- animonly = false,\
- message = \"Select mode allows the creation and use of the selection rectangle, to highlight specific areas on \"..\
- \"the screen and perform operations on the selected area of the image. The selection rectangle can contain an \"..\
- \"image on the clipboard- if it does, the image will flash inside the rectangle, and the rectangle edges will \"..\
- \"be light grey instead of dark grey.\",\
- controls = {\
- { \"C Key\", \"Copy: Moves selection into the clipboard\" },\
- { \"X Key\", \"Cut: Clears canvas under the rectangle, and moves it into the clipboard\" },\
- { \"V Key\", \"Paste: Copys clipboard to the canvas\" },\
- { \"Z Key\", \"Clears clipboard\" },\
- { \"Left Click\", \"Moves top-left corner of rectangle to selected pixel\" },\
- { \"Right Click\", \"Opens selection menu\" },\
- { \"Arrow Keys\", \"Moves rectangle one pixel in any direction\" }\
- }\
- },\
- [7] = {\
- name = \"Corner Select Mode\",\
- key = nil,\
- animonly = false,\
- message = \"If a selection rectangle isn't visible, this mode is selected automatically. It allows the \"..\
- \"defining of the corners of the rectangle- one the top-left and bottom-right corners have been defined, \"..\
- \"NPaintPro switches to selection mode. Note rectangle must be at least 2 pixels wide and high.\",\
- controls = {\
- { \"Left/Right Click\", \"Defines a corner of the selection rectangle\" }\
- }\
- },\
- [8] = {\
- name = \"Play Mode\",\
- key = \"space\",\
- animonly = true,\
- message = \"Play mode will loop through each frame in your animation at a constant rate. Editing tools are \"..\
- \"locked in this mode, and the coordinate display will turn green to indicate it is on.\",\
- controls = {\
- { \"</> Keys\", \"Increases/Decreases speed of the animation\" },\
- { \"Space Bar\", \"Returns to paint mode\" }\
- }\
- },\
- [9] = {\
- name = \"Record Mode\",\
- key = \"\\\\\",\
- animonly = true,\
- message = \"Record mode is not a true mode, but influences how other modes work. Changes made that modify the \"..\
- \"canvas in record mode will affect ALL frames in the animation. The coordinates will turn red to indicate that \"..\
- \"record mode is on.\",\
- controls = {\
- { \"\", \"Affects:\" },\
- { \"- Paint Mode\", \"\" },\
- { \"- Brush Mode\", \"\" },\
- { \"- Cut and Paste in Select Mode\", \"\"},\
- { \"- Move Mode\", \"\"}\
- }\
- },\
- [10] = {\
- name = \"Help Mode\",\
- key = \"h\",\
- animonly = false,\
- message = \"Displays this help screen. Clicking on options will display help on that topic. Clicking out of the screen\"..\
- \" will leave this mode.\",\
- controls = {\
- { \"Left/Right Click\", \"Displays a topic/Leaves the mode\" }\
- }\
- },\
- [11] = {\
- name = \"File Mode\",\
- keys = nil,\
- animonly = false,\
- message = \"Clicking on the mode display at the bottom of the screen will open the options menu. Here you can\"..\
- \" activate all of the modes in the program with a simple mouse click. Pressing left control will open up the\"..\
- \" file menu automatically.\",\
- controls = { \
- { \"leftCtrl\", \"Opens the file menu\" },\
- { \"leftAlt\", \"Opens the paint menu\" }\
- \
- }\
- }\
- }\
- --The \"bounds\" of the image- the first/last point on both axes where a pixel appears\
- local toplim,botlim,leflim,riglim = nil,nil,nil,nil\
- --The selected path\
- local sPath = nil\
- \
- --[[ \
- Section: Helpers \
- ]]--\
- \
- --[[Converts a colour parameter into a single-digit hex coordinate for the colour\
- Params: colour:int = The colour to be converted\
- Returns:string A string conversion of the colour\
- ]]--\
- local function getHexOf(colour)\
- if not colour or not tonumber(colour) then \
- return \" \" \
- end\
- local value = math.log(colour)/math.log(2)\
- if value > 9 then \
- value = hexnums[value] \
- end\
- return value\
- end\
- \
- --[[Converts a hex digit into a colour value\
- Params: hex:?string = the hex digit to be converted\
- Returns:string A colour value corresponding to the hex, or nil if the character is invalid\
- ]]--\
- local function getColourOf(hex)\
- local value = tonumber(hex, 16)\
- if not value then return nil end\
- value = math.pow(2,value)\
- return value\
- end\
- \
- --[[Finds the biggest and smallest bounds of the image- the outside points beyond which pixels do not appear\
- These values are assigned to the \"lim\" parameters for access by other methods\
- Params: forAllFrames:bool = True if all frames should be used to find bounds, otherwise false or nil\
- Returns:nil\
- ]]--\
- local function updateImageLims(forAllFrames)\
- local f,l = sFrame,sFrame\
- if forAllFrames == true then f,l = 1,framecount end\
- \
- toplim,botlim,leflim,riglim = nil,nil,nil,nil\
- for locf = f,l do\
- for y,_ in pairs(frames[locf]) do\
- for x,_ in pairs(frames[locf][y]) do\
- if frames[locf][y][x] ~= nil then\
- if leflim == nil or x < leflim then leflim = x end\
- if toplim == nil or y < toplim then toplim = y end\
- if riglim == nil or x > riglim then riglim = x end\
- if botlim == nil or y > botlim then botlim = y end\
- end\
- end\
- end\
- end\
- end\
- \
- --[[Determines how much of each material is required for a print. Done each time printing is called.\
- Params: none\
- Returns:table A complete list of how much of each material is required.\
- ]]--\
- function calculateMaterials()\
- updateImageLims(animated)\
- requiredMaterials = {}\
- for i=1,16 do \
- requiredMaterials[i] = 0 \
- end\
- \
- if not toplim then return end\
- \
- for i=1,#frames do\
- for y = toplim, botlim do\
- for x = leflim, riglim do\
- if type(frames[i][y][x]) == \"number\" then\
- requiredMaterials[math.log10(frames[i][y][x])/math.log10(2) + 1] = \
- requiredMaterials[math.log10(frames[i][y][x])/math.log10(2) + 1] + 1\
- end \
- end\
- end\
- end\
- end\
- \
- \
- --[[Updates the rectangle blink timer. Should be called anywhere events are captured, along with a timer capture.\
- Params: nil\
- Returns:nil\
- ]]--\
- local function updateTimer(id)\
- if id == recttimer then\
- recttimer = os.startTimer(0.5)\
- rectblink = (rectblink % 2) + 1\
- end\
- end\
- \
- --[[Constructs a message based on the state currently selected\
- Params: nil\
- Returns:string A message regarding the state of the application\
- ]]--\
- local function getStateMessage()\
- local msg = \" \"..string.upper(string.sub(state, 1, 1))..string.sub(state, 2, #state)..\" mode\"\
- if state == \"brush\" then msg = msg..\", size=\"..brushsize end\
- return msg\
- end\
- \
- --[[Calls the rednet_message event, but also looks for timer events to keep then\
- system timer ticking.\
- Params: timeout:number how long before the event times out\
- Returns:number the id of the sender\
- :number the message send\
- ]]--\
- local function rsTimeReceive(timeout)\
- local timerID\
- if timeout then timerID = os.startTimer(timeout) end\
- \
- local id,key,msg = nil,nil\
- while true do\
- id,key,msg = os.pullEvent()\
- \
- if id == \"timer\" then\
- if key == timerID then return\
- else updateTimer(key) end\
- end\
- if id == \"rednet_message\" then \
- return key,msg\
- end\
- end\
- end\
- \
- --[[Draws a picture, in paint table format on the screen\
- Params: image:table = the image to display\
- xinit:number = the x position of the top-left corner of the image\
- yinit:number = the y position of the top-left corner of the image\
- alpha:number = the color to display for the alpha channel. Default is white.\
- Returns:nil\
- ]]--\
- local function drawPictureTable(image, xinit, yinit, alpha)\
- if not alpha then alpha = 1 end\
- for y=1,#image do\
- for x=1,#image[y] do\
- term.setCursorPos(xinit + x-1, yinit + y-1)\
- local col = getColourOf(string.sub(image[y], x, x))\
- if not col then col = alpha end\
- term.setBackgroundColour(col)\
- term.write(\" \")\
- end\
- end\
- end\
- \
- --[[ \
- Section: Loading \
- ]]-- \
- \
- --[[Loads a non-animted paint file into the program\
- Params: path:string = The path in which the file is located\
- Returns:nil\
- ]]--\
- local function loadNFP(path)\
- sFrame = 1\
- frames[sFrame] = { }\
- if fs.exists(path) then\
- local file = io.open(path, \"r\" )\
- local sLine = file:read()\
- local num = 1\
- while sLine do\
- table.insert(frames[sFrame], num, {})\
- for i=1,#sLine do\
- frames[sFrame][num][i] = getColourOf(string.sub(sLine,i,i))\
- end\
- num = num+1\
- sLine = file:read()\
- end\
- file:close()\
- end\
- end\
- \
- --[[Saves a non-animated paint file to the specified path\
- Params: path:string = The path to save the file to\
- Returns:nil\
- ]]--\
- local function saveNFP(path)\
- local sDir = string.sub(sPath, 1, #sPath - #fs.getName(sPath))\
- if not fs.exists(sDir) then\
- fs.makeDir(sDir)\
- end\
- \
- local file = io.open(path, \"w\")\
- updateImageLims(false)\
- if not toplim then \
- file:close()\
- return\
- end\
- for y=1,botlim do\
- local line = \"\"\
- if frames[sFrame][y] then \
- for x=1,riglim do\
- line = line..getHexOf(frames[sFrame][y][x])\
- end\
- end\
- file:write(line..\"\\n\")\
- end\
- file:close()\
- end\
- \
- --[[Loads an animated paint file into the program\
- Params: path:string = The path in which the file is located\
- Returns:nil\
- ]]--\
- local function loadNFA(path)\
- frames[sFrame] = { }\
- if fs.exists(path) then\
- local file = io.open(path, \"r\" )\
- local sLine = file:read()\
- local num = 1\
- while sLine do\
- table.insert(frames[sFrame], num, {})\
- if sLine == \"~\" then\
- sFrame = sFrame + 1\
- frames[sFrame] = { }\
- num = 1\
- else\
- for i=1,#sLine do\
- frames[sFrame][num][i] = getColourOf(string.sub(sLine,i,i))\
- end\
- num = num+1\
- end\
- sLine = file:read()\
- end\
- file:close()\
- end\
- framecount = sFrame\
- sFrame = 1\
- end\
- \
- --[[Saves a animated paint file to the specified path\
- Params: path:string = The path to save the file to\
- Returns:nil\
- ]]--\
- local function saveNFA(path)\
- local file = io.open(path, \"w\")\
- updateImageLims(true)\
- if not toplim then \
- file:close()\
- return\
- end\
- for i=1,#frames do\
- for y=1,botlim do\
- local line = \"\"\
- if frames[i][y] then \
- for x=1,riglim do\
- line = line..getHexOf(frames[i][y][x])\
- end\
- end\
- file:write(line..\"\\n\")\
- end\
- if i < #frames then file:write(\"~\\n\") end\
- end\
- file:close()\
- end\
- \
- --[[Initializes the program, by loading in the paint file. Called at the start of each program.\
- Params: none\
- Returns:nil\
- ]]--\
- local function init()\
- if animated then \
- loadNFA(sPath)\
- table.insert(ddModes, #ddModes, { \"record\", \"play\", name = \"anim\" })\
- table.insert(ddModes, #ddModes, { \"go to\", \"remove\", name = \"frames\"})\
- else loadNFP(sPath) end\
- \
- for i=0,15 do\
- table.insert(column, math.pow(2,i))\
- end\
- end\
- \
- --[[ \
- Section: Drawing \
- ]]--\
- \
- \
- --[[Draws the rather superflous logo. Takes about 1 second, before user is able to move to the\
- actual program.\
- Params: none\
- Returns:nil\
- ]]--\
- local function drawLogo()\
- term.setBackgroundColour(colours.white)\
- term.clear()\
- drawPictureTable(logo, w/2 - #logo[1]/2, h/2 - #logo/2, colours.white)\
- term.setBackgroundColour(colours.white)\
- term.setTextColour(colours.black)\
- local msg = \"NPaintPro\"\
- term.setCursorPos(w/2 - #msg/2, h-3)\
- term.write(msg)\
- msg = \"By NitrogenFingers\"\
- term.setCursorPos(w/2 - #msg/2, h-2)\
- term.write(msg)\
- msg = \"Thanks to faubiguy for testing\"\
- term.setCursorPos(w/2 - #msg/2, h)\
- term.write(msg)\
- \
- os.pullEvent()\
- end\
- \
- --[[Clears the display to the alpha channel colour, draws the canvas, the image buffer and the selection\
- rectanlge if any of these things are present.\
- Params: none\
- Returns:nil\
- ]]--\
- local function drawCanvas()\
- --We have to readjust the position of the canvas if we're printing\
- turtlechar = \"@\"\
- if state == \"active print\" then\
- if layering == \"up\" then\
- if py >= 1 and py <= #frames then\
- sFrame = py\
- end\
- if pz < sy then sy = pz\
- elseif pz > sy + h - 1 then sy = pz + h - 1 end\
- if px < sx then sx = px\
- elseif px > sx + w - 2 then sx = px + w - 2 end\
- else\
- if pz >= 1 and pz <= #frames then\
- sFrame = pz\
- end\
- \
- if py < sy then sy = py\
- elseif py > sy + h - 1 then sy = py + h - 1 end\
- if px < sx then sx = px\
- elseif px > sx + w - 2 then sx = px + w - 2 end\
- end\
- \
- if pfx == 1 then turtlechar = \">\"\
- elseif pfx == -1 then turtlechar = \"<\"\
- elseif pfz == 1 then turtlechar = \"V\"\
- elseif pfz == -1 then turtlechar = \"^\"\
- end\
- end\
- \
- --Picture next\
- local topLayer, botLayer\
- if layerDisplay then\
- topLayer = sFrame\
- botLayer = 1\
- else\
- topLayer,botLayer = sFrame,sFrame\
- end\
- \
- for currframe = botLayer,topLayer,1 do\
- for y=sy+1,sy+h-1 do\
- if frames[currframe][y] then \
- for x=sx+1,sx+w-2 do\
- term.setCursorPos(x-sx,y-sy)\
- if frames[currframe][y][x] then\
- term.setBackgroundColour(frames[currframe][y][x])\
- term.write(\" \")\
- else \
- tileExists = false\
- for i=currframe-1,botLayer,-1 do\
- if frames[i][y][x] then\
- tileExists = true\
- break\
- end\
- end\
- \
- if not tileExists then\
- if blueprint then\
- term.setBackgroundColour(colours.blue)\
- term.setTextColour(colours.white)\
- if x == sx+1 and y % 4 == 1 then\
- term.write(\"\"..((y/4) % 10))\
- elseif y == sy + 1 and x % 4 == 1 then\
- term.write(\"\"..((x/4) % 10))\
- elseif x % 2 == 1 and y % 2 == 1 then\
- term.write(\"+\")\
- elseif x % 2 == 1 then\
- term.write(\"|\")\
- elseif y % 2 == 1 then\
- term.write(\"-\")\
- else\
- term.write(\" \")\
- end\
- else\
- term.setBackgroundColour(alphaC) \
- term.write(\" \")\
- end\
- end\
- end\
- end\
- else\
- for x=sx+1,sx+w-2 do\
- term.setCursorPos(x-sx,y-sy)\
- \
- tileExists = false\
- for i=currframe-1,botLayer,-1 do\
- if frames[i][y] and frames[i][y][x] then\
- tileExists = true\
- break\
- end\
- end\
- \
- if not tileExists then\
- if blueprint then\
- term.setBackgroundColour(colours.blue)\
- term.setTextColour(colours.white)\
- if x == sx+1 and y % 4 == 1 then\
- term.write(\"\"..((y/4) % 10))\
- elseif y == sy + 1 and x % 4 == 1 then\
- term.write(\"\"..((x/4) % 10))\
- elseif x % 2 == 1 and y % 2 == 1 then\
- term.write(\"+\")\
- elseif x % 2 == 1 then\
- term.write(\"|\")\
- elseif y % 2 == 1 then\
- term.write(\"-\")\
- else\
- term.write(\" \")\
- end\
- else\
- term.setBackgroundColour(alphaC) \
- term.write(\" \")\
- end\
- end\
- end\
- end\
- end\
- end\
- \
- --Then the printer, if he's on\
- if state == \"active print\" then\
- local bgColour = alphaC\
- if layering == \"up\" then\
- term.setCursorPos(px-sx,pz-sy)\
- if frames[sFrame] and frames[sFrame][pz-sy] and frames[sFrame][pz-sy][px-sx] then\
- bgColour = frames[sFrame][pz-sy][px-sx]\
- elseif blueprint then bgColour = colours.blue end\
- else\
- term.setCursorPos(px-sx,py-sy)\
- if frames[sFrame] and frames[sFrame][py-sy] and frames[sFrame][py-sy][px-sx] then\
- bgColour = frames[sFrame][py-sy][px-sx]\
- elseif blueprint then bgColour = colours.blue end\
- end\
- \
- term.setBackgroundColour(bgColour)\
- if bgColour == colours.black then term.setTextColour(colours.white)\
- else term.setTextColour(colours.black) end\
- \
- term.write(turtlechar)\
- end\
- \
- --Then the buffer\
- if selectrect then\
- if buffer and rectblink == 1 then\
- for y=selectrect.y1, math.min(selectrect.y2, selectrect.y1 + buffer.height-1) do\
- for x=selectrect.x1, math.min(selectrect.x2, selectrect.x1 + buffer.width-1) do\
- if buffer.contents[y-selectrect.y1+1][x-selectrect.x1+1] then\
- term.setCursorPos(x+sx,y+sy)\
- term.setBackgroundColour(buffer.contents[y-selectrect.y1+1][x-selectrect.x1+1])\
- term.write(\" \")\
- end\
- end\
- end\
- end\
- \
- --This draws the \"selection\" box\
- local add = nil\
- if buffer then\
- term.setBackgroundColour(colours.lightGrey)\
- else \
- term.setBackgroundColour(colours.grey)\
- end\
- for i=selectrect.x1, selectrect.x2 do\
- add = (i + selectrect.y1 + rectblink) % 2 == 0\
- term.setCursorPos(i-sx,selectrect.y1-sy)\
- if add then term.write(\" \") end\
- add = (i + selectrect.y2 + rectblink) % 2 == 0\
- term.setCursorPos(i-sx,selectrect.y2-sy)\
- if add then term.write(\" \") end\
- end\
- for i=selectrect.y1 + 1, selectrect.y2 - 1 do\
- add = (i + selectrect.x1 + rectblink) % 2 == 0\
- term.setCursorPos(selectrect.x1-sx,i-sy)\
- if add then term.write(\" \") end\
- add = (i + selectrect.x2 + rectblink) % 2 == 0\
- term.setCursorPos(selectrect.x2-sx,i-sy)\
- if add then term.write(\" \") end\
- end\
- end\
- end\
- \
- --[[Draws the colour picker on the right side of the screen, the colour pallette and the footer with any \
- messages currently being displayed\
- Params: none\
- Returns:nil\
- ]]--\
- local function drawInterface()\
- --Picker\
- for i=1,#column do\
- term.setCursorPos(w-1, i)\
- term.setBackgroundColour(column[i])\
- if state == \"print\" then\
- if i == 16 then\
- term.setTextColour(colours.white)\
- else\
- term.setTextColour(colours.black)\
- end\
- if requirementsDisplayed then\
- if requiredMaterials[i] < 10 then term.write(\" \") end\
- term.setCursorPos(w-#tostring(requiredMaterials[i])+1, i)\
- term.write(requiredMaterials[i])\
- else\
- if i < 10 then term.write(\" \") end\
- term.write(i)\
- end\
- else\
- term.write(\" \")\
- end\
- end\
- term.setCursorPos(w-1,#column+1)\
- term.setBackgroundColour(colours.black)\
- term.setTextColour(colours.red)\
- term.write(\"XX\")\
- --Pallette\
- term.setCursorPos(w-1,h-1)\
- if not lSel then\
- term.setBackgroundColour(colours.black)\
- term.setTextColour(colours.red)\
- term.write(\"X\")\
- else\
- term.setBackgroundColour(lSel)\
- term.setTextColour(lSel)\
- term.write(\" \")\
- end\
- if not rSel then\
- term.setBackgroundColour(colours.black)\
- term.setTextColour(colours.red)\
- term.write(\"X\")\
- else\
- term.setBackgroundColour(rSel)\
- term.setTextColour(rSel)\
- term.write(\" \")\
- end\
- --Footer\
- if inMenu then return end\
- \
- term.setCursorPos(1, h)\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- term.clearLine()\
- if inDropDown then\
- term.write(string.rep(\" \", 6))\
- else\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.write(\"menu \")\
- end\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- term.write(getStateMessage())\
- \
- local coords=\"X:\"..sx..\" Y:\"..sy\
- if animated then coords = coords..\" Frame:\"..sFrame..\"/\"..framecount..\" \" end\
- term.setCursorPos(w-#coords+1,h)\
- if state == \"play\" then term.setBackgroundColour(colours.lime)\
- elseif record then term.setBackgroundColour(colours.red) end\
- term.write(coords)\
- \
- if animated then\
- term.setCursorPos(w-1,h)\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.write(\"<>\")\
- end\
- end\
- \
- --[[Runs an interface where users can select topics of help. Will return once the user quits the help screen.\
- Params: none\
- Returns:nil\
- ]]--\
- local function drawHelpScreen()\
- local selectedHelp = nil\
- while true do\
- term.setBackgroundColour(colours.lightGrey)\
- term.clear()\
- if not selectedHelp then\
- term.setCursorPos(4, 1)\
- term.setTextColour(colours.brown)\
- term.write(\"Available modes (click for info):\")\
- for i=1,#helpTopics do\
- term.setCursorPos(2, 2 + i)\
- term.setTextColour(colours.black)\
- term.write(helpTopics[i].name)\
- if helpTopics[i].key then\
- term.setTextColour(colours.red)\
- term.write(\" (\"..helpTopics[i].key..\")\")\
- end\
- end\
- term.setCursorPos(4,h)\
- term.setTextColour(colours.black)\
- term.write(\"Press any key to exit\")\
- else\
- term.setCursorPos(4,1)\
- term.setTextColour(colours.brown)\
- term.write(helpTopics[selectedHelp].name)\
- if helpTopics[selectedHelp].key then\
- term.setTextColour(colours.red)\
- term.write(\" (\"..helpTopics[selectedHelp].key..\")\")\
- end\
- term.setCursorPos(1,3)\
- term.setTextColour(colours.black)\
- print(helpTopics[selectedHelp].message..\"\\n\")\
- for i=1,#helpTopics[selectedHelp].controls do\
- term.setTextColour(colours.brown)\
- term.write(helpTopics[selectedHelp].controls[i][1]..\" \")\
- term.setTextColour(colours.black)\
- print(helpTopics[selectedHelp].controls[i][2])\
- end\
- end\
- \
- local id,p1,p2,p3 = os.pullEvent()\
- \
- if id == \"timer\" then updateTimer(p1)\
- elseif id == \"key\" then \
- if selectedHelp then selectedHelp = nil\
- else break end\
- elseif id == \"mouse_click\" then\
- if not selectedHelp then \
- if p3 >=3 and p3 <= 2+#helpTopics then\
- selectedHelp = p3-2 \
- else break end\
- else\
- selectedHelp = nil\
- end\
- end\
- end\
- end\
- \
- --[[Draws a message in the footer bar. A helper for DrawInterface, but can be called for custom messages, if the\
- inMenu paramter is set to true while this is being done (remember to set it back when done!)\
- Params: message:string = The message to be drawn\
- Returns:nil\
- ]]--\
- local function drawMessage(message)\
- term.setCursorPos(1,h)\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- term.clearLine()\
- term.write(message)\
- end\
- \
- --[[\
- Section: Generic Interfaces\
- ]]--\
- \
- \
- --[[One of my generic text printing methods, printing a message at a specified position with width and offset.\
- No colour materials included.\
- Params: msg:string = The message to print off-center\
- height:number = The starting height of the message\
- width:number = The limit as to how many characters long each line may be\
- offset:number = The starting width offset of the message\
- Returns:number the number of lines used in printing the message\
- ]]--\
- local function wprintOffCenter(msg, height, width, offset)\
- local inc = 0\
- local ops = 1\
- while #msg - ops > width do\
- local nextspace = 0\
- while string.find(msg, \" \", ops + nextspace) and\
- string.find(msg, \" \", ops + nextspace) - ops < width do\
- nextspace = string.find(msg, \" \", nextspace + ops) + 1 - ops\
- end\
- local ox,oy = term.getCursorPos()\
- term.setCursorPos(width/2 - (nextspace)/2 + offset, height + inc)\
- inc = inc + 1\
- term.write(string.sub(msg, ops, nextspace + ops - 1))\
- ops = ops + nextspace\
- end\
- term.setCursorPos(width/2 - #string.sub(msg, ops)/2 + offset, height + inc)\
- term.write(string.sub(msg, ops))\
- \
- return inc + 1\
- end\
- \
- --[[Draws a message that must be clicked on or a key struck to be cleared. No options, so used for displaying\
- generic information.\
- Params: ctitle:string = The title of the confirm dialogue\
- msg:string = The message displayed in the dialogue\
- Returns:nil\
- ]]--\
- local function displayConfirmDialogue(ctitle, msg)\
- local dialogoffset = 8\
- --We actually print twice- once to get the lines, second time to print proper. Easier this way.\
- local lines = wprintOffCenter(msg, 5, w - (dialogoffset+2) * 2, dialogoffset + 2)\
- \
- term.setCursorPos(dialogoffset, 3)\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.write(string.rep(\" \", w - dialogoffset * 2))\
- term.setCursorPos(dialogoffset + (w - dialogoffset * 2)/2 - #ctitle/2, 3)\
- term.write(ctitle)\
- term.setTextColour(colours.grey)\
- term.setBackgroundColour(colours.lightGrey)\
- term.setCursorPos(dialogoffset, 4)\
- term.write(string.rep(\" \", w - dialogoffset * 2))\
- for i=5,5+lines do\
- term.setCursorPos(dialogoffset, i) \
- term.write(\" \"..string.rep(\" \", w - (dialogoffset) * 2 - 2)..\" \")\
- end\
- wprintOffCenter(msg, 5, w - (dialogoffset+2) * 2, dialogoffset + 2)\
- \
- --In the event of a message, the player hits anything to continue\
- while true do\
- local id,key = os.pullEvent()\
- if id == \"timer\" then updateTimer(key);\
- elseif id == \"key\" or id == \"mouse_click\" or id == \"mouse_drag\" then break end\
- end\
- end\
- \
- --[[Produces a nice dropdown menu based on a table of strings. Depending on the position, this will auto-adjust the position\
- of the menu drawn, and allows nesting of menus and sub menus. Clicking anywhere outside the menu will cancel and return nothing\
- Params: x:int = the x position the menu should be displayed at\
- y:int = the y position the menu should be displayed at\
- options:table = the list of options available to the user, as strings or submenus (tables of strings, with a name parameter)\
- Returns:string the selected menu option.\
- ]]--\
- local function displayDropDown(x, y, options)\
- inDropDown = true\
- --Figures out the dimensions of our thing\
- local longestX = #options.name\
- for i=1,#options do\
- local currVal = options[i]\
- if type(currVal) == \"table\" then currVal = currVal.name end\
- \
- longestX = math.max(longestX, #currVal)\
- end\
- local xOffset = math.max(0, longestX - ((w-2) - x) + 1)\
- local yOffset = math.max(0, #options - ((h-1) - y))\
- \
- local clickTimes = 0\
- local tid = nil\
- local selection = nil\
- while clickTimes < 2 do\
- drawCanvas()\
- drawInterface()\
- \
- term.setCursorPos(x-xOffset,y-yOffset)\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.write(options.name..string.rep(\" \", longestX-#options.name + 2))\
- \
- for i=1,#options do\
- term.setCursorPos(x-xOffset, y-yOffset+i)\
- if i==selection and clickTimes % 2 == 0 then\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- else\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- end\
- local currVal = options[i]\
- if type(currVal) == \"table\" then \
- term.write(currVal.name..string.rep(\" \", longestX-#currVal.name + 1))\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.write(\">\")\
- else\
- term.write(currVal..string.rep(\" \", longestX-#currVal + 2))\
- end\
- end\
- \
- local id, p1, p2, p3 = os.pullEvent()\
- if id == \"timer\" then\
- if p1 == tid then \
- clickTimes = clickTimes + 1\
- if clickTimes > 2 then \
- break\
- else \
- tid = os.startTimer(0.1) \
- end\
- else \
- updateTimer(p1) \
- drawCanvas()\
- drawInterface()\
- end\
- elseif id == \"mouse_click\" then\
- if p2 >=x-xOffset and p2 <= x-xOffset + longestX + 1 and p3 >= y-yOffset+1 and p3 <= y-yOffset+#options then\
- selection = p3-(y-yOffset)\
- tid = os.startTimer(0.1)\
- else\
- selection = \"\"\
- break\
- end\
- end\
- end\
- \
- if type(selection) == \"number\" then\
- selection = options[selection]\
- end\
- \
- if type(selection) == \"string\" then \
- inDropDown = false\
- return selection\
- elseif type(selection) == \"table\" then \
- return displayDropDown(x, y, selection)\
- end\
- end\
- \
- --[[A custom io.read() function with a few differences- it limits the number of characters being printed,\
- waits a 1/100th of a second so any keys still in the event library are removed before input is read and\
- the timer for the selectionrectangle is continuously updated during the process.\
- Params: lim:int = the number of characters input is allowed\
- Returns:string the inputted string, trimmed of leading and tailing whitespace\
- ]]--\
- local function readInput(lim)\
- term.setCursorBlink(true)\
- \
- local inputString = \"\"\
- if not lim or type(lim) ~= \"number\" or lim < 1 then lim = w - ox end\
- local ox,oy = term.getCursorPos()\
- --We only get input from the footer, so this is safe. Change if recycling\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- term.write(string.rep(\" \", lim))\
- term.setCursorPos(ox, oy)\
- --As events queue immediately, we may get an unwanted key... this will solve that problem\
- local inputTimer = os.startTimer(0.01)\
- local keysAllowed = false\
- \
- while true do\
- local id,key = os.pullEvent()\
- \
- if keysAllowed then\
- if id == \"key\" and key == 14 and #inputString > 0 then\
- inputString = string.sub(inputString, 1, #inputString-1)\
- term.setCursorPos(ox + #inputString,oy)\
- term.write(\" \")\
- elseif id == \"key\" and key == 28 and inputString ~= string.rep(\" \", #inputString) then \
- break\
- elseif id == \"key\" and key == keys.leftCtrl then\
- return \"\"\
- elseif id == \"char\" and #inputString < lim then\
- inputString = inputString..key\
- end\
- end\
- \
- if id == \"timer\" then\
- if key == inputTimer then \
- keysAllowed = true\
- else\
- updateTimer(key)\
- drawCanvas()\
- drawInterface()\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- end\
- end\
- term.setCursorPos(ox,oy)\
- term.write(inputString)\
- term.setCursorPos(ox + #inputString, oy)\
- end\
- \
- while string.sub(inputString, 1, 1) == \" \" do\
- inputString = string.sub(inputString, 2, #inputString)\
- end\
- while string.sub(inputString, #inputString, #inputString) == \" \" do\
- inputString = string.sub(inputString, 1, #inputString-1)\
- end\
- term.setCursorBlink(false)\
- \
- return inputString\
- end\
- \
- --[[ \
- Section: Image tools \
- ]]--\
- \
- \
- --[[Copies all pixels beneath the selection rectangle into the image buffer. Empty buffers are converted to nil.\
- Params: removeImage:bool = true if the image is to be erased after copying, false otherwise\
- Returns:nil\
- ]]--\
- local function copyToBuffer(removeImage)\
- buffer = { width = selectrect.x2 - selectrect.x1 + 1, height = selectrect.y2 - selectrect.y1 + 1, contents = { } }\
- \
- local containsSomething = false\
- for y=1,buffer.height do\
- buffer.contents[y] = { }\
- local f,l = sFrame,sFrame\
- if record then f,l = 1, framecount end\
- \
- for fra = f,l do\
- if frames[fra][selectrect.y1 + y - 1] then\
- for x=1,buffer.width do\
- buffer.contents[y][x] = frames[sFrame][selectrect.y1 + y - 1][selectrect.x1 + x - 1]\
- if removeImage then frames[fra][selectrect.y1 + y - 1][selectrect.x1 + x - 1] = nil end\
- if buffer.contents[y][x] then containsSomething = true end\
- end\
- end\
- end\
- end\
- --I don't classify an empty buffer as a real buffer- confusing to the user.\
- if not containsSomething then buffer = nil end\
- end\
- \
- --[[Replaces all pixels under the selection rectangle with the image buffer (or what can be seen of it). Record-dependent.\
- Params: removeBuffer:bool = true if the buffer is to be emptied after copying, false otherwise\
- Returns:nil\
- ]]--\
- local function copyFromBuffer(removeBuffer)\
- if not buffer then return end\
- \
- for y = 1, math.min(buffer.height,selectrect.y2-selectrect.y1+1) do\
- local f,l = sFrame, sFrame\
- if record then f,l = 1, framecount end\
- \
- for fra = f,l do\
- if not frames[fra][selectrect.y1+y-1] then frames[fra][selectrect.y1+y-1] = { } end\
- for x = 1, math.min(buffer.width,selectrect.x2-selectrect.x1+1) do\
- frames[fra][selectrect.y1+y-1][selectrect.x1+x-1] = buffer.contents[y][x]\
- end\
- end\
- end\
- \
- if removeBuffer then buffer = nil end\
- end\
- \
- --[[Moves the entire image (or entire animation) to the specified coordinates. Record-dependent.\
- Params: newx:int = the X coordinate to move the image to\
- newy:int = the Y coordinate to move the image to\
- Returns:nil\
- ]]--\
- local function moveImage(newx,newy)\
- if not leflim or not toplim then return end\
- if newx <=0 or newy <=0 then return end\
- local f,l = sFrame,sFrame\
- if record then f,l = 1,framecount end\
- \
- for i=f,l do\
- local newlines = { }\
- for y,line in pairs(frames[i]) do\
- newlines[y-toplim+newy] = { }\
- for x,char in pairs(line) do\
- newlines[y-toplim+newy][x-leflim+newx] = char\
- end\
- end\
- frames[i] = newlines\
- end\
- end\
- \
- --[[Prompts the user to clear the current frame or all frames. Record-dependent.,\
- Params: none\
- Returns:nil\
- ]]--\
- local function clearImage()\
- inMenu = true\
- if not animated then\
- drawMessage(\"Clear image? Y/N: \")\
- elseif record then\
- drawMessage(\"Clear ALL frames? Y/N: \")\
- else\
- drawMessage(\"Clear current frame? Y/N :\")\
- end\
- if string.find(string.upper(readInput(1)), \"Y\") then\
- local f,l = sFrame,sFrame\
- if record then f,l = 1,framecount end\
- \
- for i=f,l do\
- frames[i] = { }\
- end\
- end\
- inMenu = false\
- end\
- \
- --[[A recursively called method (watch out for big calls!) in which every pixel of a set colour is\
- changed to another colour. Does not work on the nil colour, for obvious reasons.\
- Params: x:int = The X coordinate of the colour to flood-fill\
- y:int = The Y coordinate of the colour to flood-fill\
- targetColour:colour = the colour that is being flood-filled\
- newColour:colour = the colour with which to replace the target colour\
- Returns:nil\
- ]]--\
- local function floodFill(x, y, targetColour, newColour)\
- if not newColour or not targetColour then return end\
- local nodeList = { }\
- \
- table.insert(nodeList, {x = x, y = y})\
- \
- while #nodeList > 0 do\
- local node = nodeList[1]\
- if frames[sFrame][node.y] and frames[sFrame][node.y][node.x] == targetColour then\
- frames[sFrame][node.y][node.x] = newColour\
- table.insert(nodeList, { x = node.x + 1, y = node.y})\
- table.insert(nodeList, { x = node.x, y = node.y + 1})\
- if x > 1 then table.insert(nodeList, { x = node.x - 1, y = node.y}) end\
- if y > 1 then table.insert(nodeList, { x = node.x, y = node.y - 1}) end\
- end\
- table.remove(nodeList, 1)\
- end\
- end\
- \
- --[[ \
- Section: Animation Tools \
- ]]--\
- \
- --[[Enters play mode, allowing the animation to play through. Interface is restricted to allow this,\
- and method only leaves once the player leaves play mode.\
- Params: none\
- Returns:nil\
- ]]--\
- local function playAnimation()\
- state = \"play\"\
- selectedrect = nil\
- \
- local animt = os.startTimer(animtime)\
- repeat\
- drawCanvas()\
- drawInterface()\
- \
- local id,key,_,y = os.pullEvent()\
- \
- if id==\"timer\" then\
- if key == animt then\
- animt = os.startTimer(animtime)\
- sFrame = (sFrame % framecount) + 1\
- else\
- updateTimer(key)\
- end\
- elseif id==\"key\" then\
- if key == keys.comma and animtime > 0.1 then animtime = animtime - 0.05\
- elseif key == keys.period and animtime < 0.5 then animtime = animtime + 0.05\
- elseif key == keys.space then state = \"paint\" end\
- elseif id==\"mouse_click\" and y == h then\
- state = \"paint\"\
- end\
- until state ~= \"play\"\
- os.startTimer(0.5)\
- end\
- \
- --[[Changes the selected frame (sFrame) to the chosen frame. If this frame is above the framecount,\
- additional frames are created with a copy of the image on the selected frame.\
- Params: newframe:int = the new frame to move to\
- Returns:nil\
- ]]--\
- local function changeFrame(newframe)\
- inMenu = true\
- if not tonumber(newframe) then\
- term.setCursorPos(1,h)\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- term.clearLine()\
- \
- term.write(\"Go to frame: \")\
- newframe = tonumber(readInput(2))\
- if not newframe or newframe <= 0 then\
- inMenu = false\
- return \
- end\
- elseif newframe <= 0 then return end\
- \
- if newframe > framecount then\
- for i=framecount+1,newframe do\
- frames[i] = {}\
- for y,line in pairs(frames[sFrame]) do\
- frames[i][y] = { }\
- for x,v in pairs(line) do\
- frames[i][y][x] = v\
- end\
- end\
- end\
- framecount = newframe\
- end\
- sFrame = newframe\
- inMenu = false\
- end\
- \
- --[[Removes every frame leading after the frame passed in\
- Params: frame:int the non-inclusive lower bounds of the delete\
- Returns:nil\
- ]]--\
- local function removeFramesAfter(frame)\
- inMenu = true\
- if frame==framecount then return end\
- drawMessage(\"Remove frames \"..(frame+1)..\"/\"..framecount..\"? Y/N :\")\
- local answer = string.upper(readInput(1))\
- \
- if string.find(answer, string.upper(\"Y\")) ~= 1 then \
- inMenu = false\
- return \
- end\
- \
- for i=frame+1, framecount do\
- frames[i] = nil\
- end\
- framecount = frame\
- inMenu = false\
- end\
- \
- --[[\
- Section: Printing Tools\
- ]]--\
- \
- --[[Constructs a new facing to the left of the current facing\
- Params: curx:number = The facing on the X axis\
- curz:number = The facing on the Z axis\
- hand:string = The hand of the axis (\"right\" or \"left\")\
- Returns:number,number = the new facing on the X and Z axis after a left turn\
- ]]--\
- local function getLeft(curx, curz)\
- local hand = \"left\"\
- if layering == \"up\" then hand = \"right\" end\
- \
- if hand == \"right\" then\
- if curx == 1 then return 0,-1 end\
- if curx == -1 then return 0,1 end\
- if curz == 1 then return 1,0 end\
- if curz == -1 then return -1,0 end\
- else\
- if curx == 1 then return 0,1 end\
- if curx == -1 then return 0,-1 end\
- if curz == 1 then return -1,0 end\
- if curz == -1 then return 1,0 end\
- end\
- end\
- \
- --[[Constructs a new facing to the right of the current facing\
- Params: curx:number = The facing on the X axis\
- curz:number = The facing on the Z axis\
- hand:string = The hand of the axis (\"right\" or \"left\")\
- Returns:number,number = the new facing on the X and Z axis after a right turn\
- ]]--\
- local function getRight(curx, curz)\
- local hand = \"left\"\
- if layering == \"up\" then hand = \"right\" end\
- \
- if hand == \"right\" then\
- if curx == 1 then return 0,1 end\
- if curx == -1 then return 0,-1 end\
- if curz == 1 then return -1,0 end\
- if curz == -1 then return 1,0 end\
- else\
- if curx == 1 then return 0,-1 end\
- if curx == -1 then return 0,1 end\
- if curz == 1 then return 1,0 end\
- if curz == -1 then return -1,0 end\
- end\
- end\
- \
- \
- --[[Sends out a rednet signal requesting local printers, and will listen for any responses. Printers found are added to the\
- printerList (for ID's) and printerNames (for names)\
- Params: nil\
- Returns:nil\
- ]]--\
- local function locatePrinters()\
- printerList = { }\
- printerNames = { name = \"Printers\" }\
- local oldState = state\
- state = \"Locating printers, please wait... \"\
- drawCanvas()\
- drawInterface()\
- state = oldState\
- \
- local modemOpened = false\
- for k,v in pairs(rs.getSides()) do\
- if peripheral.isPresent(v) and peripheral.getType(v) == \"modem\" then\
- rednet.open(v)\
- modemOpened = true\
- break\
- end\
- end\
- \
- if not modemOpened then\
- displayConfirmDialogue(\"Modem not found!\", \"No modem peripheral. Must have network modem to locate printers.\")\
- return false\
- end\
- \
- rednet.broadcast(\"$3DPRINT IDENTIFY\")\
- \
- while true do\
- local id, msg = rsTimeReceive(1)\
- \
- if not id then break end\
- if string.find(msg, \"$3DPRINT IDACK\") == 1 then\
- msg = string.gsub(msg, \"$3DPRINT IDACK \", \"\")\
- table.insert(printerList, id)\
- table.insert(printerNames, msg)\
- end\
- end\
- \
- if #printerList == 0 then\
- displayConfirmDialogue(\"Printers not found!\", \"No active printers found in proximity of this computer.\")\
- return false\
- else\
- return true\
- end\
- end\
- \
- --[[Sends a request to the printer. Waits on a response and updates the state of the application accordingly.\
- Params: command:string the command to send\
- param:string a parameter to send, if any\
- Returns:nil\
- ]]--\
- local function sendPC(command,param)\
- local msg = \"$PC \"..command\
- if param then msg = msg..\" \"..param end\
- rednet.send(printerList[selectedPrinter], msg)\
- \
- while true do\
- local id,key = rsTimeReceive()\
- if id == printerList[selectedPrinter] then\
- if key == \"$3DPRINT ACK\" then\
- break\
- elseif key == \"$3DPRINT DEP\" then\
- displayConfirmDialogue(\"Printer Empty\", \"The printer has exhasted a material. Please refill slot \"..param..\
- \", and click this message when ready to continue.\")\
- rednet.send(printerList[selectedPrinter], msg)\
- end\
- end\
- end\
- \
- --Changes to position are handled after the event has been successfully completed\
- if command == \"FW\" then\
- px = px + pfx\
- pz = pz + pfz\
- elseif command == \"BK\" then\
- px = px - pfx\
- pz = pz - pfz\
- elseif command == \"UP\" then\
- if layering == \"up\" then\
- py = py + 1\
- else \
- py = py - 1\
- end\
- elseif command == \"DW\" then\
- if layering == \"up\" then\
- py = py - 1\
- else \
- py = py + 1\
- end\
- elseif command == \"TL\" then\
- pfx,pfz = getLeft(pfx,pfz)\
- elseif command == \"TR\" then\
- pfx,pfz = getRight(pfx,pfz)\
- elseif command == \"TU\" then\
- pfx = -pfx\
- pfz = -pfz\
- end\
- \
- drawCanvas()\
- drawInterface()\
- end\
- \
- --[[A printing function that commands the printer to turn to face the desired direction, if it is not already doing so\
- Params: desx:number = the normalized x direction to face\
- desz:number = the normalized z direction to face\
- Returns:nil\
- ]]--\
- local function turnToFace(desx,desz)\
- if desx ~= 0 then\
- if pfx ~= desx then\
- local temppfx,_ = getLeft(pfx,pfz)\
- if temppfx == desx then\
- sendPC(\"TL\")\
- elseif temppfx == -desx then\
- sendPC(\"TR\")\
- else\
- sendPC(\"TU\")\
- end\
- end\
- else\
- print(\"on the z axis\")\
- if pfz ~= desz then\
- local _,temppfz = getLeft(pfx,pfz)\
- if temppfz == desz then\
- sendPC(\"TL\")\
- elseif temppfz == -desz then\
- sendPC(\"TR\")\
- else\
- sendPC(\"TU\")\
- end\
- end\
- end\
- end\
- \
- --[[Performs the print\
- Params: nil\
- Returns:nil\
- ]]--\
- local function performPrint()\
- state = \"active print\"\
- if layering == \"up\" then\
- --An up layering starts our builder bot on the bottom left corner of our build\
- px,py,pz = leflim, 0, botlim + 1\
- pfx,pfz = 0,-1\
- \
- --We move him forward and up a bit from his original position.\
- sendPC(\"FW\")\
- sendPC(\"UP\")\
- --For each layer that needs to be completed, we go up by one each time\
- for layers=1,#frames do\
- --We first decide if we're going forwards or back, depending on what side we're on\
- local rowbot,rowtop,rowinc = nil,nil,nil\
- if pz == botlim then\
- rowbot,rowtop,rowinc = botlim,toplim,-1\
- else\
- rowbot,rowtop,rowinc = toplim,botlim,1\
- end\
- \
- for rows = rowbot,rowtop,rowinc do\
- --Then we decide if we're going left or right, depending on what side we're on\
- local linebot,linetop,lineinc = nil,nil,nil\
- if px == leflim then\
- --Facing from the left side has to be easterly- it's changed here\
- turnToFace(1,0)\
- linebot,linetop,lineinc = leflim,riglim,1\
- else\
- --Facing from the right side has to be westerly- it's changed here\
- turnToFace(-1,0)\
- linebot,linetop,lineinc = riglim,leflim,-1\
- end\
- \
- for lines = linebot,linetop,lineinc do\
- --We move our turtle forward, placing the right material at each step\
- local material = frames[py][pz][px]\
- if material then\
- material = math.log10(frames[py][pz][px])/math.log10(2) + 1\
- sendPC(\"SS\", material)\
- sendPC(\"PD\")\
- end\
- if lines ~= linetop then\
- sendPC(\"FW\")\
- end\
- end\
- \
- --The printer then has to do a U-turn, depending on which way he's facing and\
- --which way he needs to go\
- local temppfx,temppfz = getLeft(pfx,pfz)\
- if temppfz == rowinc and rows ~= rowtop then\
- sendPC(\"TL\")\
- sendPC(\"FW\")\
- sendPC(\"TL\")\
- elseif temppfz == -rowinc and rows ~= rowtop then\
- sendPC(\"TR\")\
- sendPC(\"FW\")\
- sendPC(\"TR\")\
- end\
- end\
- --Now at the end of a run he does a 180 and moves up to begin the next part of the print\
- sendPC(\"TU\")\
- if layers ~= #frames then\
- sendPC(\"UP\")\
- end\
- end\
- --All done- now we head back to where we started.\
- if px ~= leflim then\
- turnToFace(-1,0)\
- while px ~= leflim do\
- sendPC(\"FW\")\
- end\
- end\
- if pz ~= botlim then\
- turnToFace(0,-1)\
- while pz ~= botlim do\
- sendPC(\"BK\")\
- end\
- end\
- turnToFace(0,-1)\
- sendPC(\"BK\")\
- while py > 0 do\
- sendPC(\"DW\")\
- end\
- else\
- --The front facing is at the top-left corner, facing south not north\
- px,py,pz = leflim, botlim, 1\
- pfx,pfz = 0,1\
- --We move the printer to the last layer- he prints from the back forwards\
- while pz < #frames do\
- sendPC(\"FW\")\
- end\
- \
- --For each layer in the frame we build our wall, the move back\
- for layers = 1,#frames do\
- --We first decide if we're going left or right based on our position\
- local rowbot,rowtop,rowinc = nil,nil,nil\
- if px == leflim then\
- rowbot,rowtop,rowinc = leflim,riglim,1\
- else\
- rowbot,rowtop,rowinc = riglim,leflim,-1\
- end\
- \
- for rows = rowbot,rowtop,rowinc do\
- --Then we decide if we're going up or down, depending on our given altitude\
- local linebot,linetop,lineinc = nil,nil,nil\
- if py == botlim then\
- linebot,linetop,lineinc = botlim,toplim,-1\
- else\
- linebot,linetop,lineinc = toplim,botlim,1\
- end\
- \
- for lines = linebot,linetop,lineinc do\
- --We move our turtle up/down, placing the right material at each step\
- local material = frames[pz][py][px]\
- if material then\
- material = math.log10(frames[pz][py][px])/math.log10(2) + 1\
- sendPC(\"SS\", material)\
- sendPC(\"PF\")\
- end\
- if lines ~= linetop then\
- if lineinc == 1 then sendPC(\"DW\")\
- else sendPC(\"UP\") end\
- end\
- end\
- \
- if rows ~= rowtop then\
- turnToFace(rowinc,0)\
- sendPC(\"FW\")\
- turnToFace(0,1)\
- end\
- end\
- \
- if layers ~= #frames then\
- sendPC(\"TU\")\
- sendPC(\"FW\")\
- sendPC(\"TU\")\
- end\
- end\
- --He's easy to reset\
- while px ~= leflim do\
- turnToFace(-1,0)\
- sendPC(\"FW\")\
- end\
- turnToFace(0,1)\
- end\
- \
- sendPC(\"DE\")\
- \
- displayConfirmDialogue(\"Print complete\", \"The 3D print was successful.\")\
- end\
- \
- --[[ \
- Section: Interface \
- ]]--\
- \
- --[[Runs the printing interface. Allows users to find/select a printer, the style of printing to perform and to begin the operation\
- Params: none\
- Returns:boolean true if printing was started, false otherwse\
- ]]--\
- local function runPrintInterface()\
- if not locatePrinters() then\
- return false\
- end\
- \
- calculateMaterials()\
- layering = \"up\"\
- requirementsDisplayed = false\
- selectedPrinter = 1\
- while true do\
- drawCanvas()\
- term.setBackgroundColour(colours.lightGrey)\
- for i=1,10 do\
- term.setCursorPos(1,i)\
- term.clearLine()\
- end\
- drawInterface()\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.black)\
- \
- local msg = \"3D Printing\"\
- term.setCursorPos(w/2-#msg/2 - 2, 1)\
- term.write(msg)\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- if(requirementsDisplayed) then\
- msg = \"Count:\"\
- else\
- msg = \" Slot:\"\
- end\
- term.setCursorPos(w-3-#msg, 1)\
- term.write(msg)\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.black)\
- \
- term.setCursorPos(7, 2)\
- term.write(\"Layering\")\
- drawPictureTable(layerUpIcon, 3, 3, colours.white)\
- drawPictureTable(layerForwardIcon, 12, 3, colours.white)\
- if layering == \"up\" then\
- term.setBackgroundColour(colours.red)\
- else\
- term.setBackgroundColour(colours.lightGrey)\
- end\
- term.setCursorPos(3, 9)\
- term.write(\"Upwards\")\
- if layering == \"forward\" then\
- term.setBackgroundColour(colours.red)\
- else\
- term.setBackgroundColour(colours.lightGrey)\
- end\
- term.setCursorPos(12, 9)\
- term.write(\"Forward\")\
- \
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.black)\
- term.setCursorPos(31, 2)\
- term.write(\"Printer ID\")\
- term.setCursorPos(33, 3)\
- if #printerList > 1 then\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- else\
- term.setTextColour(colours.red)\
- end\
- term.write(\" \"..printerNames[selectedPrinter]..\" \")\
- \
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.setCursorPos(25, 10)\
- term.write(\" Cancel \")\
- term.setCursorPos(40, 10)\
- term.write(\" Print \")\
- \
- local id, p1, p2, p3 = os.pullEvent()\
- \
- if id == \"timer\" then\
- updateTimer(p1)\
- elseif id == \"mouse_click\" then\
- --Layering Buttons\
- if p2 >= 3 and p2 <= 9 and p3 >= 3 and p3 <= 9 then\
- layering = \"up\"\
- elseif p2 >= 12 and p2 <= 18 and p3 >= 3 and p3 <= 9 then\
- layering = \"forward\"\
- --Count/Slot\
- elseif p2 >= w - #msg - 3 and p2 <= w - 3 and p3 == 1 then\
- requirementsDisplayed = not requirementsDisplayed\
- --Printer ID\
- elseif p2 >= 33 and p2 <= 33 + #printerNames[selectedPrinter] and p3 == 3 and #printerList > 1 then\
- local chosenName = displayDropDown(33, 3, printerNames)\
- for i=1,#printerNames do\
- if printerNames[i] == chosenName then\
- selectedPrinter = i\
- break;\
- end\
- end\
- --Print and Cancel\
- elseif p2 >= 25 and p2 <= 32 and p3 == 10 then\
- break\
- elseif p2 >= 40 and p2 <= 46 and p3 == 10 then\
- rednet.send(printerList[selectedPrinter], \"$3DPRINT ACTIVATE\")\
- ready = false\
- while true do\
- local id,msg = rsTimeReceive(10)\
- \
- if id == printerList[selectedPrinter] and msg == \"$3DPRINT ACTACK\" then\
- ready = true\
- break\
- end\
- end\
- if ready then\
- performPrint()\
- break\
- else\
- displayConfirmDialogue(\"Printer Didn't Respond\", \"The printer didn't respond to the activation command. Check to see if it's online\")\
- end\
- end\
- end\
- end\
- state = \"paint\"\
- end\
- \
- --[[This function changes the current paint program to another tool or mode, depending on user input. Handles\
- any necessary changes in logic involved in that.\
- Params: mode:string = the name of the mode to change to\
- Returns:nil\
- ]]--\
- local function performSelection(mode)\
- if not mode or mode == \"\" then return\
- \
- elseif mode == \"help\" then\
- drawHelpScreen()\
- \
- elseif mode == \"blueprint on\" then\
- blueprint = true\
- ddModes[2][3] = \"blueprint off\"\
- \
- elseif mode == \"blueprint off\" then\
- blueprint = false\
- ddModes[2][3] = \"blueprint on\"\
- \
- elseif mode == \"layers on\" then\
- layerDisplay = true\
- ddModes[2][4] = \"layers off\"\
- \
- elseif mode == \"layers off\" then\
- layerDisplay = false\
- ddModes[2][4] = \"layers on\"\
- \
- elseif mode == \"direction on\" then\
- printDirection = true\
- ddModes[2][5] = \"direction off\"\
- \
- elseif mode == \"direction off\" then\
- printDirection = false\
- ddModes[2][5] = \"direction on\"\
- \
- elseif mode == \"go to\" then\
- changeFrame()\
- \
- elseif mode == \"remove\" then\
- removeFramesAfter(sFrame)\
- \
- elseif mode == \"play\" then\
- playAnimation()\
- \
- elseif mode == \"copy\" then\
- if selectrect and selectrect.x1 ~= selectrect.x2 then\
- copyToBuffer(false)\
- end\
- \
- elseif mode == \"cut\" then\
- if selectrect and selectrect.x1 ~= selectrect.x2 then \
- copyToBuffer(true)\
- end\
- \
- elseif mode == \"paste\" then\
- if selectrect and selectrect.x1 ~= selectrect.x2 then \
- copyFromBuffer(false)\
- end\
- \
- elseif mode == \"hide\" then\
- selectrect = nil\
- if state == \"select\" then state = \"corner select\" end\
- \
- elseif mode == \"alpha to left\" then\
- if lSel then alphaC = lSel end\
- \
- elseif mode == \"alpha to right\" then\
- if rSel then alphaC = rSel end\
- \
- elseif mode == \"record\" then\
- record = not record\
- \
- elseif mode == \"clear\" then\
- if state==\"select\" then buffer = nil\
- else clearImage() end\
- \
- elseif mode == \"select\" then\
- if state==\"corner select\" or state==\"select\" then\
- state = \"paint\"\
- elseif selectrect and selectrect.x1 ~= selectrect.x2 then\
- state = \"select\"\
- else\
- state = \"corner select\" \
- end\
- \
- elseif mode == \"print\" then\
- state = \"print\"\
- runPrintInterface()\
- state = \"paint\"\
- \
- elseif mode == \"save\" then\
- if animated then saveNFA(sPath)\
- else saveNFP(sPath) end\
- \
- elseif mode == \"exit\" then\
- isRunning = false\
- \
- elseif mode ~= state then state = mode\
- else state = \"paint\"\
- end\
- end\
- \
- --[[The main function of the program, reads and handles all events and updates them accordingly. Mode changes,\
- painting to the canvas and general selections are done here.\
- Params: none\
- Returns:nil\
- ]]--\
- local function handleEvents()\
- recttimer = os.startTimer(0.5)\
- while isRunning do\
- drawCanvas()\
- drawInterface()\
- local id,p1,p2,p3 = os.pullEvent()\
- if id==\"timer\" then\
- updateTimer(p1)\
- elseif id==\"mouse_click\" or id==\"mouse_drag\" then\
- if p2 >=w-1 and p3 < #column+1 then\
- if p1==1 then lSel = column[p3]\
- else rSel = column[p3] end\
- elseif p2 >=w-1 and p3==#column+1 then\
- if p1==1 then lSel = nil\
- else rSel = nil end\
- elseif p2==w-1 and p3==h and animated then\
- changeFrame(sFrame-1)\
- elseif p2==w and p3==h and animated then\
- changeFrame(sFrame+1)\
- elseif p2 < w-10 and p3==h then\
- local sel = displayDropDown(1, h-1, ddModes)\
- performSelection(sel)\
- elseif p2 < w-1 and p3 <= h-1 then\
- if state==\"pippette\" then\
- if p1==1 then\
- if frames[sFrame][p3+sy] and frames[sFrame][p3+sy][p2+sx] then\
- lSel = frames[sFrame][p3+sy][p2+sx] \
- end\
- elseif p1==2 then\
- if frames[sFrame][p3+sy] and frames[sFrame][p3+sy][p2+sx] then\
- rSel = frames[sFrame][p3+sy][p2+sx] \
- end\
- end\
- elseif state==\"move\" then\
- updateImageLims(record)\
- moveImage(p2,p3)\
- elseif state==\"flood\" then\
- if p1 == 1 and lSel and frames[sFrame][p3+sy] then \
- floodFill(p2,p3,frames[sFrame][p3+sy][p2+sx],lSel)\
- elseif p1 == 2 and rSel and frames[sFrame][p3+sy] then \
- floodFill(p2,p3,frames[sFrame][p3+sy][p2+sx],rSel)\
- end\
- elseif state==\"corner select\" then\
- if not selectrect then\
- selectrect = { x1=p2+sx, x2=p2+sx, y1=p3+sy, y2=p3+sy }\
- elseif selectrect.x1 ~= p2+sx and selectrect.y1 ~= p3+sy then\
- if p2+sx<selectrect.x1 then selectrect.x1 = p2+sx\
- else selectrect.x2 = p2+sx end\
- \
- if p3+sy<selectrect.y1 then selectrect.y1 = p3+sy\
- else selectrect.y2 = p3+sy end\
- \
- state = \"select\"\
- end\
- elseif state==\"select\" then\
- if p1 == 1 then\
- local swidth = selectrect.x2 - selectrect.x1\
- local sheight = selectrect.y2 - selectrect.y1\
- \
- selectrect.x1 = p2 + sx\
- selectrect.y1 = p3 + sy\
- selectrect.x2 = p2 + swidth + sx\
- selectrect.y2 = p3 + sheight + sy\
- elseif p1 == 2 and p2 < w-2 and p3 < h-1 then\
- inMenu = true\
- local sel = displayDropDown(p2, p3, srModes) \
- inMenu = false\
- performSelection(sel)\
- end\
- else\
- local f,l = sFrame,sFrame\
- if record then f,l = 1,framecount end\
- local bwidth = 0\
- if state == \"brush\" then bwidth = brushsize-1 end\
- \
- for i=f,l do\
- for x = math.max(1,p2+sx-bwidth),p2+sx+bwidth do\
- for y = math.max(1,p3+sy-bwidth), p3+sy+bwidth do\
- if math.abs(x - (p2+sx)) + math.abs(y - (p3+sy)) <= bwidth then\
- if not frames[i][y] then frames[i][y] = {} end\
- if p1==1 then frames[i][y][x] = lSel\
- else frames[i][y][x] = rSel end\
- end\
- end\
- end\
- end\
- end\
- end\
- elseif id==\"key\" then\
- if p1==keys.leftCtrl then\
- local sel = displayDropDown(1, h-1, ddModes[#ddModes]) \
- performSelection(sel)\
- elseif p1==keys.leftAlt then\
- local sel = displayDropDown(1, h-1, ddModes[1]) \
- performSelection(sel)\
- elseif p1==keys.h then \
- performSelection(\"help\")\
- elseif p1==keys.x then \
- performSelection(\"cut\")\
- elseif p1==keys.c then\
- performSelection(\"copy\")\
- elseif p1==keys.v then\
- performSelection(\"paste\")\
- elseif p1==keys.z then\
- performSelection(\"clear\")\
- elseif p1==keys.s then\
- performSelection(\"select\")\
- elseif p1==keys.tab then\
- performSelection(\"hide\")\
- elseif p1==keys.q then\
- performSelection(\"alpha to left\")\
- elseif p1==keys.w then\
- performSelection(\"alpha to right\")\
- elseif p1==keys.f then\
- performSelection(\"flood\")\
- elseif p1==keys.b then\
- performSelection(\"brush\")\
- elseif p1==keys.m then\
- performSelection(\"move\")\
- elseif p1==keys.backslash and animated then\
- performSelection(\"record\")\
- elseif p1==keys.p then\
- performSelection(\"pippette\")\
- elseif p1==keys.g and animated then\
- performSelection(\"go to\")\
- elseif p1==keys.period and animated then\
- changeFrame(sFrame+1)\
- elseif p1==keys.comma and animated then\
- changeFrame(sFrame-1)\
- elseif p1==keys.r and animated then\
- performSelection(\"remove\")\
- elseif p1==keys.space and animated then\
- performSelection(\"play\")\
- elseif p1==keys.left then\
- if state == \"move\" then\
- updateImageLims(record)\
- moveImage(leflim-1,toplim)\
- elseif state==\"select\" and selectrect.x1 > 1 then\
- selectrect.x1 = selectrect.x1-1\
- selectrect.x2 = selectrect.x2-1\
- elseif sx > 0 then sx=sx-1 end\
- elseif p1==keys.right then\
- if state == \"move\" then\
- updateImageLims(record)\
- moveImage(leflim+1,toplim)\
- elseif state==\"select\" then\
- selectrect.x1 = selectrect.x1+1\
- selectrect.x2 = selectrect.x2+1\
- else sx=sx+1 end\
- elseif p1==keys.up then\
- if state == \"move\" then\
- updateImageLims(record)\
- moveImage(leflim,toplim-1)\
- elseif state==\"select\" and selectrect.y1 > 1 then\
- selectrect.y1 = selectrect.y1-1\
- selectrect.y2 = selectrect.y2-1\
- elseif sy > 0 then sy=sy-1 end\
- elseif p1==keys.down then \
- if state == \"move\" then\
- updateImageLims(record)\
- moveImage(leflim,toplim+1)\
- elseif state==\"select\" then\
- selectrect.y1 = selectrect.y1+1\
- selectrect.y2 = selectrect.y2+1\
- else sy=sy+1 end\
- end\
- elseif id==\"char\" and tonumber(p1) then\
- if state==\"brush\" and tonumber(p1) > 1 then\
- brushsize = tonumber(p1)\
- elseif tonumber(p1) > 0 then\
- changeFrame(tonumber(p1))\
- end\
- end\
- end\
- end\
- \
- --[[ \
- Section: Main \
- ]]--\
- \
- --Taken almost directly from edit (for consistency)\
- local tArgs = {...}\
- \
- local ca = 1\
- \
- if tArgs[ca] == \"-a\" then\
- animated = true\
- ca = ca + 1\
- end\
- \
- if #tArgs < ca then\
- print(\"Usage: npaintpro [-a] <path>\")\
- return\
- end\
- \
- sPath = shell.resolve(tArgs[ca])\
- local bReadOnly = fs.isReadOnly(sPath)\
- if fs.exists(sPath) then\
- if fs.isDir(sPath) then\
- print(\"Cannot edit a directory.\")\
- return\
- elseif string.find(sPath, \".nfp\") ~= #sPath-3 and string.find(sPath, \".nfa\") ~= #sPath-3 then\
- print(\"Can only edit .nfp and nfa files:\",string.find(sPath, \".nfp\"),#sPath-3)\
- return\
- end\
- \
- if string.find(sPath, \".nfa\") == #sPath-3 then\
- animated = true\
- end\
- \
- if string.find(sPath, \".nfp\") == #sPath-3 and animated then\
- print(\"Convert to nfa? Y/N\")\
- if string.find(string.lower(io.read()), \"y\") then\
- local nsPath = string.sub(sPath, 1, #sPath-1)..\"a\"\
- fs.move(sPath, nsPath)\
- sPath = nsPath\
- else\
- animated = false\
- end\
- end\
- else\
- if not animated and string.find(sPath, \".nfp\") ~= #sPath-3 then \
- sPath = sPath..\".nfp\"\
- elseif animated and string.find(sPath, \".nfa\") ~= #sPath-3 then \
- sPath = sPath..\".nfa\"\
- end\
- end \
- \
- if not term.isColour() then\
- print(\"For colour computers only\")\
- return\
- end\
- \
- drawLogo()\
- init()\
- handleEvents()\
- \
- term.setBackgroundColour(colours.black)\
- shell.run(\"clear\")",
- edit = "-- Get file to edit\
- local tArgs = { ... }\
- if #tArgs == 0 then\
- print( \"Usage: edit <path>\" )\
- return\
- end\
- \
- -- Error checking\
- local sPath = shell.resolve( tArgs[1] )\
- local bReadOnly = fs.isReadOnly( sPath )\
- if fs.exists( sPath ) and fs.isDir( sPath ) then\
- print( \"Cannot edit a directory.\" )\
- return\
- end\
- \
- local x,y = 1,1\
- local w,h = term.getSize()\
- local scrollX, scrollY = 0,0\
- \
- local tLines = {}\
- local bRunning = true\
- \
- -- Colours\
- local highlightColour, keywordColour, commentColour, textColour, bgColour\
- if term.isColour() then\
- bgColour = colours.black\
- textColour = colours.white\
- highlightColour = colours.yellow\
- keywordColour = colours.yellow\
- commentColour = colours.green\
- stringColour = colours.red\
- else\
- bgColour = colours.black\
- textColour = colours.white\
- highlightColour = colours.white\
- keywordColour = colours.white\
- commentColour = colours.white\
- stringColour = colours.white\
- end\
- \
- -- Menus\
- local bMenu = false\
- local nMenuItem = 1\
- local tMenuItems\
- if bReadOnly then\
- tMenuItems = { \"Exit\", \"Print\" }\
- else\
- tMenuItems = { \"Save\", \"Exit\", \"Print\" }\
- end\
- \
- local sStatus = \"Press Ctrl to access menu\"\
- \
- local function load( _sPath )\
- tLines = {}\
- if fs.exists( _sPath ) then\
- local file = io.open( _sPath, \"r\" )\
- local sLine = file:read()\
- while sLine do\
- table.insert( tLines, sLine )\
- sLine = file:read()\
- end\
- file:close()\
- end\
- \
- if #tLines == 0 then\
- table.insert( tLines, \"\" )\
- end\
- end\
- \
- local function save( _sPath )\
- -- Create intervening folder\
- local sDir = sPath:sub(1, sPath:len() - fs.getName(sPath):len() )\
- if not fs.exists( sDir ) then\
- fs.makeDir( sDir )\
- end\
- \
- -- Save\
- local file = nil\
- local function innerSave()\
- file = fs.open( _sPath, \"w\" )\
- if file then\
- for n, sLine in ipairs( tLines ) do\
- file.write( sLine .. \"\\n\" )\
- end\
- else\
- error( \"Failed to open \".._sPath )\
- end\
- end\
- \
- local ok = pcall( innerSave )\
- if file then \
- file.close()\
- end\
- return ok\
- end\
- \
- local tKeywords = {\
- [\"and\"] = true,\
- [\"break\"] = true,\
- [\"do\"] = true,\
- [\"else\"] = true,\
- [\"elseif\"] = true,\
- [\"end\"] = true,\
- [\"false\"] = true,\
- [\"for\"] = true,\
- [\"function\"] = true,\
- [\"if\"] = true,\
- [\"in\"] = true,\
- [\"local\"] = true,\
- [\"nil\"] = true,\
- [\"not\"] = true,\
- [\"or\"] = true,\
- [\"repeat\"] = true,\
- [\"return\"] = true,\
- [\"then\"] = true,\
- [\"true\"] = true,\
- [\"until\"]= true,\
- [\"while\"] = true,\
- }\
- \
- local function tryWrite( sLine, regex, colour )\
- local match = string.match( sLine, regex )\
- if match then\
- if type(colour) == \"number\" then\
- term.setTextColour( colour )\
- else\
- term.setTextColour( colour(match) )\
- end\
- term.write( match )\
- term.setTextColour( textColour )\
- return string.sub( sLine, string.len(match) + 1 )\
- end\
- return nil\
- end\
- \
- local function writeHighlighted( sLine )\
- while string.len(sLine) > 0 do \
- sLine = \
- tryWrite( sLine, \"^%-%-%[%[.-%]%]\", commentColour ) or\
- tryWrite( sLine, \"^%-%-.*\", commentColour ) or\
- tryWrite( sLine, \"^\\\".-[^\\\\]\\\"\", stringColour ) or\
- tryWrite( sLine, \"^\\'.-[^\\\\]\\'\", stringColour ) or\
- tryWrite( sLine, \"^%[%[.-%]%]\", stringColour ) or\
- tryWrite( sLine, \"^[%w_]+\", function( match )\
- if tKeywords[ match ] then\
- return keywordColour\
- end\
- return textColour\
- end ) or\
- tryWrite( sLine, \"^[^%w_]\", textColour )\
- end\
- end\
- \
- local function redrawText()\
- for y=1,h-1 do\
- term.setCursorPos( 1 - scrollX, y )\
- term.clearLine()\
- \
- local sLine = tLines[ y + scrollY ]\
- if sLine ~= nil then\
- writeHighlighted( sLine )\
- end\
- end\
- term.setCursorPos( x - scrollX, y - scrollY )\
- end\
- \
- local function redrawLine(_nY)\
- local sLine = tLines[_nY]\
- term.setCursorPos( 1 - scrollX, _nY - scrollY )\
- term.clearLine()\
- writeHighlighted( sLine )\
- term.setCursorPos( x - scrollX, _nY - scrollY )\
- end\
- \
- local function redrawMenu()\
- -- Clear line\
- term.setCursorPos( 1, h )\
- term.clearLine()\
- \
- -- Draw line numbers\
- term.setCursorPos( w - string.len( \"Ln \"..y ) + 1, h )\
- term.setTextColour( highlightColour )\
- term.write( \"Ln \" )\
- term.setTextColour( textColour )\
- term.write( y )\
- \
- term.setCursorPos( 1, h )\
- if bMenu then\
- -- Draw menu\
- term.setTextColour( textColour )\
- for nItem,sItem in pairs( tMenuItems ) do\
- if nItem == nMenuItem then\
- term.setTextColour( highlightColour )\
- term.write( \"[\" )\
- term.setTextColour( textColour )\
- term.write( sItem )\
- term.setTextColour( highlightColour )\
- term.write( \"]\" )\
- term.setTextColour( textColour )\
- else\
- term.write( \" \"..sItem..\" \" )\
- end\
- end\
- else\
- -- Draw status\
- term.setTextColour( highlightColour )\
- term.write( sStatus )\
- term.setTextColour( textColour )\
- end\
- \
- -- Reset cursor\
- term.setCursorPos( x - scrollX, y - scrollY )\
- end\
- \
- local tMenuFuncs = { \
- Save=function()\
- if bReadOnly then\
- sStatus = \"Access denied\"\
- else\
- local ok, err = save( sPath )\
- if ok then\
- sStatus=\"Saved to \"..sPath\
- else\
- sStatus=\"Error saving to \"..sPath\
- end\
- end\
- redrawMenu()\
- end,\
- Print=function()\
- local printer = peripheral.find( \"printer\" )\
- if not printer then\
- sStatus = \"No printer attached\"\
- return\
- end\
- \
- local nPage = 0\
- local sName = fs.getName( sPath )\
- if printer.getInkLevel() < 1 then\
- sStatus = \"Printer out of ink\"\
- return\
- elseif printer.getPaperLevel() < 1 then\
- sStatus = \"Printer out of paper\"\
- return\
- end\
- \
- local screenTerminal = term.current()\
- local printerTerminal = {\
- getCursorPos = printer.getCursorPos,\
- setCursorPos = printer.setCursorPos,\
- getSize = printer.getPageSize,\
- write = printer.write,\
- }\
- printerTerminal.scroll = function()\
- if nPage == 1 then\
- printer.setPageTitle( sName..\" (page \"..nPage..\")\" ) \
- end\
- \
- while not printer.newPage() do\
- if printer.getInkLevel() < 1 then\
- sStatus = \"Printer out of ink, please refill\"\
- elseif printer.getPaperLevel() < 1 then\
- sStatus = \"Printer out of paper, please refill\"\
- else\
- sStatus = \"Printer output tray full, please empty\"\
- end\
- \
- term.redirect( screenTerminal )\
- redrawMenu()\
- term.redirect( printerTerminal )\
- \
- local timer = os.startTimer(0.5)\
- sleep(0.5)\
- end\
- \
- nPage = nPage + 1\
- if nPage == 1 then\
- printer.setPageTitle( sName )\
- else\
- printer.setPageTitle( sName..\" (page \"..nPage..\")\" )\
- end\
- end\
- \
- bMenu = false\
- term.redirect( printerTerminal )\
- local ok, error = pcall( function()\
- term.scroll()\
- for n, sLine in ipairs( tLines ) do\
- print( sLine )\
- end\
- end )\
- term.redirect( screenTerminal )\
- if not ok then\
- print( error )\
- end\
- \
- while not printer.endPage() do\
- sStatus = \"Printer output tray full, please empty\"\
- redrawMenu()\
- sleep( 0.5 )\
- end\
- bMenu = true\
- \
- if nPage > 1 then\
- sStatus = \"Printed \"..nPage..\" Pages\"\
- else\
- sStatus = \"Printed 1 Page\"\
- end\
- redrawMenu()\
- end,\
- Exit=function()\
- bRunning = false\
- end\
- }\
- \
- local function doMenuItem( _n )\
- tMenuFuncs[tMenuItems[_n]]()\
- if bMenu then\
- bMenu = false\
- term.setCursorBlink( true )\
- end\
- redrawMenu()\
- end\
- \
- local function setCursor( x, y )\
- local screenX = x - scrollX\
- local screenY = y - scrollY\
- \
- local bRedraw = false\
- if screenX < 1 then\
- scrollX = x - 1\
- screenX = 1\
- bRedraw = true\
- elseif screenX > w then\
- scrollX = x - w\
- screenX = w\
- bRedraw = true\
- end\
- \
- if screenY < 1 then\
- scrollY = y - 1\
- screenY = 1\
- bRedraw = true\
- elseif screenY > h-1 then\
- scrollY = y - (h-1)\
- screenY = h-1\
- bRedraw = true\
- end\
- \
- if bRedraw then\
- redrawText()\
- end\
- term.setCursorPos( screenX, screenY )\
- \
- -- Statusbar now pertains to menu, it would probably be safe to redraw the menu on every key event.\
- redrawMenu()\
- end\
- \
- -- Actual program functionality begins\
- load(sPath)\
- \
- term.setBackgroundColour( bgColour )\
- term.clear()\
- term.setCursorPos(x,y)\
- term.setCursorBlink( true )\
- \
- redrawText()\
- redrawMenu()\
- \
- -- Handle input\
- while bRunning do\
- local sEvent, param, param2, param3 = os.pullEvent()\
- if sEvent == \"key\" then\
- if param == keys.up then\
- -- Up\
- if not bMenu then\
- if y > 1 then\
- -- Move cursor up\
- y = y - 1\
- x = math.min( x, string.len( tLines[y] ) + 1 )\
- setCursor( x, y )\
- end\
- end\
- elseif param == keys.down then\
- -- Down\
- if not bMenu then\
- -- Move cursor down\
- if y < #tLines then\
- y = y + 1\
- x = math.min( x, string.len( tLines[y] ) + 1 )\
- setCursor( x, y )\
- end\
- end\
- elseif param == keys.tab then\
- -- Tab\
- if not bMenu and not bReadOnly then\
- -- Indent line\
- tLines[y]=\" \"..tLines[y]\
- x = x + 2\
- setCursor( x, y )\
- redrawLine(y)\
- end\
- elseif param == keys.pageUp then\
- -- Page Up\
- if not bMenu then\
- -- Move up a page\
- if y - (h - 1) >= 1 then\
- y = y - (h - 1)\
- else\
- y = 1\
- end\
- x = math.min( x, string.len( tLines[y] ) + 1 )\
- setCursor( x, y )\
- end\
- elseif param == keys.pageDown then\
- -- Page Down\
- if not bMenu then\
- -- Move down a page\
- if y + (h - 1) <= #tLines then\
- y = y + (h - 1)\
- else\
- y = #tLines\
- end\
- x = math.min( x, string.len( tLines[y] ) + 1 )\
- setCursor( x, y )\
- end\
- elseif param == keys.home then\
- -- Home\
- if not bMenu then\
- -- Move cursor to the beginning\
- x=1\
- setCursor(x,y)\
- end\
- elseif param == keys[\"end\"] then\
- -- End\
- if not bMenu then\
- -- Move cursor to the end\
- x = string.len( tLines[y] ) + 1\
- setCursor(x,y)\
- end\
- elseif param == keys.left then\
- -- Left\
- if not bMenu then\
- if x > 1 then\
- -- Move cursor left\
- x = x - 1\
- elseif x==1 and y>1 then\
- x = string.len( tLines[y-1] ) + 1\
- y = y - 1\
- end\
- setCursor( x, y )\
- else\
- -- Move menu left\
- nMenuItem = nMenuItem - 1\
- if nMenuItem < 1 then\
- nMenuItem = #tMenuItems\
- end\
- redrawMenu()\
- end\
- elseif param == keys.right then\
- -- Right\
- if not bMenu then\
- if x < string.len( tLines[y] ) + 1 then\
- -- Move cursor right\
- x = x + 1\
- elseif x==string.len( tLines[y] ) + 1 and y<#tLines then\
- x = 1\
- y = y + 1\
- end\
- setCursor( x, y )\
- else\
- -- Move menu right\
- nMenuItem = nMenuItem + 1\
- if nMenuItem > #tMenuItems then\
- nMenuItem = 1\
- end\
- redrawMenu()\
- end\
- elseif param == keys.delete then\
- -- Delete\
- if not bMenu and not bReadOnly then\
- if x < string.len( tLines[y] ) + 1 then\
- local sLine = tLines[y]\
- tLines[y] = string.sub(sLine,1,x-1) .. string.sub(sLine,x+1)\
- redrawLine(y)\
- elseif y<#tLines then\
- tLines[y] = tLines[y] .. tLines[y+1]\
- table.remove( tLines, y+1 )\
- redrawText()\
- redrawMenu()\
- end\
- end\
- elseif param == keys.backspace then\
- -- Backspace\
- if not bMenu and not bReadOnly then\
- if x > 1 then\
- -- Remove character\
- local sLine = tLines[y]\
- tLines[y] = string.sub(sLine,1,x-2) .. string.sub(sLine,x)\
- redrawLine(y)\
- \
- x = x - 1\
- setCursor( x, y )\
- elseif y > 1 then\
- -- Remove newline\
- local sPrevLen = string.len( tLines[y-1] )\
- tLines[y-1] = tLines[y-1] .. tLines[y]\
- table.remove( tLines, y )\
- redrawText()\
- \
- x = sPrevLen + 1\
- y = y - 1\
- setCursor( x, y )\
- end\
- end\
- elseif param == keys.enter then\
- -- Enter\
- if not bMenu and not bReadOnly then\
- -- Newline\
- local sLine = tLines[y]\
- local _,spaces=string.find(sLine,\"^[ ]+\")\
- if not spaces then\
- spaces=0\
- end\
- tLines[y] = string.sub(sLine,1,x-1)\
- table.insert( tLines, y+1, string.rep(' ',spaces)..string.sub(sLine,x) )\
- redrawText()\
- \
- x = spaces+1\
- y = y + 1\
- setCursor( x, y )\
- elseif bMenu then\
- -- Menu selection\
- doMenuItem( nMenuItem )\
- end\
- elseif param == keys.leftCtrl or param == keys.rightCtrl then\
- -- Menu toggle\
- bMenu = not bMenu\
- if bMenu then\
- term.setCursorBlink( false )\
- else\
- term.setCursorBlink( true )\
- end\
- redrawMenu()\
- end\
- \
- elseif sEvent == \"char\" then\
- if not bMenu and not bReadOnly then\
- -- Input text\
- local sLine = tLines[y]\
- tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)\
- redrawLine(y)\
- \
- x = x + 1\
- setCursor( x, y )\
- elseif bMenu then\
- -- Select menu items\
- for n,sMenuItem in ipairs( tMenuItems ) do\
- if string.lower(string.sub(sMenuItem,1,1)) == string.lower(param) then\
- doMenuItem( n )\
- break\
- end\
- end\
- end\
- \
- elseif sEvent == \"paste\" then\
- if not bMenu and not bReadOnly then\
- -- Input text\
- local sLine = tLines[y]\
- tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)\
- redrawLine(y)\
- \
- x = x + string.len( param )\
- setCursor( x, y )\
- end\
- \
- elseif sEvent == \"mouse_click\" then\
- if not bMenu then\
- if param == 1 then\
- -- Left click\
- local cx,cy = param2, param3\
- if cy < h then\
- y = math.min( math.max( scrollY + cy, 1 ), #tLines )\
- x = math.min( math.max( scrollX + cx, 1 ), string.len( tLines[y] ) + 1 )\
- setCursor( x, y )\
- end\
- end\
- end\
- \
- elseif sEvent == \"mouse_scroll\" then\
- if not bMenu then\
- if param == -1 then\
- -- Scroll up\
- if scrollY > 0 then\
- -- Move cursor up\
- scrollY = scrollY - 1\
- redrawText()\
- end\
- \
- elseif param == 1 then\
- -- Scroll down\
- local nMaxScroll = #tLines - (h-1)\
- if scrollY < nMaxScroll then\
- -- Move cursor down\
- scrollY = scrollY + 1\
- redrawText()\
- end\
- \
- end\
- end\
- \
- elseif sEvent == \"term_resize\" then\
- w,h = term.getSize()\
- setCursor( x, y )\
- redrawMenu()\
- redrawText()\
- \
- end\
- end\
- \
- -- Cleanup\
- term.clear()\
- term.setCursorBlink( false )\
- term.setCursorPos( 1, 1 )",
- },
- [ "FileX.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- {\
- 16,\
- \"F\",\
- 32768,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 16,\
- \"X\",\
- 32768,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- },\
- {},\
- [ 0 ] = {\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- },\
- [ 14 ] = {},\
- [ 12 ] = {},\
- [ 24 ] = {},\
- [ 26 ] = {},\
- [ 13 ] = {},\
- }",
- },
- [ "Edit.app" ] = {
- [ "permission.data" ] = "userTest",
- [ "Edit.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 2048,\
- \"-\",\
- 1,\
- },\
- {\
- 2048,\
- \"-\",\
- 1,\
- },\
- {\
- 2048,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2048,\
- \"-\",\
- 1,\
- },\
- {\
- 2048,\
- \"-\",\
- 1,\
- },\
- {\
- 2048,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2048,\
- \"-\",\
- 1,\
- },\
- {\
- 2048,\
- \"-\",\
- 1,\
- },\
- {\
- 2048,\
- \"-\",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 128,\
- \"|\",\
- 1,\
- },\
- {\
- 128,\
- \"|\",\
- 1,\
- },\
- {\
- 128,\
- \"|\",\
- 1,\
- },\
- },\
- }",
- [ "Main.lua" ] = "-- Get file to edit\
- local tArgs = { ... }\
- if #tArgs == 0 then\
- term.setTextColour(colors.white)\
- term.setBackgroundColour(colors.black)\
- term.clear()\
- term.write(\"Path please!\")\
- tArgs[1] = \"OmniOS/Data/\"..read()\
- end\
- \
- -- Error checking\
- --local sPath = shell.resolve( tArgs[1] )\
- local sPath = tArgs[1]\
- local bReadOnly = fs.isReadOnly( sPath )\
- if fs.exists( sPath ) and fs.isDir( sPath ) then\
- print( \"Cannot edit a directory.\" )\
- return\
- end\
- \
- local x,y = 1,1\
- local w,h = term.getSize()\
- local scrollX, scrollY = 0,0\
- \
- local tLines = {}\
- local bRunning = true\
- \
- -- Colours\
- local highlightColour, keywordColour, commentColour, textColour, bgColour\
- if term.isColour() then\
- bgColour = colours.black\
- textColour = colours.white\
- highlightColour = colours.yellow\
- keywordColour = colours.yellow\
- commentColour = colours.green\
- stringColour = colours.red\
- else\
- bgColour = colours.black\
- textColour = colours.white\
- highlightColour = colours.white\
- keywordColour = colours.white\
- commentColour = colours.white\
- stringColour = colours.white\
- end\
- \
- -- Menus\
- local bMenu = false\
- local nMenuItem = 1\
- local tMenuItems\
- if bReadOnly then\
- tMenuItems = { \"Exit\", \"Print\" }\
- else\
- tMenuItems = { \"Save\", \"Exit\", \"Print\" }\
- end\
- \
- local sStatus = \"Press Ctrl to access menu\"\
- \
- local function load( _sPath )\
- tLines = {}\
- if fs.exists( _sPath ) then\
- local file = io.open( _sPath, \"r\" )\
- local sLine = file:read()\
- while sLine do\
- table.insert( tLines, sLine )\
- sLine = file:read()\
- end\
- file:close()\
- end\
- \
- if #tLines == 0 then\
- table.insert( tLines, \"\" )\
- end\
- end\
- \
- local function save( _sPath )\
- -- Create intervening folder\
- local sDir = sPath:sub(1, sPath:len() - fs.getName(sPath):len() )\
- if not fs.exists( sDir ) then\
- fs.makeDir( sDir )\
- end\
- \
- -- Save\
- local file = nil\
- local function innerSave()\
- file = fs.open( _sPath, \"w\" )\
- if file then\
- for n, sLine in ipairs( tLines ) do\
- file.write( sLine .. \"\\n\" )\
- end\
- else\
- error( \"Failed to open \".._sPath )\
- end\
- end\
- \
- local ok = pcall( innerSave )\
- if file then \
- file.close()\
- end\
- return ok\
- end\
- \
- local tKeywords = {\
- [\"and\"] = true,\
- [\"break\"] = true,\
- [\"do\"] = true,\
- [\"else\"] = true,\
- [\"elseif\"] = true,\
- [\"end\"] = true,\
- [\"false\"] = true,\
- [\"for\"] = true,\
- [\"function\"] = true,\
- [\"if\"] = true,\
- [\"in\"] = true,\
- [\"local\"] = true,\
- [\"nil\"] = true,\
- [\"not\"] = true,\
- [\"or\"] = true,\
- [\"repeat\"] = true,\
- [\"return\"] = true,\
- [\"then\"] = true,\
- [\"true\"] = true,\
- [\"until\"]= true,\
- [\"while\"] = true,\
- }\
- \
- local function tryWrite( sLine, regex, colour )\
- local match = string.match( sLine, regex )\
- if match then\
- if type(colour) == \"number\" then\
- term.setTextColour( colour )\
- else\
- term.setTextColour( colour(match) )\
- end\
- term.write( match )\
- term.setTextColour( textColour )\
- return string.sub( sLine, string.len(match) + 1 )\
- end\
- return nil\
- end\
- \
- local function writeHighlighted( sLine )\
- while string.len(sLine) > 0 do \
- sLine = \
- tryWrite( sLine, \"^%-%-%[%[.-%]%]\", commentColour ) or\
- tryWrite( sLine, \"^%-%-.*\", commentColour ) or\
- tryWrite( sLine, \"^\\\".-[^\\\\]\\\"\", stringColour ) or\
- tryWrite( sLine, \"^\\'.-[^\\\\]\\'\", stringColour ) or\
- tryWrite( sLine, \"^%[%[.-%]%]\", stringColour ) or\
- tryWrite( sLine, \"^[%w_]+\", function( match )\
- if tKeywords[ match ] then\
- return keywordColour\
- end\
- return textColour\
- end ) or\
- tryWrite( sLine, \"^[^%w_]\", textColour )\
- end\
- end\
- \
- local function redrawText()\
- for y=1,h-1 do\
- term.setCursorPos( 1 - scrollX, y )\
- term.clearLine()\
- \
- local sLine = tLines[ y + scrollY ]\
- if sLine ~= nil then\
- writeHighlighted( sLine )\
- end\
- end\
- term.setCursorPos( x - scrollX, y - scrollY )\
- end\
- \
- local function redrawLine(_nY)\
- local sLine = tLines[_nY]\
- term.setCursorPos( 1 - scrollX, _nY - scrollY )\
- term.clearLine()\
- writeHighlighted( sLine )\
- term.setCursorPos( x - scrollX, _nY - scrollY )\
- end\
- \
- local function redrawMenu()\
- -- Clear line\
- term.setCursorPos( 1, h )\
- term.clearLine()\
- \
- -- Draw line numbers\
- term.setCursorPos( w - string.len( \"Ln \"..y ) + 1, h )\
- term.setTextColour( highlightColour )\
- term.write( \"Ln \" )\
- term.setTextColour( textColour )\
- term.write( y )\
- \
- term.setCursorPos( 1, h )\
- if bMenu then\
- -- Draw menu\
- term.setTextColour( textColour )\
- for nItem,sItem in pairs( tMenuItems ) do\
- if nItem == nMenuItem then\
- term.setTextColour( highlightColour )\
- term.write( \"[\" )\
- term.setTextColour( textColour )\
- term.write( sItem )\
- term.setTextColour( highlightColour )\
- term.write( \"]\" )\
- term.setTextColour( textColour )\
- else\
- term.write( \" \"..sItem..\" \" )\
- end\
- end\
- else\
- -- Draw status\
- term.setTextColour( highlightColour )\
- term.write( sStatus )\
- term.setTextColour( textColour )\
- end\
- \
- -- Reset cursor\
- term.setCursorPos( x - scrollX, y - scrollY )\
- end\
- \
- local tMenuFuncs = { \
- Save=function()\
- if bReadOnly then\
- sStatus = \"Access denied\"\
- else\
- local ok, err = save( sPath )\
- if ok then\
- sStatus=\"Saved to \"..sPath\
- else\
- sStatus=\"Error saving to \"..sPath\
- end\
- end\
- redrawMenu()\
- end,\
- Print=function()\
- local printer = peripheral.find( \"printer\" )\
- if not printer then\
- sStatus = \"No printer attached\"\
- return\
- end\
- \
- local nPage = 0\
- local sName = fs.getName( sPath )\
- if printer.getInkLevel() < 1 then\
- sStatus = \"Printer out of ink\"\
- return\
- elseif printer.getPaperLevel() < 1 then\
- sStatus = \"Printer out of paper\"\
- return\
- end\
- \
- local screenTerminal = term.current()\
- local printerTerminal = {\
- getCursorPos = printer.getCursorPos,\
- setCursorPos = printer.setCursorPos,\
- getSize = printer.getPageSize,\
- write = printer.write,\
- }\
- printerTerminal.scroll = function()\
- if nPage == 1 then\
- printer.setPageTitle( sName..\" (page \"..nPage..\")\" ) \
- end\
- \
- while not printer.newPage() do\
- if printer.getInkLevel() < 1 then\
- sStatus = \"Printer out of ink, please refill\"\
- elseif printer.getPaperLevel() < 1 then\
- sStatus = \"Printer out of paper, please refill\"\
- else\
- sStatus = \"Printer output tray full, please empty\"\
- end\
- \
- term.redirect( screenTerminal )\
- redrawMenu()\
- term.redirect( printerTerminal )\
- \
- local timer = os.startTimer(0.5)\
- sleep(0.5)\
- end\
- \
- nPage = nPage + 1\
- if nPage == 1 then\
- printer.setPageTitle( sName )\
- else\
- printer.setPageTitle( sName..\" (page \"..nPage..\")\" )\
- end\
- end\
- \
- bMenu = false\
- term.redirect( printerTerminal )\
- local ok, error = pcall( function()\
- term.scroll()\
- for n, sLine in ipairs( tLines ) do\
- print( sLine )\
- end\
- end )\
- term.redirect( screenTerminal )\
- if not ok then\
- print( error )\
- end\
- \
- while not printer.endPage() do\
- sStatus = \"Printer output tray full, please empty\"\
- redrawMenu()\
- sleep( 0.5 )\
- end\
- bMenu = true\
- \
- if nPage > 1 then\
- sStatus = \"Printed \"..nPage..\" Pages\"\
- else\
- sStatus = \"Printed 1 Page\"\
- end\
- redrawMenu()\
- end,\
- Exit=function()\
- bRunning = false\
- end\
- }\
- \
- local function doMenuItem( _n )\
- tMenuFuncs[tMenuItems[_n]]()\
- if bMenu then\
- bMenu = false\
- term.setCursorBlink( true )\
- end\
- redrawMenu()\
- end\
- \
- local function setCursor( x, y )\
- local screenX = x - scrollX\
- local screenY = y - scrollY\
- \
- local bRedraw = false\
- if screenX < 1 then\
- scrollX = x - 1\
- screenX = 1\
- bRedraw = true\
- elseif screenX > w then\
- scrollX = x - w\
- screenX = w\
- bRedraw = true\
- end\
- \
- if screenY < 1 then\
- scrollY = y - 1\
- screenY = 1\
- bRedraw = true\
- elseif screenY > h-1 then\
- scrollY = y - (h-1)\
- screenY = h-1\
- bRedraw = true\
- end\
- \
- if bRedraw then\
- redrawText()\
- end\
- term.setCursorPos( screenX, screenY )\
- \
- -- Statusbar now pertains to menu, it would probably be safe to redraw the menu on every key event.\
- redrawMenu()\
- end\
- \
- -- Actual program functionality begins\
- load(sPath)\
- \
- term.setBackgroundColour( bgColour )\
- term.clear()\
- term.setCursorPos(x,y)\
- term.setCursorBlink( true )\
- \
- redrawText()\
- redrawMenu()\
- \
- -- Handle input\
- while bRunning do\
- local sEvent, param, param2, param3 = os.pullEvent()\
- if sEvent == \"key\" then\
- if param == keys.up then\
- -- Up\
- if not bMenu then\
- if y > 1 then\
- -- Move cursor up\
- y = y - 1\
- x = math.min( x, string.len( tLines[y] ) + 1 )\
- setCursor( x, y )\
- end\
- end\
- elseif param == keys.down then\
- -- Down\
- if not bMenu then\
- -- Move cursor down\
- if y < #tLines then\
- y = y + 1\
- x = math.min( x, string.len( tLines[y] ) + 1 )\
- setCursor( x, y )\
- end\
- end\
- elseif param == keys.tab then\
- -- Tab\
- if not bMenu and not bReadOnly then\
- -- Indent line\
- tLines[y]=\" \"..tLines[y]\
- x = x + 2\
- setCursor( x, y )\
- redrawLine(y)\
- end\
- elseif param == keys.pageUp then\
- -- Page Up\
- if not bMenu then\
- -- Move up a page\
- if y - (h - 1) >= 1 then\
- y = y - (h - 1)\
- else\
- y = 1\
- end\
- x = math.min( x, string.len( tLines[y] ) + 1 )\
- setCursor( x, y )\
- end\
- elseif param == keys.pageDown then\
- -- Page Down\
- if not bMenu then\
- -- Move down a page\
- if y + (h - 1) <= #tLines then\
- y = y + (h - 1)\
- else\
- y = #tLines\
- end\
- x = math.min( x, string.len( tLines[y] ) + 1 )\
- setCursor( x, y )\
- end\
- elseif param == keys.home then\
- -- Home\
- if not bMenu then\
- -- Move cursor to the beginning\
- x=1\
- setCursor(x,y)\
- end\
- elseif param == keys[\"end\"] then\
- -- End\
- if not bMenu then\
- -- Move cursor to the end\
- x = string.len( tLines[y] ) + 1\
- setCursor(x,y)\
- end\
- elseif param == keys.left then\
- -- Left\
- if not bMenu then\
- if x > 1 then\
- -- Move cursor left\
- x = x - 1\
- elseif x==1 and y>1 then\
- x = string.len( tLines[y-1] ) + 1\
- y = y - 1\
- end\
- setCursor( x, y )\
- else\
- -- Move menu left\
- nMenuItem = nMenuItem - 1\
- if nMenuItem < 1 then\
- nMenuItem = #tMenuItems\
- end\
- redrawMenu()\
- end\
- elseif param == keys.right then\
- -- Right\
- if not bMenu then\
- if x < string.len( tLines[y] ) + 1 then\
- -- Move cursor right\
- x = x + 1\
- elseif x==string.len( tLines[y] ) + 1 and y<#tLines then\
- x = 1\
- y = y + 1\
- end\
- setCursor( x, y )\
- else\
- -- Move menu right\
- nMenuItem = nMenuItem + 1\
- if nMenuItem > #tMenuItems then\
- nMenuItem = 1\
- end\
- redrawMenu()\
- end\
- elseif param == keys.delete then\
- -- Delete\
- if not bMenu and not bReadOnly then\
- if x < string.len( tLines[y] ) + 1 then\
- local sLine = tLines[y]\
- tLines[y] = string.sub(sLine,1,x-1) .. string.sub(sLine,x+1)\
- redrawLine(y)\
- elseif y<#tLines then\
- tLines[y] = tLines[y] .. tLines[y+1]\
- table.remove( tLines, y+1 )\
- redrawText()\
- redrawMenu()\
- end\
- end\
- elseif param == keys.backspace then\
- -- Backspace\
- if not bMenu and not bReadOnly then\
- if x > 1 then\
- -- Remove character\
- local sLine = tLines[y]\
- tLines[y] = string.sub(sLine,1,x-2) .. string.sub(sLine,x)\
- redrawLine(y)\
- \
- x = x - 1\
- setCursor( x, y )\
- elseif y > 1 then\
- -- Remove newline\
- local sPrevLen = string.len( tLines[y-1] )\
- tLines[y-1] = tLines[y-1] .. tLines[y]\
- table.remove( tLines, y )\
- redrawText()\
- \
- x = sPrevLen + 1\
- y = y - 1\
- setCursor( x, y )\
- end\
- end\
- elseif param == keys.enter then\
- -- Enter\
- if not bMenu and not bReadOnly then\
- -- Newline\
- local sLine = tLines[y]\
- local _,spaces=string.find(sLine,\"^[ ]+\")\
- if not spaces then\
- spaces=0\
- end\
- tLines[y] = string.sub(sLine,1,x-1)\
- table.insert( tLines, y+1, string.rep(' ',spaces)..string.sub(sLine,x) )\
- redrawText()\
- \
- x = spaces+1\
- y = y + 1\
- setCursor( x, y )\
- elseif bMenu then\
- -- Menu selection\
- doMenuItem( nMenuItem )\
- end\
- elseif param == keys.leftCtrl or param == keys.rightCtrl then\
- -- Menu toggle\
- bMenu = not bMenu\
- if bMenu then\
- term.setCursorBlink( false )\
- else\
- term.setCursorBlink( true )\
- end\
- redrawMenu()\
- end\
- \
- elseif sEvent == \"char\" then\
- if not bMenu and not bReadOnly then\
- -- Input text\
- local sLine = tLines[y]\
- tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)\
- redrawLine(y)\
- \
- x = x + 1\
- setCursor( x, y )\
- elseif bMenu then\
- -- Select menu items\
- for n,sMenuItem in ipairs( tMenuItems ) do\
- if string.lower(string.sub(sMenuItem,1,1)) == string.lower(param) then\
- doMenuItem( n )\
- break\
- end\
- end\
- end\
- \
- elseif sEvent == \"paste\" then\
- if not bMenu and not bReadOnly then\
- -- Input text\
- local sLine = tLines[y]\
- tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)\
- redrawLine(y)\
- \
- x = x + string.len( param )\
- setCursor( x, y )\
- end\
- \
- elseif sEvent == \"mouse_click\" then\
- if not bMenu then\
- if param == 1 then\
- -- Left click\
- local cx,cy = param2, param3\
- if cy < h then\
- y = math.min( math.max( scrollY + cy, 1 ), #tLines )\
- x = math.min( math.max( scrollX + cx, 1 ), string.len( tLines[y] ) + 1 )\
- setCursor( x, y )\
- end\
- end\
- end\
- \
- elseif sEvent == \"mouse_scroll\" then\
- if not bMenu then\
- if param == -1 then\
- -- Scroll up\
- if scrollY > 0 then\
- -- Move cursor up\
- scrollY = scrollY - 1\
- redrawText()\
- end\
- \
- elseif param == 1 then\
- -- Scroll down\
- local nMaxScroll = #tLines - (h-1)\
- if scrollY < nMaxScroll then\
- -- Move cursor down\
- scrollY = scrollY + 1\
- redrawText()\
- end\
- \
- end\
- end\
- \
- elseif sEvent == \"term_resize\" then\
- w,h = term.getSize()\
- setCursor( x, y )\
- redrawMenu()\
- redrawText()\
- \
- end\
- end\
- \
- -- Cleanup\
- term.clear()\
- term.setCursorBlink( false )\
- term.setCursorPos( 1, 1 )",
- OmniOS = {
- Data = {
- here = "hi",
- },
- },
- },
- [ "Calculator.app" ] = {
- [ "Calculator.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 8192,\
- \"a\",\
- 1,\
- },\
- {\
- 8192,\
- \"+\",\
- 1,\
- },\
- {\
- 8192,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"l\",\
- 1,\
- },\
- {\
- 8192,\
- \"*\",\
- 1,\
- },\
- {\
- 8192,\
- \"/\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"c\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 8192,\
- \"C\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- },\
- }",
- [ "permission.data" ] = "user",
- [ "Main.lua" ] = "--[[\
- Calculator App\
- for OmniOS by\
- Creator\
- ]]--\
- \
- --Varialbles--\
- local gui = {}\
- local path = OmniOS and \"OmniOS/Programs/Calculator.app/Data/\" or \"Calculator/\"\
- local MainLayout = {}\
- local env = {\
- deg = math.deg,\
- fmod = math.fmod,\
- random = math.random,\
- asin = math.asin,\
- max = math.max,\
- modf = math.modf,\
- log10 = math.log10,\
- floor = math.floor,\
- cosh = math.cosh,\
- ldexp = math.ldexp,\
- log = math.log,\
- pow = math.pow,\
- rndsd = math.randomseed,\
- frexp = math.frexp,\
- abs = math.abs,\
- tanh = math.tanh,\
- acos = math.acos,\
- atan2 = math.atan2,\
- tan = math.tan,\
- min = math.min,\
- ceil = math.ceil,\
- sinh = math.sinh,\
- sqrt = math.sqrt,\
- huge = math.huge,\
- rad = math.rad,\
- sin = math.sin,\
- exp = math.exp,\
- cos = math.cos,\
- atan = math.atan,\
- pi = math.pi,\
- }\
- \
- --Functions--\
- local function readLayoutFile(sLayout)\
- local func, err = loadfile(path..\"Layouts/\"..sLayout..\".layout\")\
- if err then\
- log.log(\"Calculator\",err)\
- end\
- setfenv(func,_G)\
- return func()\
- end\
- \
- \
- --Code--\
- if not OmniOS or not Interact then\
- shell.run(\"pastebin --- Interact\")\
- os.loadAPI(\"Intearct\")\
- end\
- gui = NewInteract:Initialize()\
- MainLayout = gui.Layout.new(readLayoutFile(\"Main\"))\
- local input = gui.Text.new({name = \"input\",text = \"\",xPos = 1,yPos = 2,bgColor = colors.orange,fgColor = colors.white})\
- \
- MainLayout:draw()\
- while true do\
- MainLayout.ColorField.Top:draw()\
- MainLayout.Button.Exit:draw()\
- MainLayout.Button.Clear:draw()\
- MainLayout.Button.Delete:draw()\
- MainLayout.Button.xxx:draw()\
- input:draw()\
- local MainLayoutEvent = gui.eventHandler(MainLayout)\
- if MainLayoutEvent[2] == \"=\" then\
- local fOutput = setfenv(loadstring(\"return \"..input.text),env)\
- local ok, output = pcall(fOutput)\
- if not ok then \
- log.log(\"Calculator\",output,\"Calculator\")\
- end\
- input.text = output\
- input:draw()\
- elseif MainLayoutEvent[2] == \"Exit\" then\
- break\
- elseif MainLayoutEvent[2] == \"Clear\" then\
- input.text = \"\"\
- elseif MainLayoutEvent[2] == \"Delete\" then\
- input.text = input.text:sub(1,-2)\
- else\
- input.text = input.text..MainLayoutEvent[2]\
- log.log(\"Calculator\",MainLayoutEvent[2])\
- end\
- end",
- Data = {
- Layouts = {
- [ "Main.layout" ] = "local w,h = term.getSize()\
- local tTable = {\
- BackgroundColor = colors.gray,\
- xPos = 1,\
- yPos = 1,\
- xLength = w,\
- yLength = h,\
- Button = {\
- Exit = {\
- name = \"Exit\",\
- label = \"x\",\
- xPos = w-1,\
- yPos = 2,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 1,\
- yLength = 1,\
- returnValue = \"Exit\",\
- xTextPos = 1,\
- yTextPos = 1,\
- },\
- Clear = {\
- name = \"Clear\",\
- label = \"Clear\",\
- xPos = w-7,\
- yPos = 2,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 5,\
- yLength = 1,\
- returnValue = \"Clear\",\
- xTextPos = 1,\
- yTextPos = 1,\
- },\
- Delete = {\
- name = \"Delete\",\
- label = \"<--\",\
- xPos = w-7,\
- yPos = 1,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 5,\
- yLength = 1,\
- returnValue = \"Delete\",\
- xTextPos = 1,\
- yTextPos = 1,\
- },\
- xxx = {\
- name = \"xxx\",\
- label = \"xxx\",\
- xPos = w-11,\
- yPos = 1,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 1,\
- returnValue = \"xxx\",\
- xTextPos = 1,\
- yTextPos = 1,\
- },\
- },\
- ColorField = {\
- Top = {\
- name = \"Top\",\
- xPos = 1,\
- yPos = 1,\
- xLength = 51, \
- yLength = 2,\
- color = colors.orange,\
- },\
- },\
- Layout = {\
- Input = {\
- name = \"Input\",\
- xPos = 1,\
- yPos = 1,\
- xLength = w,\
- yLength = h,\
- BackgroundColor = colors.gray,\
- Button = {\
- One = {\
- name = \"One\",\
- label = \"1\",\
- xPos = 35,\
- yPos = 4,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"1\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Two = {\
- name = \"Two\",\
- label = \"2\",\
- xPos = 39,\
- yPos = 4,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"2\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Three = {\
- name = \"Three\",\
- label = \"3\",\
- xPos = 43,\
- yPos = 4,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"3\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Four = {\
- name = \"Four\",\
- label = \"4\",\
- xPos = 35,\
- yPos = 8,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"4\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Five = {\
- name = \"Five\",\
- label = \"5\",\
- xPos = 39,\
- yPos = 8,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"5\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Six = {\
- name = \"Six\",\
- label = \"6\",\
- xPos = 43,\
- yPos = 8,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"6\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Seven = {\
- name = \"Seven\",\
- label = \"7\",\
- xPos = 35,\
- yPos = 12,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"7\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Eight = {\
- name = \"Eight\",\
- label = \"8\",\
- xPos = 39,\
- yPos = 12,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"8\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Nine = {\
- name = \"Nine\",\
- label = \"9\",\
- xPos = 43,\
- yPos = 12,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"9\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Zero = {\
- name = \"Zero\",\
- label = \"0\",\
- xPos = 35,\
- yPos = 16,\
- fgColor = colors.white,\
- bgColor = colors.orange,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"0\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Equals = {\
- name = \"Equals\",\
- label = \"=\",\
- xPos = 39,\
- yPos = 16,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 7,\
- yLength = 3,\
- returnValue = \"=\",\
- xTextPos = 4,\
- yTextPos = 2,\
- },\
- Add = {\
- name = \"Add\",\
- label = \"+\",\
- xPos = 47,\
- yPos = 4,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"+\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Sub = {\
- name = \"Sub\",\
- label = \"-\",\
- xPos = 47,\
- yPos = 8,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"-\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Mul = {\
- name = \"Mul\",\
- label = \"*\",\
- xPos = 47,\
- yPos = 12,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"*\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Div = {\
- name = \"Div\",\
- label = \"/\",\
- xPos = 47,\
- yPos = 16,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"/\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- LPar = {\
- name = \"LPar\",\
- label = \"(\",\
- xPos = 31,\
- yPos = 12,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- RPar = {\
- name = \"RPar\",\
- label = \")\",\
- xPos = 31,\
- yPos = 16,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \")\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Mod = {\
- name = \"Mod\",\
- label = \"%\",\
- xPos = 31,\
- yPos = 8,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \"%\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Comma = {\
- name = \"Comma\",\
- label = \",\",\
- xPos = 31,\
- yPos = 4,\
- fgColor = colors.white,\
- bgColor = colors.green,\
- xLength = 3,\
- yLength = 3,\
- returnValue = \",\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Abs = {\
- name = \"Abs\",\
- label = \"abs\",\
- xPos = 25,\
- yPos = 4,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"abs(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Deg = {\
- name = \"Deg\",\
- label = \"deg\",\
- xPos = 25,\
- yPos = 8,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"deg(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Max = {\
- name = \"Max\",\
- label = \"max\",\
- xPos = 25,\
- yPos = 12,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"max(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Log = {\
- name = \"Log\",\
- label = \"log\",\
- xPos = 25,\
- yPos = 16,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"log(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Pow = {\
- name = \"Pow\",\
- label = \"pow\",\
- xPos = 19,\
- yPos = 4,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"pow(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Tan = {\
- name = \"Tan\",\
- label = \"tan\",\
- xPos = 19,\
- yPos = 8,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"tan(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Min = {\
- name = \"Min\",\
- label = \"min\",\
- xPos = 19,\
- yPos = 12,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"min(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Rad = {\
- name = \"Rad\",\
- label = \"rad\",\
- xPos = 19,\
- yPos = 16,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"rad(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Sin = {\
- name = \"Sin\",\
- label = \"sin\",\
- xPos = 13,\
- yPos = 4,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"sin(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Exp = {\
- name = \"Exp\",\
- label = \"exp\",\
- xPos = 13,\
- yPos = 8,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"exp(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Cos = {\
- name = \"Cos\",\
- label = \"cos\",\
- xPos = 13,\
- yPos = 12,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 5,\
- yLength = 3,\
- returnValue = \"cos(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Pi = {\
- name = \"Pi\",\
- label = \"pi\",\
- xPos = 14,\
- yPos = 16,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 4,\
- yLength = 3,\
- returnValue = \"pi\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- Atan = {\
- name = \"Atan\",\
- label = \"atan\",\
- xPos = 7,\
- yPos = 16,\
- fgColor = colors.white,\
- bgColor = colors.lightGray,\
- xLength = 6,\
- yLength = 3,\
- returnValue = \"atan(\",\
- xTextPos = 2,\
- yTextPos = 2,\
- },\
- },\
- }\
- }\
- }\
- \
- return tTable",
- },
- },
- },
- [ "BetterPaint.app" ] = {
- [ "BetterPaint.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 2,\
- \"D\",\
- 1,\
- },\
- {\
- 2,\
- \"E\",\
- 1,\
- },\
- {\
- 2,\
- \"F\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"G\",\
- 1,\
- },\
- {\
- 8192,\
- \"H\",\
- 1,\
- },\
- {\
- 8192,\
- \"I\",\
- 1,\
- },\
- },\
- {\
- {\
- 2048,\
- \"J\",\
- 1,\
- },\
- {\
- 2048,\
- \"K\",\
- 1,\
- },\
- {\
- 2048,\
- \"L\",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 16384,\
- \"A\",\
- 1,\
- },\
- {\
- 16384,\
- \"B\",\
- 1,\
- },\
- {\
- 16384,\
- \"C\",\
- 1,\
- },\
- },\
- }",
- [ "main.lua" ] = "transparentIcon = \"-\"\
- args = {...}\
- tX, tY = term.getSize()\
- \
- function drawImage(file,xSet,ySet,redirection)\
- init()\
- lastImage = file\
- lastX = xSet\
- lastY = ySet\
- lastRedirection = redirection\
- if redirection then\
- current = term.current()\
- term.redirect(redirection)\
- end\
- drawData(xSet,ySet,file)\
- if redirection then\
- term.redirect(current)\
- end\
- end\
- \
- function overWrite(textSet,xSet,ySet,colorSet)\
- init()\
- exists = true\
- if not lastImage then\
- error(\"Use drawImage first!\")\
- end\
- if not writeBuffer then\
- writeBuffer = {}\
- end\
- if not writeBuffer[lastImage] then\
- writeBuffer[lastImage] = {}\
- end\
- plusPos = 0\
- for char in string.gmatch(textSet,\".\") do\
- if not writeBuffer[lastImage][xSet+plusPos] then\
- writeBuffer[lastImage][xSet+plusPos] = {}\
- end\
- if not writeBuffer[lastImage][xSet+plusPos][ySet] then\
- writeBuffer[lastImage][xSet+plusPos][ySet] = {colors.black,\" \",colors.white}\
- end\
- writeBuffer[lastImage][xSet+plusPos][ySet][2] = char\
- writeBuffer[lastImage][xSet+plusPos][ySet][3] = colorSet\
- plusPos = plusPos + 1 \
- end\
- drawImage(lastImage,lastX,lastY,lastRedirection)\
- end\
- \
- function init()\
- function eventHandler()\
- while true do\
- event = {os.pullEvent()}\
- if event[1] == \"key\" then\
- if event[2] == keys.leftCtrl or event[2] == 157 then\
- menuStatus = not menuStatus\
- writeMenuBar(menuStatus)\
- end\
- if menuStatus == true then\
- if event[2] == keys.right or event[2] == keys.left then\
- if menuItemSelected == 1 then\
- menuItemSelected = 2\
- else\
- menuItemSelected = 1\
- end\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.enter then\
- if menuItemSelected == 1 then\
- save()\
- writeMenuBar(false)\
- else\
- term.setTextColor(colors.yellow)\
- term.setBackgroundColor(colors.black)\
- term.clear()\
- term.setCursorPos(1,1)\
- error()\
- end\
- end\
- else \
- if event[2] == keys.right then\
- drawData(offSetX-1,offSetY)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.left then\
- drawData(offSetX+1,offSetY)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.up then\
- drawData(offSetX,offSetY+1)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.down then\
- drawData(offSetX,offSetY-1)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- end\
- end\
- end\
- if event[1] == \"mouse_click\" or event[1] == \"mouse_drag\" then\
- if event[3] > 2 and event[4] ~= tY then\
- insertItem(event[3],event[4],event[2])\
- elseif event[4] < 18 and event[4] > 1 then\
- if event[3] == 1 then\
- bgSelected = 2^(event[4]-2)\
- elseif event[3] == 2 then\
- tSelected = 2^(event[4]-2)\
- end\
- drawMenu()\
- elseif event[4] == tY - 1 and event[3] == 1 then\
- setLetter()\
- drawData(offSetX,offSetY)\
- drawMenu()\
- elseif event[3] == tX and event[4] == tY and menuStatus == false then\
- writeHelp()\
- end\
- end\
- if event[1] == \"char\" then\
- textSelected = string.sub(event[2],1,1)\
- drawMenu()\
- end\
- --drawData(offSetX,offSetY)\
- end\
- end\
- \
- function writeHelp()\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.green)\
- term.clear()\
- term.setCursorPos(1,1)\
- term.write(\"Help:\")\
- term.setTextColor(colors.white)\
- term.setCursorPos(1,3)\
- print(\"Usage:\")\
- term.setTextColor(colors.lightGray)\
- print(\" Select color: Click on the color on the left\")\
- print(\" Change draw char: Press a key on the keyboard\")\
- print(\" Change transparent icon: Click on the icon's char in the menu\")\
- print(\" Change text color: Click on a color in the menu on the right side\")\
- print(\" Change background color: Click on a color in the menu on the left side\")\
- term.setTextColor(colors.white)\
- print()\
- print(\"Controls:\")\
- term.setTextColor(colors.lightGray)\
- print(\" Arrow keys to pan\")\
- print(\" Left mouse button to select and draw\")\
- print(\" Right mouse button to delete\")\
- print(\" Ctrl to open menu\")\
- print()\
- term.setTextColor(colors.white)\
- term.write(\"Click a mouse button to exit.\")\
- term.setTextColor(colors.orange)\
- term.setCursorPos(tX-9,1)\
- term.write(\"API help >\")\
- event = {os.pullEvent(\"mouse_click\")}\
- if event[3] > tX-10 and event[4] == 1 then\
- drawAPIhelp()\
- end\
- drawData(offSetX,offSetY)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- end\
- \
- function drawAPIhelp()\
- term.clear()\
- term.setCursorPos(1,1)\
- term.setTextColor(colors.orange)\
- print(\"API help menu:\")\
- print()\
- term.setTextColor(colors.white)\
- print(\"Drawing an image: \")\
- term.setTextColor(colors.lightGray)\
- print(shell.getRunningProgram(),\".drawImage(<file name>,<x pos>,<y pos>,[redirection object])\")\
- print()\
- term.setTextColor(colors.white)\
- print(\"Overlaying text on the last image:\")\
- term.setTextColor(colors.lightGray)\
- print(shell.getRunningProgram(),\".overWrite(<Text>,<x pos>,<y pos>,<text color>\")\
- print()\
- term.setTextColor(colors.red)\
- print(\"Overwriting text will only work AFTER drawing an image!\")\
- term.setTextColor(colors.white)\
- print()\
- print(\"Example:\")\
- term.setTextColor(colors.lightGray)\
- print(\"os.loadAPI(\\\"\",shell.getRunningProgram(),\"\\\")\")\
- print(shell.getRunningProgram(),\".drawImage(\\\"myPicture\\\",1,1)\")\
- print(shell.getRunningProgram(),\".overWrite(\\\"Hello!\\\",2,3,colors.orange)\")\
- os.pullEvent(\"mouse_click\")\
- end\
- \
- function setLetter()\
- term.setBackgroundColor(colors.red)\
- term.setTextColor(colors.black)\
- for i=1,4 do\
- term.setCursorPos(tX/2-11,(tY/2-4)+i)\
- term.write(\" \")\
- end\
- term.setCursorPos(tX/2-10,tY/2-2)\
- term.write(\"Change transparancy\")\
- term.setCursorPos(tX/2-10,tY/2-1)\
- term.write(\"character to: (key)\")\
- event = {os.pullEvent(\"char\")}\
- transparentIcon = event[2]\
- end\
- \
- function insertItem(xPos,yPos,modeSet)\
- if saved == true then\
- saved = false\
- writeMenuBar(false)\
- end\
- --bgSelected\
- --tSelected\
- --textSelected\
- if not painted then\
- painted = {}\
- end\
- if not painted[xPos-offSetX] then\
- painted[xPos-offSetX] = {}\
- end\
- if modeSet == 1 then\
- if not textSelected then\
- textSelected = \" \"\
- end\
- TMPtextSelected = textSelected\
- painted[xPos-offSetX][yPos-offSetY] = {bgSelected,textSelected,tSelected}\
- term.setBackgroundColor(bgSelected)\
- term.setTextColor(tSelected)\
- else\
- TMPtextSelected = transparentIcon\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.gray)\
- painted[xPos-offSetX][yPos-offSetY] = nil\
- end\
- term.setCursorPos(xPos,yPos)\
- term.write(TMPtextSelected)\
- end\
- \
- --if #args ~= 1 then\
- -- print(\"Usage: \"..shell.getRunningProgram()..\" <path>\")\
- -- return\
- --end\
- \
- if args[1] and fs.exists(args[1]) == true then\
- buff = fs.open(args[1],\"r\")\
- previousData = buff.readAll()\
- buff.close()\
- processed = string.sub(previousData,43)\
- painted = textutils.unserialize(processed)\
- else\
- painted = {}\
- end\
- \
- function save()\
- file = fs.open(args[1],\"w\")\
- file.write(\"error('This is an image, not a program!')\\n\"..textutils.serialize(painted))\
- file.close()\
- saved = true\
- end\
- \
- function drawData(xStart, yStart, file)\
- offSetX = xStart\
- offSetY = yStart\
- if not file then\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.gray)\
- transparentLine = \"\"\
- for x=1,tX-2 do\
- transparentLine = transparentIcon..transparentLine\
- end\
- for y=1,tY-1 do\
- term.setCursorPos(3,y)\
- term.write(transparentLine)\
- end\
- else\
- if fs.exists(file) == false then\
- error(\"File given doesnt exists! file name: \"..file)\
- else\
- local fileD = fs.open(file,\"r\")\
- raw = fileD.readAll()\
- --ignoreL = string.len(fileD.readLine(1))\
- processed = string.sub(raw,43)\
- --term.redirect(term.native())\
- -- textutils.pagedPrint(processed)\
- painted = textutils.unserialize(processed)\
- fileD.close()\
- end\
- end\
- if not painted then\
- painted = {}\
- end\
- paintedF = painted\
- count = 0\
- repeat ---------\
- count = count + 1\
- for xPos,v in pairs(paintedF) do\
- for yPos in pairs (paintedF[xPos]) do\
- overWrite = true\
- if not lastImage or not writeBuffer or not writeBuffer[lastImage] then\
- overWrite = false\
- end\
- if overWrite == true then\
- if not writeBuffer[lastImage][xPos] then\
- overWrite = false\
- end\
- end\
- if overWrite == true then\
- if not writeBuffer[lastImage][xPos][yPos] then\
- overWrite = false\
- end\
- end\
- if overWrite == false then\
- bgColor = paintedF[xPos][yPos][1]\
- text = paintedF[xPos][yPos][2]\
- tColor = paintedF[xPos][yPos][3]\
- else\
- if painted and painted[xPos] and painted[xPos][yPos] and painted[xPos][yPos][1] then\
- bgColor = painted[xPos][yPos][1]\
- else\
- bgColor = colors.black\
- end\
- --if not bgColor then\
- -- bgColor = colors.black\
- --end\
- text = writeBuffer[lastImage][xPos][yPos][2]\
- tColor = writeBuffer[lastImage][xPos][yPos][3]\
- end\
- if not tColor then\
- tColor = colors.white\
- end\
- if not text then\
- text = \" \"\
- end\
- term.setCursorPos(xPos+xStart,yPos+yStart)\
- term.setBackgroundColor(bgColor)\
- term.setTextColor(tColor)\
- term.write(text)\
- end\
- end\
- if count == 1 and writeBuffer and lastImage then\
- paintedF = writeBuffer[lastImage]\
- elseif count == 1 and not lastImage or not writeBuffer then\
- count = 2\
- end\
- until count == 2\
- term.setCursorPos(1,tY)\
- end\
- \
- function drawMenu()\
- term.setCursorPos(1,1)\
- term.setTextColor(colors.white)\
- if not bgSelected then\
- bgSelected = colors.black\
- elseif bgSelected == colors.white then\
- term.setTextColor(colors.black)\
- end\
- if not tSelected then\
- tSelected = colors.white\
- elseif tSelected == colors.white then\
- term.setTextColor(colors.black)\
- end\
- if not textSelected then\
- textSelected = \" \"\
- end\
- term.setBackgroundColor(bgSelected)\
- term.write(\"B\")\
- term.setBackgroundColor(tSelected)\
- term.write(\"T\")\
- for i=1,16 do\
- i=i-1\
- term.setCursorPos(1,i+2)\
- term.setBackgroundColor(2^i)\
- term.write(\" \")\
- end\
- term.setCursorPos(1,18)\
- term.setBackgroundColor(colors.black)\
- if not textSelected then\
- textSelected = \" \"\
- elseif string.len(textSelected) > 1 then\
- textSelected = string.sub(textSelected,1,1)\
- end\
- term.setTextColor(colors.gray)\
- term.setBackgroundColor(colors.black)\
- term.write(transparentIcon)\
- term.setTextColor(tSelected)\
- term.setBackgroundColor(bgSelected)\
- term.write(textSelected)\
- end\
- \
- function writeMenuBar(booly)\
- menuStatus = booly\
- term.setBackgroundColor(colors.black)\
- if booly == true then\
- term.setCursorPos(1,tY)\
- term.clearLine()\
- if not menuItemSelected then\
- menuItemSelected = 1\
- end\
- term.setTextColor(colors.white)\
- term.write(\" Save Exit \")\
- term.setCursorPos(6*menuItemSelected-5,tY)\
- term.setTextColor(colors.yellow)\
- term.write(\"[\")\
- term.setCursorPos(6*menuItemSelected,tY)\
- term.write(\"]\")\
- elseif booly == false then\
- term.setCursorPos(1,tY)\
- term.setTextColor(colors.yellow)\
- term.clearLine()\
- if saved == true then\
- term.write(\"Saved to \"..args[1])\
- else\
- term.write(\"Press Ctrl to access menu\")\
- end\
- term.setCursorPos(tX,tY)\
- term.setTextColor(colors.lightGray)\
- term.write(\"?\")\
- end\
- end\
- end\
- \
- if #args > 0 then\
- init()\
- menuStatus = false\
- saved = false\
- writeMenuBar(menuStatus)\
- menuItemSelected = 1\
- drawData(3,0)\
- drawMenu()\
- eventHandler()\
- else\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.white)\
- term.clear()\
- term.setCursorPos(1,1)\
- term.write(\"Do you want to create a new file? <y/n>\")\
- local answ = read()\
- if answ:sub(1,1) == \"y\" then\
- print()\
- term.write(\"Path please!\")\
- args[1] = \"OmniOS/Data/\"..read()\
- init()\
- menuStatus = false\
- saved = false\
- writeMenuBar(menuStatus)\
- menuItemSelected = 1\
- drawData(3,0)\
- drawMenu()\
- eventHandler()\
- end\
- end",
- [ "permission.data" ] = "user",
- },
- [ "nPaintPro.app" ] = {
- [ "nPaintPro.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 2048,\
- \"N\",\
- 1,\
- },\
- {\
- 2048,\
- \"p\",\
- 1,\
- },\
- {\
- 2048,\
- \"p\",\
- 1,\
- },\
- },\
- {\
- {\
- 2048,\
- \" \",\
- 1,\
- },\
- {\
- 2048,\
- \" \",\
- 2048,\
- },\
- {\
- 2048,\
- \" \",\
- 2048,\
- },\
- },\
- {\
- {\
- 2048,\
- \" \",\
- 2048,\
- },\
- {\
- 2048,\
- \" \",\
- 2048,\
- },\
- {\
- 2048,\
- \" \",\
- 2048,\
- },\
- },\
- [ 0 ] = {\
- {\
- 2048,\
- \" \",\
- 2048,\
- },\
- {\
- 2048,\
- \" \",\
- 2048,\
- },\
- {\
- 2048,\
- \" \",\
- 2048,\
- },\
- },\
- }",
- [ "main.lua" ] = "--[[\
- NPaintPro\
- By NitrogenFingers\
- ]]--\
- \
- --The screen size\
- local w,h = term.getSize()\
- --Whether or not the program is currently waiting on user input\
- local inMenu = false\
- --Whether or not a drop down menu is active\
- local inDropDown = false\
- --Whether or not animation tools are enabled (use -a to turn them on)\
- local animated = false\
- --Whether or not \"blueprint\" display mode is on\
- local blueprint = false\
- --Whether or not the \"layer\" display is on\
- local layerDisplay = false\
- --Whether or not the \"direction\" display is on\
- local printDirection = false\
- --The tool/mode npaintpro is currently in. Default is \"paint\"\
- --For a list of modes, check out the help file\
- local state = \"paint\"\
- --Whether or not the program is presently running\
- local isRunning = true\
- --The rednet address of the 3D printer, if one has been attached\
- local printer = nil\
- \
- --The list of every frame, containing every image in the picture/animation\
- --Note: nfp files always have the picture at frame 1\
- local frames = { }\
- --How many frames are currently in the given animation.\
- local frameCount = 1\
- --The Colour Picker column\
- local column = {}\
- --The currently selected left and right colours\
- local lSel,rSel = colours.white,nil\
- --The amount of scrolling on the X and Y axis\
- local sx,sy = 0,0\
- --The alpha channel colour\
- --Change this to change default canvas colour\
- local alphaC = colours.yellow\
- --The currently selected frame. Default is 1\
- local sFrame = 1\
- --The contents of the image buffer- contains contents, width and height\
- local buffer = nil\
- --The position, width and height of the selection rectangle\
- local selectrect = nil\
- \
- --The currently calculated required materials\
- local requiredMaterials = {}\
- --Whether or not required materials are being displayed in the pallette\
- local requirementsDisplayed = false\
- --A list of the rednet ID's all in-range printers located\
- local printerList = { }\
- --A list of the names of all in-range printers located. Same as the printerList in reference\
- local printerNames = { }\
- --The selected printer\
- local selectedPrinter = 1\
- --The X,Y,Z and facing of the printer\
- local px,py,pz,pfx,pfz = 0,0,0,0,0\
- --The form of layering used\
- local layering = \"up\"\
- \
- --The animation state of the selection rectangle and image buffer \
- local rectblink = 0\
- --The ID for the timer\
- local recttimer = nil\
- --The radius of the brush tool\
- local brushsize = 3\
- --Whether or not \"record\" mode is activated (animation mode only)\
- local record = false\
- --The time between each frame when in play mode (animation mode only)\
- local animtime = 0.3\
- \
- --A list of hexidecimal conversions from numbers to hex digits\
- local hexnums = { [10] = \"a\", [11] = \"b\", [12] = \"c\", [13] = \"d\", [14] = \"e\" , [15] = \"f\" }\
- --The NPaintPro logo (divine, isn't it?)\
- local logo = {\
- \"fcc 3 339\";\
- \" fcc 9333 33\";\
- \" fcc 933 333 33\";\
- \" fcc 933 33 33\";\
- \" fcc 933 33 33\";\
- \" c88 333 93333\";\
- \" 888 333 9333\";\
- \" 333 3 333 939\";\
- }\
- --The Layer Up and Layer Forward printing icons\
- local layerUpIcon = {\
- \"0000000\";\
- \"0088880\";\
- \"0888870\";\
- \"07777f0\";\
- \"0ffff00\";\
- \"0000000\";\
- }\
- local layerForwardIcon = {\
- \"0000000\";\
- \"000fff0\";\
- \"00777f0\";\
- \"0888700\";\
- \"0888000\";\
- \"0000000\";\
- }\
- --The available menu options in the ctrl menu\
- local mChoices = {\"Save\",\"Exit\"}\
- --The available modes from the dropdown menu- tables indicate submenus (include a name!)\
- local ddModes = { { \"paint\", \"brush\", \"pippette\", \"flood\", \"move\", \"clear\", \"select\", name = \"painting\" }, { \"alpha to left\", \"alpha to right\", \"blueprint on\", \"layers on\", name = \"display\" }, \"help\", { \"print\", \"save\", \"exit\", name = \"file\" }, name = \"menu\" }\
- --The available modes from the selection right-click menu\
- local srModes = { \"cut\", \"copy\", \"paste\", \"clear\", \"hide\", name = \"selection\" }\
- --The list of available help topics for each mode 127\
- local helpTopics = {\
- [1] = {\
- name = \"Paint Mode\",\
- key = nil,\
- animonly = false,\
- message = \"The default mode for NPaintPro, for painting pixels.\"\
- ..\" Controls here that are not overridden will apply for all other modes. Leaving a mode by selecting that mode \"\
- ..\" again will always send the user back to paint mode.\",\
- controls = {\
- { \"Arrow keys\", \"Scroll the canvas\" },\
- { \"Left Click\", \"Paint/select left colour\" },\
- { \"Right Click\", \"Paint/select right colour\" },\
- { \"Z Key\", \"Clear image on screen\" },\
- { \"Tab Key\", \"Hide selection rectangle if visible\" },\
- { \"Q Key\", \"Set alpha mask to left colour\" },\
- { \"W Key\", \"Set alpha mask to right colour\" },\
- { \"Number Keys\", \"Swich between frames 1-9\" },\
- { \"</> keys\", \"Move to the next/last frame\" },\
- { \"R Key\", \"Removes every frame after the current frame\"}\
- }\
- },\
- [2] = {\
- name = \"Brush Mode\",\
- key = \"b\",\
- animonly = false,\
- message = \"Brush mode allows painting a circular area of variable diameter rather than a single pixel, working in \"..\
- \"the exact same way as paint mode in all other regards.\",\
- controls = {\
- { \"Left Click\", \"Paints a brush blob with the left colour\" },\
- { \"Right Click\", \"Paints a brush blob with the right colour\" },\
- { \"Number Keys\", \"Changes the radius of the brush blob from 2-9\" }\
- }\
- },\
- [3] = {\
- name = \"Pippette Mode\",\
- key = \"p\",\
- animonly = false,\
- message = \"Pippette mode allows the user to click the canvas and set the colour clicked to the left or right \"..\
- \"selected colour, for later painting.\",\
- controls = {\
- { \"Left Click\", \"Sets clicked colour to the left selected colour\" },\
- { \"Right Click\", \"Sets clicked colour to the right selected colour\" }\
- }\
- },\
- [4] = {\
- name = \"Move Mode\",\
- key = \"m\",\
- animonly = false,\
- message = \"Mode mode allows the moving of the entire image on the screen. This is especially useful for justifying\"..\
- \" the image to the top-left for animations or game assets.\",\
- controls = {\
- { \"Left/Right Click\", \"Moves top-left corner of image to selected square\" },\
- { \"Arrow keys\", \"Moves image one pixel in any direction\" }\
- }\
- },\
- [5] = {\
- name = \"Flood Mode (NYI)\",\
- key = \"f\",\
- animonly = false,\
- message = \"Flood mode allows the changing of an area of a given colour to that of the selected colour. \"..\
- \"The tool uses a flood4 algorithm and will not fill diagonally. Transparency cannot be flood filled.\",\
- controls = {\
- { \"Left Click\", \"Flood fills selected area to left colour\" },\
- { \"Right Click\", \"Flood fills selected area to right colour\" }\
- }\
- },\
- [6] = {\
- name = \"Select Mode\",\
- key = \"s\",\
- animonly = false,\
- message = \"Select mode allows the creation and use of the selection rectangle, to highlight specific areas on \"..\
- \"the screen and perform operations on the selected area of the image. The selection rectangle can contain an \"..\
- \"image on the clipboard- if it does, the image will flash inside the rectangle, and the rectangle edges will \"..\
- \"be light grey instead of dark grey.\",\
- controls = {\
- { \"C Key\", \"Copy: Moves selection into the clipboard\" },\
- { \"X Key\", \"Cut: Clears canvas under the rectangle, and moves it into the clipboard\" },\
- { \"V Key\", \"Paste: Copys clipboard to the canvas\" },\
- { \"Z Key\", \"Clears clipboard\" },\
- { \"Left Click\", \"Moves top-left corner of rectangle to selected pixel\" },\
- { \"Right Click\", \"Opens selection menu\" },\
- { \"Arrow Keys\", \"Moves rectangle one pixel in any direction\" }\
- }\
- },\
- [7] = {\
- name = \"Corner Select Mode\",\
- key = nil,\
- animonly = false,\
- message = \"If a selection rectangle isn't visible, this mode is selected automatically. It allows the \"..\
- \"defining of the corners of the rectangle- one the top-left and bottom-right corners have been defined, \"..\
- \"NPaintPro switches to selection mode. Note rectangle must be at least 2 pixels wide and high.\",\
- controls = {\
- { \"Left/Right Click\", \"Defines a corner of the selection rectangle\" }\
- }\
- },\
- [8] = {\
- name = \"Play Mode\",\
- key = \"space\",\
- animonly = true,\
- message = \"Play mode will loop through each frame in your animation at a constant rate. Editing tools are \"..\
- \"locked in this mode, and the coordinate display will turn green to indicate it is on.\",\
- controls = {\
- { \"</> Keys\", \"Increases/Decreases speed of the animation\" },\
- { \"Space Bar\", \"Returns to paint mode\" }\
- }\
- },\
- [9] = {\
- name = \"Record Mode\",\
- key = \"\\\\\",\
- animonly = true,\
- message = \"Record mode is not a true mode, but influences how other modes work. Changes made that modify the \"..\
- \"canvas in record mode will affect ALL frames in the animation. The coordinates will turn red to indicate that \"..\
- \"record mode is on.\",\
- controls = {\
- { \"\", \"Affects:\" },\
- { \"- Paint Mode\", \"\" },\
- { \"- Brush Mode\", \"\" },\
- { \"- Cut and Paste in Select Mode\", \"\"},\
- { \"- Move Mode\", \"\"}\
- }\
- },\
- [10] = {\
- name = \"Help Mode\",\
- key = \"h\",\
- animonly = false,\
- message = \"Displays this help screen. Clicking on options will display help on that topic. Clicking out of the screen\"..\
- \" will leave this mode.\",\
- controls = {\
- { \"Left/Right Click\", \"Displays a topic/Leaves the mode\" }\
- }\
- },\
- [11] = {\
- name = \"File Mode\",\
- keys = nil,\
- animonly = false,\
- message = \"Clicking on the mode display at the bottom of the screen will open the options menu. Here you can\"..\
- \" activate all of the modes in the program with a simple mouse click. Pressing left control will open up the\"..\
- \" file menu automatically.\",\
- controls = { \
- { \"leftCtrl\", \"Opens the file menu\" },\
- { \"leftAlt\", \"Opens the paint menu\" }\
- \
- }\
- }\
- }\
- --The \"bounds\" of the image- the first/last point on both axes where a pixel appears\
- local toplim,botlim,leflim,riglim = nil,nil,nil,nil\
- --The selected path\
- local sPath = nil\
- \
- --[[ \
- Section: Helpers \
- ]]--\
- \
- --[[Converts a colour parameter into a single-digit hex coordinate for the colour\
- Params: colour:int = The colour to be converted\
- Returns:string A string conversion of the colour\
- ]]--\
- local function getHexOf(colour)\
- if not colour or not tonumber(colour) then \
- return \" \" \
- end\
- local value = math.log(colour)/math.log(2)\
- if value > 9 then \
- value = hexnums[value] \
- end\
- return value\
- end\
- \
- --[[Converts a hex digit into a colour value\
- Params: hex:?string = the hex digit to be converted\
- Returns:string A colour value corresponding to the hex, or nil if the character is invalid\
- ]]--\
- local function getColourOf(hex)\
- local value = tonumber(hex, 16)\
- if not value then return nil end\
- value = math.pow(2,value)\
- return value\
- end\
- \
- --[[Finds the biggest and smallest bounds of the image- the outside points beyond which pixels do not appear\
- These values are assigned to the \"lim\" parameters for access by other methods\
- Params: forAllFrames:bool = True if all frames should be used to find bounds, otherwise false or nil\
- Returns:nil\
- ]]--\
- local function updateImageLims(forAllFrames)\
- local f,l = sFrame,sFrame\
- if forAllFrames == true then f,l = 1,framecount end\
- \
- toplim,botlim,leflim,riglim = nil,nil,nil,nil\
- for locf = f,l do\
- for y,_ in pairs(frames[locf]) do\
- for x,_ in pairs(frames[locf][y]) do\
- if frames[locf][y][x] ~= nil then\
- if leflim == nil or x < leflim then leflim = x end\
- if toplim == nil or y < toplim then toplim = y end\
- if riglim == nil or x > riglim then riglim = x end\
- if botlim == nil or y > botlim then botlim = y end\
- end\
- end\
- end\
- end\
- end\
- \
- --[[Determines how much of each material is required for a print. Done each time printing is called.\
- Params: none\
- Returns:table A complete list of how much of each material is required.\
- ]]--\
- function calculateMaterials()\
- updateImageLims(animated)\
- requiredMaterials = {}\
- for i=1,16 do \
- requiredMaterials[i] = 0 \
- end\
- \
- if not toplim then return end\
- \
- for i=1,#frames do\
- for y = toplim, botlim do\
- for x = leflim, riglim do\
- if type(frames[i][y][x]) == \"number\" then\
- requiredMaterials[math.log10(frames[i][y][x])/math.log10(2) + 1] = \
- requiredMaterials[math.log10(frames[i][y][x])/math.log10(2) + 1] + 1\
- end \
- end\
- end\
- end\
- end\
- \
- \
- --[[Updates the rectangle blink timer. Should be called anywhere events are captured, along with a timer capture.\
- Params: nil\
- Returns:nil\
- ]]--\
- local function updateTimer(id)\
- if id == recttimer then\
- recttimer = os.startTimer(0.5)\
- rectblink = (rectblink % 2) + 1\
- end\
- end\
- \
- --[[Constructs a message based on the state currently selected\
- Params: nil\
- Returns:string A message regarding the state of the application\
- ]]--\
- local function getStateMessage()\
- local msg = \" \"..string.upper(string.sub(state, 1, 1))..string.sub(state, 2, #state)..\" mode\"\
- if state == \"brush\" then msg = msg..\", size=\"..brushsize end\
- return msg\
- end\
- \
- --[[Calls the rednet_message event, but also looks for timer events to keep then\
- system timer ticking.\
- Params: timeout:number how long before the event times out\
- Returns:number the id of the sender\
- :number the message send\
- ]]--\
- local function rsTimeReceive(timeout)\
- local timerID\
- if timeout then timerID = os.startTimer(timeout) end\
- \
- local id,key,msg = nil,nil\
- while true do\
- id,key,msg = os.pullEvent()\
- \
- if id == \"timer\" then\
- if key == timerID then return\
- else updateTimer(key) end\
- end\
- if id == \"rednet_message\" then \
- return key,msg\
- end\
- end\
- end\
- \
- --[[Draws a picture, in paint table format on the screen\
- Params: image:table = the image to display\
- xinit:number = the x position of the top-left corner of the image\
- yinit:number = the y position of the top-left corner of the image\
- alpha:number = the color to display for the alpha channel. Default is white.\
- Returns:nil\
- ]]--\
- local function drawPictureTable(image, xinit, yinit, alpha)\
- if not alpha then alpha = 1 end\
- for y=1,#image do\
- for x=1,#image[y] do\
- term.setCursorPos(xinit + x-1, yinit + y-1)\
- local col = getColourOf(string.sub(image[y], x, x))\
- if not col then col = alpha end\
- term.setBackgroundColour(col)\
- term.write(\" \")\
- end\
- end\
- end\
- \
- --[[ \
- Section: Loading \
- ]]-- \
- \
- --[[Loads a non-animted paint file into the program\
- Params: path:string = The path in which the file is located\
- Returns:nil\
- ]]--\
- local function loadNFP(path)\
- sFrame = 1\
- frames[sFrame] = { }\
- if fs.exists(path) then\
- local file = io.open(path, \"r\" )\
- local sLine = file:read()\
- local num = 1\
- while sLine do\
- table.insert(frames[sFrame], num, {})\
- for i=1,#sLine do\
- frames[sFrame][num][i] = getColourOf(string.sub(sLine,i,i))\
- end\
- num = num+1\
- sLine = file:read()\
- end\
- file:close()\
- end\
- end\
- \
- --[[Saves a non-animated paint file to the specified path\
- Params: path:string = The path to save the file to\
- Returns:nil\
- ]]--\
- local function saveNFP(path)\
- local sDir = string.sub(sPath, 1, #sPath - #fs.getName(sPath))\
- if not fs.exists(sDir) then\
- fs.makeDir(sDir)\
- end\
- \
- local file = io.open(path, \"w\")\
- updateImageLims(false)\
- if not toplim then \
- file:close()\
- return\
- end\
- for y=1,botlim do\
- local line = \"\"\
- if frames[sFrame][y] then \
- for x=1,riglim do\
- line = line..getHexOf(frames[sFrame][y][x])\
- end\
- end\
- file:write(line..\"\\n\")\
- end\
- file:close()\
- end\
- \
- --[[Loads an animated paint file into the program\
- Params: path:string = The path in which the file is located\
- Returns:nil\
- ]]--\
- local function loadNFA(path)\
- frames[sFrame] = { }\
- if fs.exists(path) then\
- local file = io.open(path, \"r\" )\
- local sLine = file:read()\
- local num = 1\
- while sLine do\
- table.insert(frames[sFrame], num, {})\
- if sLine == \"~\" then\
- sFrame = sFrame + 1\
- frames[sFrame] = { }\
- num = 1\
- else\
- for i=1,#sLine do\
- frames[sFrame][num][i] = getColourOf(string.sub(sLine,i,i))\
- end\
- num = num+1\
- end\
- sLine = file:read()\
- end\
- file:close()\
- end\
- framecount = sFrame\
- sFrame = 1\
- end\
- \
- --[[Saves a animated paint file to the specified path\
- Params: path:string = The path to save the file to\
- Returns:nil\
- ]]--\
- local function saveNFA(path)\
- local file = io.open(path, \"w\")\
- updateImageLims(true)\
- if not toplim then \
- file:close()\
- return\
- end\
- for i=1,#frames do\
- for y=1,botlim do\
- local line = \"\"\
- if frames[i][y] then \
- for x=1,riglim do\
- line = line..getHexOf(frames[i][y][x])\
- end\
- end\
- file:write(line..\"\\n\")\
- end\
- if i < #frames then file:write(\"~\\n\") end\
- end\
- file:close()\
- end\
- \
- --[[Initializes the program, by loading in the paint file. Called at the start of each program.\
- Params: none\
- Returns:nil\
- ]]--\
- local function init()\
- if animated then \
- loadNFA(sPath)\
- table.insert(ddModes, #ddModes, { \"record\", \"play\", name = \"anim\" })\
- table.insert(ddModes, #ddModes, { \"go to\", \"remove\", name = \"frames\"})\
- else loadNFP(sPath) end\
- \
- for i=0,15 do\
- table.insert(column, math.pow(2,i))\
- end\
- end\
- \
- --[[ \
- Section: Drawing \
- ]]--\
- \
- \
- --[[Draws the rather superflous logo. Takes about 1 second, before user is able to move to the\
- actual program.\
- Params: none\
- Returns:nil\
- ]]--\
- local function drawLogo()\
- term.setBackgroundColour(colours.white)\
- term.clear()\
- drawPictureTable(logo, w/2 - #logo[1]/2, h/2 - #logo/2, colours.white)\
- term.setBackgroundColour(colours.white)\
- term.setTextColour(colours.black)\
- local msg = \"NPaintPro\"\
- term.setCursorPos(w/2 - #msg/2, h-3)\
- term.write(msg)\
- msg = \"By NitrogenFingers\"\
- term.setCursorPos(w/2 - #msg/2, h-2)\
- term.write(msg)\
- msg = \"Thanks to faubiguy for testing\"\
- term.setCursorPos(w/2 - #msg/2, h)\
- term.write(msg)\
- \
- os.pullEvent()\
- end\
- \
- --[[Clears the display to the alpha channel colour, draws the canvas, the image buffer and the selection\
- rectanlge if any of these things are present.\
- Params: none\
- Returns:nil\
- ]]--\
- local function drawCanvas()\
- --We have to readjust the position of the canvas if we're printing\
- turtlechar = \"@\"\
- if state == \"active print\" then\
- if layering == \"up\" then\
- if py >= 1 and py <= #frames then\
- sFrame = py\
- end\
- if pz < sy then sy = pz\
- elseif pz > sy + h - 1 then sy = pz + h - 1 end\
- if px < sx then sx = px\
- elseif px > sx + w - 2 then sx = px + w - 2 end\
- else\
- if pz >= 1 and pz <= #frames then\
- sFrame = pz\
- end\
- \
- if py < sy then sy = py\
- elseif py > sy + h - 1 then sy = py + h - 1 end\
- if px < sx then sx = px\
- elseif px > sx + w - 2 then sx = px + w - 2 end\
- end\
- \
- if pfx == 1 then turtlechar = \">\"\
- elseif pfx == -1 then turtlechar = \"<\"\
- elseif pfz == 1 then turtlechar = \"V\"\
- elseif pfz == -1 then turtlechar = \"^\"\
- end\
- end\
- \
- --Picture next\
- local topLayer, botLayer\
- if layerDisplay then\
- topLayer = sFrame\
- botLayer = 1\
- else\
- topLayer,botLayer = sFrame,sFrame\
- end\
- \
- for currframe = botLayer,topLayer,1 do\
- for y=sy+1,sy+h-1 do\
- if frames[currframe][y] then \
- for x=sx+1,sx+w-2 do\
- term.setCursorPos(x-sx,y-sy)\
- if frames[currframe][y][x] then\
- term.setBackgroundColour(frames[currframe][y][x])\
- term.write(\" \")\
- else \
- tileExists = false\
- for i=currframe-1,botLayer,-1 do\
- if frames[i][y][x] then\
- tileExists = true\
- break\
- end\
- end\
- \
- if not tileExists then\
- if blueprint then\
- term.setBackgroundColour(colours.blue)\
- term.setTextColour(colours.white)\
- if x == sx+1 and y % 4 == 1 then\
- term.write(\"\"..((y/4) % 10))\
- elseif y == sy + 1 and x % 4 == 1 then\
- term.write(\"\"..((x/4) % 10))\
- elseif x % 2 == 1 and y % 2 == 1 then\
- term.write(\"+\")\
- elseif x % 2 == 1 then\
- term.write(\"|\")\
- elseif y % 2 == 1 then\
- term.write(\"-\")\
- else\
- term.write(\" \")\
- end\
- else\
- term.setBackgroundColour(alphaC) \
- term.write(\" \")\
- end\
- end\
- end\
- end\
- else\
- for x=sx+1,sx+w-2 do\
- term.setCursorPos(x-sx,y-sy)\
- \
- tileExists = false\
- for i=currframe-1,botLayer,-1 do\
- if frames[i][y] and frames[i][y][x] then\
- tileExists = true\
- break\
- end\
- end\
- \
- if not tileExists then\
- if blueprint then\
- term.setBackgroundColour(colours.blue)\
- term.setTextColour(colours.white)\
- if x == sx+1 and y % 4 == 1 then\
- term.write(\"\"..((y/4) % 10))\
- elseif y == sy + 1 and x % 4 == 1 then\
- term.write(\"\"..((x/4) % 10))\
- elseif x % 2 == 1 and y % 2 == 1 then\
- term.write(\"+\")\
- elseif x % 2 == 1 then\
- term.write(\"|\")\
- elseif y % 2 == 1 then\
- term.write(\"-\")\
- else\
- term.write(\" \")\
- end\
- else\
- term.setBackgroundColour(alphaC) \
- term.write(\" \")\
- end\
- end\
- end\
- end\
- end\
- end\
- \
- --Then the printer, if he's on\
- if state == \"active print\" then\
- local bgColour = alphaC\
- if layering == \"up\" then\
- term.setCursorPos(px-sx,pz-sy)\
- if frames[sFrame] and frames[sFrame][pz-sy] and frames[sFrame][pz-sy][px-sx] then\
- bgColour = frames[sFrame][pz-sy][px-sx]\
- elseif blueprint then bgColour = colours.blue end\
- else\
- term.setCursorPos(px-sx,py-sy)\
- if frames[sFrame] and frames[sFrame][py-sy] and frames[sFrame][py-sy][px-sx] then\
- bgColour = frames[sFrame][py-sy][px-sx]\
- elseif blueprint then bgColour = colours.blue end\
- end\
- \
- term.setBackgroundColour(bgColour)\
- if bgColour == colours.black then term.setTextColour(colours.white)\
- else term.setTextColour(colours.black) end\
- \
- term.write(turtlechar)\
- end\
- \
- --Then the buffer\
- if selectrect then\
- if buffer and rectblink == 1 then\
- for y=selectrect.y1, math.min(selectrect.y2, selectrect.y1 + buffer.height-1) do\
- for x=selectrect.x1, math.min(selectrect.x2, selectrect.x1 + buffer.width-1) do\
- if buffer.contents[y-selectrect.y1+1][x-selectrect.x1+1] then\
- term.setCursorPos(x+sx,y+sy)\
- term.setBackgroundColour(buffer.contents[y-selectrect.y1+1][x-selectrect.x1+1])\
- term.write(\" \")\
- end\
- end\
- end\
- end\
- \
- --This draws the \"selection\" box\
- local add = nil\
- if buffer then\
- term.setBackgroundColour(colours.lightGrey)\
- else \
- term.setBackgroundColour(colours.grey)\
- end\
- for i=selectrect.x1, selectrect.x2 do\
- add = (i + selectrect.y1 + rectblink) % 2 == 0\
- term.setCursorPos(i-sx,selectrect.y1-sy)\
- if add then term.write(\" \") end\
- add = (i + selectrect.y2 + rectblink) % 2 == 0\
- term.setCursorPos(i-sx,selectrect.y2-sy)\
- if add then term.write(\" \") end\
- end\
- for i=selectrect.y1 + 1, selectrect.y2 - 1 do\
- add = (i + selectrect.x1 + rectblink) % 2 == 0\
- term.setCursorPos(selectrect.x1-sx,i-sy)\
- if add then term.write(\" \") end\
- add = (i + selectrect.x2 + rectblink) % 2 == 0\
- term.setCursorPos(selectrect.x2-sx,i-sy)\
- if add then term.write(\" \") end\
- end\
- end\
- end\
- \
- --[[Draws the colour picker on the right side of the screen, the colour pallette and the footer with any \
- messages currently being displayed\
- Params: none\
- Returns:nil\
- ]]--\
- local function drawInterface()\
- --Picker\
- for i=1,#column do\
- term.setCursorPos(w-1, i)\
- term.setBackgroundColour(column[i])\
- if state == \"print\" then\
- if i == 16 then\
- term.setTextColour(colours.white)\
- else\
- term.setTextColour(colours.black)\
- end\
- if requirementsDisplayed then\
- if requiredMaterials[i] < 10 then term.write(\" \") end\
- term.setCursorPos(w-#tostring(requiredMaterials[i])+1, i)\
- term.write(requiredMaterials[i])\
- else\
- if i < 10 then term.write(\" \") end\
- term.write(i)\
- end\
- else\
- term.write(\" \")\
- end\
- end\
- term.setCursorPos(w-1,#column+1)\
- term.setBackgroundColour(colours.black)\
- term.setTextColour(colours.red)\
- term.write(\"XX\")\
- --Pallette\
- term.setCursorPos(w-1,h-1)\
- if not lSel then\
- term.setBackgroundColour(colours.black)\
- term.setTextColour(colours.red)\
- term.write(\"X\")\
- else\
- term.setBackgroundColour(lSel)\
- term.setTextColour(lSel)\
- term.write(\" \")\
- end\
- if not rSel then\
- term.setBackgroundColour(colours.black)\
- term.setTextColour(colours.red)\
- term.write(\"X\")\
- else\
- term.setBackgroundColour(rSel)\
- term.setTextColour(rSel)\
- term.write(\" \")\
- end\
- --Footer\
- if inMenu then return end\
- \
- term.setCursorPos(1, h)\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- term.clearLine()\
- if inDropDown then\
- term.write(string.rep(\" \", 6))\
- else\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.write(\"menu \")\
- end\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- term.write(getStateMessage())\
- \
- local coords=\"X:\"..sx..\" Y:\"..sy\
- if animated then coords = coords..\" Frame:\"..sFrame..\"/\"..framecount..\" \" end\
- term.setCursorPos(w-#coords+1,h)\
- if state == \"play\" then term.setBackgroundColour(colours.lime)\
- elseif record then term.setBackgroundColour(colours.red) end\
- term.write(coords)\
- \
- if animated then\
- term.setCursorPos(w-1,h)\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.write(\"<>\")\
- end\
- end\
- \
- --[[Runs an interface where users can select topics of help. Will return once the user quits the help screen.\
- Params: none\
- Returns:nil\
- ]]--\
- local function drawHelpScreen()\
- local selectedHelp = nil\
- while true do\
- term.setBackgroundColour(colours.lightGrey)\
- term.clear()\
- if not selectedHelp then\
- term.setCursorPos(4, 1)\
- term.setTextColour(colours.brown)\
- term.write(\"Available modes (click for info):\")\
- for i=1,#helpTopics do\
- term.setCursorPos(2, 2 + i)\
- term.setTextColour(colours.black)\
- term.write(helpTopics[i].name)\
- if helpTopics[i].key then\
- term.setTextColour(colours.red)\
- term.write(\" (\"..helpTopics[i].key..\")\")\
- end\
- end\
- term.setCursorPos(4,h)\
- term.setTextColour(colours.black)\
- term.write(\"Press any key to exit\")\
- else\
- term.setCursorPos(4,1)\
- term.setTextColour(colours.brown)\
- term.write(helpTopics[selectedHelp].name)\
- if helpTopics[selectedHelp].key then\
- term.setTextColour(colours.red)\
- term.write(\" (\"..helpTopics[selectedHelp].key..\")\")\
- end\
- term.setCursorPos(1,3)\
- term.setTextColour(colours.black)\
- print(helpTopics[selectedHelp].message..\"\\n\")\
- for i=1,#helpTopics[selectedHelp].controls do\
- term.setTextColour(colours.brown)\
- term.write(helpTopics[selectedHelp].controls[i][1]..\" \")\
- term.setTextColour(colours.black)\
- print(helpTopics[selectedHelp].controls[i][2])\
- end\
- end\
- \
- local id,p1,p2,p3 = os.pullEvent()\
- \
- if id == \"timer\" then updateTimer(p1)\
- elseif id == \"key\" then \
- if selectedHelp then selectedHelp = nil\
- else break end\
- elseif id == \"mouse_click\" then\
- if not selectedHelp then \
- if p3 >=3 and p3 <= 2+#helpTopics then\
- selectedHelp = p3-2 \
- else break end\
- else\
- selectedHelp = nil\
- end\
- end\
- end\
- end\
- \
- --[[Draws a message in the footer bar. A helper for DrawInterface, but can be called for custom messages, if the\
- inMenu paramter is set to true while this is being done (remember to set it back when done!)\
- Params: message:string = The message to be drawn\
- Returns:nil\
- ]]--\
- local function drawMessage(message)\
- term.setCursorPos(1,h)\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- term.clearLine()\
- term.write(message)\
- end\
- \
- --[[\
- Section: Generic Interfaces\
- ]]--\
- \
- \
- --[[One of my generic text printing methods, printing a message at a specified position with width and offset.\
- No colour materials included.\
- Params: msg:string = The message to print off-center\
- height:number = The starting height of the message\
- width:number = The limit as to how many characters long each line may be\
- offset:number = The starting width offset of the message\
- Returns:number the number of lines used in printing the message\
- ]]--\
- local function wprintOffCenter(msg, height, width, offset)\
- local inc = 0\
- local ops = 1\
- while #msg - ops > width do\
- local nextspace = 0\
- while string.find(msg, \" \", ops + nextspace) and\
- string.find(msg, \" \", ops + nextspace) - ops < width do\
- nextspace = string.find(msg, \" \", nextspace + ops) + 1 - ops\
- end\
- local ox,oy = term.getCursorPos()\
- term.setCursorPos(width/2 - (nextspace)/2 + offset, height + inc)\
- inc = inc + 1\
- term.write(string.sub(msg, ops, nextspace + ops - 1))\
- ops = ops + nextspace\
- end\
- term.setCursorPos(width/2 - #string.sub(msg, ops)/2 + offset, height + inc)\
- term.write(string.sub(msg, ops))\
- \
- return inc + 1\
- end\
- \
- --[[Draws a message that must be clicked on or a key struck to be cleared. No options, so used for displaying\
- generic information.\
- Params: ctitle:string = The title of the confirm dialogue\
- msg:string = The message displayed in the dialogue\
- Returns:nil\
- ]]--\
- local function displayConfirmDialogue(ctitle, msg)\
- local dialogoffset = 8\
- --We actually print twice- once to get the lines, second time to print proper. Easier this way.\
- local lines = wprintOffCenter(msg, 5, w - (dialogoffset+2) * 2, dialogoffset + 2)\
- \
- term.setCursorPos(dialogoffset, 3)\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.write(string.rep(\" \", w - dialogoffset * 2))\
- term.setCursorPos(dialogoffset + (w - dialogoffset * 2)/2 - #ctitle/2, 3)\
- term.write(ctitle)\
- term.setTextColour(colours.grey)\
- term.setBackgroundColour(colours.lightGrey)\
- term.setCursorPos(dialogoffset, 4)\
- term.write(string.rep(\" \", w - dialogoffset * 2))\
- for i=5,5+lines do\
- term.setCursorPos(dialogoffset, i) \
- term.write(\" \"..string.rep(\" \", w - (dialogoffset) * 2 - 2)..\" \")\
- end\
- wprintOffCenter(msg, 5, w - (dialogoffset+2) * 2, dialogoffset + 2)\
- \
- --In the event of a message, the player hits anything to continue\
- while true do\
- local id,key = os.pullEvent()\
- if id == \"timer\" then updateTimer(key);\
- elseif id == \"key\" or id == \"mouse_click\" or id == \"mouse_drag\" then break end\
- end\
- end\
- \
- --[[Produces a nice dropdown menu based on a table of strings. Depending on the position, this will auto-adjust the position\
- of the menu drawn, and allows nesting of menus and sub menus. Clicking anywhere outside the menu will cancel and return nothing\
- Params: x:int = the x position the menu should be displayed at\
- y:int = the y position the menu should be displayed at\
- options:table = the list of options available to the user, as strings or submenus (tables of strings, with a name parameter)\
- Returns:string the selected menu option.\
- ]]--\
- local function displayDropDown(x, y, options)\
- inDropDown = true\
- --Figures out the dimensions of our thing\
- local longestX = #options.name\
- for i=1,#options do\
- local currVal = options[i]\
- if type(currVal) == \"table\" then currVal = currVal.name end\
- \
- longestX = math.max(longestX, #currVal)\
- end\
- local xOffset = math.max(0, longestX - ((w-2) - x) + 1)\
- local yOffset = math.max(0, #options - ((h-1) - y))\
- \
- local clickTimes = 0\
- local tid = nil\
- local selection = nil\
- while clickTimes < 2 do\
- drawCanvas()\
- drawInterface()\
- \
- term.setCursorPos(x-xOffset,y-yOffset)\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.write(options.name..string.rep(\" \", longestX-#options.name + 2))\
- \
- for i=1,#options do\
- term.setCursorPos(x-xOffset, y-yOffset+i)\
- if i==selection and clickTimes % 2 == 0 then\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- else\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- end\
- local currVal = options[i]\
- if type(currVal) == \"table\" then \
- term.write(currVal.name..string.rep(\" \", longestX-#currVal.name + 1))\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.write(\">\")\
- else\
- term.write(currVal..string.rep(\" \", longestX-#currVal + 2))\
- end\
- end\
- \
- local id, p1, p2, p3 = os.pullEvent()\
- if id == \"timer\" then\
- if p1 == tid then \
- clickTimes = clickTimes + 1\
- if clickTimes > 2 then \
- break\
- else \
- tid = os.startTimer(0.1) \
- end\
- else \
- updateTimer(p1) \
- drawCanvas()\
- drawInterface()\
- end\
- elseif id == \"mouse_click\" then\
- if p2 >=x-xOffset and p2 <= x-xOffset + longestX + 1 and p3 >= y-yOffset+1 and p3 <= y-yOffset+#options then\
- selection = p3-(y-yOffset)\
- tid = os.startTimer(0.1)\
- else\
- selection = \"\"\
- break\
- end\
- end\
- end\
- \
- if type(selection) == \"number\" then\
- selection = options[selection]\
- end\
- \
- if type(selection) == \"string\" then \
- inDropDown = false\
- return selection\
- elseif type(selection) == \"table\" then \
- return displayDropDown(x, y, selection)\
- end\
- end\
- \
- --[[A custom io.read() function with a few differences- it limits the number of characters being printed,\
- waits a 1/100th of a second so any keys still in the event library are removed before input is read and\
- the timer for the selectionrectangle is continuously updated during the process.\
- Params: lim:int = the number of characters input is allowed\
- Returns:string the inputted string, trimmed of leading and tailing whitespace\
- ]]--\
- local function readInput(lim)\
- term.setCursorBlink(true)\
- \
- local inputString = \"\"\
- if not lim or type(lim) ~= \"number\" or lim < 1 then lim = w - ox end\
- local ox,oy = term.getCursorPos()\
- --We only get input from the footer, so this is safe. Change if recycling\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- term.write(string.rep(\" \", lim))\
- term.setCursorPos(ox, oy)\
- --As events queue immediately, we may get an unwanted key... this will solve that problem\
- local inputTimer = os.startTimer(0.01)\
- local keysAllowed = false\
- \
- while true do\
- local id,key = os.pullEvent()\
- \
- if keysAllowed then\
- if id == \"key\" and key == 14 and #inputString > 0 then\
- inputString = string.sub(inputString, 1, #inputString-1)\
- term.setCursorPos(ox + #inputString,oy)\
- term.write(\" \")\
- elseif id == \"key\" and key == 28 and inputString ~= string.rep(\" \", #inputString) then \
- break\
- elseif id == \"key\" and key == keys.leftCtrl then\
- return \"\"\
- elseif id == \"char\" and #inputString < lim then\
- inputString = inputString..key\
- end\
- end\
- \
- if id == \"timer\" then\
- if key == inputTimer then \
- keysAllowed = true\
- else\
- updateTimer(key)\
- drawCanvas()\
- drawInterface()\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- end\
- end\
- term.setCursorPos(ox,oy)\
- term.write(inputString)\
- term.setCursorPos(ox + #inputString, oy)\
- end\
- \
- while string.sub(inputString, 1, 1) == \" \" do\
- inputString = string.sub(inputString, 2, #inputString)\
- end\
- while string.sub(inputString, #inputString, #inputString) == \" \" do\
- inputString = string.sub(inputString, 1, #inputString-1)\
- end\
- term.setCursorBlink(false)\
- \
- return inputString\
- end\
- \
- --[[ \
- Section: Image tools \
- ]]--\
- \
- \
- --[[Copies all pixels beneath the selection rectangle into the image buffer. Empty buffers are converted to nil.\
- Params: removeImage:bool = true if the image is to be erased after copying, false otherwise\
- Returns:nil\
- ]]--\
- local function copyToBuffer(removeImage)\
- buffer = { width = selectrect.x2 - selectrect.x1 + 1, height = selectrect.y2 - selectrect.y1 + 1, contents = { } }\
- \
- local containsSomething = false\
- for y=1,buffer.height do\
- buffer.contents[y] = { }\
- local f,l = sFrame,sFrame\
- if record then f,l = 1, framecount end\
- \
- for fra = f,l do\
- if frames[fra][selectrect.y1 + y - 1] then\
- for x=1,buffer.width do\
- buffer.contents[y][x] = frames[sFrame][selectrect.y1 + y - 1][selectrect.x1 + x - 1]\
- if removeImage then frames[fra][selectrect.y1 + y - 1][selectrect.x1 + x - 1] = nil end\
- if buffer.contents[y][x] then containsSomething = true end\
- end\
- end\
- end\
- end\
- --I don't classify an empty buffer as a real buffer- confusing to the user.\
- if not containsSomething then buffer = nil end\
- end\
- \
- --[[Replaces all pixels under the selection rectangle with the image buffer (or what can be seen of it). Record-dependent.\
- Params: removeBuffer:bool = true if the buffer is to be emptied after copying, false otherwise\
- Returns:nil\
- ]]--\
- local function copyFromBuffer(removeBuffer)\
- if not buffer then return end\
- \
- for y = 1, math.min(buffer.height,selectrect.y2-selectrect.y1+1) do\
- local f,l = sFrame, sFrame\
- if record then f,l = 1, framecount end\
- \
- for fra = f,l do\
- if not frames[fra][selectrect.y1+y-1] then frames[fra][selectrect.y1+y-1] = { } end\
- for x = 1, math.min(buffer.width,selectrect.x2-selectrect.x1+1) do\
- frames[fra][selectrect.y1+y-1][selectrect.x1+x-1] = buffer.contents[y][x]\
- end\
- end\
- end\
- \
- if removeBuffer then buffer = nil end\
- end\
- \
- --[[Moves the entire image (or entire animation) to the specified coordinates. Record-dependent.\
- Params: newx:int = the X coordinate to move the image to\
- newy:int = the Y coordinate to move the image to\
- Returns:nil\
- ]]--\
- local function moveImage(newx,newy)\
- if not leflim or not toplim then return end\
- if newx <=0 or newy <=0 then return end\
- local f,l = sFrame,sFrame\
- if record then f,l = 1,framecount end\
- \
- for i=f,l do\
- local newlines = { }\
- for y,line in pairs(frames[i]) do\
- newlines[y-toplim+newy] = { }\
- for x,char in pairs(line) do\
- newlines[y-toplim+newy][x-leflim+newx] = char\
- end\
- end\
- frames[i] = newlines\
- end\
- end\
- \
- --[[Prompts the user to clear the current frame or all frames. Record-dependent.,\
- Params: none\
- Returns:nil\
- ]]--\
- local function clearImage()\
- inMenu = true\
- if not animated then\
- drawMessage(\"Clear image? Y/N: \")\
- elseif record then\
- drawMessage(\"Clear ALL frames? Y/N: \")\
- else\
- drawMessage(\"Clear current frame? Y/N :\")\
- end\
- if string.find(string.upper(readInput(1)), \"Y\") then\
- local f,l = sFrame,sFrame\
- if record then f,l = 1,framecount end\
- \
- for i=f,l do\
- frames[i] = { }\
- end\
- end\
- inMenu = false\
- end\
- \
- --[[A recursively called method (watch out for big calls!) in which every pixel of a set colour is\
- changed to another colour. Does not work on the nil colour, for obvious reasons.\
- Params: x:int = The X coordinate of the colour to flood-fill\
- y:int = The Y coordinate of the colour to flood-fill\
- targetColour:colour = the colour that is being flood-filled\
- newColour:colour = the colour with which to replace the target colour\
- Returns:nil\
- ]]--\
- local function floodFill(x, y, targetColour, newColour)\
- if not newColour or not targetColour then return end\
- local nodeList = { }\
- \
- table.insert(nodeList, {x = x, y = y})\
- \
- while #nodeList > 0 do\
- local node = nodeList[1]\
- if frames[sFrame][node.y] and frames[sFrame][node.y][node.x] == targetColour then\
- frames[sFrame][node.y][node.x] = newColour\
- table.insert(nodeList, { x = node.x + 1, y = node.y})\
- table.insert(nodeList, { x = node.x, y = node.y + 1})\
- if x > 1 then table.insert(nodeList, { x = node.x - 1, y = node.y}) end\
- if y > 1 then table.insert(nodeList, { x = node.x, y = node.y - 1}) end\
- end\
- table.remove(nodeList, 1)\
- end\
- end\
- \
- --[[ \
- Section: Animation Tools \
- ]]--\
- \
- --[[Enters play mode, allowing the animation to play through. Interface is restricted to allow this,\
- and method only leaves once the player leaves play mode.\
- Params: none\
- Returns:nil\
- ]]--\
- local function playAnimation()\
- state = \"play\"\
- selectedrect = nil\
- \
- local animt = os.startTimer(animtime)\
- repeat\
- drawCanvas()\
- drawInterface()\
- \
- local id,key,_,y = os.pullEvent()\
- \
- if id==\"timer\" then\
- if key == animt then\
- animt = os.startTimer(animtime)\
- sFrame = (sFrame % framecount) + 1\
- else\
- updateTimer(key)\
- end\
- elseif id==\"key\" then\
- if key == keys.comma and animtime > 0.1 then animtime = animtime - 0.05\
- elseif key == keys.period and animtime < 0.5 then animtime = animtime + 0.05\
- elseif key == keys.space then state = \"paint\" end\
- elseif id==\"mouse_click\" and y == h then\
- state = \"paint\"\
- end\
- until state ~= \"play\"\
- os.startTimer(0.5)\
- end\
- \
- --[[Changes the selected frame (sFrame) to the chosen frame. If this frame is above the framecount,\
- additional frames are created with a copy of the image on the selected frame.\
- Params: newframe:int = the new frame to move to\
- Returns:nil\
- ]]--\
- local function changeFrame(newframe)\
- inMenu = true\
- if not tonumber(newframe) then\
- term.setCursorPos(1,h)\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.grey)\
- term.clearLine()\
- \
- term.write(\"Go to frame: \")\
- newframe = tonumber(readInput(2))\
- if not newframe or newframe <= 0 then\
- inMenu = false\
- return \
- end\
- elseif newframe <= 0 then return end\
- \
- if newframe > framecount then\
- for i=framecount+1,newframe do\
- frames[i] = {}\
- for y,line in pairs(frames[sFrame]) do\
- frames[i][y] = { }\
- for x,v in pairs(line) do\
- frames[i][y][x] = v\
- end\
- end\
- end\
- framecount = newframe\
- end\
- sFrame = newframe\
- inMenu = false\
- end\
- \
- --[[Removes every frame leading after the frame passed in\
- Params: frame:int the non-inclusive lower bounds of the delete\
- Returns:nil\
- ]]--\
- local function removeFramesAfter(frame)\
- inMenu = true\
- if frame==framecount then return end\
- drawMessage(\"Remove frames \"..(frame+1)..\"/\"..framecount..\"? Y/N :\")\
- local answer = string.upper(readInput(1))\
- \
- if string.find(answer, string.upper(\"Y\")) ~= 1 then \
- inMenu = false\
- return \
- end\
- \
- for i=frame+1, framecount do\
- frames[i] = nil\
- end\
- framecount = frame\
- inMenu = false\
- end\
- \
- --[[\
- Section: Printing Tools\
- ]]--\
- \
- --[[Constructs a new facing to the left of the current facing\
- Params: curx:number = The facing on the X axis\
- curz:number = The facing on the Z axis\
- hand:string = The hand of the axis (\"right\" or \"left\")\
- Returns:number,number = the new facing on the X and Z axis after a left turn\
- ]]--\
- local function getLeft(curx, curz)\
- local hand = \"left\"\
- if layering == \"up\" then hand = \"right\" end\
- \
- if hand == \"right\" then\
- if curx == 1 then return 0,-1 end\
- if curx == -1 then return 0,1 end\
- if curz == 1 then return 1,0 end\
- if curz == -1 then return -1,0 end\
- else\
- if curx == 1 then return 0,1 end\
- if curx == -1 then return 0,-1 end\
- if curz == 1 then return -1,0 end\
- if curz == -1 then return 1,0 end\
- end\
- end\
- \
- --[[Constructs a new facing to the right of the current facing\
- Params: curx:number = The facing on the X axis\
- curz:number = The facing on the Z axis\
- hand:string = The hand of the axis (\"right\" or \"left\")\
- Returns:number,number = the new facing on the X and Z axis after a right turn\
- ]]--\
- local function getRight(curx, curz)\
- local hand = \"left\"\
- if layering == \"up\" then hand = \"right\" end\
- \
- if hand == \"right\" then\
- if curx == 1 then return 0,1 end\
- if curx == -1 then return 0,-1 end\
- if curz == 1 then return -1,0 end\
- if curz == -1 then return 1,0 end\
- else\
- if curx == 1 then return 0,-1 end\
- if curx == -1 then return 0,1 end\
- if curz == 1 then return 1,0 end\
- if curz == -1 then return -1,0 end\
- end\
- end\
- \
- \
- --[[Sends out a rednet signal requesting local printers, and will listen for any responses. Printers found are added to the\
- printerList (for ID's) and printerNames (for names)\
- Params: nil\
- Returns:nil\
- ]]--\
- local function locatePrinters()\
- printerList = { }\
- printerNames = { name = \"Printers\" }\
- local oldState = state\
- state = \"Locating printers, please wait... \"\
- drawCanvas()\
- drawInterface()\
- state = oldState\
- \
- local modemOpened = false\
- for k,v in pairs(rs.getSides()) do\
- if peripheral.isPresent(v) and peripheral.getType(v) == \"modem\" then\
- rednet.open(v)\
- modemOpened = true\
- break\
- end\
- end\
- \
- if not modemOpened then\
- displayConfirmDialogue(\"Modem not found!\", \"No modem peripheral. Must have network modem to locate printers.\")\
- return false\
- end\
- \
- rednet.broadcast(\"$3DPRINT IDENTIFY\")\
- \
- while true do\
- local id, msg = rsTimeReceive(1)\
- \
- if not id then break end\
- if string.find(msg, \"$3DPRINT IDACK\") == 1 then\
- msg = string.gsub(msg, \"$3DPRINT IDACK \", \"\")\
- table.insert(printerList, id)\
- table.insert(printerNames, msg)\
- end\
- end\
- \
- if #printerList == 0 then\
- displayConfirmDialogue(\"Printers not found!\", \"No active printers found in proximity of this computer.\")\
- return false\
- else\
- return true\
- end\
- end\
- \
- --[[Sends a request to the printer. Waits on a response and updates the state of the application accordingly.\
- Params: command:string the command to send\
- param:string a parameter to send, if any\
- Returns:nil\
- ]]--\
- local function sendPC(command,param)\
- local msg = \"$PC \"..command\
- if param then msg = msg..\" \"..param end\
- rednet.send(printerList[selectedPrinter], msg)\
- \
- while true do\
- local id,key = rsTimeReceive()\
- if id == printerList[selectedPrinter] then\
- if key == \"$3DPRINT ACK\" then\
- break\
- elseif key == \"$3DPRINT DEP\" then\
- displayConfirmDialogue(\"Printer Empty\", \"The printer has exhasted a material. Please refill slot \"..param..\
- \", and click this message when ready to continue.\")\
- rednet.send(printerList[selectedPrinter], msg)\
- end\
- end\
- end\
- \
- --Changes to position are handled after the event has been successfully completed\
- if command == \"FW\" then\
- px = px + pfx\
- pz = pz + pfz\
- elseif command == \"BK\" then\
- px = px - pfx\
- pz = pz - pfz\
- elseif command == \"UP\" then\
- if layering == \"up\" then\
- py = py + 1\
- else \
- py = py - 1\
- end\
- elseif command == \"DW\" then\
- if layering == \"up\" then\
- py = py - 1\
- else \
- py = py + 1\
- end\
- elseif command == \"TL\" then\
- pfx,pfz = getLeft(pfx,pfz)\
- elseif command == \"TR\" then\
- pfx,pfz = getRight(pfx,pfz)\
- elseif command == \"TU\" then\
- pfx = -pfx\
- pfz = -pfz\
- end\
- \
- drawCanvas()\
- drawInterface()\
- end\
- \
- --[[A printing function that commands the printer to turn to face the desired direction, if it is not already doing so\
- Params: desx:number = the normalized x direction to face\
- desz:number = the normalized z direction to face\
- Returns:nil\
- ]]--\
- local function turnToFace(desx,desz)\
- if desx ~= 0 then\
- if pfx ~= desx then\
- local temppfx,_ = getLeft(pfx,pfz)\
- if temppfx == desx then\
- sendPC(\"TL\")\
- elseif temppfx == -desx then\
- sendPC(\"TR\")\
- else\
- sendPC(\"TU\")\
- end\
- end\
- else\
- print(\"on the z axis\")\
- if pfz ~= desz then\
- local _,temppfz = getLeft(pfx,pfz)\
- if temppfz == desz then\
- sendPC(\"TL\")\
- elseif temppfz == -desz then\
- sendPC(\"TR\")\
- else\
- sendPC(\"TU\")\
- end\
- end\
- end\
- end\
- \
- --[[Performs the print\
- Params: nil\
- Returns:nil\
- ]]--\
- local function performPrint()\
- state = \"active print\"\
- if layering == \"up\" then\
- --An up layering starts our builder bot on the bottom left corner of our build\
- px,py,pz = leflim, 0, botlim + 1\
- pfx,pfz = 0,-1\
- \
- --We move him forward and up a bit from his original position.\
- sendPC(\"FW\")\
- sendPC(\"UP\")\
- --For each layer that needs to be completed, we go up by one each time\
- for layers=1,#frames do\
- --We first decide if we're going forwards or back, depending on what side we're on\
- local rowbot,rowtop,rowinc = nil,nil,nil\
- if pz == botlim then\
- rowbot,rowtop,rowinc = botlim,toplim,-1\
- else\
- rowbot,rowtop,rowinc = toplim,botlim,1\
- end\
- \
- for rows = rowbot,rowtop,rowinc do\
- --Then we decide if we're going left or right, depending on what side we're on\
- local linebot,linetop,lineinc = nil,nil,nil\
- if px == leflim then\
- --Facing from the left side has to be easterly- it's changed here\
- turnToFace(1,0)\
- linebot,linetop,lineinc = leflim,riglim,1\
- else\
- --Facing from the right side has to be westerly- it's changed here\
- turnToFace(-1,0)\
- linebot,linetop,lineinc = riglim,leflim,-1\
- end\
- \
- for lines = linebot,linetop,lineinc do\
- --We move our turtle forward, placing the right material at each step\
- local material = frames[py][pz][px]\
- if material then\
- material = math.log10(frames[py][pz][px])/math.log10(2) + 1\
- sendPC(\"SS\", material)\
- sendPC(\"PD\")\
- end\
- if lines ~= linetop then\
- sendPC(\"FW\")\
- end\
- end\
- \
- --The printer then has to do a U-turn, depending on which way he's facing and\
- --which way he needs to go\
- local temppfx,temppfz = getLeft(pfx,pfz)\
- if temppfz == rowinc and rows ~= rowtop then\
- sendPC(\"TL\")\
- sendPC(\"FW\")\
- sendPC(\"TL\")\
- elseif temppfz == -rowinc and rows ~= rowtop then\
- sendPC(\"TR\")\
- sendPC(\"FW\")\
- sendPC(\"TR\")\
- end\
- end\
- --Now at the end of a run he does a 180 and moves up to begin the next part of the print\
- sendPC(\"TU\")\
- if layers ~= #frames then\
- sendPC(\"UP\")\
- end\
- end\
- --All done- now we head back to where we started.\
- if px ~= leflim then\
- turnToFace(-1,0)\
- while px ~= leflim do\
- sendPC(\"FW\")\
- end\
- end\
- if pz ~= botlim then\
- turnToFace(0,-1)\
- while pz ~= botlim do\
- sendPC(\"BK\")\
- end\
- end\
- turnToFace(0,-1)\
- sendPC(\"BK\")\
- while py > 0 do\
- sendPC(\"DW\")\
- end\
- else\
- --The front facing is at the top-left corner, facing south not north\
- px,py,pz = leflim, botlim, 1\
- pfx,pfz = 0,1\
- --We move the printer to the last layer- he prints from the back forwards\
- while pz < #frames do\
- sendPC(\"FW\")\
- end\
- \
- --For each layer in the frame we build our wall, the move back\
- for layers = 1,#frames do\
- --We first decide if we're going left or right based on our position\
- local rowbot,rowtop,rowinc = nil,nil,nil\
- if px == leflim then\
- rowbot,rowtop,rowinc = leflim,riglim,1\
- else\
- rowbot,rowtop,rowinc = riglim,leflim,-1\
- end\
- \
- for rows = rowbot,rowtop,rowinc do\
- --Then we decide if we're going up or down, depending on our given altitude\
- local linebot,linetop,lineinc = nil,nil,nil\
- if py == botlim then\
- linebot,linetop,lineinc = botlim,toplim,-1\
- else\
- linebot,linetop,lineinc = toplim,botlim,1\
- end\
- \
- for lines = linebot,linetop,lineinc do\
- --We move our turtle up/down, placing the right material at each step\
- local material = frames[pz][py][px]\
- if material then\
- material = math.log10(frames[pz][py][px])/math.log10(2) + 1\
- sendPC(\"SS\", material)\
- sendPC(\"PF\")\
- end\
- if lines ~= linetop then\
- if lineinc == 1 then sendPC(\"DW\")\
- else sendPC(\"UP\") end\
- end\
- end\
- \
- if rows ~= rowtop then\
- turnToFace(rowinc,0)\
- sendPC(\"FW\")\
- turnToFace(0,1)\
- end\
- end\
- \
- if layers ~= #frames then\
- sendPC(\"TU\")\
- sendPC(\"FW\")\
- sendPC(\"TU\")\
- end\
- end\
- --He's easy to reset\
- while px ~= leflim do\
- turnToFace(-1,0)\
- sendPC(\"FW\")\
- end\
- turnToFace(0,1)\
- end\
- \
- sendPC(\"DE\")\
- \
- displayConfirmDialogue(\"Print complete\", \"The 3D print was successful.\")\
- end\
- \
- --[[ \
- Section: Interface \
- ]]--\
- \
- --[[Runs the printing interface. Allows users to find/select a printer, the style of printing to perform and to begin the operation\
- Params: none\
- Returns:boolean true if printing was started, false otherwse\
- ]]--\
- local function runPrintInterface()\
- if not locatePrinters() then\
- return false\
- end\
- \
- calculateMaterials()\
- layering = \"up\"\
- requirementsDisplayed = false\
- selectedPrinter = 1\
- while true do\
- drawCanvas()\
- term.setBackgroundColour(colours.lightGrey)\
- for i=1,10 do\
- term.setCursorPos(1,i)\
- term.clearLine()\
- end\
- drawInterface()\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.black)\
- \
- local msg = \"3D Printing\"\
- term.setCursorPos(w/2-#msg/2 - 2, 1)\
- term.write(msg)\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- if(requirementsDisplayed) then\
- msg = \"Count:\"\
- else\
- msg = \" Slot:\"\
- end\
- term.setCursorPos(w-3-#msg, 1)\
- term.write(msg)\
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.black)\
- \
- term.setCursorPos(7, 2)\
- term.write(\"Layering\")\
- drawPictureTable(layerUpIcon, 3, 3, colours.white)\
- drawPictureTable(layerForwardIcon, 12, 3, colours.white)\
- if layering == \"up\" then\
- term.setBackgroundColour(colours.red)\
- else\
- term.setBackgroundColour(colours.lightGrey)\
- end\
- term.setCursorPos(3, 9)\
- term.write(\"Upwards\")\
- if layering == \"forward\" then\
- term.setBackgroundColour(colours.red)\
- else\
- term.setBackgroundColour(colours.lightGrey)\
- end\
- term.setCursorPos(12, 9)\
- term.write(\"Forward\")\
- \
- term.setBackgroundColour(colours.lightGrey)\
- term.setTextColour(colours.black)\
- term.setCursorPos(31, 2)\
- term.write(\"Printer ID\")\
- term.setCursorPos(33, 3)\
- if #printerList > 1 then\
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- else\
- term.setTextColour(colours.red)\
- end\
- term.write(\" \"..printerNames[selectedPrinter]..\" \")\
- \
- term.setBackgroundColour(colours.grey)\
- term.setTextColour(colours.lightGrey)\
- term.setCursorPos(25, 10)\
- term.write(\" Cancel \")\
- term.setCursorPos(40, 10)\
- term.write(\" Print \")\
- \
- local id, p1, p2, p3 = os.pullEvent()\
- \
- if id == \"timer\" then\
- updateTimer(p1)\
- elseif id == \"mouse_click\" then\
- --Layering Buttons\
- if p2 >= 3 and p2 <= 9 and p3 >= 3 and p3 <= 9 then\
- layering = \"up\"\
- elseif p2 >= 12 and p2 <= 18 and p3 >= 3 and p3 <= 9 then\
- layering = \"forward\"\
- --Count/Slot\
- elseif p2 >= w - #msg - 3 and p2 <= w - 3 and p3 == 1 then\
- requirementsDisplayed = not requirementsDisplayed\
- --Printer ID\
- elseif p2 >= 33 and p2 <= 33 + #printerNames[selectedPrinter] and p3 == 3 and #printerList > 1 then\
- local chosenName = displayDropDown(33, 3, printerNames)\
- for i=1,#printerNames do\
- if printerNames[i] == chosenName then\
- selectedPrinter = i\
- break;\
- end\
- end\
- --Print and Cancel\
- elseif p2 >= 25 and p2 <= 32 and p3 == 10 then\
- break\
- elseif p2 >= 40 and p2 <= 46 and p3 == 10 then\
- rednet.send(printerList[selectedPrinter], \"$3DPRINT ACTIVATE\")\
- ready = false\
- while true do\
- local id,msg = rsTimeReceive(10)\
- \
- if id == printerList[selectedPrinter] and msg == \"$3DPRINT ACTACK\" then\
- ready = true\
- break\
- end\
- end\
- if ready then\
- performPrint()\
- break\
- else\
- displayConfirmDialogue(\"Printer Didn't Respond\", \"The printer didn't respond to the activation command. Check to see if it's online\")\
- end\
- end\
- end\
- end\
- state = \"paint\"\
- end\
- \
- --[[This function changes the current paint program to another tool or mode, depending on user input. Handles\
- any necessary changes in logic involved in that.\
- Params: mode:string = the name of the mode to change to\
- Returns:nil\
- ]]--\
- local function performSelection(mode)\
- if not mode or mode == \"\" then return\
- \
- elseif mode == \"help\" then\
- drawHelpScreen()\
- \
- elseif mode == \"blueprint on\" then\
- blueprint = true\
- ddModes[2][3] = \"blueprint off\"\
- \
- elseif mode == \"blueprint off\" then\
- blueprint = false\
- ddModes[2][3] = \"blueprint on\"\
- \
- elseif mode == \"layers on\" then\
- layerDisplay = true\
- ddModes[2][4] = \"layers off\"\
- \
- elseif mode == \"layers off\" then\
- layerDisplay = false\
- ddModes[2][4] = \"layers on\"\
- \
- elseif mode == \"direction on\" then\
- printDirection = true\
- ddModes[2][5] = \"direction off\"\
- \
- elseif mode == \"direction off\" then\
- printDirection = false\
- ddModes[2][5] = \"direction on\"\
- \
- elseif mode == \"go to\" then\
- changeFrame()\
- \
- elseif mode == \"remove\" then\
- removeFramesAfter(sFrame)\
- \
- elseif mode == \"play\" then\
- playAnimation()\
- \
- elseif mode == \"copy\" then\
- if selectrect and selectrect.x1 ~= selectrect.x2 then\
- copyToBuffer(false)\
- end\
- \
- elseif mode == \"cut\" then\
- if selectrect and selectrect.x1 ~= selectrect.x2 then \
- copyToBuffer(true)\
- end\
- \
- elseif mode == \"paste\" then\
- if selectrect and selectrect.x1 ~= selectrect.x2 then \
- copyFromBuffer(false)\
- end\
- \
- elseif mode == \"hide\" then\
- selectrect = nil\
- if state == \"select\" then state = \"corner select\" end\
- \
- elseif mode == \"alpha to left\" then\
- if lSel then alphaC = lSel end\
- \
- elseif mode == \"alpha to right\" then\
- if rSel then alphaC = rSel end\
- \
- elseif mode == \"record\" then\
- record = not record\
- \
- elseif mode == \"clear\" then\
- if state==\"select\" then buffer = nil\
- else clearImage() end\
- \
- elseif mode == \"select\" then\
- if state==\"corner select\" or state==\"select\" then\
- state = \"paint\"\
- elseif selectrect and selectrect.x1 ~= selectrect.x2 then\
- state = \"select\"\
- else\
- state = \"corner select\" \
- end\
- \
- elseif mode == \"print\" then\
- state = \"print\"\
- runPrintInterface()\
- state = \"paint\"\
- \
- elseif mode == \"save\" then\
- if animated then saveNFA(sPath)\
- else saveNFP(sPath) end\
- \
- elseif mode == \"exit\" then\
- isRunning = false\
- \
- elseif mode ~= state then state = mode\
- else state = \"paint\"\
- end\
- end\
- \
- --[[The main function of the program, reads and handles all events and updates them accordingly. Mode changes,\
- painting to the canvas and general selections are done here.\
- Params: none\
- Returns:nil\
- ]]--\
- local function handleEvents()\
- recttimer = os.startTimer(0.5)\
- while isRunning do\
- drawCanvas()\
- drawInterface()\
- local id,p1,p2,p3 = os.pullEvent()\
- if id==\"timer\" then\
- updateTimer(p1)\
- elseif id==\"mouse_click\" or id==\"mouse_drag\" then\
- if p2 >=w-1 and p3 < #column+1 then\
- if p1==1 then lSel = column[p3]\
- else rSel = column[p3] end\
- elseif p2 >=w-1 and p3==#column+1 then\
- if p1==1 then lSel = nil\
- else rSel = nil end\
- elseif p2==w-1 and p3==h and animated then\
- changeFrame(sFrame-1)\
- elseif p2==w and p3==h and animated then\
- changeFrame(sFrame+1)\
- elseif p2 < w-10 and p3==h then\
- local sel = displayDropDown(1, h-1, ddModes)\
- performSelection(sel)\
- elseif p2 < w-1 and p3 <= h-1 then\
- if state==\"pippette\" then\
- if p1==1 then\
- if frames[sFrame][p3+sy] and frames[sFrame][p3+sy][p2+sx] then\
- lSel = frames[sFrame][p3+sy][p2+sx] \
- end\
- elseif p1==2 then\
- if frames[sFrame][p3+sy] and frames[sFrame][p3+sy][p2+sx] then\
- rSel = frames[sFrame][p3+sy][p2+sx] \
- end\
- end\
- elseif state==\"move\" then\
- updateImageLims(record)\
- moveImage(p2,p3)\
- elseif state==\"flood\" then\
- if p1 == 1 and lSel and frames[sFrame][p3+sy] then \
- floodFill(p2,p3,frames[sFrame][p3+sy][p2+sx],lSel)\
- elseif p1 == 2 and rSel and frames[sFrame][p3+sy] then \
- floodFill(p2,p3,frames[sFrame][p3+sy][p2+sx],rSel)\
- end\
- elseif state==\"corner select\" then\
- if not selectrect then\
- selectrect = { x1=p2+sx, x2=p2+sx, y1=p3+sy, y2=p3+sy }\
- elseif selectrect.x1 ~= p2+sx and selectrect.y1 ~= p3+sy then\
- if p2+sx<selectrect.x1 then selectrect.x1 = p2+sx\
- else selectrect.x2 = p2+sx end\
- \
- if p3+sy<selectrect.y1 then selectrect.y1 = p3+sy\
- else selectrect.y2 = p3+sy end\
- \
- state = \"select\"\
- end\
- elseif state==\"select\" then\
- if p1 == 1 then\
- local swidth = selectrect.x2 - selectrect.x1\
- local sheight = selectrect.y2 - selectrect.y1\
- \
- selectrect.x1 = p2 + sx\
- selectrect.y1 = p3 + sy\
- selectrect.x2 = p2 + swidth + sx\
- selectrect.y2 = p3 + sheight + sy\
- elseif p1 == 2 and p2 < w-2 and p3 < h-1 then\
- inMenu = true\
- local sel = displayDropDown(p2, p3, srModes) \
- inMenu = false\
- performSelection(sel)\
- end\
- else\
- local f,l = sFrame,sFrame\
- if record then f,l = 1,framecount end\
- local bwidth = 0\
- if state == \"brush\" then bwidth = brushsize-1 end\
- \
- for i=f,l do\
- for x = math.max(1,p2+sx-bwidth),p2+sx+bwidth do\
- for y = math.max(1,p3+sy-bwidth), p3+sy+bwidth do\
- if math.abs(x - (p2+sx)) + math.abs(y - (p3+sy)) <= bwidth then\
- if not frames[i][y] then frames[i][y] = {} end\
- if p1==1 then frames[i][y][x] = lSel\
- else frames[i][y][x] = rSel end\
- end\
- end\
- end\
- end\
- end\
- end\
- elseif id==\"key\" then\
- if p1==keys.leftCtrl then\
- local sel = displayDropDown(1, h-1, ddModes[#ddModes]) \
- performSelection(sel)\
- elseif p1==keys.leftAlt then\
- local sel = displayDropDown(1, h-1, ddModes[1]) \
- performSelection(sel)\
- elseif p1==keys.h then \
- performSelection(\"help\")\
- elseif p1==keys.x then \
- performSelection(\"cut\")\
- elseif p1==keys.c then\
- performSelection(\"copy\")\
- elseif p1==keys.v then\
- performSelection(\"paste\")\
- elseif p1==keys.z then\
- performSelection(\"clear\")\
- elseif p1==keys.s then\
- performSelection(\"select\")\
- elseif p1==keys.tab then\
- performSelection(\"hide\")\
- elseif p1==keys.q then\
- performSelection(\"alpha to left\")\
- elseif p1==keys.w then\
- performSelection(\"alpha to right\")\
- elseif p1==keys.f then\
- performSelection(\"flood\")\
- elseif p1==keys.b then\
- performSelection(\"brush\")\
- elseif p1==keys.m then\
- performSelection(\"move\")\
- elseif p1==keys.backslash and animated then\
- performSelection(\"record\")\
- elseif p1==keys.p then\
- performSelection(\"pippette\")\
- elseif p1==keys.g and animated then\
- performSelection(\"go to\")\
- elseif p1==keys.period and animated then\
- changeFrame(sFrame+1)\
- elseif p1==keys.comma and animated then\
- changeFrame(sFrame-1)\
- elseif p1==keys.r and animated then\
- performSelection(\"remove\")\
- elseif p1==keys.space and animated then\
- performSelection(\"play\")\
- elseif p1==keys.left then\
- if state == \"move\" then\
- updateImageLims(record)\
- moveImage(leflim-1,toplim)\
- elseif state==\"select\" and selectrect.x1 > 1 then\
- selectrect.x1 = selectrect.x1-1\
- selectrect.x2 = selectrect.x2-1\
- elseif sx > 0 then sx=sx-1 end\
- elseif p1==keys.right then\
- if state == \"move\" then\
- updateImageLims(record)\
- moveImage(leflim+1,toplim)\
- elseif state==\"select\" then\
- selectrect.x1 = selectrect.x1+1\
- selectrect.x2 = selectrect.x2+1\
- else sx=sx+1 end\
- elseif p1==keys.up then\
- if state == \"move\" then\
- updateImageLims(record)\
- moveImage(leflim,toplim-1)\
- elseif state==\"select\" and selectrect.y1 > 1 then\
- selectrect.y1 = selectrect.y1-1\
- selectrect.y2 = selectrect.y2-1\
- elseif sy > 0 then sy=sy-1 end\
- elseif p1==keys.down then \
- if state == \"move\" then\
- updateImageLims(record)\
- moveImage(leflim,toplim+1)\
- elseif state==\"select\" then\
- selectrect.y1 = selectrect.y1+1\
- selectrect.y2 = selectrect.y2+1\
- else sy=sy+1 end\
- end\
- elseif id==\"char\" and tonumber(p1) then\
- if state==\"brush\" and tonumber(p1) > 1 then\
- brushsize = tonumber(p1)\
- elseif tonumber(p1) > 0 then\
- changeFrame(tonumber(p1))\
- end\
- end\
- end\
- end\
- \
- --[[ \
- Section: Main \
- ]]--\
- \
- --Taken almost directly from edit (for consistency)\
- local tArgs = {...}\
- \
- local ca = 1\
- \
- if tArgs[ca] == \"-a\" then\
- animated = true\
- ca = ca + 1\
- end\
- \
- if #tArgs < ca then\
- print(\"Usage: npaintpro [-a] <path>\")\
- return\
- end\
- \
- sPath = shell.resolve(tArgs[ca])\
- local bReadOnly = fs.isReadOnly(sPath)\
- if fs.exists(sPath) then\
- if fs.isDir(sPath) then\
- print(\"Cannot edit a directory.\")\
- return\
- elseif string.find(sPath, \".nfp\") ~= #sPath-3 and string.find(sPath, \".nfa\") ~= #sPath-3 then\
- print(\"Can only edit .nfp and nfa files:\",string.find(sPath, \".nfp\"),#sPath-3)\
- return\
- end\
- \
- if string.find(sPath, \".nfa\") == #sPath-3 then\
- animated = true\
- end\
- \
- if string.find(sPath, \".nfp\") == #sPath-3 and animated then\
- print(\"Convert to nfa? Y/N\")\
- if string.find(string.lower(io.read()), \"y\") then\
- local nsPath = string.sub(sPath, 1, #sPath-1)..\"a\"\
- fs.move(sPath, nsPath)\
- sPath = nsPath\
- else\
- animated = false\
- end\
- end\
- else\
- if not animated and string.find(sPath, \".nfp\") ~= #sPath-3 then \
- sPath = sPath..\".nfp\"\
- elseif animated and string.find(sPath, \".nfa\") ~= #sPath-3 then \
- sPath = sPath..\".nfa\"\
- end\
- end \
- \
- if not term.isColour() then\
- print(\"For colour computers only\")\
- return\
- end\
- \
- drawLogo()\
- init()\
- handleEvents()\
- \
- term.setBackgroundColour(colours.black)\
- shell.run(\"clear\")",
- [ "permission.data" ] = "",
- },
- },
- Languages = {
- [ "Boot_EN.lang" ] = "{\
- \"Loading API list...\",\
- \"Finished loading API list...\",\
- \"Loading APIs...\",\
- \"Finished loading APIs...\",\
- \"\",\
- }",
- },
- Settings = {
- Language = {
- CurrentLang = "EN",
- },
- Users = {
- Admin = "8e7d6efe3995f32fa9481828d3d52f0777e740f2d8cb468a82506b9e5dc78f8a",
- },
- },
- }
- local function writeFile(path,content)
- local file = fs.open(path,"w")
- file.write(content)
- file.close()
- end
- function writeDown(input,dir)
- for i,v in pairs(input) do
- if type(v) == "table" then
- writeDown(v,dir.."/"..i)
- elseif type(v) == "string" then
- writeFile(dir.."/"..i,v)
- end
- end
- end
- args = {...}
- if #args == 0 then
- print("Please input a destination folder.")
- else
- writeDown(inputTable,args[1])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement