Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- OS Freeware v2
- Revisions from OS Freeware v1:
- - more stable window api
- - better app management
- - less code with more stable engine
- - more user friendly
- - code more clear for developers to monkey with
- - more avaliable settings for desktop
- Just Does Games
- ]]
- version = "Freeware v2.1.0" -- os version
- dir = "/freewarev2/" -- os directory
- -- pre-functions
- function clr() return term.clear() end
- function cp(x,y) return term.setCursorPos(x,y) end
- function setText(col) return term.setTextColor(colors[col]) end
- function setBack(col) return term.setBackgroundColor(colors[col]) end
- function notnil(vari) if vari == nil then return false else return true end end
- -- pre-functions
- -- pre-values
- w,h = term.getSize() -- gets size of computer (entire computer, not the window api)
- if not http or not term.isColor() or w ~= 51 or h ~= 19 then -- strict requirements
- if not http then
- return print("Http is not present")
- elseif not term.isColor() then
- return print("Advanced Computer Required")
- elseif w ~= 51 or h ~= 19 then
- return print("51x19 Device Only")
- end
- end
- --== Global Values ==--
- running = true -- loop for the os (if false, ends entire os)
- update = true -- update apps on the screen (used for after running a program or to update desktop)
- apps = {} -- used for loading all apps (format: name [string], type [number], location [string], texture [table])
- loaded_apps = {} -- used to load the currently displaying apps easier
- page = 1 -- current page
- maxPage = 1 -- max amount of pages
- app_locations = {8,22,36} -- app x-axis
- title_color = "white" -- app title color (default: "white")
- desktop_color = "black" -- desktop background color (default: "black")
- scroll_color = "gray" -- desktop scroll left to right background color (default: "gray")
- scroll_text_color = "white" -- desktop scroll left to right text color (default: "white")
- bar_color = "lightBlue" -- desktop bar color (default: "lightBlue")
- bar_text_color = "blue" -- desktop bar text color (default: "blue")
- --== Global Values ==--
- -- pre-values
- -- load icons
- _t = { -- default app textures
- {
- "noTexture",
- "eeeeeeee",
- "eeeeeeee",
- "55555555",
- "55555555",
- "bbbbbbbb",
- "bbbbbbbb"
- },
- {
- "ShellOS",
- "11111111",
- "10fffff1",
- "1f0ffff1",
- "10ff00f1",
- "1ffffff1",
- "11111111"
- },
- {
- "Homebrew",
- "90999909",
- "90999909",
- "90000009",
- "90000009",
- "90999909",
- "90999909"
- },
- {
- "Reboot",
- " 77777",
- " 71117",
- " 71717",
- " 71117",
- " 71777",
- " 777"
- },
- {
- "Shutdown",
- " 77777",
- " 7eee7",
- " 7e7e7",
- " 7eee7",
- " 7e777",
- " 777"
- },
- {
- "Worm",
- " 777777",
- "7777ddd7",
- "7e77d777",
- "7777d777",
- "7dddd7e7",
- " 777777"
- },
- {
- "Adventure",
- " 777777",
- "77000077",
- "77077077",
- "77000077",
- "77077077",
- " 777777"
- },
- {
- "Landslide",
- " cccccc ",
- "cc0ccccc",
- "cc0ccccc",
- "cc0ccccc",
- "cc0000cc",
- " cccccc "
- },
- {
- "Pastebin",
- " 000000",
- "08887000",
- "08087770",
- "08887070",
- "08007770",
- " 000000"
- },
- {
- "Lua",
- " bbbb",
- " b0bbbb",
- "bb0bbbbb",
- "bb0bbbbb",
- " b0000b",
- " bbbb"
- },
- {
- "Crash",
- " bbbb",
- " b0000b",
- "bb0bbbbb",
- "bb0bbbbb",
- " b0000b",
- " bbbb"
- },
- {
- "Desktop",
- "ffffffff",
- "fef1f4ff",
- "ffffffff",
- "fdfbfaff",
- "fdfbfaff",
- "ffffffff",
- },
- {
- "Files",
- "48884444",
- "48884444",
- "44444444",
- "44444444",
- "43333334",
- "43444434"
- },
- }
- for i=1, #_t do -- verifies that the files exists. If the file does not exists, creates the file again.
- if not fs.exists(dir.."icons/".._t[i][1]..".nfp") then
- local file = fs.open(dir.."icons/".._t[i][1]..".nfp", "w")
- for ii=1, #_t[i]-1 do
- file.writeLine(_t[i][ii+1])
- end
- file.close()
- end
- end
- t_noTexture = paintutils.loadImage(dir.."icons/noTexture.nfp")
- t_ShellOS = paintutils.loadImage(dir.."icons/ShellOS.nfp")
- t_Homebrew = paintutils.loadImage(dir.."icons/Homebrew.nfp")
- t_Reboot = paintutils.loadImage(dir.."icons/Reboot.nfp")
- t_Shutdown = paintutils.loadImage(dir.."icons/Shutdown.nfp")
- t_Worm = paintutils.loadImage(dir.."icons/Worm.nfp")
- t_Adventure = paintutils.loadImage(dir.."icons/Adventure.nfp")
- t_Landslide = paintutils.loadImage(dir.."icons/Landslide.nfp")
- t_Pastebin = paintutils.loadImage(dir.."icons/Pastebin.nfp")
- t_Lua = paintutils.loadImage(dir.."icons/Lua.nfp")
- t_Crash = paintutils.loadImage(dir.."icons/Crash.nfp")
- t_Desktop = paintutils.loadImage(dir.."icons/Desktop.nfp")
- t_Files = paintutils.loadImage(dir.."icons/Files.nfp")
- -- load icons
- -- os games
- 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 notnil(rocks[i]) 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 notnil(rocks[i]) 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 notnil(rocks[i]) 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 notnil(rocks[i]) 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
- -- os games
- -- os programs
- function runFileProgram(browse)
- --
- 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 notnil(name) 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 runPastebin()
- 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 runDesktop(browse)
- -- Desktop
- --[[
- if notnil(browse) then browse = true else browse = false end
- local w,h = term.getSize()
- local run = true
- local selected = 1
- local scroll = 0
- local updat = true
- local display
- local l_apps = apps
- for i=1, 10 do
- table.insert(l_apps, {"Debug "..i, 2, "", t_noTexture, false})
- end
- while run do
- if updat then
- updat = false cp(1,1) setText("white") setBack("black") clr()
- end
- display = {}
- if #l_apps > h-math.ceil(#l_apps/6) then
- for i=1, h do
- table.insert(display, l_apps[i+scroll])
- end
- else
- display = l_apps
- end
- cp(1,1)
- for i=1, #display do
- if i == selected then
- setText("lime")
- write("> ")
- else
- write(" ")
- end
- if display[i][1] == "ShellOS" or display[i][1] == "Desktop" then
- setText("orange")
- else
- if display[i][5] == true then
- setText("white")
- else
- setText("gray")
- end
- end
- if i == #display then
- write(display[i][1].." ")
- else
- print(display[i][1].." ")
- end
- end
- a,i = os.pullEvent("key")
- if i == keys.w or i == keys.up then
- if selected == 3 and scroll ~= 0 then
- scroll = scroll - 1
- elseif selected ~= 1 then
- selected = selected - 1
- end
- elseif i == keys.s or i == keys.down then
- if selected == #display-3 and display[#display] ~= l_apps[#l_apps] then
- scroll = scroll + 1
- elseif selected ~= #display then
- selected = selected + 1
- end
- elseif i == keys.enter or i == keys.e then
- _playAnimation("drag",1,selected,1,1,display[selected][1],.005)
- clr()
- local menu = {}
- local sel = 1
- if browse then
- table.insert(menu, "Select App")
- else
- if display[selected][1] ~= "ShellOS" and display[selected][1] ~= "Desktop" then
- table.insert(menu, "Toggle App")
- end
- if display[selected][2] ~= 1 then
- table.insert(menu, "Remove App")
- end
- table.insert(menu, "Move App")
- end
- table.insert(menu, "Exit")
- repeat
- cp(1,1)
- if display[selected][1] == "ShellOS" or display[selected][1] == "Desktop" then
- setText("orange")
- else
- if display[selected][5] == true then
- setText("white")
- else
- setText("gray")
- end
- end
- print(display[selected][1])
- print("")
- for i=1, #menu do
- if i == sel then
- setText("white")
- print("> "..menu[i].." ")
- else
- setText("gray")
- print(" "..menu[i].." ")
- end
- end
- a,i = os.pullEvent("key")
- if i == keys.w or i == keys.up then
- if sel > 1 then sel = sel - 1 end
- elseif i == keys.s or i == keys.down then
- if sel < #menu then sel = sel + 1 end
- elseif i == keys.enter or i == keys.e then
- if menu[sel] == "Exit" then
- sel = true
- elseif menu[sel] == "Toggle App" then
- display[selected][5] = not display[selected][5]
- l_apps[selected+scroll][5] = display[selected][5]
- elseif menu[sel] == "Remove App" then
- table.remove(display, selected)
- table.remove(l_apps, selected+scroll)
- sel = false
- elseif menu[sel] == "Select App" then
- return display[selected]
- elseif menu[sel] == "Move App" then
- local animate_display = true
- local function main()
- local loop = true
- clr()
- while loop do
- display = {}
- if #l_apps > h-math.ceil(#l_apps/6) then
- for i=1, h do
- table.insert(display, l_apps[i+scroll])
- end
- else
- display = l_apps
- end
- cp(1,1)
- for i=1, #display do
- if i == selected then
- setText("yellow")
- write("> ")
- else
- write(" ")
- end
- if display[i][1] == "ShellOS" or display[i][1] == "Desktop" and selected ~= i then
- setText("orange")
- elseif i == selected and animate_display then
- setText("purple")
- else
- if display[i][5] == true then
- setText("white")
- else
- setText("gray")
- end
- end
- if not animate_display and i == selected then
- if i == #display then
- write(" ")
- else
- print(" ")
- end
- else
- if i == #display then
- write(display[i][1].." ")
- else
- print(display[i][1].." ")
- end
- end
- end
- a,i = os.pullEvent("key")
- if i == keys.w or i == keys.up then
- if selected == 3 and scroll ~= 0 then
- scroll = scroll - 1
- local tmp1 = l_apps[selected+1+scroll]
- local tmp2 = l_apps[selected+scroll]
- l_apps[selected+1+scroll] = tmp2
- l_apps[selected+scroll] = tmp1
- elseif selected ~= 1 then
- selected = selected - 1
- local tmp1 = l_apps[selected+1+scroll]
- local tmp2 = l_apps[selected+scroll]
- l_apps[selected+1+scroll] = tmp2
- l_apps[selected+scroll] = tmp1
- end
- elseif i == keys.s or i == keys.down then
- if selected == #display-3 and display[#display] ~= l_apps[#l_apps] then
- scroll = scroll + 1
- local tmp1 = l_apps[selected-1+scroll]
- local tmp2 = l_apps[selected+scroll]
- l_apps[selected-1+scroll] = tmp2
- l_apps[selected+scroll] = tmp1
- elseif selected ~= #display then
- selected = selected + 1
- local tmp1 = l_apps[selected-1+scroll]
- local tmp2 = l_apps[selected+scroll]
- l_apps[selected-1+scroll] = tmp2
- l_apps[selected+scroll] = tmp1
- end
- elseif i == keys.enter or i == keys.e then
- loop = false
- end
- end
- end
- local function animate()
- while true do
- cp(1,selected) setText("yellow") write("> ") setText("purple") if selected == #display then write(l_apps[selected+scroll][1]) else print(l_apps[selected+scroll][1]) end animate_display = true sleep(.5) cp(1,selected) term.clearLine() setText("yellow") write("> ") animate_display = false sleep(.5)
- end
- end
- parallel.waitForAny(main, animate)
- clr()
- end
- end
- until type(sel) ~= "number"
- if sel == true then
- _playAnimation("drag",1,1,1,selected,display[selected][1],.005)
- else
- selected = 1
- scroll = 0
- end
- apps = l_apps
- _save()
- end
- end
- ]]
- end
- -- os programs
- -- base os-functions
- function _save() -- save all apps
- local file = fs.open(dir.."apps/list.lua", "w")
- file.write(textutils.serialize(apps))
- file.close()
- local cnt = 0
- for i=1, #apps do
- if apps[i][5] == false then
- cnt = cnt + 1
- end
- end
- page = 1
- maxPage = math.ceil((#apps-cnt)/6)
- end
- function _load() -- load all apps
- local default_apps = {{"ShellOS", 1, "", t_ShellOS, true},{"Homebrew", 1, "", t_Homebrew, true}, {"Shutdown", 1, "", t_Shutdown, true}, {"Files", 1, "", t_Files, true}, {"Reboot", 1, "", t_Reboot, true}, {"Worm", 1, "", t_Worm, true}, {"Adventure", 1, "", t_Adventure, true}, {"Landslide", 1, "", t_Landslide, true}, {"Pastebin", 1, "", t_Pastebin, true}, {"Lua", 1, "", t_Lua, true}, {"Crash", 1, "", t_Crash, true}, {"Desktop", 1, "", t_Desktop, true}, --[[{"Test", 1, "", t_noTexture, true}]]}
- if fs.exists(dir.."apps/list.lua") then
- local file = fs.open(dir.."apps/list.lua","r")
- local data = file.readAll()
- file.close()
- apps = textutils.unserialize(data)
- else
- apps = default_apps
- end
- if apps ~= nil then if #apps < 1 then
- apps = default_apps
- end end
- if apps == nil then
- apps = default_apps
- end
- page = 1
- maxPage = math.ceil(#apps/6)
- end
- function _display_desktop()
- loaded_apps = {}
- paintutils.drawLine(1,h,w,h,colors[bar_color]) cp(1,h) setText(bar_text_color) write("Page: "..page.."/"..maxPage)
- local _appsLoaded = apps
- local _rm = {}
- for i=1, #_appsLoaded do
- if _appsLoaded[i][5] == false then
- table.insert(_rm, i)
- end
- end
- for i=1, #_rm do
- table.remove(_appsLoaded, _rm[i])
- end
- for i=1, 6 do
- loaded_apps[i] = _appsLoaded[i+(6*(page-1))]
- end
- if page ~= 1 then
- setBack(scroll_color)
- setText(scroll_text_color)
- else
- setBack("black")
- setText("gray")
- end
- for i=1, 6 do
- cp(1,h/2-i+4)
- write(" ")
- end
- cp(1,h/2-3) write("<")
- cp(1,h/2+3) write("<")
- if page ~= maxPage then
- setBack(scroll_color)
- setText(scroll_text_color)
- else
- setBack("black")
- setText("gray")
- end
- for i=1, 6 do
- cp(w, h/2-i+4)
- write(" ")
- end
- cp(w,h/2-3) write(">")
- cp(w,h/2+3) write(">")
- setText(title_color)
- for i=1, #loaded_apps do
- if loaded_apps[i][5] ~= false then
- if i <= 3 then -- top
- setBack(desktop_color)
- cp(app_locations[i], 1) write(loaded_apps[i][1])
- if loaded_apps[i][4] == nil then loaded_apps[i][4] = t_noTexture end
- paintutils.drawImage(loaded_apps[i][4], app_locations[i], 2)
- else -- bottom
- setBack(desktop_color)
- cp(app_locations[i-3], h-8) write(loaded_apps[i][1])
- if loaded_apps[i][4] == nil then loaded_apps[i][4] = t_noTexture end
- paintutils.drawImage(loaded_apps[i][4], app_locations[i-3], h-7)
- end
- sleep(.05)
- end
- end
- end
- function _playAnimation(animation, arg1, arg2, arg3, arg4, arg5, arg6)
- if animation == "drag" then
- if notnil(arg1) == true and notnil(arg2) and notnil(arg3) and notnil(arg4) and notnil(arg5) and notnil(arg6) then
- -- est. variables: arg1 = current_x_pos, arg2 = current_y_pos, arg3 = target_x_pos, arg4 = target_y_pos, text, speed
- setText("purple")
- local total
- local rn = (arg1-arg3)+(arg2-arg4)
- if rn < 0 then rn = rn*-1 end
- for i=1, rn do
- clr()
- cp(arg1, arg2)
- write(arg5)
- sleep(arg6)
- if arg1 ~= arg3 then
- if arg1 > arg3 then
- arg1 = arg1 - 1
- else
- arg1 = arg1 + 1
- end
- end
- if arg2 ~= arg4 then
- if arg2 > arg4 then
- arg2 = arg2 - 1
- else
- arg2 = arg2 + 1
- end
- end
- end
- else
- return error("One or more of the values provided are nil")
- end
- end
- end
- function _update()
- update = false setBack(desktop_color) clr()
- _display_desktop()
- end
- -- base os-functions
- -- os-program index
- function runProgram(location, wd)
- local old = term.current() local mainw
- if notnil(wd) then
- mainw = window.create(term.current(),3,3,w-4,h-5)
- paintutils.drawBox(2,2,w-1,h-2,colors["gray"])
- setText("lightGray")
- cp(3,2)
- for i=1, w-4 do
- write("-")
- end
- for i=1, h-5 do
- cp(2,2+i)
- write("|")
- cp(w-1,2+i)
- write("|")
- end
- cp(3,h-2)
- for i=1, w-4 do
- write("-")
- end
- paintutils.drawPixel(w-1,2,colors["red"])
- else
- 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"])
- end
- local run = true
- local function window()
- while run do
- a,i,x,y = os.pullEvent()
- if a == "mouse_click" then
- if x == w and y == h and not notnil(wd) then
- run = false
- elseif x == w-1 and y == 2 and notnil(wd) then
- run = false
- end
- end
- end
- end
- local _program_return = ""
- local function program()
- if type(location) == "string" then
- cp(1,1) setText("white") setBack("black") clr() print("Loading App...") sleep(.7)
- _program_return = shell.run(location)
- sleep(1)
- print("Press any key to exit...")
- os.pullEvent()
- elseif type(location) == "function" then
- _program_return = location()
- end
- end
- local oldTerm = term.redirect(mainw)
- local r,e = pcall(function() parallel.waitForAny(window, program) end)
- local newTerm = term.redirect(old)
- term.setCursorBlink(false)
- update = true
- if not r then
- return error(e)
- end
- if run == true then
- return _program_return
- else
- return false
- end
- end
- function _test()
- local w,h = term.getSize()
- for i=1, h+5 do
- print("Debug "..i)
- sleep(.1)
- end
- local res = runProgram(function() return runFileProgram(true) end, true)
- local w,h = term.getSize()
- for i=1, h+5 do
- print("Debug "..i.."res: "..type(res))
- sleep(.1)
- end
- sleep(1)
- end
- _index = {
- ShellOS = function()
- runProgram(function() shell.run("shell") end)
- end,
- Homebrew = function()
- running = false
- end,
- Shutdown = function()
- os.shutdown()
- end,
- Reboot = function()
- os.reboot()
- end,
- Worm = function()
- runProgram(function() shell.run("worm") end)
- end,
- Adventure = function()
- runProgram(function() shell.run("adventure") end)
- end,
- Landslide = function()
- runProgram(function() playLandslide() end)
- end,
- Pastebin = function()
- runProgram(function() runPastebin() end)
- end,
- Lua = function()
- runProgram(function() shell.run("lua") end)
- end,
- Crash = function()
- error("Crash App")
- end,
- Desktop = function()
- runProgram(function() runDesktop() end)
- end,
- Test = function() -- use this to test anything
- runProgram(function() _test() end)
- end,
- Files = function()
- runProgram(function() runFileProgram() end)
- end
- }
- -- os-program index
- -- os
- function runtime() -- Main Loop
- -- main script
- _load()
- _save()
- while running do
- -- main loop
- if update then
- _update()
- end
- local a,i,x,y = os.pullEvent("mouse_click")
- if i == 1 then -- left-click
- if x == 1 and y >= 6 and y <= 12 then
- if page > 1 then page = page - 1 update = true end
- elseif x == w and y >= 6 and y <= 12 then
- if page < maxPage then page = page + 1 update = true end
- elseif x >= app_locations[1] and x <= app_locations[1]+7 then -- row 1 (left)
- if y >= 1 and y <= 7 then
- -- top-left
- if notnil(loaded_apps[1]) then
- if loaded_apps[1][2] == 1 then
- _index[string.gsub(loaded_apps[1][1], " ","")]()
- else
- runProgram(loaded_apps[1][3])
- end
- end
- elseif y >= 11 and y <= 17 then
- -- bottom-left
- if notnil(loaded_apps[4]) then
- if loaded_apps[4][2] == 1 then
- _index[string.gsub(loaded_apps[4][1], " ","")]()
- else
- runProgram(loaded_apps[4][3])
- end
- end
- end
- elseif x >= app_locations[2] and x <= app_locations[2]+7 then -- row 2 (middle)
- if y >= 1 and y <= 7 then
- -- top-mid
- if notnil(loaded_apps[2]) then
- if loaded_apps[2][2] == 1 then
- _index[string.gsub(loaded_apps[2][1], " ","")]()
- else
- runProgram(loaded_apps[2][3])
- end
- end
- elseif y >= 11 and y <= 17 then
- -- bottom-mid
- if notnil(loaded_apps[5]) then
- if loaded_apps[5][2] == 1 then
- _index[string.gsub(loaded_apps[5][1], " ","")]()
- else
- runProgram(loaded_apps[5][3])
- end
- end
- end
- elseif x >= app_locations[3] and x <= app_locations[3]+7 then -- row 3 (right)
- if y >= 1 and y <= 7 then
- -- top-right
- if notnil(loaded_apps[3]) then
- if loaded_apps[3][2] == 1 then
- _index[string.gsub(loaded_apps[3][1], " ","")]()
- else
- runProgram(loaded_apps[3][3])
- end
- end
- elseif y >= 11 and y <= 17 then
- -- bottom-right
- if notnil(loaded_apps[6]) then
- if loaded_apps[6][2] == 1 then
- _index[string.gsub(loaded_apps[6][1], " ","")]()
- else
- runProgram(loaded_apps[6][3])
- end
- end
- end
- end
- elseif i == 2 then -- right-click
- end
- end
- end
- function os_background_task_a()
- local _os_root_dir = shell.getRunningProgram()
- local _os_display_fps = false
- while true do
- local _os_tmp1 = fs.getSize(_os_root_dir)
- local _os_root_fps = 1
- parallel.waitForAny(function() while true do _os_root_fps = _os_root_fps + 1 sleep(.0000001) end end, function() sleep(1) end, function() while true do _os_a, _os_i = os.pullEvent("key") if _os_i == keys.leftAlt then _os_display_fps = not _os_display_fps end end end)
- if _os_display_fps then local _os_x,_os_y = term.getCursorPos() cp(1,1) setBack("black") setText("white") write("FPS: ".._os_root_fps.." ") cp(_os_x, _os_y) end
- if _os_tmp1 ~= fs.getSize(_os_root_dir) then
- os.reboot()
- end
- end
- end
- local res, er
- parallel.waitForAny(function() res, er = pcall(runtime) end, function() res, er = pcall(os_background_task_a) end)
- -- os
- -- end-of-code results
- if not res then -- Crashed
- setText("white")
- setBack("cyan")
- cp(1,1) clr()
- print("A problem has been detected and Freeware has been shut down to prevent damage to your computer.")
- print("")
- print("If this is the first time you've seen this Stop error screen, restart your computer. If this appears again, feel free to contact me.") print("")
- write("Discord Server: ") setText("blue") print("https://discord.gg/SA5tBQ2") setText("white")
- write("Email: ") setText("yellow") print("edwardelric32578@gmail.com") setText("white") print("")
- if er == nil then er = "error code was not found! (api?)" end
- write("Error: ")
- printError(er)
- print("")
- sleep(2)
- print("Press any key to reboot...")
- os.pullEvent() os.reboot()
- end
- -- Only runs if it didn't crash
- setText("white")
- setBack("black")
- cp(1,1) clr()
- print("Freeware v2")
- sleep(1)
- -- end-of-code results
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement