Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inputTable = {
- Settings = {
- Language = {
- CurrentLang = "EN",
- },
- Users = {
- Admin = "8e7d6efe3995f32fa9481828d3d52f0777e740f2d8cb468a82506b9e5dc78f8a",
- },
- },
- [ "README.md" ] = "# OmniOS\
- GitHub repository of OmniOS",
- [ "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" ] = "bbbbb b\
- b b \
- b b bbbbb bbb b\
- b b b b b b b b\
- bbbbb b b b b b b\
- \
- 11111111111111111",
- [ "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 = {
- [ "PeripheralAPI.lua" ] = "local oldPeripheralWrap = peripheral.wrap\
- function peripheral.wrap(...)\
- local tArgs = {...}\
- if tArgs[1] == \"term\" then return term.current() end\
- return oldPeripheralWrap(...)\
- end\
- print(\"Loaded peripheral driver.\")",
- [ "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\")",
- 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\",\
- }\
- }",
- [ "vfs.lua" ] = "--[[\
- VFS by Creator\
- ]]--\
- \
- --Variables\
- filesystem = {}\
- \
- --Functions\
- \
- --Table generation and mapping\
- local function makeTable(t,path)\
- path = fs.combine(\"\",path)\
- local first = path:match(\"[^/]+\")\
- if first then\
- if t[first] then\
- return makeTable(t[first],path:sub(#first+2,-1))\
- else\
- t[first] = {}\
- return makeTable(t[first],path:sub(#first+2,-1))\
- end\
- else\
- return t\
- end\
- end\
- \
- local function explore(dir,parentTable)\
- local sBuffer = fs.list(dir)\
- for i,v in pairs(sBuffer) do\
- if fs.isDir(dir..\"/\"..v) then\
- if v ~= \".git\" then\
- print(\"Indexing directory: \"..dir..\"/\"..v)\
- parentTable[v] = {}\
- explore(dir..\"/\"..v,parentTable[v])\
- end\
- else\
- print(\"Indexing file: \"..dir..\"/\"..v)\
- parentTable[v] = dir..\"/\"..v\
- end\
- end\
- parentTable[\"&&dir\"] = dir\
- end\
- \
- \
- --Internal\
- local function localExists(t,path)\
- path = fs.combine(\"\",path)\
- local first = path:match(\"[^/]+\")\
- if first then\
- if t[first] then\
- return localExists(t[first],path:sub(#first+2,-1))\
- else\
- return false\
- end\
- else\
- return true\
- end\
- end\
- \
- local function localIsDir(t,path)\
- path = fs.combine(\"\",path)\
- --print(\"Path: \"..path)\
- local first = path:match(\"[^/]+\")\
- if first then\
- return localIsDir(t[first],path:sub(#first+2,-1))\
- else\
- return type(t) == \"table\" and t or false\
- end\
- end\
- \
- local function localList(t,path)\
- path = fs.combine(\"\",path)\
- print(\"Path: \"..path)\
- local first = path:match(\"[^/]+\")\
- if first then\
- return localList(t[first],path:sub(#first+2,-1))\
- else\
- return t\
- end\
- end\
- \
- local function localIsReadOnly(t,path)\
- path = fs.combine(\"\",path)\
- print(\"Pathm: \"..path)\
- local first = path:match(\"[^/]+\")\
- if first then\
- return localIsReadOnly(t[first],path:sub(#first+2,-1))\
- else\
- if type(t) == \"table\" then\
- local final = \"\"\
- for i,v in pairs(t) do\
- if type(v) == \"string\" then\
- final = v\
- break\
- end\
- end\
- return fs.isReadOnly(fs.getDir(final))\
- else\
- return fs.isReadOnly(t)\
- end\
- end\
- end\
- \
- local function localGetDrive(t,path)\
- path = fs.combine(\"\",path)\
- print(\"Pathm: \"..path)\
- local first = path:match(\"[^/]+\")\
- if first then\
- return localGetDrive(t[first],path:sub(#first+2,-1))\
- else\
- print(\"T: \",t)\
- return type(t) == \"table\" and true or fs.getDrive(t)\
- end\
- end\
- \
- \
- --External\
- function mount(source,destination)\
- tab = makeTable(filesystem,destination)\
- explore(source,tab)\
- end\
- \
- function unmount()\
- \
- end\
- \
- function exists(path)\
- return localExists(filesystem,path)\
- end\
- \
- function isDir(path)\
- if localExists(filesystem,path) then\
- return localIsDir(filesystem,path)\
- end\
- end\
- \
- function list(path)\
- if isDir(path) then\
- local buffer = localList(filesystem,path)\
- local toReturn = {}\
- for i,v in pairs(buffer) do\
- toReturn[#toReturn+1] = i\
- end\
- table.sort(toReturn)\
- return toReturn\
- else\
- return false\
- end\
- end\
- \
- function isReadOnly(path)\
- if localExists(filesystem,path) then\
- return localIsReadOnly(filesystem,path)\
- else \
- return \"wow\"\
- end\
- end\
- \
- --mount(\"rom\",\"/rom/\")\
- --print(isReadOnly(\"/rom/autorun\"))\
- --print(fs.isReadOnly(\"rom\"))",
- [ "bios.lua" ] = "\
- --[[\
- -- Install safe versions of various library functions\
- -- These will not put cfunctions on the stack, so don't break serialisation\
- xpcall = function( _fn, _fnErrorHandler )\
- local typeT = type( _fn )\
- assert( typeT == \"function\", \"bad argument #1 to xpcall (function expected, got \"..typeT..\")\" )\
- local co = coroutine.create( _fn )\
- local tResults = { coroutine.resume( co ) }\
- while coroutine.status( co ) ~= \"dead\" do\
- tResults = { coroutine.resume( co, coroutine.yield() ) }\
- end\
- if tResults[1] == true then\
- return true, unpack( tResults, 2 )\
- else\
- return false, _fnErrorHandler( tResults[2] )\
- end\
- end\
- \
- pcall = function( _fn, ... )\
- local typeT = type( _fn )\
- assert( typeT == \"function\", \"bad argument #1 to pcall (function expected, got \"..typeT..\")\" )\
- local tArgs = { ... }\
- return xpcall( \
- function()\
- return _fn( unpack( tArgs ) )\
- end,\
- function( _error )\
- return _error\
- end\
- )\
- end\
- \
- function pairs( _t )\
- local typeT = type( _t )\
- if typeT ~= \"table\" then\
- error( \"bad argument #1 to pairs (table expected, got \"..typeT..\")\", 2 )\
- end\
- return next, _t, nil\
- end\
- \
- function ipairs( _t )\
- local typeT = type( _t )\
- if typeT ~= \"table\" then\
- error( \"bad argument #1 to ipairs (table expected, got \"..typeT..\")\", 2 )\
- end\
- return function( t, var )\
- var = var + 1\
- local value = t[var] \
- if value == nil then\
- return\
- end\
- return var, value\
- end, _t, 0\
- end\
- \
- function coroutine.wrap( _fn )\
- local typeT = type( _fn )\
- if typeT ~= \"function\" then\
- error( \"bad argument #1 to coroutine.wrap (function expected, got \"..typeT..\")\", 2 )\
- end\
- local co = coroutine.create( _fn )\
- return function( ... )\
- local tResults = { coroutine.resume( co, ... ) }\
- if tResults[1] then\
- return unpack( tResults, 2 )\
- else\
- error( tResults[2], 2 )\
- end\
- end\
- end\
- \
- function string.gmatch( _s, _pattern )\
- local type1 = type( _s )\
- if type1 ~= \"string\" then\
- error( \"bad argument #1 to string.gmatch (string expected, got \"..type1..\")\", 2 )\
- end\
- local type2 = type( _pattern )\
- if type2 ~= \"string\" then\
- error( \"bad argument #2 to string.gmatch (string expected, got \"..type2..\")\", 2 )\
- end\
- \
- local nPos = 1\
- return function()\
- local nFirst, nLast = string.find( _s, _pattern, nPos )\
- if nFirst == nil then\
- return\
- end \
- nPos = nLast + 1\
- return string.match( _s, _pattern, nFirst )\
- end\
- end\
- \
- local nativesetmetatable = setmetatable\
- function setmetatable( _o, _t )\
- if _t and type(_t) == \"table\" then\
- local idx = rawget( _t, \"__index\" )\
- if idx and type( idx ) == \"table\" then\
- rawset( _t, \"__index\", function( t, k ) return idx[k] end )\
- end\
- local newidx = rawget( _t, \"__newindex\" )\
- if newidx and type( newidx ) == \"table\" then\
- rawset( _t, \"__newindex\", function( t, k, v ) newidx[k] = v end )\
- end\
- end\
- return nativesetmetatable( _o, _t )\
- end\
- ]]\
- \
- -- Install fix for luaj's broken string.sub/string.find\
- local nativestringfind = string.find\
- local nativestringsub = string.sub\
- function string.sub( ... )\
- local r = nativestringsub( ... )\
- if r then\
- return r .. \"\"\
- end\
- return nil\
- end\
- function string.find( s, ... )\
- return nativestringfind( s .. \"\", ... );\
- end\
- \
- -- Install lua parts of the os api\
- function os.version()\
- return \"CraftOS 1.7\"\
- end\
- \
- function os.pullEventRaw( sFilter )\
- return coroutine.yield( sFilter )\
- end\
- \
- function os.pullEvent( sFilter )\
- local eventData = { os.pullEventRaw( sFilter ) }\
- if eventData[1] == \"terminate\" then\
- error( \"Terminated\", 0 )\
- end\
- return unpack( eventData )\
- end\
- \
- -- Install globals\
- function sleep( nTime )\
- local timer = os.startTimer( nTime or 0 )\
- repeat\
- local sEvent, param = os.pullEvent( \"timer\" )\
- until param == timer\
- end\
- \
- function write( sText )\
- local w,h = term.getSize() \
- local x,y = term.getCursorPos()\
- \
- local nLinesPrinted = 0\
- local function newLine()\
- if y + 1 <= h then\
- term.setCursorPos(1, y + 1)\
- else\
- term.setCursorPos(1, h)\
- term.scroll(1)\
- end\
- x, y = term.getCursorPos()\
- nLinesPrinted = nLinesPrinted + 1\
- end\
- \
- -- Print the line with proper word wrapping\
- while string.len(sText) > 0 do\
- local whitespace = string.match( sText, \"^[ \\t]+\" )\
- if whitespace then\
- -- Print whitespace\
- term.write( whitespace )\
- x,y = term.getCursorPos()\
- sText = string.sub( sText, string.len(whitespace) + 1 )\
- end\
- \
- local newline = string.match( sText, \"^\\n\" )\
- if newline then\
- -- Print newlines\
- newLine()\
- sText = string.sub( sText, 2 )\
- end\
- \
- local text = string.match( sText, \"^[^ \\t\\n]+\" )\
- if text then\
- sText = string.sub( sText, string.len(text) + 1 )\
- if string.len(text) > w then\
- -- Print a multiline word \
- while string.len( text ) > 0 do\
- if x > w then\
- newLine()\
- end\
- term.write( text )\
- text = string.sub( text, (w-x) + 2 )\
- x,y = term.getCursorPos()\
- end\
- else\
- -- Print a word normally\
- if x + string.len(text) - 1 > w then\
- newLine()\
- end\
- term.write( text )\
- x,y = term.getCursorPos()\
- end\
- end\
- end\
- \
- return nLinesPrinted\
- end\
- \
- function print( ... )\
- local nLinesPrinted = 0\
- for n,v in ipairs( { ... } ) do\
- nLinesPrinted = nLinesPrinted + write( tostring( v ) )\
- end\
- nLinesPrinted = nLinesPrinted + write( \"\\n\" )\
- return nLinesPrinted\
- end\
- \
- function printError( ... )\
- if term.isColour() then\
- term.setTextColour( colours.red )\
- end\
- local x,y = term.getCursorPos()\
- print( ... )\
- term.setTextColour( colours.white )\
- end\
- \
- function read( _sReplaceChar, _tHistory )\
- term.setCursorBlink( true )\
- \
- local sLine = \"\"\
- local nHistoryPos\
- local nPos = 0\
- if _sReplaceChar then\
- _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )\
- end\
- \
- local w = term.getSize()\
- local sx = term.getCursorPos()\
- \
- local function redraw( _sCustomReplaceChar )\
- local nScroll = 0\
- if sx + nPos >= w then\
- nScroll = (sx + nPos) - w\
- end\
- \
- local cx,cy = term.getCursorPos()\
- term.setCursorPos( sx, cy )\
- local sReplace = _sCustomReplaceChar or _sReplaceChar\
- if sReplace then\
- term.write( string.rep( sReplace, math.max( string.len(sLine) - nScroll, 0 ) ) )\
- else\
- term.write( string.sub( sLine, nScroll + 1 ) )\
- end\
- term.setCursorPos( sx + nPos - nScroll, cy )\
- end\
- \
- while true do\
- local sEvent, param = os.pullEvent()\
- if sEvent == \"char\" then\
- -- Typed key\
- sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )\
- nPos = nPos + 1\
- redraw()\
- \
- elseif sEvent == \"paste\" then\
- -- Pasted text\
- sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )\
- nPos = nPos + string.len( param )\
- redraw()\
- \
- elseif sEvent == \"key\" then\
- if param == keys.enter then\
- -- Enter\
- break\
- \
- elseif param == keys.left then\
- -- Left\
- if nPos > 0 then\
- nPos = nPos - 1\
- redraw()\
- end\
- \
- elseif param == keys.right then\
- -- Right \
- if nPos < string.len(sLine) then\
- redraw(\" \")\
- nPos = nPos + 1\
- redraw()\
- end\
- \
- elseif param == keys.up or param == keys.down then\
- -- Up or down\
- if _tHistory then\
- redraw(\" \")\
- if param == keys.up then\
- -- Up\
- if nHistoryPos == nil then\
- if #_tHistory > 0 then\
- nHistoryPos = #_tHistory\
- end\
- elseif nHistoryPos > 1 then\
- nHistoryPos = nHistoryPos - 1\
- end\
- else\
- -- Down\
- if nHistoryPos == #_tHistory then\
- nHistoryPos = nil\
- elseif nHistoryPos ~= nil then\
- nHistoryPos = nHistoryPos + 1\
- end \
- end\
- if nHistoryPos then\
- sLine = _tHistory[nHistoryPos]\
- nPos = string.len( sLine ) \
- else\
- sLine = \"\"\
- nPos = 0\
- end\
- redraw()\
- end\
- elseif param == keys.backspace then\
- -- Backspace\
- if nPos > 0 then\
- redraw(\" \")\
- sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )\
- nPos = nPos - 1 \
- redraw()\
- end\
- elseif param == keys.home then\
- -- Home\
- redraw(\" \")\
- nPos = 0\
- redraw() \
- elseif param == keys.delete then\
- -- Delete\
- if nPos < string.len(sLine) then\
- redraw(\" \")\
- sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 ) \
- redraw()\
- end\
- elseif param == keys[\"end\"] then\
- -- End\
- redraw(\" \")\
- nPos = string.len(sLine)\
- redraw()\
- end\
- \
- elseif sEvent == \"term_resize\" then\
- -- Terminal resized\
- w = term.getSize()\
- redraw()\
- \
- end\
- end\
- \
- local cx, cy = term.getCursorPos()\
- term.setCursorBlink( false )\
- term.setCursorPos( w + 1, cy )\
- print()\
- \
- return sLine\
- end\
- \
- loadfile = function( _sFile )\
- local file = fs.open( _sFile, \"r\" )\
- if file then\
- local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )\
- file.close()\
- return func, err\
- end\
- return nil, \"File not found\"\
- end\
- \
- dofile = function( _sFile )\
- local fnFile, e = loadfile( _sFile )\
- if fnFile then\
- setfenv( fnFile, getfenv(2) )\
- return fnFile()\
- else\
- error( e, 2 )\
- end\
- end\
- \
- -- Install the rest of the OS api\
- function os.run( _tEnv, _sPath, ... )\
- local tArgs = { ... }\
- local fnFile, err = loadfile( _sPath )\
- if fnFile then\
- local tEnv = _tEnv\
- --setmetatable( tEnv, { __index = function(t,k) return _G[k] end } )\
- setmetatable( tEnv, { __index = _G } )\
- setfenv( fnFile, tEnv )\
- local ok, err = pcall( function()\
- fnFile( unpack( tArgs ) )\
- end )\
- if not ok then\
- if err and err ~= \"\" then\
- printError( err )\
- end\
- return false\
- end\
- return true\
- end\
- if err and err ~= \"\" then\
- printError( err )\
- end\
- return false\
- end\
- \
- -- Prevent access to metatables or environments of strings, as these are global between all computers\
- do\
- local nativegetfenv = getfenv\
- local nativegetmetatable = getmetatable\
- local nativeerror = error\
- local nativetype = type\
- local string_metatable = nativegetmetatable(\"\")\
- local string_env = nativegetfenv((\"\").gsub)\
- function getmetatable( t )\
- local mt = nativegetmetatable( t )\
- if mt == string_metatable or mt == string_env then\
- nativeerror( \"Attempt to access string metatable\", 2 )\
- else\
- return mt\
- end\
- end\
- function getfenv( env )\
- if env == nil then\
- env = 2\
- elseif nativetype( env ) == \"number\" and env > 0 then\
- env = env + 1\
- end\
- local fenv = nativegetfenv(env)\
- if fenv == string_metatable or fenv == string_env then\
- --nativeerror( \"Attempt to access string metatable\", 2 )\
- return nativegetfenv( 0 )\
- else\
- return fenv\
- end\
- end\
- end\
- \
- local tAPIsLoading = {}\
- function os.loadAPI( _sPath )\
- local sName = fs.getName( _sPath )\
- if tAPIsLoading[sName] == true then\
- printError( \"API \"..sName..\" is already being loaded\" )\
- return false\
- end\
- tAPIsLoading[sName] = true\
- \
- 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 )\
- tAPIsLoading[sName] = nil\
- return false\
- end\
- else\
- printError( err )\
- tAPIsLoading[sName] = nil\
- return false\
- end\
- \
- local tAPI = {}\
- for k,v in pairs( tEnv ) do\
- tAPI[k] = v\
- end\
- \
- _G[sName] = tAPI \
- tAPIsLoading[sName] = nil\
- return true\
- end\
- \
- function os.unloadAPI( _sName )\
- if _sName ~= \"_G\" and type(_G[_sName]) == \"table\" then\
- _G[_sName] = nil\
- end\
- end\
- \
- function os.sleep( nTime )\
- sleep( nTime )\
- end\
- \
- local nativeShutdown = os.shutdown\
- function os.shutdown()\
- nativeShutdown()\
- while true do\
- coroutine.yield()\
- end\
- end\
- \
- local nativeReboot = os.reboot\
- function os.reboot()\
- nativeReboot()\
- while true do\
- coroutine.yield()\
- end\
- end\
- \
- -- Install the lua part of the HTTP api (if enabled)\
- if http then\
- local nativeHTTPRequest = http.request\
- \
- local function wrapRequest( _url, _post, _headers )\
- local ok, err = nativeHTTPRequest( _url, _post, _headers )\
- if ok then\
- while true do\
- local event, param1, param2 = os.pullEvent()\
- if event == \"http_success\" and param1 == _url then\
- return param2\
- elseif event == \"http_failure\" and param1 == _url then\
- return nil, param2\
- end\
- end\
- end\
- return nil, err\
- end\
- \
- http.get = function( _url, _headers )\
- return wrapRequest( _url, nil, _headers )\
- end\
- \
- http.post = function( _url, _post, _headers )\
- return wrapRequest( _url, _post or \"\", _headers )\
- end\
- \
- http.request = function( _url, _post, _headers )\
- local ok, err = nativeHTTPRequest( _url, _post, _headers )\
- if not ok then\
- os.queueEvent( \"http_failure\", _url, err )\
- end\
- return ok, err\
- end\
- end\
- \
- -- Load APIs\
- local bAPIError = false\
- local tApis = fs.list( \"rom/apis\" )\
- for n,sFile in ipairs( tApis ) do\
- if string.sub( sFile, 1, 1 ) ~= \".\" then\
- local sPath = fs.combine( \"rom/apis\", sFile )\
- if not fs.isDir( sPath ) then\
- if not os.loadAPI( sPath ) then\
- bAPIError = true\
- end\
- end\
- end\
- end\
- \
- if turtle then\
- -- Load turtle APIs\
- local tApis = fs.list( \"rom/apis/turtle\" )\
- for n,sFile in ipairs( tApis ) do\
- if string.sub( sFile, 1, 1 ) ~= \".\" then\
- local sPath = fs.combine( \"rom/apis/turtle\", sFile )\
- if not fs.isDir( sPath ) then\
- if not os.loadAPI( sPath ) then\
- bAPIError = true\
- end\
- end\
- end\
- end\
- end\
- \
- if pocket and fs.isDir( \"rom/apis/pocket\" ) then\
- -- Load pocket APIs\
- local tApis = fs.list( \"rom/apis/pocket\" )\
- for n,sFile in ipairs( tApis ) do\
- if string.sub( sFile, 1, 1 ) ~= \".\" then\
- local sPath = fs.combine( \"rom/apis/pocket\", sFile )\
- if not fs.isDir( sPath ) then\
- if not os.loadAPI( sPath ) then\
- bAPIError = true\
- end\
- end\
- end\
- end\
- end\
- \
- if commands and fs.isDir( \"rom/apis/command\" ) then\
- -- Load command APIs\
- if os.loadAPI( \"rom/apis/command/commands\" ) then\
- -- Add a special case-insensitive metatable to the commands api\
- local tCaseInsensitiveMetatable = {\
- __index = function( table, key )\
- local value = rawget( table, key )\
- if value ~= nil then\
- return value\
- end\
- if type(key) == \"string\" then\
- local value = rawget( table, string.lower(key) )\
- if value ~= nil then\
- return value\
- end\
- end\
- return nil\
- end\
- }\
- setmetatable( commands, tCaseInsensitiveMetatable )\
- setmetatable( commands.async, tCaseInsensitiveMetatable )\
- \
- -- Add global \"exec\" function\
- exec = commands.exec\
- else\
- bAPIError = true\
- end\
- end\
- \
- if bAPIError then\
- print( \"Press any key to continue\" )\
- os.pullEvent( \"key\" )\
- term.clear()\
- term.setCursorPos( 1,1 )\
- end\
- \
- -- Run the shell\
- local ok, err = pcall( function()\
- parallel.waitForAny( \
- function()\
- if term.isColour() then\
- os.run( {}, \"rom/programs/advanced/multishell\" )\
- else\
- os.run( {}, \"rom/programs/shell\" )\
- end\
- os.run( {}, \"rom/programs/shutdown\" )\
- end,\
- function()\
- rednet.run()\
- end )\
- end )\
- \
- -- If the shell errored, let the user read it.\
- term.redirect( term.native() )\
- if not ok then\
- printError( err )\
- pcall( function()\
- term.setCursorBlink( false )\
- print( \"Press any key to continue\" )\
- os.pullEvent( \"key\" )\
- end )\
- end\
- \
- -- End\
- os.shutdown()",
- [ "fsh.lua" ] = "--[[\
- VFS helper and moumting manager\
- Author: Wassil Janssen a.k.a. Creator\
- ]]--\
- \
- --Variables\
- local mounts = {}\
- local Internal = {}\
- local filesystems = {}\
- \
- --Functions\
- function Internal.getFirstElement(path)\
- return path:sub(1,path:find(\"/\") and path:find(\"/\")-1 or -1)\
- end\
- \
- function Internal.makeTable(path,tabl)\
- if type(path) ~= \"string\" then error(\"Expected string, got \"..type(path)..\"!\",2) end\
- if type(tabl) ~= \"table\" then error(\"Expected table, got \"..type(path)..\"!\",2) end\
- path = fs.combine(\"\",path)\
- local first = Internal.getFirstElement(path)\
- if first == path then\
- return tabl, first\
- else\
- if not tabl[first] then tabl[first] = {} end\
- return Internal.makeTable(path:sub(path:find(\"/\")+1,-1),tabl[first])\
- end\
- end\
- \
- function mount(destination,source,fss)\
- fss = fss or \"ccfs\"\
- if not fs.exists(destination) then fs.makeDir(destination) end\
- if not fs.exists(source) then fs.makeDir(source) end\
- local tabl, dir = Internal.makeTable(destination,mounts)\
- tabl[dir] = source\
- if fss ~= \"ccfs\" then\
- local tabl, dir = Internal.makeTable(destination,filesystems)\
- tabl[dir] = fss\
- end\
- end\
- \
- function setFS(path,fss)\
- if fss ~= \"ccfs\" then\
- local tabl, dir = Internal.makeTable(destination,filesystems)\
- tabl[dir] = fss\
- end\
- end\
- \
- function Internal.resolveLinks(path,tabl)\
- local first = Internal.getFirstElement(path)\
- if first == path then return false end\
- if tabl[first] then\
- if type(tabl[first]) == \"table\" then\
- return Internal.resolveLinks(path:sub(path:find(\"/\")+1,-1),tabl[first])\
- elseif type(tabl[first]) == \"string\" then\
- return tabl[first]..\"/\"..path:sub(#Internal.getFirstElement(path)+2,-1)\
- end\
- end\
- return false\
- end\
- \
- function resolveLinks(path)\
- resolved = Internal.resolveLinks(path,mounts)\
- if resolved == false then\
- log.log(\"Symlinks\",path..\" \"..path)\
- return path\
- else\
- local lol = resolveLinks(resolved)\
- log.log(\"Symlinks\",path..\" \"..lol)\
- return lol\
- end\
- end\
- \
- function Internal.getFS(path,tabl)\
- local first = Internal.getFirstElement(path)\
- if first == path then return false end\
- if tabl[first] then\
- if type(tabl[first]) == \"table\" then\
- return Internal.getFS(path:sub(path:find(\"/\")+1,-1),tabl[first])\
- elseif type(tabl[first]) == \"string\" then\
- return tabl[first]\
- end\
- end\
- return false\
- end\
- \
- function getFS(path)\
- resolved = Internal.getFS(path,filesystems)\
- if not resolved then\
- return \"ccfs\"\
- else\
- return resolved\
- end\
- end\
- \
- --mount(\"OmniOS/Programs/FileX.app\",\"disk1\",\"mls\")\
- --mount(\"disk1\",\"OmniOS/API\",\"lol\")\
- --print(\"lol\")\
- --print(resolveLinks(\"OmniOS/Programs/FileX.app/Data/coo\"))\
- --print(\"lol\")\
- --print(getFS(\"OmniOS/Programs\"))\
- --print(textutils.serialize(filesystems))",
- },
- Screen = {
- [ "571.13.878" ] = "",
- },
- [ ".gitmodules" ] = "[submodule \"API/Interact\"]\
- path = API/Interact\
- url = ../Interact",
- Core = {
- [ "LoadAPIs.lua" ] = "--Code--\
- local 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\
- log.log(\"API\",err,sName)\
- return false\
- end\
- else\
- --log.log(\"API\",err,sName)\
- return false\
- end\
- \
- local tAPI = {}\
- for k,v in pairs( tEnv ) do\
- tAPI[k] = v\
- end\
- \
- _G[sName:match(\"[^%.]+\")] = tAPI\
- return true\
- end\
- loadAPI(\"OmniOS/API/Utils.lua\")\
- loadAPI(\"OmniOS/API/log.lua\")\
- local function explore(dir)\
- --log.log(\"SpecialStuff\",dir)\
- local ignore = {}\
- if fs.exists(dir..\"/.ignoreme\") and not fs.isDir(dir..\"/.ignoreme\") then\
- local file = fs.open(dir..\"/.ignoreme\",\"r\")\
- ignore = textutils.unserialize(file.readAll())\
- file.close()\
- end\
- for i,v in pairs(fs.list(dir)) do\
- if fs.isDir(dir..\"/\"..v) then\
- if ignore[v] == nil then\
- explore(dir..\"/\"..v)\
- end\
- else\
- if ignore[v] == nil then\
- loadAPI(dir..\"/\"..v)\
- term.setTextColor(colors.black)\
- nPrint(v:match(\"[^%.]+\"))\
- end\
- end\
- end\
- ignore = nil\
- end\
- explore(\"OmniOS/API\")",
- [ "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--\
- \
- 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/NewKernel.lua\")\
- if err then print(err) os.pullEvent() log.log(\"Error\",err) end\
- local startup, err = loadfile(\"OmniOS/Programs/Debug/Main.lua\")\
- if err then print(err) os.pullEvent() Utils.debug(\"Error\",err) end\
- kernel(startup,\"term\",\"admin\",\"Debug\")\
- end\
- \
- ok, err = pcall(goOn)\
- \
- if not ok then\
- Utils.debug(\"Crash\",err)\
- pcall(shell.run(\"OmniOS/Core/Crash.lua \",err))\
- end",
- [ "NewKernel.lua" ] = "--[[\
- Kernel\
- By: Creator a.k.a. Wassil Janssen\
- For OmniOS\
- ]]--\
- --[[\
- Specifications:\
- newProcess:\
- @parent: the object on which the process will be drawn\
- @func: the function, usually from a file\
- ]]--\
- \
- --Variables\
- local ids = {}\
- local process = {}\
- local tasks = {}\
- local active = 1\
- local bindings = {}\
- local eventFilter = {[\"key\"] = true, [\"mouse_click\"] = true, [\"paste\"] = true,[\"char\"] = true, [\"terminate\"] = true, [\"mouse_scroll\"] = true, [\"mouse_drag\"] = true}\
- local Internal = {}\
- local eventBuffer = {}\
- local nameIDLink = {}\
- local currTerm = term.current()\
- local w,h = term.getSize()\
- Kernel = {}\
- \
- --Functions\
- --Local\
- function Internal.finalKill(id)\
- process[id] = nil\
- end\
- \
- function Internal.kill(id)\
- if id == 1 then\
- return\
- elseif id == active then\
- Kernel.switch(1)\
- end\
- Internal.queueTask(\"finalKill\",id)\
- end\
- \
- function Internal.drawClosed()\
- local col = process[active].preferences.sideBarColor or colors.black\
- paintutils.drawLine(w,1,w,h,col)\
- term.setBackgroundColor(col)\
- term.setCursorPos(w,math.floor(h/2)+1)\
- term.setTextColor(col == colors.black and colors.white or colors.white)\
- term.write(\"<\")\
- end\
- \
- function Internal.drawOpen()\
- process[active].window.setVisible(false)\
- term.setCursorBlink(false)\
- paintutils.drawFilledBox(w-15,1,w,h,colors.black)\
- term.setTextColor(colors.white)\
- local amount = 0\
- local links = {}\
- for i,v in pairs(process) do\
- if active == i then paintutils.drawLine(w-15,i,w,i,colors.blue) end\
- term.setCursorPos(w-14,i)\
- term.setBackgroundColor(active == i and colors.blue or colors.black)\
- --term.setTextColor(colors.white)\
- term.write(\"x \"..i..\" \"..v.name)\
- amount = amount + 1\
- links[amount] = i\
- end\
- \
- while true do\
- local evnt = {os.pullEventRaw()}\
- if evnt[1] == \"mouse_click\" then\
- if evnt[3] < w-15 then break\
- elseif evnt[3] == w-14 and evnt[4] <= amount then\
- Kernel.kill(links[evnt[4]])\
- if links[evnt[4]] == active then break end\
- elseif evnt[3] >= w-12 and evnt[4] <= amount then\
- Kernel.switch(links[evnt[4]])\
- break\
- end\
- else eventBuffer[#eventBuffer+1] = evnt end\
- end\
- process[active].window.setVisible(true)\
- process[active].window.redraw()\
- Internal.drawClosed()\
- end\
- \
- \
- function Internal.newProcess(func,parent,permission,name,...)\
- local id = 1\
- while true do\
- if not process[id] then break end\
- id = id + 1\
- end\
- Utils.debug(\"Found ID\")\
- if permission == \"user\" then\
- local env = Sandbox.newEnv(name)\
- setfenv(func,env)\
- Utils.debug(\"User permission.\")\
- end\
- process[id] = {\
- [\"environement\"] = env,\
- [\"routine\"] = coroutine.create(func),\
- [\"name\"] = name,\
- [\"filter\"] = \"\",\
- [\"parent\"] = parent,\
- [\"window\"] = window.create(parent == \"term\" and term.current() or peripheral.wrap(parent),1,1,w-1,h,false),\
- [\"preferences\"] = {}\
- }\
- Utils.debug(\"Added process table.\")\
- \
- if not nameIDLink[name] then nameIDLink[name] = {id} else nameIDLink[name][#nameIDLink[name]+1] = id end\
- Utils.debug(\"Added links.\")\
- if id == active then\
- process[id].window.setVisible(true)\
- end\
- term.redirect(process[id].window)\
- ok, process[id].filter = coroutine.resume(process[id].routine,...)\
- if not ok then Utils.debug(\"routines/\"..name,process[id].filter) end\
- term.redirect(currTerm)\
- end\
- \
- function Internal.runBinds(event)\
- if bindings[event[1]] then\
- for i,v in pairs(bindings[event[1]]) do\
- v(event)\
- end\
- end\
- end\
- \
- function Internal.queueTask(...)\
- tasks[#tasks+1] = {...}\
- end\
- \
- function Internal.switch(...)\
- local args={...}\
- Utils.debug(\"Switch in kernel \"..(function(tabl) local x = \"\" for i,v in pairs(tabl) do x = x..\" \"..tostring(i)..\": \"..tostring(v) end return x end)(args))\
- if not type(args[1]) == \"number\" then Utils.debug(\"Expected number, got \"..type(args[1])) return end\
- Utils.debug(\"Args \"..tostring(args[1])..type(args[1]))\
- if process[args[1]] then\
- process[active].window.setVisible(false)\
- process[args[1]].window.setVisible(true)\
- process[args[1]].window.redraw()\
- active = args[1]\
- end\
- end\
- \
- --API\
- function Kernel.newProcess(func,parent,permission,name,...)\
- Internal.queueTask(\"newProcess\",func,parent,permission,name,...)\
- end\
- \
- function Kernel.list()\
- local ret = {}\
- for i,v in pairs(process) do\
- ret[#ret+1] = {i,v.name,coroutine.status(v.routine)}\
- end\
- return ret\
- end\
- \
- function Kernel.switch(newTaskID)\
- Utils.debug(\"Queueing switch event: \"..tostring(newTaskID))\
- Internal.queueTask(\"switch\",newTaskID)\
- end\
- \
- function Kernel.bindEvent(event,func)\
- if type(func) ~= \"function\" then error(\"Ecxpected function, got \"..type(func)..\"!\",2) end\
- if bindings[event] then\
- bindings[event][#bindings[event]+1] = func\
- else\
- bindings[event] = {[1] = func}\
- end\
- end\
- \
- function Kernel.kill(id)\
- Utils.debug(\"Killing \"..tostring(id))\
- Internal.queueTask(\"kill\",id)\
- end\
- \
- --Code\
- local function loadDrivers(path)\
- for k, v in pairs(fs.list(path)) do\
- if not fs.isDir(fs.combine(path,v)) then\
- dofile(fs.combine(path,v))\
- end\
- end\
- end\
- \
- loadDrivers('OmniOS/Drivers')\
- \
- Internal.newProcess(...)\
- \
- fs.mount(\"OmniOS/Programs/FileX/disk1\",\"rom\",\"ccfs\")\
- fs.link(\"a\",\"/\")\
- Internal.drawClosed()\
- \
- while true do\
- if tasks[1] then\
- if Internal[tasks[1][1]] then\
- Internal[tasks[1][1]](unpack(tasks[1],2))\
- Utils.debug(\"Completed task \"..tasks[1][1])\
- table.remove(tasks,1)\
- end\
- else\
- local event = #eventBuffer == 0 and {os.pullEvent()} or table.remove(eventBuffer,1)\
- Internal.runBinds(event)\
- if event[1] == \"mouse_click\" and event[3] == w then Internal.drawOpen() end\
- if eventFilter[event[1]] then\
- if process[active].filter == nil or process[active].filter == \"\" or process[active].filter == event[1] then\
- Utils.debug(\"Running main routine with event \"..tostring(event[1]))\
- term.redirect(process[active].window)\
- ok, process[active].filter = coroutine.resume(process[active].routine,unpack(event))\
- if not ok then Utils.debug(process[active].filter) end\
- term.redirect(currTerm)\
- Internal.drawClosed()\
- if coroutine.status(process[active].routine) == \"dead\" then Kernel.kill(active) end\
- end\
- else\
- for i,v in pairs(process) do\
- if process[i].filter == nil or process[i].filter == \"\" or process[i].filter == event[1] then\
- Utils.debug(\"Running secindary routine with event \"..tostring(event[1]))\
- term.redirect(v.window)\
- ok, process[i].filter = coroutine.resume(v.routine,unpack(event))\
- if not ok then Utils.debug(process[i].filter) end\
- term.redirect(currTerm)\
- if coroutine.status(process[i].routine) == \"dead\" then Kernel.kill(i) end\
- end\
- 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(\"OmniOS 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()",
- [ "OldKernel.lua" ] = "--[[\
- TheOS Kernel\
- by Creator\
- for OmniOS &\
- 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.\
- ]]--\
- --[[::VARIABLES::]]--\
- local logMessage = \"\"\
- local newRoutine = \"\"\
- local history = {}\
- local w,h = term.getSize()\
- local monitors = {}\
- local currTerm, routines, activeRoutine, eventBuffer = term.current(), {}, \"\", {}\
- local eventFilter = {[\"key\"] = true, [\"mouse_click\"] = true, [\"paste\"] = true,[\"char\"] = true, [\"terminate\"] = true, [\"mouse_scroll\"] = true, [\"mouse_drag\"] = true}\
- \
- \
- --[[::FUNCTIONS::]]--\
- 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 switch()\
- if routines[newRoutine] and not newRoutine == \"\" then\
- routines[activeRoutine].window.setVisible( false )\
- activeRoutine = newRoutine\
- routines[activeRoutine].window.setVisible(true)\
- newRoutine = \"\"\
- end\
- 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\
- \
- while true do\
- local evnt = {os.pullEventRaw()}\
- log.log(\"Close\",xVsProcess[evnt[4]])\
- 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)\
- log.log(\"Multitask\",\"Current: \"..activeRoutine..\" New: \"..xVsProcess[evnt[4]])\
- activeRoutine = xVsProcess[evnt[4]]\
- --routines[activeRoutine].window.setVisible(true)\
- routines[activeRoutine].window.redraw()\
- return\
- end\
- elseif w-14 == evnt[3] then\
- if xVsProcess[evnt[4]] and xVsProcess[evnt[4]] ~= \"Debug1\" then\
- if activeRoutine == xVsProcess[evnt[4]] then\
- routines[xVsProcess[evnt[4]]].window.setVisible(false)\
- activeRoutine = \"Debug1\"\
- routines[activeRoutine].window.setVisible(true)\
- else\
- routines[activeRoutine].window.redraw()\
- 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\
- activeRoutine = \"Debug1\"\
- routines[activeRoutine].window.redraw()\
- end\
- return true\
- else return false end\
- end\
- \
- Kernel = {}\
- \
- function Kernel.newRoutine(name,title,func,permission,tParent,...)\
- if tParent == term or tParent == term.current() or tParent == \"term\" then\
- tParent = term.current()\
- else\
- if monitors[tParent] then\
- log.log(\"Processes/Mon\",\"A program is using the monitor!\")\
- return \"A program is using the monitor!\"\
- end\
- if not peripheral.isPresent(tParent) then\
- log.log(\"Processes/Mon\",\"The monitor does not exist!\")\
- return \"The monitor does not exist!\"\
- end\
- if not peripheral.getType(tParent) == \"monitor\" then\
- log.log(\"Processes/Mon\",\"The peripheral is not a monitor!\")\
- return \"The peripheral is not a monitor!\"\
- end\
- monitors[tParent] = true\
- end\
- log.log(\"System\",\"Launching task \"..name..\". By kernel\")\
- local oldName = name\
- do\
- local tries = 1\
- while routines[name .. tries] do tries = tries + 1 end\
- name = name .. tries\
- end\
- if permission == \"userTest\" then\
- log.log(\"Env\",\"Launching task \"..name..\": adding environment. By kernel\")\
- local env = Sandbox.newEnv(oldName)\
- log.log(\"Env\",\"Environment was successful\")\
- setfenv(func,env)\
- end\
- \
- routines[name] = {\
- [\"title\"] = title,\
- [\"permission\"] = permission,\
- [\"path\"] = path,\
- [\"routine\"] = coroutine.create(func),\
- [\"window\"] = (tParent == term or tParent == term.current()) and OmniWindow.create(tParent,1,1,w-1,h,false) or OmniWindow.create(peripheral.wrap(tParent),1,1,w-1,h,true),\
- [\"filter\"] = \"\",\
- [\"parent\"] = (tParent == term or tParent == term.current()) and \"term\" or \"mon\",\
- }\
- \
- --Run it!\
- if routines[activeRoutine] then\
- term.redirect(routines[name].window)\
- --routines[name].window.setVisible(false)\
- logMessage, routines[name].filter = coroutine.resume(routines[name].routine,...)\
- if not logMessage then\
- log.log(name,\"Error: \"..tostring(routines[name].filter),name)\
- end\
- term.redirect(currTerm)\
- checkIfDead(name)\
- --routines[activeRoutine].window.redraw()\
- else\
- 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\
- --routines[activeRoutine].window.setVisible(false)\
- term.redirect(currTerm)\
- checkIfDead(activeRoutine)\
- end\
- end\
- \
- function Kernel.getPermission(program)\
- return routines[program].permission or \"Not a valid program\"\
- end\
- \
- function Kernel.kill(thread)\
- if thread == \"Debug1\" then\
- return \"Cannot kill debug, instead use kill !zygote\"\
- else\
- if thread == activeRoutine then\
- activeRoutine = \"Debug1\"\
- routines[activeRoutine].window.setVisible(true)\
- end\
- routines[thread] = nil\
- end\
- end\
- \
- function Kernel.getScreen(routine)\
- return routines[routine] and routines[routine].window.getBuffer() or false\
- end\
- \
- function Kernel.list()\
- local buffer = {}\
- for i,v in pairs(routines) do\
- buffer[#buffer+1] = i\
- end\
- return buffer\
- end\
- \
- function Kernel.switch(newTask)\
- newRoutine = newTask\
- end\
- \
- drawClosed()\
- \
- Kernel.newRoutine(...)\
- \
- while true do\
- drawClosed()\
- --switch()\
- local event = #eventBuffer == 0 and {os.pullEventRaw()} or table.remove(eventBuffer,1)\
- if fs.exists(\"OmniOS/Drivers/\"..event[1]..\".lua\") then\
- local func = loadfile(\"OmniOS/Drivers/\"..event[1]..\".lua\")\
- func(unpack(event))\
- routines[activeRoutine].window.redraw()\
- else\
- 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)\
- --routines[activeRoutine].window.setVisible(true)\
- 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\
- --routines[activeRoutine].window.setVisible(false)\
- term.redirect(currTerm)\
- checkIfDead(activeRoutine,\"term\")\
- end\
- else\
- for i,v in safePairs(routines) do\
- if routines[i] and routines[i].filter == event[1] or routines[i].filter == nil then\
- 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,\"term\")\
- end\
- end\
- end\
- end\
- 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",
- },
- [ ".gitignore" ] = "*.log",
- Programs = {
- Debug = {
- Commands = {
- [ "cmds.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- \
- print(\"The commands are:\")\
- for i,v in pairs(fs.list(\"OmniOS/Programs/Debug/Commands\")) do\
- print(\" \"..v:match(\"[^.]+\"))\
- end",
- [ "help.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- local tArgs = {...}\
- help = tArgs[1]\
- local p = print\
- if help == \"cmds\" then\
- p(\"Usage: cmds\")\
- p(\" Prints all the commands. \")\
- elseif help == \"kill\" then\
- p(\"Usage: kill <process>\")\
- p(\" Kils the specified process\")\
- p(\" !all will terminate every process except Debug1.\")\
- p(\" !zygote will terminate every process.\")\
- elseif help == \"launch\" then\
- p(\"Usage: launch <app>\")\
- p(\" Will launch an app on the terminal\")\
- elseif help == \"list\" then\
- p(\"Usage: list\")\
- p(\" Lists the processes.\")\
- elseif help == \"logs\" then\
- p(\"Usage: logs <log>\")\
- p(\" Deletes the specified log.\")\
- p(\" !all will delete all the logs.\")\
- elseif help == \"ls\" then\
- p(\"Type help list\")\
- elseif help == \"monitor\" then\
- p(\"Usage: monitor <action> <args>\")\
- p(\" What each action does:\")\
- p(\"Launch:\")\
- p(\" Usage: monitor launch <monitor> <app>\")\
- p(\" Is the same as launch, but uses a monitor instead.\")\
- p(\"List:\")\
- p(\" Lists the available monitors.\")\
- else\
- p(\"Usage: help <command>\")\
- end",
- [ "kill.lua" ] = "--[[\
- Author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- local tArgs = {...}\
- if tArgs[1] == \"!zygote\" then\
- error(\"Zygote killed!\")\
- elseif tArgs[1] == \"!all\" then\
- for i,v in pairs(Kernel.list()) do\
- Kernel.kill(v)\
- end\
- else\
- if tonumber(tArgs[1]:sub(-1,-1)) then\
- local resp = Kernel.kill(tArgs[1])\
- if resp then\
- print(resp)\
- end\
- else\
- print(\"The routines have a number at the end. Don't forget it!\")\
- end\
- end",
- [ "ls.lua" ] = "--[[\
- Author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- print(\"The threads are:\")\
- for i,v in pairs(Kernel.list()) do\
- print(v[1]..string.rep(\" \",5-#tostring(v[1]))..v[2]..\": \"..v[3])\
- end",
- [ "clear.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- promptColour = colours.yellow\
- textColour = colours.white\
- bgColour = colours.black\
- \
- \
- term.setBackgroundColor( bgColour )\
- term.setTextColour( promptColour )\
- term.clear()\
- term.setCursorPos(1,1)\
- print(\"OmniOS/Debug\")\
- term.setTextColour( textColour )",
- [ "logs.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- local tArgs = {...}\
- if tArgs[1] == \"clear\" then\
- if tArgs[2] == \"!all\" then\
- fs.delete(\"OmniOS/Logs\")\
- elseif fs.exists(\"OmniOS/Logs/\"..tArgs[2]) then\
- tArgs[2] = tArgs[2]:gsub(\"%.%.\",\"\")\
- fs.delete(\"OmniOS/Logs/\"..tArgs[2])\
- end\
- end",
- [ "shutdown.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- os.shutdown()",
- [ "switch.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- local tArgs = {...}\
- num = tonumber(tArgs[1])\
- if type(num) == \"number\" then\
- Kernel.switch(num)\
- end",
- [ "terminate.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- error(\"OmniOS is being terminated...\")",
- [ "panic.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- OmniOS.debug.run(\"kill !all\")\
- os.pullEvent = os.pullEventRaw\
- local countdown = 1000\
- while true do\
- print(\"We're under attack\")\
- print(\"System will self destroy in \"..tostring(countdown)..\" seconds\")\
- sleep(1)\
- countdown = countdown - 1\
- if countdown == 0 then error() end\
- end",
- [ "screen.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- local tArgs = {...}\
- local tArgs = {...}\
- if #tArgs == 0 then\
- print(\"Usage:\")\
- print(\"screen get <routine>\")\
- print(\"screen set <routine> <table>\")\
- error(\"wow\")\
- --return\
- end\
- \
- if tArgs[1] == \"get\" then\
- local file = fs.open(\"OmniOS/Screen/\"..tostring(os.day())..\".\"..tostring(os.time()),\"w\")\
- file.write(textutils.serialze(OmniOS.screen.getScreen(tArgs[2])))\
- file.close()\
- end",
- [ "launch.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- local links = {\
- [\"-p:\"] = \"permission\",\
- [\"-t:\"] = \"terminal\",\
- [\"-n:\"] = \"name\",\
- }\
- \
- local tArgs = {...}\
- if #tArgs == 0 then\
- print(\"Usage: Program, terminal object, permission, name\")\
- print(\"The flags are respectively: -t, -p, -n\")\
- print(\"The first does not have a flag!\")\
- end\
- local second = {unpack(tArgs,2)}\
- local final = {}\
- \
- if not fs.exists(\"OmniOS/Programs/\"..tArgs[1]..\"/Main.lua\") then error(tArgs[1]..\" is not a valid program!\") end\
- local func = loadfile(\"OmniOS/Programs/\"..tArgs[1]..\"/Main.lua\")\
- setfenv(func,_G)\
- \
- for i,v in pairs(second) do\
- if links[v:sub(1,3)] then\
- final[links[v:sub(1,3)]] = v:sub(4,-1)\
- end\
- end\
- \
- local parent = final.terminal and (final.terminal == \"term\" and \"term\" or peripheral.isPresent(final.terminal) and final.terminal or \"term\") or \"term\"\
- \
- local permission = final.permission or \"user\"\
- \
- local name = final.name or tArgs[1]\
- \
- Kernel.newProcess(func,parent,permission,name)",
- [ "shell.lua" ] = "--[[\
- author: Dan200 a.k.a. Daniel Ratcliff\
- ]]\
- \
- 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\
- \
- 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\
- \
- function shell.getRunningProgram()\
- if #tProgramStack > 0 then\
- return tProgramStack[#tProgramStack]\
- end\
- return nil\
- end\
- \
- function shell.setAlias( _sCommand, _sProgram )\
- tAliases[ _sCommand ] = _sProgram\
- end\
- \
- function shell.clearAlias( _sCommand )\
- tAliases[ _sCommand ] = nil\
- end\
- \
- function shell.aliases()\
- -- Add aliases\
- local tCopy = {}\
- for sAlias, sCommand in pairs( tAliases ) do\
- tCopy[sAlias] = sCommand\
- end\
- return tCopy\
- 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 )\
- \
- -- Run the startup program\
- if parentShell == nil then\
- shell.run( \"/rom/startup\" )\
- end\
- \
- -- 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",
- [ "list.lua" ] = "--[[\
- Author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- print(\"The threads are:\")\
- for i,v in pairs(Kernel.list()) do\
- print(v[1]..string.rep(\" \",5-#tostring(v[1]))..v[2]..\": \"..v[3])\
- end",
- [ "reboot.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- os.reboot()",
- [ "restart.lua" ] = "--[[\
- author: Wassil Janssen a.k.a. Creator\
- ]]\
- \
- os.reboot()",
- },
- [ "permission.data" ] = "admin",
- [ "startup.txt" ] = "FileX -p:admin",
- [ "Main.lua" ] = "--[[\
- OmniOS debug\
- app\
- ]]--\
- --Startup\
- local file = fs.open(\"OmniOS/Programs/Debug/startup.txt\",\"r\")\
- local data = file.readAll()\
- file.close()\
- local toOpen = {}\
- for token in data:gmatch(\"[^\\n]+\") do\
- toOpen[#toOpen+1] = token\
- end\
- for i,v in pairs(toOpen) do\
- --OmniOS.debug.run(v)\
- end\
- --Kernel.switch(\"FileX1\")\
- \
- --[[\
- Modified version of Shell\
- ]]--\
- promptColour = colours.yellow\
- textColour = colours.white\
- bgColour = colours.black\
- \
- \
- local function run(command,...)\
- if fs.exists(\"OmniOS/Programs/Debug/Commands/\"..command..\".lua\") and not fs.isDir(\"OmniOS/Programs/Debug/Commands/\"..command..\".lua\") then\
- local func, err = loadfile(\"OmniOS/Programs/Debug/Commands/\"..command..\".lua\")\
- if err then log.log(\"Debug\",err) return false end\
- local overArgs = {...}\
- setfenv(func,_G)\
- if command == \"kill\" or command == \"terminate\" then\
- func(firstArg,unpack(overArgs))\
- elseif #overArgs == 0 then\
- local ok, data = pcall(func)\
- if not ok then log.log(\"Debug\",data) end\
- else\
- local ok, data = pcall(func,unpack(overArgs))\
- if not ok then log.log(\"Debug\",data) end\
- end\
- else\
- print(\"Command is non-existent! Pay more attention when writting!\")\
- 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\
- \
- if not OmniOS or not type(OmniOS) == \"table\" then OmniOS = {} end\
- OmniOS.debug = {}\
- \
- function OmniOS.debug.run( ... )\
- local tWords = tokenise( ... )\
- local sCommand = tWords[1]\
- if sCommand then\
- return run( sCommand, unpack( tWords, 2 ) )\
- end\
- return false\
- end\
- \
- term.setCursorPos(1,1)\
- term.setBackgroundColor( bgColour )\
- term.setTextColour( promptColour )\
- term.clear()\
- print(\"OmniOS/Debug\")\
- term.setTextColour( textColour )\
- \
- -- Read commands and execute them\
- local tCommandHistory = {}\
- while true do\
- term.setBackgroundColor( bgColour )\
- term.setTextColour( promptColour )\
- write(\"> \")\
- term.setTextColour( textColour )\
- \
- local sLine = read( nil, tCommandHistory )\
- table.insert( tCommandHistory, sLine )\
- OmniOS.debug.run( sLine )\
- end",
- },
- Settings = {
- [ "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",
- },
- },
- },
- Aware = {
- [ "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",
- },
- BetterPaint = {
- [ "BetterPaint.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 1,\
- \"'\",\
- 256,\
- },\
- {\
- 8,\
- \" \",\
- 8,\
- },\
- {\
- 32,\
- \"w\",\
- 8192,\
- },\
- },\
- {\
- {\
- 8,\
- \" \",\
- 8,\
- },\
- {\
- 8,\
- \" \",\
- 8,\
- },\
- {\
- 32,\
- \"w\",\
- 8192,\
- },\
- },\
- {\
- {\
- 8,\
- \"@\",\
- 16,\
- },\
- {\
- 8,\
- \" \",\
- 8,\
- },\
- {\
- 32,\
- \"w\",\
- 8192,\
- },\
- },\
- [ 0 ] = {\
- {\
- 1,\
- \"'\",\
- 256,\
- },\
- {\
- 8,\
- \" \",\
- 8,\
- },\
- {\
- 32,\
- \"w\",\
- 8192,\
- },\
- },\
- }",
- [ "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",
- },
- Calculator = {
- [ "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",
- },
- },
- },
- nPaintPro = {
- [ "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" ] = "",
- },
- FileX = {
- disk1 = {},
- [ "permission.data" ] = "user",
- [ "hohoho.txt" ] = "",
- 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 )",
- },
- [ "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)",
- [ "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 = {
- wow = "hi",
- [ "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] =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 )",
- meh = "such much",
- startup = "",
- p = "d",
- [ "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,\
- },\
- },\
- }",
- h = "",
- here = "hi",
- OmniOS = {
- Data = {
- here = "hi",
- },
- },
- },
- Test = {
- [ "Main.lua" ] = "term.clear()\
- local timer = 0\
- while true do\
- Utils.debug(\"Timer is at \"..tostring(timer)..\" seconds.\")\
- log.log(\"test\",\"Timer: \"..tostring(timer))\
- print(timer)\
- sleep(1)\
- timer = timer + 1\
- end",
- [ "permission.data" ] = "userTest",
- },
- Shell = {
- [ "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" ] = "userTest",
- [ "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,\
- },\
- },\
- }",
- },
- Desktop = {
- [ "permission.data" ] = "userTest",
- [ "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 paths = {}\
- local scroll = 0\
- local programPath = \"Data/\"\
- OmniOS.loadAPI(\"NewInteract\")\
- \
- --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 loadGUI()\
- --Initializing GUI components\
- gui = NewInteract.Initialize()\
- mainLayout = gui.Layout.new(dofile(programPath..\"Layouts/Main.layout\"))\
- quickSettingsLayout = gui.Layout.new(dofile(programPath..\"Layouts/QuickSettings.layout\"))\
- 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\
- \
- 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 readFile(_path)\
- local file = fs.open(_path,\"r\")\
- local data = file.readAll()\
- file.close()\
- return data\
- end\
- \
- local w,h = term.getSize()\
- \
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- \
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- \
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- \
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- \
- \
- 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 = {\
- xPos = 1,\
- yPos = 1,\
- xLength = w,\
- yLength = h,\
- }\
- \
- 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.layout" ] = "local function readFile(_path)\
- local file = fs.open(_path,\"r\")\
- local data = file.readAll()\
- file.close()\
- return data\
- end\
- \
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- \
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- \
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- \
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- \
- 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,\
- }\
- },\
- \
- return QuickSettings",
- },
- },
- },
- },
- Data = {
- [ ".toGitHub" ] = "",
- },
- Drivers = {
- [ "disk.lua" ] = "local function mountDisk(disk,side)\
- for i,v in pairs(fs.list(\"OmniOS/Programs\")) do\
- fs.mount(disk.getMountPath(side),\"OmniOS/Programs/\"..v..\"/\"..disk.getMountPath(side))\
- end\
- print(\"lol\")\
- end\
- \
- Kernel.bindEvent(\"disk\",mountDisk)",
- [ "FS.lua" ] = "--[[\
- FS overwrite\
- Author: Wassil JAnssen a.k.a. Creator\
- ]]--\
- \
- --Variables\
- local altFS = {}\
- local altFS_mt = {\
- __index = function(t,k) Utils.debug(\"Tried to acces fs \"..k..\", total fail!\") return altFS.ccfs end\
- }\
- setmetatable(altFS,altFS_mt)\
- \
- altFS.ccfs = Utils.table.copy(fs)\
- print(\"Loading FSes\")\
- for i,v in pairs(fs.list(\"OmniOS/Drivers/FS\")) do\
- print(\"Loading FS \"..v)\
- altFS[v:match(\"[^%.]+\")] = dofile(\"OmniOS/Drivers/FS/\"..v)\
- Utils.debug(\"Loading FS \"..v)\
- end\
- --Functions\
- \
- fs.getFS = fsh.getFS\
- fs.mount = fsh.mount\
- fs.getMountPath = fsh.resolveLinks\
- fs.setFS = fsh.setFS\
- fs.link = fsh.link\
- fs.fs = altFS\
- \
- function fs.isReadOnly(path)\
- local path = fsh.resolveLinks(path)\
- local fss = fs.getFS(path)\
- --ffs = altFS[fss] or altFS.ccfs\
- return altFS[fss].isReadOnly(path)\
- end\
- \
- function fs.list(path)\
- Utils.debug(path)\
- local path = fsh.resolveLinks(path)\
- Utils.debug(path)\
- local fss = fs.getFS(path)\
- Utils.debug(\"The fs for \"..path..\" is \"..fss)\
- --local ffs = altFS[fss] or altFS.ccfs\
- return altFS[fss].list(path)\
- end\
- \
- function fs.exists(path)\
- local path = Utils.debug(fsh.resolveLinks(path))\
- local fss = fs.getFS(path)\
- --local ffs = altFS[fss] or altFS.ccfs\
- return altFS[fss].exists(path)\
- end\
- \
- function fs.isDir(path)\
- local path = fsh.resolveLinks(path)\
- local fss = fs.getFS(path)\
- --ffs = altFS[fss] or altFS.ccfs\
- return altFS[fss].isDir(path)\
- end\
- \
- function fs.getDrive(path)\
- local path = fsh.resolveLinks(path)\
- local fss = fs.getFS(path)\
- --local ffs = altFS[fss] or altFS.ccfs\
- return altFS[fss].getDrive(path)\
- end\
- \
- function fs.getSize(path)\
- local path = fsh.resolveLinks(path)\
- local fss = fs.getFS(path)\
- --local ffs = altFS[fss] or altFS.ccfs\
- return altFS[fss].getSize(path)\
- end\
- \
- function fs.getFreeSpace(path)\
- local path = fsh.resolveLinks(path)\
- local fss = fs.getFS(path)\
- --local ffs = altFS[fss] or altFS.ccfs\
- return altFS[fss].getFreeSpace(path)\
- end\
- \
- function fs.makeDir(path)\
- local path = fsh.resolveLinks(path)\
- local fss = fs.getFS(path)\
- --local ffs = altFS[fss] or altFS.ccfs\
- return altFS[fss].makeDir(path)\
- end\
- --[[Elaborate]]--\
- function fs.copy(path1,path2)\
- local path1 = fsh.resolveLinks(path1)\
- local fss1 = fs.getFS(path1)\
- local path2 = fsh.resolveLinks(path2)\
- local fss2 = fs.getFS(path2)\
- local buffer = {}\
- if (altFS[fss] or altFS.ccfs).isDir(path1) then\
- \
- else\
- \
- end\
- return oldFS.copy(path1,path2)\
- end\
- \
- function fs.move(path1,path2)\
- local path1 = fsh.resolveLinks(path1)\
- local path2 = fsh.resolveLinks(path2)\
- return oldFS.move(path1,path2)\
- end\
- \
- function fs.delete(path)\
- local path = fsh.resolveLinks(path)\
- local fss = fs.getFS(path)\
- --local ffs = altFS[fss] or altFS.ccfs\
- return altFS[fss].delete(path)\
- end\
- \
- function fs.open(path,mode)\
- local path = fsh.resolveLinks(path)\
- local fss = fs.getFS(path)\
- --local ffs = altFS[fss] or altFS.ccfs\
- return altFS[fss].open(path,mode)\
- end\
- \
- Utils.debug(\"Loaded FS driver.\")\
- fs.setFS(\"/dev\",\"devfs\")\
- fs.link(\"p\",\"OmniOS/Programs\")",
- FS = {
- [ "devfs.lua" ] = "--[[\
- Everything is a file!\
- Author: Wassil Janssen a.k.a. Creator\
- ]]--\
- \
- --Variables\
- devfs = {}\
- \
- local oldFS = Utils.table.copy(fs)\
- local peripheral = Utils.table.copy(peripheral)\
- devfs.getName = oldFS.getName\
- devfs.getSize = oldFS.getSize\
- devfs.isDir = oldFS.isDir\
- devfs.getDrive = oldFS.getDrive\
- \
- --Functions\
- function devfs.isReadOnly() return false end\
- function devfs.getFreeSpace() return oldFS.getFreeSpace('OmniOS') end\
- function devfs.makeDir() return false end\
- function devfs.move() return false end\
- function devfs.copy() return false end\
- function devfs.delete() return false end\
- \
- function devfs.list()\
- local ret = {}\
- for i,v in pairs(peripheral.getNames()) do\
- ret[i] = peripheral.getType(v)..\"_\"..v\
- end\
- return ret\
- end\
- \
- function devfs.exists(path)\
- local path = oldFS.getName(path)\
- return peripheral.isPresent(path) or (function(path) for i,v in pairs(devfs.list()) do if v == path then return true end end return false end)(path)\
- end\
- \
- function devfs.open(path)\
- assert(path:find(\"_\"),\"Path is invalid\")\
- assert(peripheral.isPresent(path:sub(path:find(\"_\")+1,-1)),\"No such peripheral!\")\
- local side = path:sub(path:find(\"_\")+1,-1)\
- local handle = {\
- ioctl = peripheral.wrap(side),\
- close = function() handle = nil end,\
- }\
- local handle_mt = {\
- __call = function(method,...)\
- return peripheral.call(side,\
- method,...)\
- end,\
- __metatable = function() return {} end,\
- }\
- setmetatable(handle.ioctl,handle_mt)\
- setmetatable(handle,{__index = handle.ioctl})\
- return handle\
- end\
- \
- return devfs",
- [ "ccfs.lua" ] = "--[[\
- Standart ComputerCraft File System\
- ]]--\
- \
- return Utils.table.copy(fs)",
- },
- },
- Languages = {
- [ "Boot_EN.lang" ] = "{\
- \"Loading API list...\",\
- \"Finished loading API list...\",\
- \"Loading APIs...\",\
- \"Finished loading APIs...\",\
- \"\",\
- }",
- },
- API = {
- [ "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",
- [ ".ignoreme" ] = "{\
- [\".ignoreme\"] = true,\
- }",
- [ "Utils.lua" ] = "--[[\
- Utils API\
- by Wassil Janssen a.k.a. Creator\
- OmniOS\
- ]]--\
- \
- debugprint = false\
- debuglog = true -- don't you judge me!\
- local oldOpen = fs.open\
- \
- function split(toSplit,sep)\
- if type(toSplit) ~= \"string\" then return false end\
- sep = sep or \"%s\"\
- local ret = {}\
- local count = 1\
- for token in toSplit:gmatch(\"[^\"..sep..\"]+\") do\
- ret[count] = token\
- count = count + 1\
- end\
- return ret\
- end\
- \
- local function tablecopy(source,destination)\
- for i,v in pairs(source) do\
- if type(v) == \"table\" then\
- destination[i] = {}\
- tablecopy(source[i],destination[i])\
- else\
- destination[i] = v\
- end\
- end\
- end\
- \
- 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 = oldOpen(\"OmniOS/Logs/\"..destination..\".log\",\"a\")\
- m.write(finalMsg..\"\\n\")\
- m.close()\
- end\
- \
- function debug(...)\
- if debugprint then\
- print(...)\
- end\
- if debuglog then\
- log(\"PrintIO\",(function(tabl,sep) local endRes = \"\" for i,v in pairs(tabl) do endRes = endRes..sep..v end return endRes:sub(#sep+1,-1) end)({...},\" && \"))\
- end\
- return ...\
- end\
- \
- table = {\
- copy = function(source,destination)\
- destination = destination or {}\
- tablecopy(source,destination)\
- return destination\
- end\
- }",
- [ "textutils.lua" ] = "\
- function slowWrite( sText, nRate )\
- nRate = nRate or 20\
- if nRate < 0 then\
- error( \"Rate must be positive\", 2 )\
- end\
- local nSleep = 1 / nRate\
- \
- sText = tostring( sText )\
- local x,y = term.getCursorPos(x,y)\
- local len = string.len( sText )\
- \
- for n=1,len do\
- term.setCursorPos( x, y )\
- sleep( nSleep )\
- local nLines = write( string.sub( sText, 1, n ) )\
- local newX, newY = term.getCursorPos()\
- y = newY - nLines\
- end\
- end\
- \
- function slowPrint( sText, nRate )\
- slowWrite( sText, nRate)\
- print()\
- end\
- \
- function formatTime( nTime, bTwentyFourHour )\
- local sTOD = nil\
- if not bTwentyFourHour then\
- if nTime >= 12 then\
- sTOD = \"PM\"\
- else\
- sTOD = \"AM\"\
- end\
- if nTime >= 13 then\
- nTime = nTime - 12\
- end\
- end\
- \
- local nHour = math.floor(nTime)\
- local nMinute = math.floor((nTime - nHour)*60)\
- if sTOD then\
- return string.format( \"%d:%02d %s\", nHour, nMinute, sTOD )\
- else\
- return string.format( \"%d:%02d\", nHour, nMinute )\
- end\
- end\
- \
- local function makePagedScroll( _term, _nFreeLines )\
- local nativeScroll = _term.scroll\
- local nFreeLines = _nFreeLines or 0\
- return function( _n )\
- for n=1,_n do\
- nativeScroll( 1 )\
- \
- if nFreeLines <= 0 then\
- local w,h = _term.getSize()\
- _term.setCursorPos( 1, h )\
- _term.write( \"Press any key to continue\" )\
- os.pullEvent( \"key\" )\
- _term.clearLine()\
- _term.setCursorPos( 1, h )\
- else\
- nFreeLines = nFreeLines - 1\
- end\
- end\
- end\
- end\
- \
- function pagedPrint( _sText, _nFreeLines )\
- -- Setup a redirector\
- local oldTerm = term.current()\
- local newTerm = {}\
- for k,v in pairs( oldTerm ) do\
- newTerm[k] = v\
- end\
- newTerm.scroll = makePagedScroll( oldTerm, _nFreeLines )\
- term.redirect( newTerm )\
- \
- -- Print the text\
- local result\
- local ok, err = pcall( function()\
- result = print( _sText )\
- end )\
- \
- -- Removed the redirector\
- term.redirect( oldTerm )\
- \
- -- Propogate errors\
- if not ok then\
- error( err, 0 )\
- end\
- return result\
- end\
- \
- local function tabulateCommon( bPaged, ... )\
- local tAll = { ... }\
- \
- local w,h = term.getSize()\
- local nMaxLen = w / 8\
- for n, t in ipairs( tAll ) do\
- if type(t) == \"table\" then\
- for n, sItem in pairs(t) do\
- nMaxLen = math.max( string.len( sItem ) + 1, nMaxLen )\
- end\
- end\
- end\
- local nCols = math.floor( w / nMaxLen )\
- local nLines = 0\
- local function newLine()\
- if bPaged and nLines >= (h-3) then\
- pagedPrint()\
- else\
- print()\
- end\
- nLines = nLines + 1\
- end\
- \
- local function drawCols( _t )\
- local nCol = 1\
- for n, s in ipairs( _t ) do\
- if nCol > nCols then\
- nCol = 1\
- newLine()\
- end\
- \
- local cx, cy = term.getCursorPos()\
- cx = 1 + ((nCol - 1) * nMaxLen)\
- term.setCursorPos( cx, cy )\
- term.write( s )\
- \
- nCol = nCol + 1 \
- end\
- print()\
- end\
- for n, t in ipairs( tAll ) do\
- if type(t) == \"table\" then\
- if #t > 0 then\
- drawCols( t )\
- end\
- elseif type(t) == \"number\" then\
- term.setTextColor( t )\
- end\
- end \
- end\
- \
- function tabulate( ... )\
- tabulateCommon( false, ... )\
- end\
- \
- function pagedTabulate( ... )\
- tabulateCommon( true, ... )\
- end\
- \
- local g_tLuaKeywords = {\
- [ \"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 serializeImpl( t, tTracking, sIndent )\
- local sType = type(t)\
- if sType == \"table\" then\
- --if tTracking[t] ~= nil then\
- -- error( \"Cannot serialize table with recursive entries\", 0 )\
- --end\
- tTracking[t] = true\
- \
- if next(t) == nil then\
- -- Empty tables are simple\
- return \"{}\"\
- else\
- -- Other tables take more work\
- local sResult = \"{\\n\"\
- local sSubIndent = sIndent .. \" \"\
- local tSeen = {}\
- for k,v in ipairs(t) do\
- tSeen[k] = true\
- sResult = sResult .. sSubIndent .. serializeImpl( v, tTracking, sSubIndent ) .. \",\\n\"\
- end\
- for k,v in pairs(t) do\
- if not tSeen[k] then\
- local sEntry\
- if type(k) == \"string\" and not g_tLuaKeywords[k] and string.match( k, \"^[%a_][%a%d_]*$\" ) then\
- sEntry = k .. \" = \" .. serializeImpl( v, tTracking, sSubIndent ) .. \",\\n\"\
- else\
- sEntry = \"[ \" .. serializeImpl( k, tTracking, sSubIndent ) .. \" ] = \" .. serializeImpl( v, tTracking, sSubIndent ) .. \",\\n\"\
- end\
- sResult = sResult .. sSubIndent .. sEntry\
- end\
- end\
- sResult = sResult .. sIndent .. \"}\"\
- return sResult\
- end\
- \
- elseif sType == \"string\" then\
- return string.format( \"%q\", t )\
- \
- elseif sType == \"number\" or sType == \"boolean\" or sType == \"nil\" then\
- return tostring(t)\
- \
- else\
- error( \"Cannot serialize type \"..sType, 0 )\
- \
- end\
- end\
- \
- EMPTY_ARRAY = {}\
- \
- local function serializeJSONImpl( t, tTracking )\
- local sType = type(t)\
- if t == EMPTY_ARRAY then\
- return \"[]\"\
- \
- elseif sType == \"table\" then\
- --if tTracking[t] ~= nil then\
- -- error( \"Cannot serialize table with recursive entries\", 0 )\
- --end\
- tTracking[t] = true\
- \
- if next(t) == nil then\
- -- Empty tables are simple\
- return \"{}\"\
- else\
- -- Other tables take more work\
- local sObjectResult = \"{\"\
- local sArrayResult = \"[\"\
- local nObjectSize = 0\
- local nArraySize = 0\
- for k,v in pairs(t) do\
- if type(k) == \"string\" then\
- local sEntry = serializeJSONImpl( k, tTracking ) .. \":\" .. serializeJSONImpl( v, tTracking )\
- if nObjectSize == 0 then\
- sObjectResult = sObjectResult .. sEntry\
- else\
- sObjectResult = sObjectResult .. \",\" .. sEntry\
- end\
- nObjectSize = nObjectSize + 1\
- end\
- end\
- for n,v in ipairs(t) do\
- local sEntry = serializeJSONImpl( v, tTracking )\
- if nArraySize == 0 then\
- sArrayResult = sArrayResult .. sEntry\
- else\
- sArrayResult = sArrayResult .. \",\" .. sEntry\
- end\
- nArraySize = nArraySize + 1\
- end\
- sObjectResult = sObjectResult .. \"}\"\
- sArrayResult = sArrayResult .. \"]\"\
- if nObjectSize > 0 or nArraySize == 0 then\
- return sObjectResult\
- else\
- return sArrayResult\
- end\
- end\
- \
- elseif sType == \"string\" then\
- return string.format( \"%q\", t )\
- \
- elseif sType == \"number\" or sType == \"boolean\" then\
- return tostring(t)\
- \
- else\
- error( \"Cannot serialize type \"..sType, 0 )\
- \
- end\
- end\
- \
- function serialize( t )\
- local tTracking = {}\
- return serializeImpl( t, tTracking, \"\" )\
- end\
- \
- function unserialize( s )\
- local func = loadstring( \"return \"..s, \"unserialize\" )\
- if func then\
- setfenv( func, {} )\
- local ok, result = pcall( func )\
- if ok then\
- return result\
- end\
- end\
- return nil\
- end\
- \
- function serializeJSON( t )\
- local tTracking = {}\
- return serializeJSONImpl( t, tTracking )\
- end\
- \
- function urlEncode( str )\
- if str then\
- str = string.gsub(str, \"\\n\", \"\\r\\n\")\
- str = string.gsub(str, \"([^%w ])\", function(c)\
- return string.format(\"%%%02X\", string.byte(c))\
- end )\
- str = string.gsub(str, \" \", \"+\")\
- end\
- return str \
- end\
- \
- -- GB versions\
- serialise = serialize\
- unserialise = unserialize\
- serialiseJSON = serializeJSON",
- [ "OmniWindow.lua" ] = "--[[\
- Author: dan200\
- Modified by: Creator\
- ]]--\
- 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\
- \
- 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\
- \
- 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 )\
- 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\
- table.insert( tSubLine, tBit )\
- elseif nBitStart < nStart and nBitEnd <= nEnd then\
- table.insert( tSubLine, {\
- string.sub( sBit, nStart - nBitStart + 1 ),\
- tBit[2], tBit[3]\
- } )\
- 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]\
- } )\
- else\
- table.insert( tSubLine, {\
- string.sub( sBit, nStart - nBitStart + 1, nEnd - nBitStart + 1 ),\
- tBit[2], tBit[3]\
- } )\
- end\
- end\
- nBitStart = nBitEnd + 1\
- end\
- 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\
- 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\
- else\
- for n=1,#tLine1 do\
- table.insert( tNewLine, tLine1[n] )\
- end\
- for n=1,#tLine2 do\
- table.insert( tNewLine, tLine2[n] )\
- end\
- 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\
- if nStart <= nWidth and nEnd >= 1 then\
- -- Construct new line\
- local tLine = tLines[ nCursorY ]\
- if nStart == 1 and nEnd == nWidth then\
- tLine = {\
- { sText, nTextColor, nBackgroundColor }\
- }\
- 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 )\
- bVisible = bVis\
- 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",
- [ "Sandbox.lua" ] = "--[[\
- Sandbox \
- environment\
- by Creator\
- for TheOS\
- ]]--\
- \
- --Variables--\
- local oldGetfenv = getfenv\
- local oldLoadfile = loadfile\
- local globalName = \"\"\
- \
- \
- --Functions--\
- \
- local function tableCopy(tbl)\
- if type(tbl) == \"table\" then\
- local buffer = {}\
- for i,v in pairs(tbl) do\
- if type(v) == \"table\" then\
- buffer[i] = tableCopy(v)\
- else\
- buffer[i] = v\
- end\
- end\
- return buffer\
- else\
- error(\"Table expected\",2)\
- sleep(3)\
- end\
- end\
- \
- function newEnv(name)\
- globalName = name\
- toReturn = {\
- redstone = tableCopy(redstone),\
- gps = tableCopy(gps),\
- _VERSION = _VERSION,\
- keys = tableCopy(keys),\
- printError = printError,\
- peripheral = tableCopy(peripheral),\
- assert = assert,\
- getfenv = function(env) if env == nil then env = toReturn elseif getfenv( env ) == \"number\" and env > 0 then env = env + 1 end local fenv = getfenv(env) return fenv end,\
- bit = tableCopy(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 = tableCopy(disk),\
- window = tableCopy(window),\
- next = next,\
- unpack = unpack,\
- colours = colours,\
- pcall = pcall,\
- sleep = sleep,\
- loadfile = function(path) return setfenv(loadfile(\"OmniOS/Programs/\"..globalName..\".app/\"..path),toReturn) 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,\
- }\
- setfenv(toReturn.loadfile,toReturn)\
- setfenv(toReturn.dofile,toReturn)\
- setfenv(toReturn.loadstring,toReturn)\
- for i,v in pairs(toReturn.io) do\
- setfenv(v,toReturn)\
- end\
- return toReturn\
- 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 = oldOpen(\"OmniOS/Logs/\"..destination..\".log\",\"a\")\
- m.write(finalMsg..\"\\n\")\
- m.close()\
- end]]--\
- \
- log = Utils.log",
- [ "OmniOS.lua" ] = "version = \"alpha\"\
- tag = \"15w16a\"\
- loadAPI = function(_sPath)\
- _sPath = fs.exists(\"OmniOS/API/\".._sPath) and \"OmniOS/API/\".._sPath or \"OmniOS/lib/\".._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\
- function getFile(path)\
- if fs.exists(path) and not fs. isDir(path) then\
- local file = fs.open(path,\"r\")\
- local data = file.readAll()\
- file.close()\
- return data\
- end\
- return false\
- end\
- screen = {\
- getScreen = function(routine) return Kernel.getScreen(routine) end\
- }\
- FS = fs",
- [ "System.lua" ] = "--[[\
- System API\
- for\
- TheOS\
- by Creator\
- ]]--\
- \
- function reboot()\
- os.reboot()\
- end\
- \
- function newProcess(name,parent,...)\
- log.log(\"System\",\"Opening app \"..name)\
- local mainPath = \"OmniOS/Programs/\"..name..\"/Main.lua\"\
- local permissionPath = \"OmniOS/Programs/\"..name..\".app/permission.data\"\
- if fs.exists(mainPath) and not fs.isDir(mainPath) then\
- 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.\")\
- local func, err = loadfile(mainPath)\
- if func then\
- log.log(\"System\",\"Opening app \"..name..\": about to launch task.\")\
- if Kernel.newRoutine then\
- Kernel.newProcess(func,\"term\",permission,name,...)\
- else\
- return false\
- end\
- log.log(\"System\",\"Opening app \"..name..\": launched task.\")\
- end\
- return true\
- end\
- return false\
- end\
- \
- function newTaskMon(side,name,title,...)\
- log.log(\"System\",\"Opening app \"..name)\
- local mainPath = \"OmniOS/Programs/\"..name..\".app/Main.lua\"\
- local permissionPath = \"OmniOS/Programs/\"..name..\".app/permission.data\"\
- if fs.exists(mainPath) and not fs.isDir(mainPath) then\
- 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.\")\
- local func, err = loadfile(mainPath)\
- if func then\
- log.log(\"System\",\"Opening app \"..name..\": about to launch task.\")\
- if Kernel.newRoutineMon then\
- Kernel.newRoutineMon(side,name,title,func,permission,...)\
- log.log(\"System\",\"Opening app on monitor \"..side..\" \"..name..\": launched task.\")\
- else\
- return false\
- end\
- return unpack(data)\
- end\
- return true\
- end\
- return false\
- end\
- \
- function getPerimssion(program)\
- return getPerimssion(program)\
- 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",
- Interact = {
- [ "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",
- Backup = {
- Interact = "--[[\
- 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 = {}\
- 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\
- 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\
- 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.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)\
- 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.draw = function(self,xPlus,yPlus)\
- local oldTerm= term.current()\
- term.redirect(self.window)\
- local buttonFunctions = {}\
- local toggleFunctions = {}\
- local colorFieldFunctions = {}\
- local betterPaintFunctions = {}\
- local textFunctions = {}\
- local textBoxFunctions = {}\
- setmetatable(buttonFunctions,{__index = Button})\
- setmetatable(toggleFunctions,{__index = Toggle})\
- setmetatable(colorFieldFunctions,{__index = ColorField})\
- setmetatable(betterPaintFunctions,{__index = BetterPaint})\
- setmetatable(textFunctions,{__index = Text})\
- setmetatable(textBoxFunctions,{__index = TextBox})\
- --paintutils.drawFilledBox(self.xPos,self.yPos,self.xPos+self.xLength-1,self.yPos+self.yLength-1,self.BackgroundColor)\
- paintutils.drawFilledBox(1,1,self.xLength,self.yLength,self.BackgroundColor)\
- for i,v in pairs(self.ColorField) do\
- colorFieldFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)\
- end\
- for i,v in pairs(self.Button) do\
- buttonFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)\
- end\
- for i,v in pairs(self.BetterPaint) do\
- betterPaintFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)\
- end\
- for i,v in pairs(self.Toggle) do\
- toggleFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)\
- end\
- for i,v in pairs(self.Text) do\
- textFunctions.draw(v,self.xPos,self.yPos,xPlus,yPlus)\
- end\
- for i,v in pairs(self.TextBox) do\
- textBoxFunctions.draw(v,self.xPos,self.yPos,xPlus,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\
- self.moveX = input.moveX or false\
- self.moveY = input.moveY or false\
- 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\
- \
- \
- \
- --Event handler function--\
- eventHandler = function(self)\
- local toAddX = self.xPos - 1\
- local toAddY = self.yPos - 1\
- while true do\
- local event, p1, p2, p3, p4, p5, p6 = os.pullEvent()\
- 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\
- \
- --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",
- },
- [ "README.md" ] = "# Interact\
- Interact is the GUI API developed by me for the need of TheOS.",
- [ ".ignoreme" ] = "{\
- [\".git\"] = true,\
- [\".ignoreme\"] = true,\
- [\"LICENSE\"] = true,\
- [\"README.md\"] = true,\
- [\"Backup\"] = true,\
- }",
- [ "KeyCodes.lua" ] = "local Keys = {\
- [ 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\",\
- }",
- [ ".git" ] = "gitdir: ../../.git/modules/API/Interact",
- [ "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",
- LICENSE = "GNU GENERAL PUBLIC LICENSE\
- Version 2, June 1991\
- \
- Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>\
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\
- Everyone is permitted to copy and distribute verbatim copies\
- of this license document, but changing it is not allowed.\
- \
- Preamble\
- \
- The licenses for most software are designed to take away your\
- freedom to share and change it. By contrast, the GNU General Public\
- License is intended to guarantee your freedom to share and change free\
- software--to make sure the software is free for all its users. This\
- General Public License applies to most of the Free Software\
- Foundation's software and to any other program whose authors commit to\
- using it. (Some other Free Software Foundation software is covered by\
- the GNU Lesser General Public License instead.) You can apply it to\
- your programs, too.\
- \
- When we speak of free software, we are referring to freedom, not\
- price. Our General Public Licenses are designed to make sure that you\
- have the freedom to distribute copies of free software (and charge for\
- this service if you wish), that you receive source code or can get it\
- if you want it, that you can change the software or use pieces of it\
- in new free programs; and that you know you can do these things.\
- \
- To protect your rights, we need to make restrictions that forbid\
- anyone to deny you these rights or to ask you to surrender the rights.\
- These restrictions translate to certain responsibilities for you if you\
- distribute copies of the software, or if you modify it.\
- \
- For example, if you distribute copies of such a program, whether\
- gratis or for a fee, you must give the recipients all the rights that\
- you have. You must make sure that they, too, receive or can get the\
- source code. And you must show them these terms so they know their\
- rights.\
- \
- We protect your rights with two steps: (1) copyright the software, and\
- (2) offer you this license which gives you legal permission to copy,\
- distribute and/or modify the software.\
- \
- Also, for each author's protection and ours, we want to make certain\
- that everyone understands that there is no warranty for this free\
- software. If the software is modified by someone else and passed on, we\
- want its recipients to know that what they have is not the original, so\
- that any problems introduced by others will not reflect on the original\
- authors' reputations.\
- \
- Finally, any free program is threatened constantly by software\
- patents. We wish to avoid the danger that redistributors of a free\
- program will individually obtain patent licenses, in effect making the\
- program proprietary. To prevent this, we have made it clear that any\
- patent must be licensed for everyone's free use or not licensed at all.\
- \
- The precise terms and conditions for copying, distribution and\
- modification follow.\
- \
- GNU GENERAL PUBLIC LICENSE\
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\
- \
- 0. This License applies to any program or other work which contains\
- a notice placed by the copyright holder saying it may be distributed\
- under the terms of this General Public License. The \"Program\", below,\
- refers to any such program or work, and a \"work based on the Program\"\
- means either the Program or any derivative work under copyright law:\
- that is to say, a work containing the Program or a portion of it,\
- either verbatim or with modifications and/or translated into another\
- language. (Hereinafter, translation is included without limitation in\
- the term \"modification\".) Each licensee is addressed as \"you\".\
- \
- Activities other than copying, distribution and modification are not\
- covered by this License; they are outside its scope. The act of\
- running the Program is not restricted, and the output from the Program\
- is covered only if its contents constitute a work based on the\
- Program (independent of having been made by running the Program).\
- Whether that is true depends on what the Program does.\
- \
- 1. You may copy and distribute verbatim copies of the Program's\
- source code as you receive it, in any medium, provided that you\
- conspicuously and appropriately publish on each copy an appropriate\
- copyright notice and disclaimer of warranty; keep intact all the\
- notices that refer to this License and to the absence of any warranty;\
- and give any other recipients of the Program a copy of this License\
- along with the Program.\
- \
- You may charge a fee for the physical act of transferring a copy, and\
- you may at your option offer warranty protection in exchange for a fee.\
- \
- 2. You may modify your copy or copies of the Program or any portion\
- of it, thus forming a work based on the Program, and copy and\
- distribute such modifications or work under the terms of Section 1\
- above, provided that you also meet all of these conditions:\
- \
- a) You must cause the modified files to carry prominent notices\
- stating that you changed the files and the date of any change.\
- \
- b) You must cause any work that you distribute or publish, that in\
- whole or in part contains or is derived from the Program or any\
- part thereof, to be licensed as a whole at no charge to all third\
- parties under the terms of this License.\
- \
- c) If the modified program normally reads commands interactively\
- when run, you must cause it, when started running for such\
- interactive use in the most ordinary way, to print or display an\
- announcement including an appropriate copyright notice and a\
- notice that there is no warranty (or else, saying that you provide\
- a warranty) and that users may redistribute the program under\
- these conditions, and telling the user how to view a copy of this\
- License. (Exception: if the Program itself is interactive but\
- does not normally print such an announcement, your work based on\
- the Program is not required to print an announcement.)\
- \
- These requirements apply to the modified work as a whole. If\
- identifiable sections of that work are not derived from the Program,\
- and can be reasonably considered independent and separate works in\
- themselves, then this License, and its terms, do not apply to those\
- sections when you distribute them as separate works. But when you\
- distribute the same sections as part of a whole which is a work based\
- on the Program, the distribution of the whole must be on the terms of\
- this License, whose permissions for other licensees extend to the\
- entire whole, and thus to each and every part regardless of who wrote it.\
- \
- Thus, it is not the intent of this section to claim rights or contest\
- your rights to work written entirely by you; rather, the intent is to\
- exercise the right to control the distribution of derivative or\
- collective works based on the Program.\
- \
- In addition, mere aggregation of another work not based on the Program\
- with the Program (or with a work based on the Program) on a volume of\
- a storage or distribution medium does not bring the other work under\
- the scope of this License.\
- \
- 3. You may copy and distribute the Program (or a work based on it,\
- under Section 2) in object code or executable form under the terms of\
- Sections 1 and 2 above provided that you also do one of the following:\
- \
- a) Accompany it with the complete corresponding machine-readable\
- source code, which must be distributed under the terms of Sections\
- 1 and 2 above on a medium customarily used for software interchange; or,\
- \
- b) Accompany it with a written offer, valid for at least three\
- years, to give any third party, for a charge no more than your\
- cost of physically performing source distribution, a complete\
- machine-readable copy of the corresponding source code, to be\
- distributed under the terms of Sections 1 and 2 above on a medium\
- customarily used for software interchange; or,\
- \
- c) Accompany it with the information you received as to the offer\
- to distribute corresponding source code. (This alternative is\
- allowed only for noncommercial distribution and only if you\
- received the program in object code or executable form with such\
- an offer, in accord with Subsection b above.)\
- \
- The source code for a work means the preferred form of the work for\
- making modifications to it. For an executable work, complete source\
- code means all the source code for all modules it contains, plus any\
- associated interface definition files, plus the scripts used to\
- control compilation and installation of the executable. However, as a\
- special exception, the source code distributed need not include\
- anything that is normally distributed (in either source or binary\
- form) with the major components (compiler, kernel, and so on) of the\
- operating system on which the executable runs, unless that component\
- itself accompanies the executable.\
- \
- If distribution of executable or object code is made by offering\
- access to copy from a designated place, then offering equivalent\
- access to copy the source code from the same place counts as\
- distribution of the source code, even though third parties are not\
- compelled to copy the source along with the object code.\
- \
- 4. You may not copy, modify, sublicense, or distribute the Program\
- except as expressly provided under this License. Any attempt\
- otherwise to copy, modify, sublicense or distribute the Program is\
- void, and will automatically terminate your rights under this License.\
- However, parties who have received copies, or rights, from you under\
- this License will not have their licenses terminated so long as such\
- parties remain in full compliance.\
- \
- 5. You are not required to accept this License, since you have not\
- signed it. However, nothing else grants you permission to modify or\
- distribute the Program or its derivative works. These actions are\
- prohibited by law if you do not accept this License. Therefore, by\
- modifying or distributing the Program (or any work based on the\
- Program), you indicate your acceptance of this License to do so, and\
- all its terms and conditions for copying, distributing or modifying\
- the Program or works based on it.\
- \
- 6. Each time you redistribute the Program (or any work based on the\
- Program), the recipient automatically receives a license from the\
- original licensor to copy, distribute or modify the Program subject to\
- these terms and conditions. You may not impose any further\
- restrictions on the recipients' exercise of the rights granted herein.\
- You are not responsible for enforcing compliance by third parties to\
- this License.\
- \
- 7. If, as a consequence of a court judgment or allegation of patent\
- infringement or for any other reason (not limited to patent issues),\
- conditions are imposed on you (whether by court order, agreement or\
- otherwise) that contradict the conditions of this License, they do not\
- excuse you from the conditions of this License. If you cannot\
- distribute so as to satisfy simultaneously your obligations under this\
- License and any other pertinent obligations, then as a consequence you\
- may not distribute the Program at all. For example, if a patent\
- license would not permit royalty-free redistribution of the Program by\
- all those who receive copies directly or indirectly through you, then\
- the only way you could satisfy both it and this License would be to\
- refrain entirely from distribution of the Program.\
- \
- If any portion of this section is held invalid or unenforceable under\
- any particular circumstance, the balance of the section is intended to\
- apply and the section as a whole is intended to apply in other\
- circumstances.\
- \
- It is not the purpose of this section to induce you to infringe any\
- patents or other property right claims or to contest validity of any\
- such claims; this section has the sole purpose of protecting the\
- integrity of the free software distribution system, which is\
- implemented by public license practices. Many people have made\
- generous contributions to the wide range of software distributed\
- through that system in reliance on consistent application of that\
- system; it is up to the author/donor to decide if he or she is willing\
- to distribute software through any other system and a licensee cannot\
- impose that choice.\
- \
- This section is intended to make thoroughly clear what is believed to\
- be a consequence of the rest of this License.\
- \
- 8. If the distribution and/or use of the Program is restricted in\
- certain countries either by patents or by copyrighted interfaces, the\
- original copyright holder who places the Program under this License\
- may add an explicit geographical distribution limitation excluding\
- those countries, so that distribution is permitted only in or among\
- countries not thus excluded. In such case, this License incorporates\
- the limitation as if written in the body of this License.\
- \
- 9. The Free Software Foundation may publish revised and/or new versions\
- of the General Public License from time to time. Such new versions will\
- be similar in spirit to the present version, but may differ in detail to\
- address new problems or concerns.\
- \
- Each version is given a distinguishing version number. If the Program\
- specifies a version number of this License which applies to it and \"any\
- later version\", you have the option of following the terms and conditions\
- either of that version or of any later version published by the Free\
- Software Foundation. If the Program does not specify a version number of\
- this License, you may choose any version ever published by the Free Software\
- Foundation.\
- \
- 10. If you wish to incorporate parts of the Program into other free\
- programs whose distribution conditions are different, write to the author\
- to ask for permission. For software which is copyrighted by the Free\
- Software Foundation, write to the Free Software Foundation; we sometimes\
- make exceptions for this. Our decision will be guided by the two goals\
- of preserving the free status of all derivatives of our free software and\
- of promoting the sharing and reuse of software generally.\
- \
- NO WARRANTY\
- \
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\
- FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\
- OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\
- PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\
- OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\
- TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\
- PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\
- REPAIR OR CORRECTION.\
- \
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\
- REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\
- INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\
- OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\
- TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\
- YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\
- PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\
- POSSIBILITY OF SUCH DAMAGES.\
- \
- END OF TERMS AND CONDITIONS\
- \
- How to Apply These Terms to Your New Programs\
- \
- If you develop a new program, and you want it to be of the greatest\
- possible use to the public, the best way to achieve this is to make it\
- free software which everyone can redistribute and change under these terms.\
- \
- To do so, attach the following notices to the program. It is safest\
- to attach them to the start of each source file to most effectively\
- convey the exclusion of warranty; and each file should have at least\
- the \"copyright\" line and a pointer to where the full notice is found.\
- \
- {description}\
- Copyright (C) {year} {fullname}\
- \
- This program is free software; you can redistribute it and/or modify\
- it under the terms of the GNU General Public License as published by\
- the Free Software Foundation; either version 2 of the License, or\
- (at your option) any later version.\
- \
- This program is distributed in the hope that it will be useful,\
- but WITHOUT ANY WARRANTY; without even the implied warranty of\
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\
- GNU General Public License for more details.\
- \
- You should have received a copy of the GNU General Public License along\
- with this program; if not, write to the Free Software Foundation, Inc.,\
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\
- \
- Also add information on how to contact you by electronic and paper mail.\
- \
- If the program is interactive, make it output a short notice like this\
- when it starts in an interactive mode:\
- \
- Gnomovision version 69, Copyright (C) year name of author\
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\
- This is free software, and you are welcome to redistribute it\
- under certain conditions; type `show c' for details.\
- \
- The hypothetical commands `show w' and `show c' should show the appropriate\
- parts of the General Public License. Of course, the commands you use may\
- be called something other than `show w' and `show c'; they could even be\
- mouse-clicks or menu items--whatever suits your program.\
- \
- You should also get your employer (if you work as a programmer) or your\
- school, if any, to sign a \"copyright disclaimer\" for the program, if\
- necessary. Here is a sample; alter the names:\
- \
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program\
- `Gnomovision' (which makes passes at compilers) written by James Hacker.\
- \
- {signature of Ty Coon}, 1 April 1989\
- Ty Coon, President of Vice\
- \
- This General Public License does not permit incorporating your program into\
- proprietary programs. If your program is a subroutine library, you may\
- consider it more useful to permit linking proprietary applications with the\
- library. If this is what you want to do, use the GNU Lesser General\
- Public License instead of this License.\
- ",
- },
- [ "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",
- [ "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",
- [ "fsh.lua" ] = "--[[\
- VFS helper and moumting manager\
- Author: Wassil Janssen a.k.a. Creator\
- ]]--\
- \
- --Variables\
- local mounts = {}\
- local Internal = {}\
- local filesystems = {}\
- \
- --Functions\
- function Internal.getFirstElement(path)\
- if not type(path) == \"string\" then error(\"This is not a string: \"..tostring(path),2) end\
- --Utils.debug(\"Getting first element: \"..tostring(path))\
- return string.sub(path,1,string.find(path,\"/\") and string.find(path,\"/\")-1 or -1)\
- end\
- \
- function Internal.makeTable(path,tabl)\
- if type(path) ~= \"string\" then error(\"Expected string, got \"..type(path)..\"!\",2) end\
- if type(tabl) ~= \"table\" then error(\"Expected table, got \"..type(tabl)..\"!\",2) end\
- path = fs.combine(\"\",path)\
- local first = Internal.getFirstElement(path)\
- if first == path then\
- return tabl, first\
- else\
- if not tabl[first] then tabl[first] = {} end\
- return Internal.makeTable(path:sub(path:find(\"/\")+1,-1),tabl[first])\
- end\
- end\
- \
- function mount(destination,source,fss)\
- fss = fss or \"ccfs\"\
- if not fs.exists(destination) then fs.makeDir(destination) end\
- if not fs.exists(source) then fs.makeDir(source) end\
- local tabl, dir = Internal.makeTable(destination,mounts)\
- tabl[dir] = source\
- if fss and fss ~= \"ccfs\" then\
- local tabl, dir = Internal.makeTable(destination,filesystems)\
- tabl[dir] = fss\
- end\
- end\
- \
- function setFS(path,fss)\
- if not fs.isDir(path) then fs.makeDir(path) end\
- if fss ~= \"ccfs\" then\
- local tabl, dir = Internal.makeTable(path,filesystems)\
- tabl[dir] = fss\
- end\
- end\
- \
- function link(destination,source)\
- if not fs.exists(destination) then fs.makeDir(destination) end\
- if not fs.exists(source) then fs.makeDir(source) end\
- local tabl, dir = Internal.makeTable(destination,mounts)\
- tabl[dir] = source\
- end\
- \
- function Internal.resolveLinks(path,tabl)\
- local first = Internal.getFirstElement(path)\
- if tabl[first] then\
- if type(tabl[first]) == \"table\" then\
- return Internal.resolveLinks(path:sub(path:find(\"/\") and path:find(\"/\")+1 or 1,-1),tabl[first])\
- elseif type(tabl[first]) == \"string\" then\
- return tabl[first]..\"/\"..path:sub(#Internal.getFirstElement(path)+2,-1)\
- end\
- end\
- return false\
- end\
- \
- function Internal.intermediateResolveLinks(path)\
- resolved = Internal.resolveLinks(path,mounts)\
- if resolved == false then\
- return path\
- else\
- Utils.debug(\"Using Immediate again\")\
- return Internal.intermediateResolveLinks(resolved)\
- end\
- end\
- \
- function resolveLinks(path)\
- --Utils.debug(\"Resolving link: \"..tostring(path))\
- local toReturn = Internal.intermediateResolveLinks(fs.combine(\"\",path))\
- --Utils.debug(\"Resolved link: \"..tostring(toReturn))\
- return toReturn\
- end\
- \
- function Internal.getFS(path,tabl)\
- --Utils.debug(\"Getinng FS, internal \"..path,tostring(tabl))\
- local first = Internal.getFirstElement(path)\
- if tabl[first] then\
- if type(tabl[first]) == \"table\" then\
- return Internal.getFS(path:sub(path:find(\"/\") and path:find(\"/\")+1 or 1,-1),tabl[first])\
- elseif type(tabl[first]) == \"string\" then\
- return tabl[first]\
- end\
- end\
- return false\
- end\
- \
- function getFS(path)\
- resolved = Internal.getFS(fs.combine(\"\",path),filesystems)\
- --Utils.debug(\"Path \"..path..\" has FS \"..(resolved or \"ccfs\")..\" while resolved is \"..(resolved or \"false\")..\".\")\
- return resolved or \"ccfs\"\
- end\
- \
- --mount(\"OmniOS/Programs/FileX.app\",\"disk1\",\"mls\")\
- --mount(\"disk1\",\"OmniOS/API\",\"lol\")\
- --print(\"lol\")\
- --print(resolveLinks(\"OmniOS/Programs/FileX.app/Data/coo\"))\
- --print(\"lol\")\
- --print(getFS(\"OmniOS/Programs\"))\
- --print(textutils.serialize(filesystems))",
- },
- }
- 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