Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------
- -- OS Freeware --
- ---------------------------------------
- -- Built simple and open for the user --
- ---------------------------------------
- ---------------------
- -- Created by --
- -- Just Does Games --
- ---------------------
- if not term.isColor() then print("Advanced Computer Only") return end
- local wl, wh = 51,19
- w,h = term.getSize()
- if w ~= wl or h ~= wh then print("Computer need to be "..wl.." by "..wh) return end
- -- Pre init --
- local function setText(col) return term.setTextColor(colors[col]) end
- local function setBack(col) return term.setBackgroundColor(colors[col]) end
- local function cp(x,y)
- if x ~= nil and y ~= nil then
- term.setCursorPos(x,y)
- end
- end
- local function clr()
- term.clear()
- end
- local dir = "/freeware/"
- local version = "OS Freeware 1.6"
- --[[
- version info:
- 1.1 (12/10/19)
- - init launch
- 1.2 (12/11/19)
- - fixed most obvious errors (moved some info below)
- 1.3 (12/13/19)
- -- General --
- - fixed sprite download error (loop endlessly)
- - created a directory for freeware things
- - redid app loading so implementing apps that modify apps are easier (Desktop app)
- - added page info next to home button (current page / max page)
- -- Apps --
- - added 'System Info' app to display info about the system you are on
- - added 'Dino' (Buggy but made in within an hour)
- - added 'Desktop' app for managing apps on the desktop (coming soon)
- -- File System --
- - you are now able to clear bin from the app directly
- - fixed bug where the last of a folder did not display at all
- 1.4 (12/14/12 -> 12/15/19)
- -- General --
- - changed page number text color to black
- - apps can now be moved around and toggled on and off using the 'Desktop' app
- - fixed crash when no app is present
- - fixed some minor bugs
- -- Apps --
- - added 'Desktop' app finally released at a stable point (new versions to come)
- -- File System --
- - fixed bug where computer would crash clearing the bin
- -- Homebrew --
- - fixed glitch that shows data from last app ran
- -- Dino --
- - fixed collision with player and pilon
- - sprites for the dino and pillars are now boxes instead of letters and symbols
- 1.5 (12/16/19)
- -- General --
- - patched some minor things on other apps
- - fixed bug where homebrew displays without the last bar (if 'Homebrew.nfp' doesn't exists)
- - app icons now need to be exactly 6x8 and cannot exeed 60 bytes
- - fixed issue where icons failed to download/update after deleting and restarting the computer
- - app icons no longer need to be downloaded from a separate file
- - fixed minor bug with boot logo
- -- Apps --
- - added 'Landslide' app
- - soon to be added custom app addition where users can add their own programs to the desktop (can be added/removed using 'Desktop' app)
- -- Desktop --
- - now compatable with touch
- - fixed issue where apps would duplicate
- - fixed apps losing the space in their names losing the app image
- - background color is alternative for easier read and better design
- -- File System --
- - fixed major bug where the back button did not display! (opens 'rom' up to be explored)
- -- System Info --
- - fixed bug where 'System OS version' did not display
- - peripherals now display on only 2 lines instead of 4 to fix the bug above and to open more room
- - added 'OS size' to give an idea of how much space the OS takes up
- 1.6 (12/17/19)
- -- General --
- - nothin much yet, just some small patches, tweaks, and ideas to the base of the os
- - pressing 'f1' at boot screen exits to shell (like a bios screen)
- - 'System Info' and 'Lua' have been added to the home menu
- - style for the home menu has been changed to gray and lightblue
- - if a default app is missing from the computer on boot, the computer adds it back to the desktop (ONLY FOR DEFAULT APPS)
- -- Apps --
- - added 'Emu Data' for users using the ccemux emulator
- - new app called 'UPM' still under development soon to be added to manage apps
- - new 'Settings' app soon to be in development
- - might consider a 'Peripheral' app
- - highly considering reverting back to an older version of the 'Desktop' app and updating it
- -- File System --
- - fixed oversight where the user can delete a file and crash the system do to it not existing anymore
- -- Desktop --
- - fixed graphical issue when moving apps
- ]]
- clr()
- local dimg = {
- {
- "boot",
- "",
- " 5557 777777 777777",
- "555557 cccccc7 cccccc",
- " c7 c7 c7 c7",
- " c7 c7 c7 c777777",
- " c7 c7 c7 cccccc7",
- " c7 c7 c7 c7",
- " c7777c7777c7 7777c7",
- " ccccccccccc cccccc",
- "",
- " 777777777777777777777777777777777777777777777",
- " 700007000077000070000707777070000700007700007",
- " 707777077077077770777707777070770707707707777",
- " 700077000077000770007707007070000700007700077",
- " 707777077707077770777707007070770707770707777",
- " 707777077707000070000700000070770707770700007",
- " 777777777777777777777777777777777777777777777"},
- {
- "console",
- "11111111",
- "10fffff1",
- "1f0ffff1",
- "10ff00f1",
- "1ffffff1",
- "11111111"},
- {
- "Crash",
- " bbbb",
- " b0000b",
- "bb0bbbbb",
- "bb0bbbbb",
- " b0000b",
- " bbbb"
- },
- {
- "Desktop",
- "77777777",
- "7e717477",
- "77777777",
- "757b7a77",
- "77777777",
- "d3333333"
- },
- {
- "Dino",
- "77777777",
- "7ffffff7",
- "7f0ffff7",
- "7ffff8f7",
- "70000007",
- "77777777"
- },
- {
- "file",
- "0000",
- "00000",
- "00000",
- "00000",
- "00000"
- },
- {
- "Files",
- "48884444",
- "48884444",
- "44444444",
- "44444444",
- "43333334",
- "43444434"
- },
- {
- "folder",
- "4444",
- "44444",
- "44444",
- "44444",
- "44444"
- },
- {
- "Homebrew",
- "90999909",
- "90999909",
- "90000009",
- "90000009",
- "90999909",
- "90999909"
- },
- {
- "IconEditor",
- "43333333",
- "33ddd333",
- "3ddddd33",
- "333c3333",
- "333c3333",
- "55555555"
- },
- {
- "Lua",
- " bbbb",
- " b0bbbb",
- "bb0bbbbb",
- "bb0bbbbb",
- " b0000b",
- " bbbb"
- },
- {
- "noTexture",
- "bbbbbbbb",
- "bbb0bbbb",
- "b0b0bbbb",
- "b0b0b0bb",
- "b0b0b0bb",
- "bbbbbbbb"
- },
- {
- "Pastebin",
- " 000000",
- "08887000",
- "08087770",
- "08887070",
- "08007770",
- " 000000"
- },
- {
- "Reboot",
- " 77777",
- " 71117",
- " 71717",
- " 71117",
- " 71777",
- " 777"
- },
- {
- "ShellOS",
- "11111111",
- "10fffff1",
- "1f0ffff1",
- "10ff00f1",
- "1ffffff1",
- "11111111"
- },
- {
- "Shutdown",
- " 77777",
- " 7eee7",
- " 7e7e7",
- " 7eee7",
- " 7e777",
- " 777"
- },
- {
- "SystemInfo",
- "44444444",
- "87000078",
- "87700778",
- "87700778",
- "87000078",
- "44444444"
- },
- {
- "Worm",
- " 777777",
- "7777ddd7",
- "7e77d777",
- "7777d777",
- "7dddd7e7",
- " 777777"
- },
- {
- "Adventure",
- " 777777",
- "77000077",
- "77077077",
- "77000077",
- "77077077",
- " 777777"
- },
- {
- "Landslide",
- " cccccc ",
- "cc0ccccc",
- "cc0ccccc",
- "cc0ccccc",
- "cc0000cc",
- " cccccc "
- },
- {
- "EmuData",
- " 788887 ",
- "74444447",
- "84444448",
- "84333348",
- "74344347",
- " 788887 "
- }
- }
- local sprite_dir = dir.."sprites/"
- if not fs.exists(dir) or not fs.exists(dir.."sprites") then -- download images
- setText("black") setBack("black") cp(1,-4)
- if fs.exists("freeware/sprites/imageDownload.lua") then -- passed
- shell.run("freeware/sprites/imageDownload.lua")
- else -- failed
- parallel.waitForAny(function() sleep(5) end, function() shell.run("pastebin get ym6K6bLU freeware/sprites/imageDownload.lua") end)
- if fs.exists("freeware/sprites/imageDownload.lua") then -- passed
- shell.run("pastebin run LYMPVbUw")
- else -- failed
- -- nothing
- end
- end
- end
- for i=1, #dimg do
- if not fs.exists(sprite_dir..dimg[i][1]..".nfp") then
- local file = fs.open(sprite_dir..dimg[i][1]..".nfp", "w")
- for ii=1, #dimg[i]-1 do
- file.writeLine(dimg[i][ii+1])
- end
- file.close()
- end
- end
- -- Boot Screen --
- clr()
- local boot = paintutils.loadImage(sprite_dir.."boot.nfp")
- paintutils.drawImage(boot,2,2)
- local bypass = 0
- parallel.waitForAny(function() sleep(1) end, function() repeat a,bypass = os.pullEvent("key") until bypass == 59 end)
- if bypass ~= 0 then if bypass == 59 then setText("white") setBack("black") clr() cp(1,1) return print("Bypass") end end
- -- Boot Screen --
- noTexture = paintutils.loadImage(sprite_dir.."noTexture.nfp")
- fileTexture = paintutils.loadImage(sprite_dir.."file.nfp")
- folderTexture = paintutils.loadImage(sprite_dir.."folder.nfp")
- if noTexture == nil then error("Failed to load noTexture") end
- maxAppName = 12
- function loadApp(name, path)
- if type(name) ~= "string" then return error("Expected string for name, got "..type(name)) end
- if type(path) ~= "string" then return error("Expected string for path, got "..type(path)) end
- if string.len(name) >= maxAppName then return false end
- if fs.exists(path..".nfp") then
- if fs.getSize(path..".nfp") <= 60 then
- local file = fs.open(path..".nfp","r")
- local preLoad = {}
- local tmp
- repeat
- tmp = file.readLine()
- if tmp ~= nil then preLoad[#preLoad+1] = tmp end
- until tmp == nil
- file.close()
- local longestTerm = 1
- for i=1, #preLoad do
- if string.len(preLoad[i]) > longestTerm then longestTerm = string.len(preLoad[i]) end
- end
- if #preLoad <= 6 and longestTerm <= 8 then
- apps[#apps+1] = {name, paintutils.loadImage(path..".nfp")}
- end
- end
- else
- apps[#apps+1] = {name, noTexture}
- end
- end
- -- OS --
- bar_color = "lightBlue"
- home_color = "green"
- desktop_color = "black"
- scroll_color = "gray"
- scroll_text_color = "white"
- title_color = "white"
- home_menu_color = "gray"
- home_menu_text_color = "lightBlue"
- dScroll = true
- dBar = true
- dApps = true
- home = false
- local debug = false
- local running = true
- local update = true
- apps = {}
- loaded_apps = {}
- user_apps = {}
- app_selected = 1
- local load_order = {}
- local app_dir = dir.."apps/"
- local tmp_lo = {}
- local tmp_s = {}
- local default_apps = {"ShellOS", "Homebrew", "Desktop", "Files", "UPM", "Pastebin", "Lua", "Reboot", "Shutdown", "System Info", "Worm", "Adventure", "Dino", "Landslide", "Crash", "Connect"}
- if fs.exists(app_dir.."load_order.lua") then
- local file = fs.open(app_dir.."load_order.lua","r")
- repeat
- tmp = file.readLine()
- if tmp ~= nil then
- tmp_lo[#tmp_lo+1] = tmp
- end
- until tmp == nil
- file.close()
- else
- tmp_lo = default_apps
- local a,i = pcall(function() ccemux.getVersion() end)
- if a then
- table.insert(tmp_lo, "Emu Data")
- end
- end
- for i=1, #default_apps do
- local exists = false
- for ii=1, #tmp_lo do
- if tmp_lo[ii] == default_apps[i] then exists = true end
- end
- if not exists then
- table.insert(tmp_lo, default_apps[i])
- end
- end
- if fs.exists(app_dir.."status.lua") then
- local file = fs.open(app_dir.."status.lua","r")
- repeat
- tmp = file.readLine()
- if tmp ~= nil then
- tmp_s[#tmp_s+1] = tonumber(tmp)
- end
- until tmp == nil
- file.close()
- else
- tmp_s = {}
- for i=1, #tmp_lo do tmp_s[#tmp_s+1] = 1 end
- end
- if #tmp_s < #tmp_lo then
- for i=1, #tmp_lo-#tmp_s do
- table.insert(tmp_s, 1.0)
- end
- end
- --[[
- if fs.exists(app_dir.."user_apps.lua") then
- local file = fs.open(app_dir.."user_apps.lua","r")
- repeat
- tmp = file.readLine()
- tmp2 = file.readLine()
- if tmp ~= nil and tmp2 ~= nil then
- user_apps[#user_apps+1] = {0, tmp, tmp2}
- end
- until tmp == nil or tmp2 == nil
- file.close()
- end
- ]]
- function loadUserApps()
- user_apps = {}
- if fs.exists(app_dir.."user_apps.lua") then
- local file = fs.open(app_dir.."user_apps.lua", "r")
- repeat
- tmp = file.readLine()
- tmp2 = file.readLine()
- if tmp ~= nil then
- table.insert(user_apps, {0,tmp,tmp2})
- end
- until tmp == nil
- file.close()
- return true
- end
- return false
- end
- function saveUserApps()
- if fs.exists(app_dir.."user_apps.lua") then fs.delete(app_dir.."user_apps.lua") end
- local file = fs.open(app_dir.."user_apps.lua", "w")
- for i=1, #user_apps do
- file.writeLine(user_apps[i][2])
- file.writeLine(user_apps[i][3])
- end
- file.close()
- end
- loadUserApps()
- function updateApps(new_load_order, new_status)
- load_order = {}
- apps = {}
- local skip = false
- for i=1, #new_load_order do
- for ii=1, #load_order do
- if new_load_order[i][1] == load_order[ii][1] then
- skip = true
- end
- end
- if not skip then
- if new_status ~= nil then
- table.insert(load_order, {new_load_order[i], new_status[i]})
- else
- table.insert(load_order, {new_load_order[i][1], new_load_order[i][2]})
- end
- if new_status ~= nil then
- if new_status[i] == 1 then loadApp(new_load_order[i], sprite_dir..new_load_order[i]) end
- else
- if new_load_order[i][2] == 1 then loadApp(new_load_order[i][1], sprite_dir..new_load_order[i][1]) end
- end
- else
- skip = false
- end
- end
- for i=1, #user_apps do
- if user_apps[i][2] == load_order[i][1] then
- user_apps[i][1] = i
- end
- end
- maxPage = math.ceil(#apps/6)
- current_page = 1
- end
- -- Load Order Contains: {name, status} (for each app)
- updateApps(tmp_lo, tmp_s)
- function AppIndex(name)
- for i=1, #load_order do
- if load_order[i][1] == name then
- return i
- end
- end
- return false
- end
- function toggleApp(name)
- name = AppIndex(name)
- if name == false then return false end
- if load_order[name][2] ~= nil then
- if load_order[name][2] == 1 then
- load_order[name][2] = 0
- else
- load_order[name][2] = 1
- end
- end
- end
- --toggleApp("Homebrew")
- --toggleApp("Shutdown")
- --toggleApp("Desktop")
- --[[
- for i=1, 31 do
- load_order[#load_order+1] = {"Debug "..i, 1}
- end
- updateApps(load_order)
- ]]
- function appLoader()
- apps = {}
- for i=1, #load_order do
- if load_order[i][2] == 1 then
- loadApp(load_order[i][1], sprite_dir..string.gsub(load_order[i][1], " ", ""))
- end
- end
- end
- appLoader()
- for i=1, 6 do
- loaded_apps[i] = apps[i]
- end
- maxPage = math.ceil(#apps/6)
- current_page = 1
- if #apps == 0 then error("no apps loaded") end
- --[[
- print("Apps: "..#apps)
- print("Pages: "..maxPage)
- print("Current Page: "..current_page)
- print("Apps/Current Page: "..#apps/current_page)
- error()
- ]]
- function drawBar()
- if dBar then
- cp(1,h)
- setBack(home_color)
- write(" ")
- setBack(bar_color)
- for i=1, w-1 do
- write(" ")
- end
- setText("black") cp(2,h) write(current_page.."/"..maxPage)
- else
- cp(1,h)
- setBack(desktop_color)
- term.clearLine()
- end
- cp(1,1)
- end
- function drawScreen()
- setBack(desktop_color)
- for i=1, h-1 do
- cp(1,i)
- term.clearLine()
- end
- if dScroll then
- setBack(scroll_color)
- for i=1, 6 do
- cp(1,h/2-i+4)
- write(" ")
- end
- for i=1, 6 do
- cp(w, h/2-i+4)
- write(" ")
- end
- setText(scroll_text_color)
- cp(1,h/2-3)
- write("<")
- cp(1,h/2+3)
- write("<")
- cp(w,h/2-3)
- write(">")
- cp(w,h/2+3)
- write(">")
- end
- end
- function toggleScroll()
- dScroll = not dScroll
- end
- function toggleBar()
- dBar = not dBar
- end
- function toggleApps()
- dApps = not dApps
- end
- function toggleHome()
- home = not home
- end
- local app_locations = {8,22,36} -- the x positions
- function updateApps()
- loaded_apps = {}
- for i=1, 6 do
- loaded_apps[i] = apps[i+(6*(current_page-1))]
- end
- end
- function drawApps()
- if dApps then
- setText(title_color) -- just text color (no biggy)
- updateApps()
- for i=1, #loaded_apps do
- if i <= 3 then -- top
- setBack(desktop_color)
- cp(app_locations[i], 1) write(loaded_apps[i][1])
- paintutils.drawImage(loaded_apps[i][2], app_locations[i], 2)
- else -- bottom
- setBack(desktop_color)
- cp(app_locations[i-3], h-8) write(loaded_apps[i][1])
- paintutils.drawImage(loaded_apps[i][2], app_locations[i-3], h-7)
- end
- end
- end
- end
- home_options = {"System Info","ShellOS", "Lua", "Reboot", "Shutdown", "Files"}
- home_options_lt_f = function()
- local tmp = 1
- for i=1, #home_options do
- if string.len(home_options[i]) > tmp then
- tmp = string.len(home_options[i])
- end
- end
- return tmp
- end
- function drawHome()
- if home then
- setBack(home_menu_color)
- setText(home_menu_text_color)
- local tmp = home_options_lt_f()
- for i=1, #home_options do
- cp(1,h-i)
- for i=1, tmp+2 do
- write(" ")
- end
- end
- for i=1, #home_options do
- cp(1,h-i)
- write(home_options[i])
- end
- end
- end
- function updateFiles(fPath)
- local fFiles = fs.list(fPath)
- local directory,readonly,file = {}, {}, {}
- for i=1, #fFiles do
- if fs.isReadOnly(fPath..fFiles[i]) then
- readonly[#readonly+1] = fFiles[i]
- elseif fs.isDir(fPath..fFiles[i]) then
- directory[#directory+1] = fFiles[i]
- else
- file[#file+1] = fFiles[i]
- end
- end
- fFiles = directory
- for i=1, #readonly do
- fFiles[#fFiles+1] = readonly[i]
- end
- for i=1, #file do
- fFiles[#fFiles+1] = file[i]
- end
- return fFiles
- end
- function displayFiles(path, files)
- setText("white")
- local bg = false
- path = path.."/"
- for i=1, #files do
- cp(1,i)
- if bg then
- bg = not bg
- setBack("black")
- else
- bg = not bg
- setBack("gray")
- end
- if files[i] == "..." then
- setText("orange")
- elseif fs.isReadOnly(path..files[i]) then
- setText("red")
- elseif fs.isDir(path..files[i]) and files[i] == "bin" and path == "/" then
- setText("purple")
- elseif fs.isDir(path..files[i]) then
- setText("yellow")
- else
- setText("white")
- end
- if string.len(files[i]) >= 25 then
- local tmp = string.sub(files[i], 20)
- files[i] = string.gsub(files[i], tmp, "...")
- end
- write(files[i])
- for i=1, math.ceil((w/2-string.len(files[i]))+string.len(files[i])) do
- write(" ")
- end
- end
- setText("white")
- end
- function math.round(v, bracket)
- bracket = bracket or 1
- return math.floor(v/bracket + (v >= 0 and 1) or -1 * 0.5) * bracket
- end
- function drawInfoScreen(file, options)
- setBack("black") clr()
- if fs.isDir(file) then
- paintutils.drawImage(folderTexture, 1,1) setBack("black")
- cp(1,8) setText("white") write("File type: ") setText("yellow") write("Directory")
- else
- paintutils.drawImage(fileTexture, 1,1) setBack("black")
- end
- cp(1,9)
- setText("white") write("File Name: ") setText("yellow") print(fs.getName(file))
- setText("white") write("Directory: ") setText("yellow") print(file)
- if not fs.isDir(file) then
- setText("white") write("Size: ") setText("yellow")
- if fs.getSize(file) >= 1000 then
- print(math.round((fs.getSize(file)/1000), 0.1).." KB")
- else
- print(fs.getSize(file).." Bytes")
- end
- end
- setBack("gray")
- setText("white")
- for i=1, #options do
- cp(1,12+i)
- write(options[i])
- for i=1, w-string.len(options[i]) do
- write(" ")
- end
- end
- end
- function loadInfo(file)
- local options = {}
- if fs.isDir(file) and file == "/bin" then
- -- Bin Exclusive
- if #fs.list("bin") > 0 then table.insert(options, "Clear Bin") end
- elseif fs.isDir(file) and file ~= "/rom" then
- -- Dir Exclusive
- if not fs.exists("bin/"..fs.getName(file)) then
- table.insert(options, "Delete")
- end
- elseif fs.isReadOnly(file) then
- -- Read Only Exclusive
- elseif string.sub(file, -3) == "nfp" then
- -- Paint Exclusive
- table.insert(options, "Paint")
- table.insert(options, "Edit")
- if not fs.exists("bin/"..fs.getName(file)) then
- table.insert(options, "Delete")
- end
- elseif string.sub(file, -3) == "lua" then
- -- Lua Exclusive
- table.insert(options, "Run")
- table.insert(options, "Edit")
- if not fs.exists("bin/"..fs.getName(file)) then
- table.insert(options, "Delete")
- end
- else
- -- File Exclusive
- table.insert(options, "Run")
- if not fs.exists("bin/"..fs.getName(file)) then
- table.insert(options, "Delete")
- end
- end
- table.insert(options, "Close")
- local run = true
- while run do
- if not fs.exists(file) then return false end
- drawInfoScreen(file, options)
- a,i,x,y = os.pullEvent("mouse_click")
- if i == 1 then
- if y >= 13 and y <= 12+#options then
- if options[y] == "Close" then
- run = false
- else
- if options[y-12] == "Edit" then
- shell.run("edit "..file)
- elseif options[y-12] == "Paint" then
- shell.run("paint "..file)
- elseif options[y-12] == "Run" then
- setText("white") setBack("black") shell.run(file)
- elseif options[y-12] == "Delete" then
- --error()
- fs.move(file, "/bin/"..fs.getName(file)) run = false
- elseif options[y-12] == "Clear Bin" then
- local bin_list = fs.list("/bin/")
- for i=1, #bin_list do
- fs.delete("bin/"..bin_list[i])
- end
- run = false
- else
- run = false
- end
- end
- end
- end
- end
- end
- function drawRightClickMenu(xpos, ypos, options)
- --
- end
- function rightClick(xpos, ypos, file)
- loadInfo(file)
- -- Add Right Click (4 Quads)
- -- Add Copy
- -- Add Paste
- -- Add Restore
- -- Add Perm Delete
- end
- function fileProgram()
- local cPath = ""
- local cTable = {}
- local cUpdate = true
- local scroll = 0
- local displayedFiles = {}
- local loadedFiles = {}
- local run = true
- while run do
- if cUpdate then
- cUpdate = not cUpdate
- scroll = 0
- setBack("black") clr()
- paintutils.drawLine(1,h,w,h,colors["lightGray"])
- paintutils.drawPixel(w,h,colors["red"])
- cPath = ""
- for i=1, #cTable do
- cPath = cPath.."/"..cTable[i]
- end
- local tmmp = cPath
- if string.len(cPath) >= 23 then
- local tmp = string.sub(cPath, 18)
- tmmp = string.gsub(cPath, tmp, "...")
- end
- cp(1,h) setBack("lightGray") setText("white") write(tmmp) setBack("black")
- loadedFiles = updateFiles(cPath)
- if #cTable > 0 then table.insert(loadedFiles, "...") end
- end
- displayedFiles = {}
- if #loadedFiles <= h-1 then
- displayedFiles = loadedFiles
- else
- for i=1, h-1 do
- displayedFiles[#displayedFiles+1] = loadedFiles[i+scroll]
- end
- end
- displayFiles(cPath, displayedFiles)
- a,i,x,y = os.pullEvent()
- if a == "mouse_click" then
- if i == 1 then -- left
- if x == w and y == h then
- run = false
- else
- if y <= #displayedFiles--[[ and cPath..displayedFiles[y] ~= "rom" ]]then
- if displayedFiles[y] == "..." then
- table.remove(cTable, #cTable) cUpdate = true
- elseif fs.isDir(cPath.."/"..displayedFiles[y]) then
- table.insert(cTable, displayedFiles[y]) cUpdate = true
- else
- if fs.exists(cPath.."/"..displayedFiles[y]) then
- loadInfo(cPath.."/"..displayedFiles[y])
- end
- cUpdate = true
- end
- end
- end
- elseif i == 2 then -- right
- if y <= #displayedFiles then
- --loadInfo(cPath.."/"..displayedFiles[y]) cUpdate = true
- rightClick(x, y, cPath.."/"..displayedFiles[y]) cUpdate = true
- end
- end
- elseif a == "mouse_scroll" then
- if i == 1 and scroll ~= #loadedFiles-h+1 then -- down
- scroll = scroll + 1
- elseif i == -1 and scroll ~= 0 then -- up
- scroll = scroll - 1
- end
- end
- end
- update = true
- end
- function playLandslide()
- -- Landslide --
- -- Just Does Games --
- term.clear()
- local x,y = term.getSize()
- local px = math.ceil(x/2)
- local rocks = {} -- Rock Data: {rock x, rock y, id}
- local maxRocks = 100
- local run = true
- local difficulty = {.1,.4}
- local gamespeed = 0.3
- local score = 0
- local maxGamespeed = 0.01
- local maxScore = 999999999
- local alt = true
- local function drawRedBar()
- term.setCursorPos(1,y-3)
- term.setBackgroundColor(colors["red"])
- term.clearLine() print("")
- term.clearLine()
- end
- local function drawRocks()
- if score > 500 then
- -- Do nothing
- elseif score > 400 then
- if alt then
- term.setCursorPos(1,y-3)
- for i=1, math.floor(x/2) do
- write(" !")
- end
- term.setCursorPos(1,y-2)
- for i=1, math.floor(x/2) do
- write("! ")
- end
- else
- term.setCursorPos(1,y-3)
- for i=1, math.floor(x/2) do
- write(" ")
- end
- term.setCursorPos(1,y-2)
- for i=1, math.floor(x/2) do
- write(" ")
- end
- end
- alt = not alt
- end
- for i=1, #rocks do
- term.setCursorPos(rocks[i][1],rocks[i][2]) term.setBackgroundColor(colors["lightGray"]) write(" ")
- if rocks[i][2] ~= y+1 then
- term.setCursorPos(rocks[i][1],rocks[i][2]-1) term.setBackgroundColor(colors["black"]) write(" ")
- end
- if rocks[i] ~= nil then
- if px == rocks[i][1] and rocks[i][2] == y then run = false end
- end
- end
- if score > 500 then
- drawRedBar()
- end
- end
- local function drawPlayer()
- term.setCursorPos(px,y) term.setBackgroundColor(colors["white"]) write(" ")
- if px ~= x then
- term.setCursorPos(px+1,y) term.setBackgroundColor(colors["black"]) write(" ")
- end
- if px ~= 1 then
- term.setCursorPos(px-1,y) term.setBackgroundColor(colors["black"]) write(" ")
- end
- end
- drawPlayer()
- local function spawnRock()
- if maxRocks ~= #rocks then
- table.insert(rocks, {math.random(1,x),0})
- end
- end
- local function destroyRock(rock)
- term.setCursorPos(rock[1],rock[2]) term.setBackgroundColor(colors["black"]) write(" ")
- table.remove(rocks, 1)
- if score ~= maxScore then score = score + 1 end
- if gamespeed < maxGamespeed then
- if score > 200 then
- gamespeed = gamespeed - 0.01
- elseif score > 400 then
- gamespeed = gamespeed - 0.02
- else
- gamespeed = gamespeed - 0.03
- end
- elseif gamespeed < 0 then
- gamespeed = maxGamespeed
- end
- end
- local function engine1() -- player location
- while run do
- sleep(.0001)
- local a,i = os.pullEvent("key")
- if a == "key" then
- if i == keys.a or i == keys.left then
- if px ~= 1 then
- px = px - 1
- end
- elseif i == keys.d or i == keys.right then
- if px ~= x then
- px = px + 1
- end
- end
- end
- for i=1, #rocks do
- if rocks[i] ~= nil then
- if px == rocks[i][1] and rocks[i][2] == y then run = false end
- end
- end
- drawPlayer()
- end
- end
- local function engine2() -- rock spawner
- while true do
- sleep(math.random(difficulty[1],difficulty[2]))
- spawnRock()
- end
- end
- local function engine3() -- rock manager
- while run do
- local rocksToDestroy = {}
- for i=1, #rocks do
- if rocks[i] ~= nil then
- if rocks[i][2] ~= y+1 then
- rocks[i][2] = rocks[i][2] + 1
- else
- table.insert(rocksToDestroy, rocks[i])
- end
- end
- end
- drawRocks()
- for i=1, #rocksToDestroy do
- destroyRock(rocksToDestroy[i])
- end
- for i=1, #rocks do
- if rocks[i] ~= nil then
- if px == rocks[i][1] and rocks[i][2] == y then run = false end
- end
- end
- sleep(gamespeed)
- end
- end
- local function gameover()
- sleep(.5)
- term.setTextColor(colors["white"])
- term.setBackgroundColor(colors["black"])
- term.clear()
- term.setCursorPos(x/2-(string.len("Game Over")/2), y/2-1)
- write("Game Over")
- term.setCursorPos(x/2-(string.len("Score - "..score)/2), y/2)
- write("Score - "..score)
- sleep(1)
- term.setCursorPos(x/2-(string.len("Press any key to exit...")/2), y/2+3)
- write("Press any key to exit...")
- os.pullEvent()
- end
- local function loop()
- parallel.waitForAny(engine1,engine2,engine3)
- gameover()
- end
- loop()
- end
- function playDino()
- -- Dino Jump --
- -- Just Does Games --
- local x,y = term.getSize()
- local objects = {} -- {x pos, y pos, col}
- local objMax = 10
- local objSpawnSpeed = {1.1,3.3}
- local score = 0
- local jumps = 0
- local speed = .09
- local _px,_py = 2,y-1
- local s_object = "I"
- local run = true
- term.setTextColor(colors["white"])
- term.clear()
- local function drawObjects()
- for i=1, #objects do
- term.setCursorPos(objects[i][1], objects[i][2]) setBack("lightGray") write(" ") setBack("black")
- if objects[i][2] ~= w then
- term.setCursorPos(objects[i][1]+1, objects[i][2]) write(" ")
- end
- if objects[i][1] == _px and objects[i][2] == _py then
- run = false
- end
- end
- end
- local function drawDino()
- term.setCursorPos(_px,_py) setBack("white") write(" ") setBack("black")
- term.setCursorPos(_px,_py-1) write(" ")
- if _py ~= y-1 then
- term.setCursorPos(_px,_py+1) write(" ")
- end
- term.setCursorPos(1,1)
- print("Score: "..score)
- print("Jumps: "..jumps)
- end
- drawDino()
- paintutils.drawLine(1,y,x,y,colors["white"])
- term.setBackgroundColor(colors["black"])
- local function createObject()
- if #objects < objMax then
- table.insert(objects, {x,y-1,"yellow"})
- end
- end
- local function destroyObject()
- term.setCursorPos(objects[1][1],objects[1][2]) write(" ")
- table.remove(objects,1)
- score = score + 1
- if score > 50 then
- speed = 0.04
- objSpawnSpeed = {.8,1.3}
- elseif score > 30 then
- speed = 0.05
- objSpawnSpeed = {.9,1.5}
- elseif score > 20 then
- speed = 0.06
- objSpawnSpeed = {1,2}
- elseif score > 10 then
- speed = 0.07
- objSpawnSpeed = {1.1,3.3}
- elseif score > 5 then
- speed = 0.08
- objSpawnSpeed = {1.1,3.3}
- end
- end
- local function engine1() -- player & col
- while run do
- sleep(.0001)
- local a,i = os.pullEvent("key")
- if i == keys.space then
- jumps = jumps + 1
- _py = _py - 1 drawDino() sleep(.1)
- _py = _py - 1 drawDino() sleep(.1)
- _py = _py - 1 drawDino() sleep(.2)
- _py = _py + 1 drawDino() sleep(.1)
- _py = _py + 1 drawDino() sleep(.1)
- _py = _py + 1 drawDino() sleep(.05)
- term.setCursorPos(1,1)
- print("Score: "..score)
- print("Jumps: "..jumps)
- for i=1, #objects do
- if objects[i][1] == _px and objects[i][2] == _py then
- run = false
- end
- end
- elseif i == keys.q then
- run = false
- end
- end
- end
- local function engine2() -- objects
- while true do
- sleep(math.random(objSpawnSpeed[1],objSpawnSpeed[2]))
- createObject()
- end
- end
- local function engine3() -- object spawn and despawn
- while run do
- if #objects > 0 then
- for i=1, #objects do
- if objects[i] ~= nil then
- if objects[i][1] == 1 then
- destroyObject()
- else
- objects[i][1] = objects[i][1] - 1
- end
- end
- end
- drawObjects()
- end
- sleep(speed)
- for i=1, #objects do
- if objects[i][1] == _px and objects[i][2] == _py then
- run = false
- end
- end
- end
- end
- local function gameover()
- term.clear()
- term.setCursorPos(x/2-string.len("Game Over")/2,y/2-3)
- write("Game Over")
- term.setCursorPos(x/2-string.len("Score: "..score)/2,y/2-1)
- write("Score: "..score)
- term.setCursorPos(x/2-string.len("Jumps: "..jumps)/2,y/2)
- write("Jumps: "..jumps)
- sleep(1)
- term.setCursorPos(x/2-string.len("Press any key to continue...")/2,y/2+2)
- write("Press any key to continue...")
- os.pullEvent()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function loop()
- parallel.waitForAny(engine1,engine2,engine3)
- gameover()
- end
- loop()
- end
- function playConnect()
- cp(1,1) setText("white") setBack("black") clr() write("Running game...") sleep(1)
- shell.run("games/connect/main.lua")
- sleep(1)
- os.pullEvent()
- end
- function pbrun(code, action, name)
- if code == nil then
- return "Invalid Code"
- elseif string.len(code) < 8 then
- return "Invalid Code Length."
- elseif action == "get" and name == nil or name == "" then
- return "File Name Missing."
- elseif name ~= nil then
- if fs.exists(name) then
- return "File Already Exists"
- end
- end
- term.setCursorBlink(false)
- cp(1,h-3) setBack("white") setText("white")
- if action == "run" then
- cp(1,1) setText("white") setBack("black") clr()
- return shell.run("pastebin "..action.." "..code)
- elseif action == "get" then
- return shell.run("pastebin "..action.." "..code.." "..name)
- end
- end
- function pastebinProgram()
- term.setCursorBlink(true)
- local buttonToggle = true
- local updat = true
- local chars = ""
- local charSelected = true
- local fsSelected = false
- local fsPath = ""
- local runPB = false
- local stattoggle = true
- local statm = ""
- local run = true
- while run do
- if runPB then
- runPB = false
- local res
- setBack("white")
- cp(6,14+string.len("GO Status: ")) setText("orange") write("Running...")
- if buttonToggle then
- res = pbrun(chars, "get", fsPath)
- else
- res = pbrun(chars, "run")
- end
- term.setCursorBlink(true)
- if res ~= true then
- statm = res
- else
- statm = "Success!"
- end
- setText("black")
- end
- if updat then
- updat = not updat
- cp(1,1)
- setText("black")
- setBack("white")
- clr()
- paintutils.drawLine(1,1,w,1,colors["lightGray"])
- cp(1,3)
- setBack("white")
- write("Pastebin Code: ")
- setBack("lightGray")
- for i=1, 9 do write(" ") end
- if buttonToggle then
- paintutils.drawFilledBox(5,5,10,8,colors["green"])
- cp(6,6) write("Get")
- paintutils.drawFilledBox(12,5,17,8,colors["gray"])
- cp(13,6) write("Run")
- else
- paintutils.drawFilledBox(5,5,10,8,colors["gray"])
- cp(6,6) write("Get")
- paintutils.drawFilledBox(12,5,17,8,colors["green"])
- cp(13,6) write("Run")
- end
- paintutils.drawFilledBox(5,12,10,15,colors["lime"])
- cp(6,13) write("GO ")
- setBack("white") write(" Status: ")
- if stattoggle then setText("green") else setText("red") end
- write(statm) setText("black")
- if buttonToggle then
- cp(1,10)
- setBack("white")
- write("File Name: ")
- setBack("lightGray")
- for i=1, w-string.len("File Name: ") do
- write(" ")
- end
- end
- end
- setBack("lightGray")
- cp(string.len("Pastebin Code: ")+1,3)
- write(chars.." ")
- cp(string.len("Pastebin Code: ")+1+string.len(chars),3)
- if buttonToggle then
- cp(string.len("File Name: ")+1,10)
- write(fsPath.." ")
- if charSelected then
- cp(string.len("Pastebin Code: ")+1+#chars, 3)
- else
- cp(string.len("File Name: ")+1+string.len(fsPath), 10)
- end
- end
- a,i,x,y = os.pullEvent()
- if a == "mouse_click" then
- if i == 1 then
- if x >= string.len("Pastebin Code: ")+1 and x <= string.len("Pastebin Code: ")+9 and y == 3 then
- term.setCursorBlink(true)
- fsSelected = false
- charSelected = true
- elseif x >= string.len("File Name: ")+1 and y == 10 and buttonToggle then
- term.setCursorBlink(true)
- fsSelected = true
- charSelected = false
- else
- term.setCursorBlink(false)
- charSelected = false
- if x >= 5 and x <= 10 and y >= 5 and y <= 8 then
- buttonToggle = true updat = true
- elseif x >= 12 and x <= 17 and y >= 5 and y <= 8 then
- buttonToggle = false updat = true
- end
- end
- end
- elseif a == "paste" then
- if charSelected then
- if string.len(chars..i) <= 8 then chars = chars..i end
- elseif fsSelected then
- if string.len(fsPath..i) < w-string.len("File Name: ")-1 then fsPath = fsPath..i end
- end
- elseif a == "char" then
- if i ~= " " then
- if charSelected then
- if string.len(chars) ~= 8 then chars = chars..i end
- else
- if string.len(fsPath) < w-string.len("File Name: ")-1 then fsPath = fsPath..i end
- end
- end
- elseif a == "key" then
- if i == keys.backspace and charSelected then
- chars = string.sub(chars,1,-2)
- elseif i == keys.backspace and fsSelected then
- fsPath = string.sub(fsPath,1,-2)
- elseif i == keys.enter or i == keys.tab then
- if charSelected then
- charSelected = false
- if buttonToggle then
- fsSelected = true
- else
- runPB = true updat = true
- end
- elseif fsSelected then
- runPB = true updat = true
- end
- end
- end
- end
- term.setCursorBlink(false)
- end
- function moveDesktopApp(selected, app_list, scroll)
- local sw,sh = term.getSize()
- local currently_displaying = {}
- local run = true
- local fr = false -- used to keep scroll from reseting when first running this
- local updat = true
- local bg = true
- while run do
- if #app_list > sh then
- for i=1, sh do
- currently_displaying[i] = app_list[i+scroll]
- end
- else
- currently_displaying = app_list
- end
- -- Update Apps --
- load_order = {}
- apps = {}
- for i=1, #app_list do
- table.insert(load_order, {app_list[i][1], app_list[i][2]})
- if app_list[i][2] == 1 then loadApp(app_list[i][1], sprite_dir..string.gsub(app_list[i][1]," ","")) end
- end
- maxPage = math.ceil(#apps/6)
- current_page = 1
- -- Update Apps --
- -- Save Settings --
- if fs.exists(app_dir.."load_order.lua") then
- fs.delete(app_dir.."load_order.lua")
- end
- if fs.exists(app_dir.."status.lua") then
- fs.delete(app_dir.."status.lua")
- end
- local file = fs.open(app_dir.."load_order.lua", "w")
- for i=1, #app_list do
- file.writeLine(app_list[i][1])
- end
- file.close()
- local file = fs.open(app_dir.."status.lua", "w")
- for i=1, #app_list do
- file.writeLine(app_list[i][2])
- end
- file.close()
- -- Save Settings --
- -- Update Screen --
- if updat then
- updat = not updat
- if not fr then
- fr = not fr
- scroll = 0
- setBack("black") clr()
- end
- --paintutils.drawLine(1,h,w,h,colors["lightGray"])
- --paintutils.drawPixel(w,h,colors["red"])
- cp(1,1)
- bg = true
- for i=1, #currently_displaying do
- if bg then setBack("black") else setBack("gray") end bg = not bg
- if i == selected then
- setText("yellow")
- write("> ")
- end
- if currently_displaying[i][1] == "ShellOS" or currently_displaying[i][1] == "Desktop" then
- setText("purple")
- else
- if currently_displaying[i][2] == 1 then
- setText("green")
- else
- setText("red")
- end
- end
- print(currently_displaying[i][1].." ")
- end
- end
- -- Update Screen --
- sleep(.00001)
- a,i,x,y = os.pullEvent("key")
- if i == keys.w or i == keys.up then
- if selected ~= 1 then
- if selected ~= 1 then
- local tmp = app_list[selected+scroll]
- local tmp2 = app_list[selected+scroll-1]
- app_list[selected+scroll] = tmp2
- app_list[selected+scroll-1] = tmp
- if selected == 3 and scroll ~= 0 then
- scroll = scroll - 1
- elseif selected ~= 1 then
- selected = selected - 1
- end
- end
- end
- elseif i == keys.s or i == keys.down then
- if selected ~= #app_list-scroll then
- local tmp = app_list[selected+scroll]
- local tmp2 = app_list[selected+scroll+1]
- app_list[selected+scroll] = tmp2
- app_list[selected+scroll+1] = tmp
- if selected == sh-2 and scroll ~= #app_list-sh then
- scroll = scroll + 1
- elseif selected ~= #app_list-scroll then
- selected = selected + 1
- end
- end
- elseif i == keys.d or i == keys.right or i == keys.a or i == keys.left then
- if app_list[selected+scroll][1] ~= "ShellOS" or app_list[selected+scroll][1] ~= "Desktop" then
- if app_list[selected+scroll][2] == 1 then
- app_list[selected+scroll][2] = 0
- else
- app_list[selected+scroll][2] = 1
- end
- end
- elseif i == keys.enter or i == keys.e then
- return true
- end
- updat = true
- end
- end
- function loadDesktopinfo(dt_app_location)
- local options = {}
- cp(1,1) setText("white") setBack("black") clr()
- write("App: ")
- if dt_app_location[1] == "ShellOS" or dt_app_location[1] == "Desktop" then
- setText("purple")
- else
- if dt_app_location[2] == 1 then
- setText("green")
- table.insert(options, "Hide")
- else
- setText("red")
- table.insert(options, "Show")
- end
- end
- for i=1, #user_apps do
- if dt_app_location[1] == user_apps[i][2] then
- if options[#options] ~= "Remove" then
- table.insert(options, "Remove")
- end
- end
- end
- table.insert(options, "Move")
- table.insert(options, "Exit")
- print(dt_app_location[1]) setText("white") cp(1,4)
- for i=1, #options do
- print(options[i])
- end
- local lx,ly
- repeat
- a,i,lx,ly = os.pullEvent("mouse_click")
- until ly >= 4 and ly <= #options+3
- ly = ly - 3
- if options[ly] == "Exit" then
- return ""
- elseif options[ly] == "Show" or options[ly] == "Hide" then
- return "toggle"
- elseif options[ly] == "Remove" then
- -- Delete an option
- return "remove"
- elseif options[ly] == "Move" then
- return "move"
- end
- end
- function desktopProgram()
- -- app manager for moving apps to places and removing them as needed. (could use this to create new apps)
- -- load_order contains: {name, status} (each app)
- local sw,sh = term.getSize()
- local new_load_order = load_order
- local run = true
- local updat = true
- print("-")
- local scroll = 0
- local options_displayed = {}
- local editing = false
- local selected = 1
- local bg = true
- while run do
- if #new_load_order > sh then
- for i=1, sh do
- options_displayed[i] = new_load_order[i+scroll]
- end
- else
- options_displayed = new_load_order
- end
- -- Update Apps --
- load_order = {}
- apps = {}
- for i=1, #new_load_order do
- --new_load_order[i][1] = string.gsub(new_load_order[i][1], " ", "")
- if new_status ~= nil then
- table.insert(load_order, {new_load_order[i], new_status[i]})
- else
- table.insert(load_order, {new_load_order[i][1], new_load_order[i][2]})
- end
- if new_status ~= nil then
- if new_status[i] == 1 then loadApp(new_load_order[i], sprite_dir..new_load_order[i]) end
- else
- if new_load_order[i][2] == 1 then loadApp(new_load_order[i][1], sprite_dir..string.gsub(new_load_order[i][1]," ","")) end
- end
- end
- maxPage = math.ceil(#apps/6)
- current_page = 1
- -- Update Apps --
- -- Save Settings --
- if fs.exists(app_dir.."load_order.lua") then
- fs.delete(app_dir.."load_order.lua")
- end
- if fs.exists(app_dir.."status.lua") then
- fs.delete(app_dir.."status.lua")
- end
- if fs.exists(app_dir.."user_apps.lua") then
- fs.delete(app_dir.."user_apps.lua")
- end
- local file = fs.open(app_dir.."load_order.lua", "w")
- for i=1, #new_load_order do
- file.writeLine(new_load_order[i][1])
- end
- file.close()
- local file = fs.open(app_dir.."status.lua", "w")
- for i=1, #new_load_order do
- file.writeLine(new_load_order[i][2])
- end
- file.close()
- local file = fs.open(app_dir.."user_apps.lua", "w")
- for i=1, #user_apps do
- file.writeLine(user_apps[i][2])
- file.writeLine(user_apps[i][3])
- end
- file.close()
- -- Save Settings --
- -- Update Screen --
- if updat then
- updat = not updat
- scroll = 0
- setBack("black") clr()
- --paintutils.drawLine(1,h,w,h,colors["lightGray"])
- --paintutils.drawPixel(w,h,colors["red"])
- cp(1,1)
- bg = true
- for i=1, #options_displayed do
- if bg then setBack("black") else setBack("gray") end bg = not bg
- if editing then setText("yellow") else setText("white") end
- if options_displayed[i][1] == "ShellOS" or options_displayed[i][1] == "Desktop" then
- setText("purple")
- else
- if options_displayed[i][2] == 1 then
- setText("green")
- else
- setText("red")
- end
- end
- if i == #options_displayed then
- write(options_displayed[i][1].." ")
- else
- print(options_displayed[i][1].." ")
- end
- end
- end
- -- Update Screen --
- sleep(.00001)
- repeat
- a,i,x,y = os.pullEvent()
- until a == "mouse_click" or a == "mouse_scroll"
- if a == "mouse_click" then
- if y <= #options_displayed then
- local tmpy = y
- local tmp = loadDesktopinfo(new_load_order[y+scroll])
- y = tmpy
- if tmp == "toggle" then
- if new_load_order[y+scroll][2] == 1 then
- new_load_order[y+scroll][2] = 0
- else
- new_load_order[y+scroll][2] = 1
- end
- elseif tmp == "remove" then
- table.remove(new_load_order, y+scroll)
- table.remove(user_apps, y+scroll)
- saveUserApps()
- elseif tmp == "move" then
- moveDesktopApp(y, new_load_order, scroll)
- end
- updat = true
- end
- elseif a == "mouse_scroll" then
- if i == 1 and scroll < #new_load_order-sh then -- down
- scroll = scroll + 2 updat = true
- elseif i == -1 and scroll > -1 then -- up
- scroll = scroll - 2 updat = true
- end
- if scroll < 0 then scroll = 0 end
- end
- --[[
- if i == keys.w or i == keys.up then
- if editing then
- if selected ~= 1 then
- local tmp = new_load_order[selected+scroll]
- local tmp2 = new_load_order[selected+scroll-1]
- new_load_order[selected+scroll] = tmp2
- new_load_order[selected+scroll-1] = tmp
- if selected == 3 and scroll ~= 0 then
- scroll = scroll - 1
- elseif selected ~= 1 then
- selected = selected - 1
- end
- end
- else
- if selected == 3 and scroll ~= 0 then
- scroll = scroll - 1
- elseif selected ~= 1 then
- selected = selected - 1
- end
- end
- elseif i == keys.s or i == keys.down then
- if editing then
- if selected ~= #new_load_order-scroll then
- local tmp = new_load_order[selected+scroll]
- local tmp2 = new_load_order[selected+scroll+1]
- new_load_order[selected+scroll] = tmp2
- new_load_order[selected+scroll+1] = tmp
- if selected == sh-2 and scroll ~= #new_load_order-sh then
- scroll = scroll + 1
- elseif selected ~= #new_load_order-scroll then
- selected = selected + 1
- end
- end
- else
- if selected == sh-3 and scroll ~= #new_load_order-sh+1 then
- scroll = scroll + 1
- elseif selected ~= #new_load_order-scroll then
- selected = selected + 1
- end
- end
- elseif i == keys.a or i == keys.left or i == keys.d or i == keys.right and editing then
- if new_load_order[selected+scroll][1] ~= "ShellOS" or new_load_order[selected+scroll][1] ~= "Desktop" then
- if new_load_order[selected+scroll][2] == 1 then
- new_load_order[selected+scroll][2] = 0
- else
- new_load_order[selected+scroll][2] = 1
- end
- end
- elseif i == keys.enter or i == keys.e then
- editing = not editing
- elseif i == keys.q and editing then
- editing = false
- run = false
- end
- ]]
- end
- end
- function UserProgramManager()
- -- user_apps contain: {app location, name, dir}
- local sw,sy = term.getSize()
- local run = true
- sleep(.1)
- local _m = {"Manage Apps", "Add App", "Remove App", "Exit UPM"} -- main menu
- local selected_app
- local _m_ma = {"Edit Name", "Edit Dir", "Edit Icon", "Back"} -- manage apps menu
- local _m_app_list = user_apps -- For use in anything
- table.insert(_m_app_list, "Exit")
- local _m_actions = {
- ManageApps = function()
- end,
- AddApp = function()
- clr() setText("white") setBack("black") cp(1,1)
- print("Create an app!")
- print(" - App name can't be any longer than 12 letters and cannot be an pre-existing app")
- print(" - App dir can be any length and be run my other apps as long as it exists on the computer or in a disk")
- print(" - App Icons can not be any larger than 6x8")
- print(" - Any invalid inputs will exit back to the main menu")
- print("")
- write("Display name: ")
- local name = read()
- local val = true
- for i=1, #load_order do
- if name == load_order[i] then val = false end
- end
- if string.len(name) > 12 then
- print("Display name is > than 12 letters") sleep(1)
- return false
- elseif name == "" then
- print("Display name needs to be at least 1 letter") sleep(1)
- return false
- elseif val == false then
- print("App already exists") sleep(1)
- end
- write("Dir: ")
- local adir = read()
- if not fs.exists(adir) then
- print("Dir does not exists") sleep(1)
- return false
- end
- table.insert(user_apps, {#load_order+1, name, adir})
- table.insert(load_order, {user_apps[#user_apps][2], 1.0})
- if fs.exists(app_dir.."load_order.lua") then
- fs.delete(app_dir.."load_order.lua")
- end
- if fs.exists(app_dir.."status.lua") then
- fs.delete(app_dir.."status.lua")
- end
- local file = fs.open(app_dir.."load_order.lua", "w")
- for i=1, #load_order do
- file.writeLine(load_order[i][1])
- end
- file.close()
- local file = fs.open(app_dir.."status.lua", "w")
- for i=1, #load_order do
- file.writeLine(load_order[i][2])
- end
- file.close()
- saveUserApps()
- local file = fs.open(app_dir.."user_apps.lua", "w")
- for i=1, #user_apps do
- file.writeLine(user_apps[i][2])
- file.writeLine(user_apps[i][3])
- end
- file.close()
- loadApp(user_apps[#user_apps][2], sprite_dir..user_apps[#user_apps][2])
- print("App has been added sucessfully!") sleep(1.3)
- end,
- RemoveApp = function()
- end,
- ExitUPM = function()
- run = false
- end,
- EditName = function()
- end,
- EditDir = function()
- end,
- EditIcon = function()
- end
- }
- local _m_s = _m -- selected menu
- local updat = true
- local scroll = 0
- local selected = 1
- local function drawMenu()
- local m = {}
- if #_m_s <= 10 then
- m = _m_s
- else
- for i=1, 10 do
- m[#m+1] = _m_s[i+scroll]
- end
- end
- cp(1,2) setText("yellow") write("UPM (User Program Manager)")
- cp(1,4)
- for i=1, #m do
- if i == selected then
- setText("white")
- print("> "..m[i].." ")
- else
- setText("gray")
- print(" "..m[i].." ")
- end
- end
- end
- while run do
- if updat then
- updat = false
- setBack("black") clr()
- end
- drawMenu()
- sleep(.001)
- a,i = os.pullEvent("key")
- if i == keys.w or i == keys.up then
- if selected == 3 and scroll ~= 0 then
- scroll = scroll - 1
- else
- if selected ~= 1 then
- selected = selected - 1
- end
- end
- elseif i == keys.s or i == keys.down then
- if selected == sy-10 and scroll ~= #_m_s-sy+8 then
- scroll = scroll + 1
- else
- if selected ~= #_m_s-scroll then
- selected = selected + 1
- end
- end
- elseif i == keys.e or i == keys.enter then
- _m_actions[string.gsub(_m_s[selected], " ", "")]() selected = 1 updat = true
- end
- end
- end
- function runUserPrograms()
- -- app_selected >> points to where the app was selected (app #10 or app #5)
- -- user_apps >> user_apps[i] = {app_selected, "name", "dir"}
- local selected = 0
- for i=1, #user_apps do
- if app_selected == user_apps[i][1] then -- gets the program to run
- selected = i
- end
- end
- if selected == 0 then
- print("Program '"..load_order[app_selected][1].."' does not exists") -- HERE ===================
- else
- if fs.exists(user_apps[selected][3]) then
- local s,e = pcall(function() shell.run(user_apps[selected][3]) end)
- setText("white")
- setBack("black")
- clr()
- cp(1,1)
- if s then
- return true
- else
- print("Program failed with the error: ")
- printError(e)
- end
- else
- print("Program does not exists")
- end
- end
- --[[
- if loaded_apps[app_selected] ~= nil then
- if fs.exists(loaded_apps[app_selected][2]) then
- local s,e = shell.run(loaded_apps[app_selected][2])
- setText("white")
- setBack("black")
- clr()
- cp(1,1)
- if s then
- return true
- else
- print("Program failed with the error: ")
- printError(e)
- end
- else
- print("Program does not exists")
- end
- else
- print("Program does not exists")
- end
- ]]
- sleep(1)
- print("")
- print("Press any key to exit...")
- os.pullEvent()
- end
- function iconeditorProgram()
- end
- function displaySI()
- while true do
- cp(1,1) setBack("black") clr()
- setText("white") write("System Version: ") setText("yellow") print(os.version())
- setText("white") write("Freeware Version: ") setText("yellow") print(version)
- setText("white") write("System ID: ") setText("yellow") print(os.getComputerID())
- setText("white") write("System Label: ") setText("yellow") print(os.getComputerLabel())
- setText("white") write("System Storage: ") setText("yellow") print(fs.getFreeSpace("/").." bytes Free")
- setText("white") write("OS Size: ") setText("yellow") print(fs.getSize(shell.getRunningProgram()).." bytes")
- setText("white") print("Connected Devices: ")
- local sides = {{"Top", peripheral.getType("top")},{"Bottom", peripheral.getType("bottom")}, {"Left", peripheral.getType("left")}, {"Right", peripheral.getType("right")}, {"Front", peripheral.getType("front")}, {"Back", peripheral.getType("back")}}
- for i=1, #sides do
- setText("white") write(sides[i][1].." - ")
- if sides[i][2] ~= nil then
- setText("green") write(sides[i][2].." ")
- else
- setText("gray") write("nil ")
- end
- end
- print("")
- setText("white") write("Http Support: ")
- if http then
- setText("green") print("True")
- else
- setText("red") print("False")
- end
- setText("white") write("ccemux: ")
- local a,i = pcall(function() ccemux.getVersion() end)
- if a == true then
- setText("green") print("ccemux v."..ccemux.getVersion())
- else
- setText("red") print("False")
- end
- setText("white") write("CC:Tweaked: ")
- local a,i = pcall(function() return fs.exists("rom/help/Speakers.txt") end)
- if a == true then
- setText("green") print("True")
- else
- setText("red") print("False")
- end
- setText("white") write("World Day: ") setText("yellow") print(os.day())
- setText("white") write("World Time: ") setText("yellow") print(textutils.formatTime(os.time()))
- sleep(4)
- end
- end
- function runProgram(program)
- local old = term.current()
- local mainw = window.create(term.current(),1,1,w,h-1)
- setBack("black")
- setText("white")
- clr()
- paintutils.drawLine(1,h,w,h,colors["lightGray"])
- paintutils.drawPixel(w,h,colors["red"])
- local function window()
- local run = true
- while run do
- a,i,x,y = os.pullEvent()
- if a == "mouse_click" then
- if x == w and y == h then
- run = false
- end
- end
- end
- end
- local oldTerm = term.redirect(mainw)
- parallel.waitForAny(window, program)
- local newTerm = term.redirect(old)
- term.setCursorBlink(false)
- update = true
- end
- function runEmuData()
- local a,i = pcall(function() ccemux.getVersion() end)
- if a then
- setText("white") setBack("black") clr() cp(1,1) print("Loading Emu Data folder...") sleep(.1) shell.run("emu data") sleep(.5)
- else
- setText("white") setBack("black") clr() cp(1,1) print("Loading Emu Data folder...") sleep(.1) print("Failed to load because system is most likely on an emulator or is outdated...") sleep(.5) print("") print("Press any key to exit...") os.pullEvent()
- end
- update = true
- end
- home_option_function = {
- ShellOS = function()
- runProgram(function() shell.run("shell") end)
- end,
- Files = function()
- runProgram(function() fileProgram() end)
- --fileProgram()
- end,
- IconEditor = function()
- -- Nothing
- end,
- Shutdown = function()
- os.shutdown()
- end,
- Reboot = function()
- os.reboot()
- end,
- Crash = function()
- error("Crash App")
- end,
- Worm = function()
- runProgram(function() shell.run("worm") end)
- end,
- Adventure = function()
- runProgram(function() shell.run("adventure") end)
- end,
- Lua = function()
- runProgram(function() shell.run("lua") end)
- end,
- Pastebin = function()
- runProgram(function() pastebinProgram() end)
- end,
- SystemInfo = function()
- runProgram(function() displaySI() end)
- end,
- Homebrew = function()
- running = false
- end,
- Desktop = function()
- runProgram(function() desktopProgram() end)
- end,
- Dino = function()
- runProgram(function() playDino() end)
- end,
- Landslide = function()
- runProgram(function() playLandslide() end)
- end,
- UPM = function()
- runProgram(function() UserProgramManager() end)
- end,
- RunUserPrograms = function()
- runProgram(function() runUserPrograms() end)
- end,
- EmuData = function()
- runProgram(function() runEmuData() end)
- end,
- Connect = function()
- runProgram(function() playConnect() end)
- end
- }
- function display()
- drawBar()
- drawScreen()
- drawApps()
- if home then
- drawHome()
- end
- end
- function clickEngine()
- running = true
- update = false
- while running do
- sEvent, param, param2, param3 = os.pullEvent("mouse_click")
- x,y = param2,param3
- if param == 1 then -- Left Click
- if home then
- if x <= home_options_lt_f()+2 and y >= h-#home_options and y ~= h then
- home_option_function[home_options[h-y]]()
- end
- toggleHome()
- drawScreen()
- drawApps()
- elseif x == 1 and y == h and dBar then
- toggleHome()
- drawHome()
- elseif x == 1 and y > h/2-4 and y < h/2+3 and dScroll then
- if current_page ~= 1 then current_page = current_page - 1 update = true end
- elseif x == w and y > h/2-4 and y < h/2+3 and dScroll then
- if current_page ~= maxPage then current_page = current_page + 1 update = true end
- elseif x >= app_locations[1] and x <= app_locations[1]+7 then
- -- Left
- if y >= 1 and y <= 7 then -- top
- app_selected = 1+(6*(current_page-1))
- if loaded_apps[1] ~= nil then
- if home_option_function[string.gsub(loaded_apps[1][1], " ", "")] ~= nil then
- home_option_function[string.gsub(loaded_apps[1][1], " ", "")]()
- else
- home_option_function["RunUserPrograms"]()
- end
- end
- elseif y >= 11 and y <= h-2 and #loaded_apps >= 4 then -- bottom
- app_selected = 4+(6*(current_page-1))
- if loaded_apps[4] ~= nil then
- if home_option_function[string.gsub(loaded_apps[4][1], " ", "")] ~= nil then
- home_option_function[string.gsub(loaded_apps[4][1], " ", "")]()
- else
- home_option_function["RunUserPrograms"]()
- end
- end
- end
- elseif x >= app_locations[2] and x <= app_locations[2]+7 then
- -- Middle
- if y >= 1 and y <= 7 and #loaded_apps >= 2 then -- top
- app_selected = 2+(6*(current_page-1))
- if loaded_apps[2] ~= nil then
- if home_option_function[string.gsub(loaded_apps[2][1], " ", "")] ~= nil then
- home_option_function[string.gsub(loaded_apps[2][1], " ", "")]()
- else
- home_option_function["RunUserPrograms"]()
- end
- end
- elseif y >= 11 and y <= h-2 and #loaded_apps >= 5 then -- bottom
- app_selected = 5+(6*(current_page-1))
- if loaded_apps[5] ~= nil then
- if home_option_function[string.gsub(loaded_apps[5][1], " ", "")] ~= nil then
- home_option_function[string.gsub(loaded_apps[5][1], " ", "")]()
- else
- home_option_function["RunUserPrograms"]()
- end
- end
- end
- elseif x >= app_locations[3] and x <= app_locations[3]+7 then
- -- Right
- if y >= 1 and y <= 7 and #loaded_apps >= 3 then -- top
- app_selected = 3+(6*(current_page-1))
- if loaded_apps[3] ~= nil then
- if home_option_function[string.gsub(loaded_apps[3][1], " ", "")] ~= nil then
- home_option_function[string.gsub(loaded_apps[3][1], " ", "")]()
- else
- home_option_function["RunUserPrograms"]()
- end
- end
- elseif y >= 11 and y <= h-2 and #loaded_apps >= 6 then -- bottom
- app_selected = 6+(6*(current_page-1))
- if loaded_apps[6] ~= nil then
- if home_option_function[string.gsub(loaded_apps[6][1], " ", "")] ~= nil then
- home_option_function[string.gsub(loaded_apps[6][1], " ", "")]()
- else
- home_option_function["RunUserPrograms"]()
- end
- end
- end
- end
- elseif param == 2 then -- Right Click
- --
- elseif param == 3 then -- Middle Click
- --
- end
- if update then
- update = not update
- display()
- end
- if debug then
- cp(1,1) setBack("black") setText("white")
- write("x:"..tostring(x).." y:"..tostring(y).." p:"..current_page.." ")
- end
- end
- end
- function runtime()
- display() -- 0.05 refresh rate flickers
- clickEngine() -- runs clicking os
- end
- local res, er = pcall(runtime)
- if res then
- setBack("black")
- setText("white")
- clr()
- cp(1,1)
- print("OS FREEWARE")
- else
- setBack("blue")
- setText("white")
- clr()
- cp(1,1)
- sleep(1)
- print("OS has crashed... :0")
- print("")
- print("Something you did caused this to happen. This happens when the OS is unable to do its job correctly on the first time. Hope that whatever you where doing was saved...")
- print("")
- print("====================")
- setText("yellow")
- print(er)
- setText("white")
- print("====================")
- print("")
- print("Press any key to reboot...")
- os.pullEvent()
- os.reboot()
- end
Add Comment
Please, Sign In to add comment