5bitesofcookies

code thingy with the bug

Sep 7th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.43 KB | None | 0 0
  1. --[[
  2. Table of contents-like thing
  3. 1. Start of goroutines stuff ~150
  4.  
  5.  
  6.  
  7. ]]
  8. logo = paintutils.loadImage("library/logo.nfp")
  9. --print the beautiful logo
  10. term.setBackgroundColor(colors.white)
  11. term.clear(1,1)
  12. --get center
  13.  w,h = term.getSize()
  14. w=w-9
  15. h=h-7
  16. w=w/2
  17. h=h/2
  18. term.setTextColor(colors.black)
  19. paintutils.drawImage(logo,w,h)
  20.   --loads a single function to assist with actually printing loading
  21.   function cPrint(x, text)
  22.     local w,h = term.getSize()
  23.     local pos = w - #text
  24.     pos = pos/2
  25.     term.setCursorPos(pos,x)
  26.     print(text)
  27.   end
  28. cPrint(14,"Loading")
  29.   function clear(px, py)
  30.     term.clear()
  31.     term.setCursorPos(px, py)
  32.   end
  33. --APIs
  34. if not redirect then
  35.   os.loadAPI("library/redirect")
  36. end
  37. if not goroutine then
  38.   os.loadAPI("library/goroutine")
  39. end
  40. --PAINTUTILS IMAGES
  41. noIconThing = paintutils.loadImage("library/border.nfp")
  42. login = paintutils.loadImage("library/login.nfp")
  43. --shell.run(program) replacement:
  44. --[[
  45. shell = {}
  46. function shell.run(program)
  47.   os.run({}, program)
  48. end
  49. function shell.exit()
  50.   error()
  51. end
  52. copied straight from shell VV
  53. function shell.resolve( _sPath )
  54.     local sStartChar = string.sub( _sPath, 1, 1 )
  55.     if sStartChar == "/" or sStartChar == "\\" then
  56.         return fs.combine( "", _sPath )
  57.     else
  58.         return fs.combine( sDir, _sPath )
  59.     end
  60. end
  61.  
  62. function shell.resolveProgram( _sCommand )
  63.    Substitute aliases firsts
  64.   if tAliases[ _sCommand ] ~= nil then
  65.     _sCommand = tAliases[ _sCommand ]
  66.     end
  67.      If the path is a global path, use it directly
  68.     local sStartChar = string.sub( _sCommand, 1, 1 )
  69.     if sStartChar == "/" or sStartChar == "\\" then
  70.         local sPath = fs.combine( "", _sCommand )
  71.         if fs.exists( sPath ) and not fs.isDir( sPath ) then
  72.             return sPath
  73.         end
  74.         return nil
  75.     end
  76.   Otherwise, look on the path variable
  77.     for sPath in string.gmatch(sPath, "[^:]+") do
  78.         sPath = fs.combine( shell.resolve( sPath ), _sCommand )
  79.         if fs.exists( sPath ) and not fs.isDir( sPath ) then
  80.             return sPath
  81.         end
  82.     end
  83.      Not found
  84.     return nil
  85. end
  86. another one copied:
  87. function shell.resolve( _sPath )
  88.     local sStartChar = string.sub( _sPath, 1, 1 )
  89.     if sStartChar == "/" or sStartChar == "\\" then
  90.         return fs.combine( "", _sPath )
  91.     else
  92.         return fs.combine( sDir, _sPath )
  93.     end
  94. end]]
  95. ---------------------------------------------------------------------------
  96. --now we find startup programs. If none are
  97. --found, we'll create an empty table.
  98. if fs.exists("config/startups") then
  99.   config = fs.open("config/startup", "w")
  100.   startups = config.readLine()
  101.   config.close()
  102.   startups = textutils.unserialize(startups)
  103. else
  104.   startups = {}
  105. end
  106. --now, we find the desktop color
  107. if fs.exists("config/desktopColor") then
  108.   config = fs.open("config/desktopColor")
  109.   desktopColor = config.readLine()
  110.   config.close()
  111. else
  112.   desktopColor = colors.green
  113. end
  114. --put a paintutil image at the center
  115. function centDrawImage(image,width,height)
  116.   local w,h=term.getSize()
  117.   local width=w-width
  118.   local height=h-height
  119.   width=width/2
  120.   height=height/2
  121.   paintutils.drawImage(image,width,height)
  122. end
  123. --find the admin account--- currently the only
  124. --one. If not found, create temp one just in
  125. --case the user has deleted it via CraftOS
  126. accountDetails = {}
  127. if fs.exists("config/adminAcc") then
  128.   config = fs.open("config/adminAcc", "r")
  129.   adminAcc = config.readLine()
  130.   config.close()
  131.   accountDetails = textutils.unserialize(adminAcc)
  132. else
  133.   accountDetails["name"] = "Pass is 'hi'."
  134.   --^^ clever right?
  135.   accountDetails["pass"] = "hi"
  136. end
  137. --Default Callbacks
  138. function clickedCyborg() end
  139. function clickedMenuProgram() end
  140. function clickedApps() end
  141. function clickedFile() end
  142. function clickedEdit() end
  143. function clickedWindow() end
  144. --moar functions
  145. --syntax types: #,#,#,#,T/F,Table
  146. dropDownMenu(x,y,width,length,scrollbar,items)
  147.  
  148. end
  149. -----------------------------------------------
  150. --GOROUTINE FUNCTIONS                         |
  151. -----------------------------------------------
  152. routines = {}
  153. --child functions
  154. --Cyborg's shell
  155. function findIt()
  156.  
  157.  
  158.  
  159.  
  160.  
  161. end
  162. --menu bar
  163. function menuBar()
  164.  
  165.   term.setBackgroundColor(colors.white)
  166.   term.setCursorPos(1,1)
  167.   print(" C  "..topProgram.."  Apps  File  Edit  Window                                     ")
  168.   paintutils.draw(5,5,colors.red)
  169.   --^^that doesn't want to draw
  170.   evt, p1, p2, p3 = os.pullEvent()
  171.   if evt == "mouse_click" and p2 == 1 then
  172.     if p1 == 2 then
  173.       --we do our callback
  174.       clickedCyborg()
  175.     end
  176.   term.setCursorPos(5,5)
  177.   print("test")
  178.   while true do
  179.    sleep(0.1)
  180.    
  181.  
  182.    
  183.    
  184.    
  185.    
  186.   end
  187.  
  188.  
  189.  
  190. end
  191. --new shells
  192. function newShell()
  193.  
  194.  
  195.  
  196.  
  197. end
  198. --dock
  199. function findItDock()
  200.  
  201.  
  202.  
  203.  
  204.  
  205. end
  206. --parrent function:
  207. function main()
  208.   -- note that main reacts badly to print,
  209.   --and generaly I/O from my experince.
  210.   test = goroutine.spawn("menu",menuBar)
  211.  
  212.  
  213.   while true do
  214.    
  215.     _, key = os.pullEvent("key")
  216.     if key == keys.backspace then
  217.       break
  218.     end
  219.    
  220.   end
  221.  
  222.  
  223.    
  224.  
  225.  
  226.  
  227. end
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250. -----------------------------------------------
  251. --[[
  252. Now that we've loaded everything there is to
  253. load, we'll check if any keys are pressed and
  254. do stuff accordinly.
  255. ]]
  256. os.startTimer(1.5)
  257. evt, p1 = os.pullEvent()
  258. if evt == "key" or evt == "char" then
  259.   if p1 == 46 or p1 == "c" then
  260.     term.setBackgroundColor(colors.black)
  261.     clear(1,1)
  262.     noErrorShutdown = true
  263.     --^^so shell runs just 1 time VV run shell
  264.     os.run({}, "rom/programs/shell")
  265.   end
  266.   elseif evt == "timer" then
  267. end
  268. --
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285. --LOGIN SCREEN(finaly)
  286. local incorrect = true
  287. while incorrect do
  288.   term.setBackgroundColor(colors.lightBlue)
  289.   clear(1,1)
  290.   paintutils.drawPixel(99,99,colors.lightGray)
  291.   centDrawImage(login,25,11)
  292.   term.setTextColor(colors.black)
  293.   term.setBackgroundColor(colors.lightGray)
  294.   cPrint(4,"Login")
  295.   term.setBackgroundColor(colors.white)
  296.   cPrint(9,"Admin Pass:")
  297.   term.setCursorPos(20,10)
  298.   term.setTextColor(colors.red)
  299.   input = read("*")
  300.   if input == accountDetails["pass"] then
  301.     incorrect = false
  302.   elseif input == "easterEgg" then
  303.     textutils.slowPrint("Nice find on the easter egg. Rebooting...")
  304.     os.reboot()
  305.   end
  306.   term.setBackgroundColor(colors.lightBlue)
  307.   term.setTextColor(colors.black)
  308.   clear(1,1)
  309. end
  310. --execute everything
  311. --temp:
  312. topProgram = "FindIt"
  313.  
  314. goroutine.run(main,false)
Advertisement
Add Comment
Please, Sign In to add comment