Wiiplay123

Kitten Arcade System 2

Jun 24th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. -- Kitten Arcade System 2
  2. term.clear()
  3. term.setCursorPos(1,1)
  4.  
  5. function getDisks()
  6.   local disks = {}
  7.   for i, v in pairs(peripheral.getNames()) do
  8.     if peripheral.getType(v) == "drive" then
  9.       if disk.getMountPath(v) ~= nil then
  10.         if fs.exists(disk.getMountPath(v).."/kas2info") and fs.exists(disk.getMountPath(v).."/kas2game") then
  11.           table.insert(disks,disk.getMountPath(v))
  12.         end  
  13.       end  
  14.     end
  15.   end
  16.   return disks
  17. end
  18. function openModem()
  19.   local sides = rs.getSides()
  20.   local side = ""
  21.   for i, v in pairs(sides) do
  22.     if peripheral.getType(v) == "modem" then
  23.       rednet.open(v)
  24.       side = v
  25.     end
  26.   end
  27.   return side
  28. end
  29. function printCenter(t,l,c)
  30.   local x, y = term.getSize()
  31.   term.setCursorPos(x/2 - string.len(t)/2,l)
  32.   if c then
  33.     term.clearLine()
  34.   end
  35.   write(t)
  36. end
  37. function menu(title, options)
  38.   local choice = 0
  39.   local selected = 1
  40.   local x, y = term.getSize()
  41.   repeat
  42.     term.clear()
  43.     printCenter(title,1,false)
  44.     while choice == 0 do
  45.       for i = 1, #options do
  46.         printCenter((i == selected and "> " or " ")..options[i]..(i == selected and " <" or " "),i+2,false)
  47.       end
  48.       local e = {os.pullEvent()}
  49.       if e[1] == "mouse_click" then
  50.         if e[4] >= 3 and e[4] <= #options + 2 then
  51.           if e[3] >= x/2 - string.len(options[e[4] - 2]) and e[3] <= x/2 + string.len(options[e[4] - 2]) then
  52.             choice = e[4] - 2
  53.           end
  54.         end
  55.       elseif e[1] == "key" then
  56.         if e[2] == 28 then
  57.           choice = selected
  58.         elseif e[2] == 208 then
  59.           if selected == #options then
  60.             selected = 1
  61.           else
  62.             selected = selected + 1
  63.           end
  64.         elseif e[2] == 200 then
  65.           if selected == 1 then
  66.             selected = #options
  67.           else
  68.             selected = selected - 1
  69.           end
  70.         end
  71.       end
  72.     end
  73.   until choice > 0
  74.   return choice
  75. end
  76. local disks = getDisks()
  77. function getDiskInfo(file)
  78.   local f = fs.open(file.."/kas2info","r")
  79.   local f2 = f.readAll()
  80.   f.close()
  81.   return textutils.unserialize(f2)
  82. end
  83. function getGames(disks)
  84.   local games = {}
  85.   for i, v in pairs(disks) do
  86.     table.insert(games,getDiskInfo(v)["name"])  
  87.   end
  88.   return games
  89. end
  90. while true do
  91.   disks = getDisks()
  92.   local gamez = {}
  93.   if #disks > 0 then
  94.     local game = menu("Kitten Arcade System",getGames(disks))
  95.     term.clear()
  96.     term.setCursorPos(1,1)
  97.     if fs.exists(disks[game].."/kas2game") then
  98.       shell.run(disks[game].."/kas2game")
  99.     else
  100.       local x, y = term.getSize()
  101.       printCenter("Error: Game Disk Missing",y/2,true)
  102.       printCenter("Returning to main menu...",1,true)
  103.       sleep(2)
  104.     end
  105.   else
  106.     printCenter("Out of Order",1,true)
  107.     sleep(2)
  108.   end
  109. end
Advertisement
Add Comment
Please, Sign In to add comment