Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Kitten Arcade System 2
- term.clear()
- term.setCursorPos(1,1)
- function getDisks()
- local disks = {}
- for i, v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "drive" then
- if disk.getMountPath(v) ~= nil then
- if fs.exists(disk.getMountPath(v).."/kas2info") and fs.exists(disk.getMountPath(v).."/kas2game") then
- table.insert(disks,disk.getMountPath(v))
- end
- end
- end
- end
- return disks
- end
- function openModem()
- local sides = rs.getSides()
- local side = ""
- for i, v in pairs(sides) do
- if peripheral.getType(v) == "modem" then
- rednet.open(v)
- side = v
- end
- end
- return side
- end
- function printCenter(t,l,c)
- local x, y = term.getSize()
- term.setCursorPos(x/2 - string.len(t)/2,l)
- if c then
- term.clearLine()
- end
- write(t)
- end
- function menu(title, options)
- local choice = 0
- local selected = 1
- local x, y = term.getSize()
- repeat
- term.clear()
- printCenter(title,1,false)
- while choice == 0 do
- for i = 1, #options do
- printCenter((i == selected and "> " or " ")..options[i]..(i == selected and " <" or " "),i+2,false)
- end
- local e = {os.pullEvent()}
- if e[1] == "mouse_click" then
- if e[4] >= 3 and e[4] <= #options + 2 then
- if e[3] >= x/2 - string.len(options[e[4] - 2]) and e[3] <= x/2 + string.len(options[e[4] - 2]) then
- choice = e[4] - 2
- end
- end
- elseif e[1] == "key" then
- if e[2] == 28 then
- choice = selected
- elseif e[2] == 208 then
- if selected == #options then
- selected = 1
- else
- selected = selected + 1
- end
- elseif e[2] == 200 then
- if selected == 1 then
- selected = #options
- else
- selected = selected - 1
- end
- end
- end
- end
- until choice > 0
- return choice
- end
- local disks = getDisks()
- function getDiskInfo(file)
- local f = fs.open(file.."/kas2info","r")
- local f2 = f.readAll()
- f.close()
- return textutils.unserialize(f2)
- end
- function getGames(disks)
- local games = {}
- for i, v in pairs(disks) do
- table.insert(games,getDiskInfo(v)["name"])
- end
- return games
- end
- while true do
- disks = getDisks()
- local gamez = {}
- if #disks > 0 then
- local game = menu("Kitten Arcade System",getGames(disks))
- term.clear()
- term.setCursorPos(1,1)
- if fs.exists(disks[game].."/kas2game") then
- shell.run(disks[game].."/kas2game")
- else
- local x, y = term.getSize()
- printCenter("Error: Game Disk Missing",y/2,true)
- printCenter("Returning to main menu...",1,true)
- sleep(2)
- end
- else
- printCenter("Out of Order",1,true)
- sleep(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment