Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Yeeet OS Main Script (startup.lua)
- -- Cat ASCII Art for Loading Screen
- local catArt = [[
- /\_/\
- ( o.o )
- > ^ <
- ]]
- -- User Profile Storage
- local function saveProfile(username)
- local profile = {
- username = username,
- preferences = { theme = "default" }
- }
- local file = fs.open("/user_profile.txt", "w")
- file.write(textutils.serialize(profile))
- file.close()
- end
- local function loadProfile()
- if fs.exists("/user_profile.txt") then
- local file = fs.open("/user_profile.txt", "r")
- local profile = textutils.unserialize(file.readAll())
- file.close()
- return profile
- else
- return nil
- end
- end
- -- Loading Screen
- local function loadingScreen()
- term.clear()
- term.setCursorPos(1, 1)
- print("===== Yeeet OS =====")
- print("")
- -- Print cat art on both sides
- local width, height = term.getSize()
- for line in string.gmatch(catArt, "[^\n]+") do
- term.setCursorPos(1, term.getCursorPos())
- print(line)
- term.setCursorPos(width - #line + 1, term.getCursorPos() - 1)
- print(line)
- end
- -- Print loading bar
- term.setCursorPos(1, height)
- print("Loading...")
- for i = 1, 20 do
- sleep(0.2)
- write("=")
- end
- sleep(1)
- term.clear()
- end
- -- Admin Copy OS Feature
- local function copyOS()
- if not disk.isPresent("left") then
- print("No disk detected. Please insert a writable disk into the left disk drive.")
- return
- end
- local diskPath = disk.getMountPath("left")
- print("Copying OS to disk...")
- -- List of files to copy
- local osFiles = { "startup.lua", "uninstall.lua", "draw.lua" }
- for _, file in ipairs(osFiles) do
- if fs.exists(file) then
- fs.copy(file, diskPath .. "/" .. file)
- end
- end
- print("OS copied successfully to the disk!")
- end
- -- Admin Login Screen
- local function adminCommands()
- while true do
- print("Admin Commands: 'copy', 'exit'")
- write("Admin Command: ")
- local adminInput = read()
- if adminInput == "copy" then
- copyOS()
- elseif adminInput == "exit" then
- break
- else
- print("Unknown admin command.")
- end
- end
- end
- local function loginScreen()
- print("Welcome to Yeeet OS!")
- local profile = loadProfile()
- if profile then
- print("Welcome back, " .. profile.username .. "!")
- else
- write("New User. Enter a Username: ")
- local username = read()
- saveProfile(username)
- print("Profile saved! Welcome, " .. username .. "!")
- end
- print("Admin Login Required:")
- write("Username: ")
- local username = read()
- write("Password: ")
- local password = read("*") -- Masks the password input
- if username == "admin" and password == "Loveycat0!" then
- print("Login successful!")
- adminCommands()
- else
- print("Invalid username or password. Shutting down.")
- sleep(2)
- os.shutdown()
- end
- end
- -- Drawing Feature
- local function drawProgram()
- shell.run("draw.lua")
- end
- -- Programming Environment
- local function programmingEnvironment()
- print("Programming Environment")
- print("Commands: 'run <file>', 'save <file>', 'load <file>', 'exit'")
- while true do
- write("> ")
- local input = read()
- local command, arg = string.match(input, "^(%S+)%s*(.*)$")
- if command == "run" and arg then
- if fs.exists(arg) then
- local success, err = pcall(function() shell.run(arg) end)
- if not success then
- print("Error: " .. err)
- local log = fs.open("/error_log.txt", "a")
- log.writeLine("Error while running " .. arg .. ": " .. err)
- log.close()
- end
- else
- print("File not found.")
- end
- elseif command == "save" and arg then
- write("Enter your code. Type 'end' to finish.")
- local code = ""
- while true do
- local line = read()
- if line == "end" then break end
- code = code .. line .. "\n"
- end
- local file = fs.open(arg, "w")
- file.write(code)
- file.close()
- print("File saved as " .. arg)
- elseif command == "load" and arg then
- if fs.exists(arg) then
- local file = fs.open(arg, "r")
- print(file.readAll())
- file.close()
- else
- print("File not found.")
- end
- elseif command == "exit" then
- break
- else
- print("Invalid command.")
- end
- end
- end
- -- Home Screen Navigation
- local menuOptions = { "Open Drawing", "Open Programming", "Show Time", "Shutdown", "Uninstall OS" }
- local selectedIndex = 1
- local function drawMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("===== Yeeet OS =====")
- print("Use Arrow Keys to Navigate and Enter to Select")
- for i, option in ipairs(menuOptions) do
- if i == selectedIndex then
- print("-> " .. option)
- else
- print(" " .. option)
- end
- end
- end
- local function homeScreen()
- while true do
- drawMenu()
- local event, key = os.pullEvent("key")
- if key == keys.up then
- selectedIndex = selectedIndex - 1
- if selectedIndex < 1 then
- selectedIndex = #menuOptions
- end
- elseif key == keys.down then
- selectedIndex = selectedIndex + 1
- if selectedIndex > #menuOptions then
- selectedIndex = 1
- end
- elseif key == keys.enter then
- if menuOptions[selectedIndex] == "Open Drawing" then
- drawProgram()
- elseif menuOptions[selectedIndex] == "Open Programming" then
- programmingEnvironment()
- elseif menuOptions[selectedIndex] == "Show Time" then
- term.clear()
- term.setCursorPos(1, 1)
- print("Current time: " .. textutils.formatTime(os.time(), true))
- print("\nPress any key to return.")
- os.pullEvent("key")
- elseif menuOptions[selectedIndex] == "Shutdown" then
- os.shutdown()
- elseif menuOptions[selectedIndex] == "Uninstall OS" then
- shell.run("uninstall.lua")
- end
- end
- end
- end
- -- Main Execution
- loadingScreen()
- loginScreen()
- homeScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement