Advertisement
1lann

Plastic Beta [WIP]

Jun 8th, 2013
11,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 38.83 KB | None | 0 0
  1. -- Plastic Beta v0.12
  2. -- [0.12] Bug fixes
  3. -- [0.11] Support for latest version of OpenPeripheral
  4. -- A Google Glass like OS/Programs/Whatever you want to call it
  5. -- That runs on Terminal Glasses in OpenPeripheral
  6. -- Just stick in a computer with a Terminal Glass Peripheral and run it!
  7. -- Have fun using it!
  8. -- Feel free to use my code in anyway you want!
  9. -- HOWEVER as stated by the policies of the APIs I used
  10. -- Please do not use my API keys. Just register for them
  11. -- Yourself! It's free and World Weather Online is instant!
  12.  
  13. local tArgs = {...}
  14.  
  15. local function searchArgs(text)
  16.     for k,v in pairs(tArgs) do
  17.         if v == text then return true end
  18.     end
  19.     return false
  20. end
  21.  
  22. if not http then print("Sorry, Plastic requires HTTP to run!") return end
  23.  
  24. local plasticInstallation = shell.getRunningProgram()
  25.  
  26. -- Find glass bridge
  27. local plastic = false
  28. local worldSensor = false
  29.  
  30. if fs.exists("/ocs/apis/sensor") then
  31.     os.loadAPI("ocs/apis/sensor")
  32. end
  33.  
  34. for k,v in pairs(rs.getSides()) do
  35.     if (peripheral.getType(v) == "openperipheral_glassesbridge") then
  36.         plastic = peripheral.wrap(v)
  37.         break
  38.     elseif (peripheral.getType(v) == "sensor") and (not worldSensor) then
  39.         worldSensor = sensor.wrap(v)
  40.         if not (worldSensor.getSensorName() == "worldCard") then
  41.             worldSensor = false
  42.         end
  43.     end
  44. end
  45.  
  46. if not plastic then print("Could not find Glass Bridge!") error() end
  47.  
  48. local rootApps = nil
  49.  
  50. if searchArgs("root") then
  51.     rootApps = {}
  52.     if term.isColor() then
  53.         term.setTextColor(colors.red)
  54.     end
  55.     print("-- [[ ROOT MODE ENABLED ]] --")
  56.     print("PLASTIC MAY BECOME UNSTABLE AND")
  57.     print("MAY CRASH. USE AT YOUR OWN RISK!")
  58.     if fs.isDir("/plasticApps") then
  59.  
  60.     else
  61.         print("Creating /plasticApps folder")
  62.         fs.delete("/plasticApps")
  63.         fs.makeDir("/plasticApps")
  64.     end
  65.     -- Example plastic root app
  66.     --   --[[Plastic Root App]]--
  67.     --   --NAME: Example App
  68.     --   if cmd == "hello" then
  69.     --   print("HELLO!")
  70.     --   end
  71.  
  72.     print("Searching for apps in /plasticApps")
  73.     print("")
  74.     for k,v in pairs(fs.list("/plasticApps")) do
  75.         if not(fs.isDir("/plasticApps/"..v)) then
  76.             local f = io.open("/plasticApps/"..v, "r")
  77.             if f:read("*l") == "--[[Plastic Root App]]--" then
  78.                 local name = f:read("*l"):match("%-%-NAME%: (.+)")
  79.                 dofile("/plasticApps/"..v)
  80.                 print("-- Application registered: ", name, " --")
  81.                 local data = f:read("*a")
  82.                 rootApps[name] = data
  83.             end
  84.             f:close()
  85.         end
  86.     end
  87.     print("")
  88.     print("Search completed!")
  89.     print("Starting Plastic...")
  90. end
  91.  
  92. if not(searchArgs("nodaemon")) and not(searchArgs("root")) then
  93.     term.clear()
  94.     term.setCursorPos(1,1)
  95.  
  96.     print("Plastic daemon now running. Use exit to exit")
  97. end
  98.  
  99. local function reliableSleep(time)
  100.     sleep(time)
  101. end
  102.  
  103.  
  104. -- Setup the actual "plastic"
  105. local gColors = {}
  106. gColors.red = 0xff3333
  107. gColors.blue = 0x7dd2e4
  108. gColors.yellow = 0xffff4d
  109. gColors.green = 0x4dff4d
  110. gColors.gray = 0xe0e0e0
  111. gColors.textGray = 0x818181
  112. gColors.text = 0x5a5a5a
  113. gColors.rain = 0x2e679f
  114.  
  115. plastic.clear()
  116. local mainBox = plastic.addBox(20, 20, 1, 48, gColors.gray, 0.7)
  117. local outlineT = plastic.addBox(18,18,2,2,gColors.blue,0.7)
  118. local outlineB = plastic.addBox(18,68,2,2,gColors.blue,0.7)
  119. --Startup Animation
  120. if not(searchArgs("lite")) then
  121.     -- 120, Edge is 140, Center is 80
  122.     for i = 0, 17 do
  123.         mainBox.setWidth(i*8)
  124.         outlineT.setWidth(i*8+4)
  125.         outlineB.setWidth(i*8+4)
  126.         reliableSleep(0.01)
  127.     end
  128. else
  129.     mainBox.setWidth(136)
  130.     outlineT.setWidth(140)
  131.     outlineB.setWidth(140)
  132.     mainBox.setHeight(48)
  133. end
  134. local header = plastic.addText(75, 25, "", gColors.textGray)
  135. local secondText = plastic.addText(50, 40, "", gColors.blue)
  136. local thirdText = plastic.addText(40, 55, "", gColors.blue)
  137. local mainText = plastic.addText(40, 27, "", gColors.blue)
  138. local forthText = plastic.addText(40, 55, "", gColors.text)
  139. local tempText = plastic.addText(40, 70, "", gColors.text)
  140. header.setZ(5)
  141. mainText.setZ(5)
  142. secondText.setZ(5)
  143. thirdText.setZ(5)
  144. tempText.setZ(5)
  145. forthText.setZ(5)
  146.  
  147. local function closeAnimation()
  148.     if mainBox then
  149.         pcall(mainText.delete)
  150.         pcall(secondText.delete)
  151.         pcall(header.delete)
  152.         pcall(thirdText.delete)
  153.         pcall(tempText.delete)
  154.         pcall(forthText.delete)
  155.         os.queueEvent("plastic_clock_manager", "kill")
  156.         reliableSleep(0.1)
  157.         if not(searchArgs("lite")) then
  158.             pcall(function()
  159.             for i = 17, 0, -1 do
  160.                 mainBox.setWidth(i*8)
  161.                 outlineT.setWidth(i*8+2)
  162.                 outlineB.setWidth(i*8+2)
  163.                 reliableSleep(0.01)
  164.             end
  165.             end)
  166.         end
  167.         pcall(outlineT.delete)
  168.         pcall(outlineB.delete)
  169.         pcall(mainBox.delete)
  170.     end
  171. end
  172.  
  173. local oldShutdown = os.shutdown
  174. local oldReboot = os.reboot
  175.  
  176. function os.shutdown()
  177.     closeAnimation()
  178.     return oldShutdown()
  179. end
  180.  
  181. function os.reboot()
  182.     closeAnimation()
  183.     return oldReboot()
  184. end
  185.  
  186. local function runPlastic()
  187.     -- Variables & Stuff
  188.     local corruption = false
  189.     local firstTime = true
  190.     local showClock = false
  191.  
  192.     -- Fancy functions
  193.     local gWidth = 24
  194.     local extraSupport = 0
  195.  
  196.     local function trimText(s)
  197.         return s:match("^%s*(.-)%s*$")
  198.     end
  199.  
  200.     local function plasticGet(url, noCancel)
  201.         http.request(url)
  202.         while true do
  203.             local e, rUrl, rmsg = os.pullEvent()
  204.             if (e == "http_success") and (rUrl == url) then
  205.                 if rmsg then
  206.                     local data = rmsg.readAll()
  207.                     rmsg.close()
  208.                     if data then
  209.                         return "success", data
  210.                     else
  211.                         sleep(1)
  212.                         http.request(url)
  213.                     end
  214.                 else
  215.                     sleep(1)
  216.                     http.request(url)
  217.                 end
  218.             elseif (e == "http_failure") and (rUrl == url) then
  219.                 return "failure"
  220.             elseif (e == "chat_command") and ((trimText(rUrl:lower()) == "cancel") or (trimText(rUrl:lower()) == "home")) and not(noCancel) then
  221.                 return "cancel"
  222.             end
  223.         end
  224.     end
  225.  
  226.     local function slowText(text, object)
  227.         if not(searchArgs("lite")) then
  228.             object.setText("")
  229.             for i = 1, #text do
  230.                 object.setText(string.sub(text, 1, i))
  231.                 reliableSleep(0.01)
  232.             end
  233.         else
  234.             object.setText(text)
  235.         end
  236.     end
  237.  
  238.     local function getCenter(text)
  239.         return math.ceil(((136/2)-(plastic.getStringWidth(text)*(0.65)/2))+20-0.5)
  240.     end
  241.  
  242.     local function centerText(text, object)
  243.         object.setText("")
  244.         object.setX(getCenter(text))
  245.         slowText(text, object)
  246.     end
  247.  
  248.     local function copyTable(tb)
  249.         local newTable = {}
  250.         for k,v in pairs(tb) do
  251.             newTable[k] = v
  252.         end
  253.         return newTable
  254.     end
  255.  
  256.     -- Load settings
  257.     local settings = {}
  258.     if fs.exists("/plasticOptions") and not(fs.isDir("/plasticOptions")) then
  259.         local f = io.open("/plasticOptions", "r")
  260.         local data = f:read("*a")
  261.         settings = textutils.unserialize(data)
  262.         f:close()
  263.         firstTime = false
  264.     end
  265.  
  266.     if not(settings) or not((type(settings["name"]) == "string") and (type(settings["use12hour"]) == "boolean") and
  267.         (type(settings["city"]) == "string") and (type(settings["showtime"]) == "string") and
  268.         ((settings["temperature"] == "c") or (settings["temperature"] == "f"))) and not(firstTime) then
  269.         corruption = true
  270.         header.setY(25)
  271.         header.setColor(gColors.red)
  272.         centerText("Error: Corruption", header)
  273.         mainText.setY(37)
  274.         mainText.setColor(gColors.yellow)
  275.         centerText("Options data is", mainText)
  276.         secondText.setY(47)
  277.         secondText.setColor(gColors.yellow)
  278.         centerText("corrupted.", secondText)
  279.         thirdText.setY(57)
  280.         thirdText.setColor(gColors.yellow)
  281.         thirdText.setX(40)
  282.         slowText("Resetting Plastic...", thirdText)
  283.         reliableSleep(2)
  284.         fs.delete("/plasticOptions")
  285.         closeAnimation()
  286.         reliableSleep(1)
  287.         shell.run(plasticInstallation, "nodaemon", unpack(tArgs))
  288.         error()
  289.     end
  290.  
  291.     local function getWT(city, canceller)
  292.         local function getRawWT(city, canceller) --f or c for unit
  293.             local unit = settings["temperature"]
  294.             local use12hour = settings["use12hour"]
  295.             local months = {"Jan", "Feb", "March", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"}
  296.             local resp, webData = nil
  297.             if canceller then
  298.                 resp, webData = plasticGet("http://api.worldweatheronline.com/free/v1/weather.ashx?q="..textutils.urlEncode(city).."&format=xml&extra=localObsTime&num_of_days=1&includelocation=yes&key=uyp4r5ekjns64pmpvv3qkynj", true)
  299.             else
  300.                 resp, webData = plasticGet("http://api.worldweatheronline.com/free/v1/weather.ashx?q="..textutils.urlEncode(city).."&format=xml&extra=localObsTime&num_of_days=1&includelocation=yes&key=uyp4r5ekjns64pmpvv3qkynj")
  301.             end
  302.             if resp == "cancel" then
  303.                 return "cancel"
  304.             elseif resp == "success" then
  305.             else
  306.                 error()
  307.             end
  308.             if webData:find("<error>") then
  309.                 return "invalid"
  310.             end
  311.             local city, country = webData:match([[<areaName><!%[CDATA%[([^>]+)%]%]></areaName><country><!%[CDATA%[([^>]+)%]%]></country>]])
  312.             if trimText(country) == "United States Of America" then
  313.                 country = "USA"
  314.             end
  315.             city = trimText(city):gsub(" City", "")
  316.             local resolvedLocation = city .. ", " .. country
  317.  
  318.             local currentTemp = nil
  319.             if unit == "c" then
  320.                 currentTemp = webData:match([[<current_condition>.+<temp_C>([^<]+)</temp_C>.+</current_condition>]])
  321.             elseif unit == "f" then
  322.                 currentTemp = webData:match([[<current_condition>.+<temp_F>([^<]+)</temp_F>.+</current_condition>]])
  323.             end
  324.             local currentHumidity = webData:match([[<current_condition>.+<humidity>([^<]+)</humidity>.+</current_condition>]])
  325.             local currentWeather = trimText(webData:match([[<current_condition>.+<weatherDesc><!%[CDATA%[([^>]+)%]%]></weatherDesc>.+</current_condition>]]))
  326.             local lowTemp, highTemp = nil
  327.             if unit == "c" then
  328.                 highTemp = webData:match([[<weather>.+<tempMaxC>([^<]+)</tempMaxC>.+</weather>]])
  329.                 lowTemp = webData:match([[<weather>.+<tempMinC>([^<]+)</tempMinC>.+</weather>]])
  330.             elseif unit == "f" then
  331.                 highTemp = webData:match([[<weather>.+<tempMaxF>([^<]+)</tempMaxF>.+</weather>]])
  332.                 lowTemp = webData:match([[<weather>.+<tempMinF>([^<]+)</tempMinF>.+</weather>]])
  333.             end
  334.             dayWeather = trimText(webData:match([[<weather>.+<weatherDesc><!%[CDATA%[([^<]+)%]%]></weatherDesc>.+</weather>]]))
  335.  
  336.             local time = nil
  337.             local year, month, day, rawTime, timeFormat = webData:match("<localObsDateTime>(%d+)%-(%d+)%-(%d+) (%d+:%d+) (%u+)</localObsDateTime>")
  338.             local resolvedDate = day .. " " .. months[tonumber(month)] .. " " .. year
  339.             if not use12hour then
  340.                 if timeFormat == "AM" then
  341.                     if rawTime:sub(1,2) == "12" then
  342.                         time = "0" .. rawTime:sub(3,-1)
  343.                     else
  344.                         time = rawTime
  345.                     end
  346.                 elseif timeFormat == "PM" then
  347.                     if rawTime:sub(1,2) == "12" then
  348.                         time = rawTime
  349.                     else
  350.                         time = tostring(tonumber(rawTime:sub(1,2))+12) .. rawTime:sub(3,-1)
  351.                     end
  352.                 else
  353.                     error()
  354.                 end
  355.             else
  356.                 time = rawTime .. " " .. timeFormat
  357.             end
  358.             if time:sub(1,1) == "0" then time = time:sub(2,-1) end
  359.             local current = {}
  360.             current["temp"] = currentTemp
  361.             current["weather"] = currentWeather
  362.             current["humidity"] = currentHumidity
  363.             current["time"] = time
  364.             current["date"] = resolvedDate
  365.             current["url"] = timeURL
  366.             current["location"] = resolvedLocation
  367.  
  368.             local day = {}
  369.             day["high"] = highTemp
  370.             day["low"] = lowTemp
  371.             day["weather"] = dayWeather
  372.  
  373.             return "success", current, day
  374.         end
  375.         local result = nil
  376.         result = {pcall(getRawWT, city, canceller)}
  377.         if result[1] then
  378.             table.remove(result, 1)
  379.         end
  380.         if result[1] then
  381.             return unpack(result)
  382.         else
  383.             return "failure"
  384.         end
  385.     end
  386.  
  387.     -- Get the time and weather!
  388.     local function getTime(city)
  389.         --local resp, time = getTime(settings["city"])
  390.         local resp, cur, today = getWT(city)
  391.         if resp == "success" then
  392.             return "success", cur["time"]
  393.         else return "failure" end
  394.     end
  395.  
  396.     local function displayTime(time)
  397.         if time then
  398.             if #time == 4 then
  399.                 mainText.setX(60)
  400.             elseif #time == 5 then
  401.                 mainText.setX(50)
  402.             elseif #time == 7 then
  403.                 mainText.setX(36)
  404.             elseif #time == 8 then
  405.                 mainText.setX(27)
  406.             end
  407.             mainText.setText(time)
  408.         end
  409.     end
  410.  
  411.     local function resetScreen()
  412.         thirdText.setText("")
  413.         header.setText("")
  414.         forthText.setText("")
  415.         tempText.setText("")
  416.         mainText.setText("")
  417.         mainText.setColor(gColors.text)
  418.         mainText.setScale(3)
  419.         mainText.setY(32)
  420.         secondText.setText("")
  421.         secondText.setColor(gColors.blue)
  422.         secondText.setY(57)
  423.         os.queueEvent("plastic_clock_manager", "show")
  424.         centerText("Welcome, " .. settings["name"], secondText)
  425.     end
  426.  
  427.     local function textScreen()
  428.         thirdText.setText("")
  429.         header.setText("")
  430.         mainText.setText("")
  431.         secondText.setText("")
  432.         os.queueEvent("plastic_clock_manager", "hide")
  433.         reliableSleep(0.05)
  434.         header.setScale(1)
  435.         mainText.setScale(1)
  436.         secondText.setScale(1)
  437.         thirdText.setScale(1)
  438.         header.setColor(gColors.text)
  439.         mainText.setColor(gColors.text)
  440.         secondText.setColor(gColors.text)
  441.         thirdText.setColor(gColors.text)
  442.         header.setY(25)
  443.         mainText.setY(37)
  444.         secondText.setY(47)
  445.         thirdText.setY(57)
  446.         reliableSleep(0.1)
  447.     end
  448.  
  449.     local function squeezeScreen()
  450.         thirdText.setText("")
  451.         header.setText("")
  452.         mainText.setText("")
  453.         secondText.setText("")
  454.         forthText.setText("")
  455.         os.queueEvent("plastic_clock_manager", "hide")
  456.         reliableSleep(0.05)
  457.         header.setScale(1)
  458.         mainText.setScale(1)
  459.         secondText.setScale(1)
  460.         thirdText.setScale(1)
  461.         forthText.setScale(1)
  462.         header.setColor(gColors.text)
  463.         mainText.setColor(gColors.text)
  464.         secondText.setColor(gColors.text)
  465.         thirdText.setColor(gColors.text)
  466.         forthText.setColor(gColors.text)
  467.         header.setY(22)
  468.         mainText.setY(31)
  469.         secondText.setY(40)
  470.         thirdText.setY(49)
  471.         forthText.setY(58)
  472.         reliableSleep(0.1)
  473.     end
  474.  
  475.     -- Setup functions
  476.     local function setupName()
  477.         thirdText.setY(57)
  478.         secondText.setText("")
  479.         mainText.setText("")
  480.         thirdText.setText("")
  481.         centerText("What's your name?", mainText)
  482.         secondText.setY(47)
  483.         secondText.setScale(1)
  484.         secondText.setColor(gColors.text)
  485.         centerText("Ex: $$John", secondText)
  486.         local e, msg = os.pullEvent("chat_command")
  487.         local name = msg
  488.         secondText.setText("")
  489.         centerText("Your name is", mainText)
  490.         centerText(name .. "?", secondText)
  491.         thirdText.setColor(gColors.blue)
  492.         centerText("Options: $$y/n", thirdText)
  493.         while true do
  494.             local e, msg = os.pullEvent("chat_command")
  495.             msg = trimText(msg:lower())
  496.             if msg:find("y") then
  497.                 return name
  498.             elseif msg:find("n") then
  499.                 return setupName()
  500.             end
  501.         end
  502.     end
  503.  
  504.  
  505.     local function setupTime()
  506.         thirdText.setY(57)
  507.         secondText.setText("")
  508.         thirdText.setText("")
  509.         centerText("Use 12h Time Format?", mainText)
  510.         secondText.setColor(gColors.blue)
  511.         centerText("Options: $$y/n", secondText)
  512.         while true do
  513.             local e, msg = os.pullEvent("chat_command")
  514.             msg = trimText(msg:lower())
  515.             if msg:find("y") then
  516.                 return true
  517.             elseif msg:find("n") then
  518.                 return false
  519.             end
  520.         end
  521.     end
  522.  
  523.     local function setupTemperature()
  524.         thirdText.setY(57)
  525.         secondText.setText("")
  526.         thirdText.setText("")
  527.         centerText("Celsius or Farenheit?", mainText)
  528.         secondText.setColor(gColors.blue)
  529.         centerText("Options: $$c/f", secondText)
  530.         while true do
  531.             local e, msg = os.pullEvent("chat_command")
  532.             msg = trimText(msg:lower())
  533.             if msg:find("c") then
  534.                 return "c"
  535.             elseif msg:find("f") then
  536.                 return "f"
  537.             end
  538.         end
  539.     end
  540.  
  541.     local function setupLocation()
  542.         thirdText.setY(57)
  543.         secondText.setText("")
  544.         thirdText.setText("")
  545.         secondText.setColor(gColors.text)
  546.         thirdText.setColor(gColors.text)
  547.         centerText("What's your city?", mainText)
  548.         centerText("(To get time/weather)", secondText)
  549.         centerText("Ex: $$New York", thirdText)
  550.         while true do
  551.             local e, city = os.pullEvent("chat_command")
  552.             thirdText.setColor(gColors.yellow)
  553.             centerText("Connecting...", thirdText)
  554.             local resp, cur = getWT(city)
  555.             if resp == "success" then
  556.                 mainText.setText("")
  557.                 secondText.setText("")
  558.                 thirdText.setText("")
  559.                 centerText("You're in", mainText)
  560.                 centerText(cur["location"] .. "?", secondText)
  561.                 thirdText.setColor(gColors.blue)
  562.                 centerText("Options: $$y/n", thirdText)
  563.                 while true do
  564.                     local e, msg = os.pullEvent("chat_command")
  565.                     msg = trimText(msg:lower())
  566.                     if msg:find("y") then
  567.                         return city
  568.                     elseif msg:find("n") then
  569.                         return setupLocation()
  570.                     end
  571.                 end
  572.             else
  573.                 thirdText.setColor(gColors.red)
  574.                 centerText("Invalid city!", thirdText)
  575.             end
  576.         end
  577.     end
  578.  
  579.     local function mainThread()
  580.         local function start()
  581.             local function welcome()
  582.                 centerText("Welcome to", mainText)
  583.                 secondText.setScale(3)
  584.                 secondText.setX(40)
  585.                 slowText("Plastic", secondText)
  586.                 reliableSleep(2)
  587.                 secondText.setText("")
  588.                 mainText.setText("")
  589.                 centerText("Setup", header)
  590.                 mainText.setText("")
  591.                 mainText.setColor(gColors.text)
  592.                 mainText.setY(37)
  593.                 thirdText.setY(57)
  594.                 return setupName()
  595.             end
  596.  
  597.             if firstTime then
  598.                 settings["name"] = welcome()
  599.                 settings["use12hour"] = setupTime()
  600.                 settings["city"] = setupLocation()
  601.                 settings["temperature"] = setupTemperature()
  602.                 settings["showtime"] = "ingame"
  603.  
  604.                 local f = io.open("/plasticOptions", "w")
  605.                 f:write(textutils.serialize(settings))
  606.                 f:close()
  607.                 closeAnimation()
  608.                 reliableSleep(1)
  609.                 shell.run(plasticInstallation, "nodaemon", unpack(tArgs))
  610.                 error()
  611.             else
  612.                 return
  613.             end
  614.         end
  615.  
  616.         local function convert(query)
  617.             secondText.setX(25)
  618.             slowText("Powered by STANDS4 APIs", secondText)
  619.             --reliableSleep(1)
  620.             --secondText.setX(35)
  621.             --slowText("Converting... | cancel", secondText)
  622.             local resp, msg = plasticGet("http://www.stands4.com/services/v2/conv.php?uid=2464&tokenid=lQAygI15b9x34e2L&expression=" .. textutils.urlEncode(query))
  623.             if resp == "success" then
  624.                 if tonumber(msg:match("<errorCode>(%d+)")) > 0 then
  625.                     centerText(trimText(msg:match("<errorMessage>([^<]+)</errorMessage>")), secondText)
  626.                     return
  627.                 else
  628.                     local response = msg:match("<result>([^<]+)</result>")
  629.                     local replaceable = {["kilogram"] = "kg", ["nautical mile"] = "nmile" , ["megabyte"] = "mb", ["gigabyte"] = "gb", ["kilobyte"] = "kb"
  630.                         ,["millimeter"] = "mm", ["centimeter"] = "cm", ["micrometer"] = "Um", ["nanometer"] = "nm", ["terrabyte"] = "tb", ["exabyte"] = "eb",
  631.                         ["British"] = "gb", ["kilometer"] = "km", ["hour"] = "h", [" / "] = "/", ["&amp;"] = "", ["deg;"] = ""}
  632.                     for k,v in pairs(replaceable) do
  633.                         response = response:lower():gsub(k,v)
  634.                         response = response:lower():gsub(k .. "s",v)
  635.                     end
  636.                     if #response >24 then
  637.                         local startSearch = response:find("%=")
  638.                         local trim = response:find("%.", startSearch)
  639.                         local units = response:find("%s", trim)
  640.                         local nresponse = response:sub(1, trim+3) .. response:sub(units,-1)
  641.                         response = trimText(nresponse)
  642.                     end
  643.                     secondText.setX(25)
  644.                     if #response > 22 then
  645.                         slowText(response, secondText)
  646.                     else
  647.                         centerText(response, secondText)
  648.                     end
  649.                     return
  650.                 end
  651.             elseif resp == "failure" then
  652.                 centerText("Service not available", secondText)
  653.                 return
  654.             elseif resp == "cancel" then
  655.                 centerText("Request Cancelled", secondText)
  656.                 return
  657.             end
  658.         end
  659.  
  660.         local function renderWeather(city)
  661.             local resp, cur, day = nil
  662.             centerText("Src: World Weather Online",secondText)
  663.             if not city then
  664.                 resp, cur, day = getWT(settings["city"], true)
  665.             else
  666.                 resp, cur, day = getWT(city, true)
  667.             end
  668.             if resp == "success" then
  669.                     squeezeScreen()
  670.                     header.setColor(gColors.blue)
  671.                     centerText(cur["location"], header)
  672.                     mainText.setColor(gColors.textGray)
  673.                     centerText(cur["weather"], mainText)
  674.                     tempText.setX(97)
  675.                     tempText.setScale(3)
  676.                     tempText.setY(43)
  677.                     tempText.setColor(gColors.blue)
  678.                     slowText(cur["temp"]..settings["temperature"]:upper(), tempText)
  679.                     secondText.setX(23)
  680.                     slowText("Humidity: " .. cur["humidity"] .. "%", secondText)
  681.                     thirdText.setX(23)
  682.                     slowText("Current", thirdText)
  683.                     forthText.setX(23)
  684.                     slowText("$$back/day", forthText)
  685.                 local function loadCurrent()
  686.                     centerText(cur["weather"], mainText)
  687.                     slowText(cur["temp"]..settings["temperature"]:upper(), tempText)
  688.                     slowText("Current", thirdText)
  689.                     slowText("$$back/day", forthText)
  690.                     while true do
  691.                         local e, msg = os.pullEvent("chat_command")
  692.                         msg = trimText(msg:lower())
  693.                         if (msg == "back") or msg == "home" then
  694.                             return resetScreen()
  695.                         elseif (msg == "day") then
  696.                             return loadDay()
  697.                         end
  698.                     end
  699.                 end
  700.                 local function loadDay()
  701.                     centerText(day["weather"], mainText)
  702.                     slowText(day["high"]..settings["temperature"]:upper(), tempText)
  703.                     slowText("Low: " .. day["low"] .. (settings["temperature"]:upper()), thirdText)
  704.                     slowText("$$back/cur", forthText)
  705.                     while true do
  706.                         local e, msg = os.pullEvent("chat_command")
  707.                         msg = trimText(msg:lower())
  708.                         if (msg == "back") or msg == "home" then
  709.                             return resetScreen()
  710.                         elseif (msg:find("cur")) then
  711.                             return loadCurrent()
  712.                         end
  713.                     end
  714.                 end
  715.                 while true do
  716.                     local e, msg = os.pullEvent("chat_command")
  717.                     msg = trimText(msg:lower())
  718.                     if (msg == "back") or msg == "home" then
  719.                         return resetScreen()
  720.                     elseif (msg == "day") then
  721.                         return loadDay()
  722.                     end
  723.                 end
  724.             elseif resp == "cancel" then
  725.                 centerText("Request Cancelled", secondText)
  726.                 return
  727.             elseif resp == "invalid" then
  728.                 centerText("Invalid location!", secondText)
  729.                 return
  730.             else
  731.                 centerText("Service not available", secondText)
  732.                 return
  733.             end
  734.         end
  735.  
  736.         local function renderDate(city)
  737.             centerText("Src: World Weather Online",secondText)
  738.             local resp, cur = getWT(city, true)
  739.             if resp == "success" then
  740.                 textScreen()
  741.                 header.setColor(gColors.blue)
  742.                 centerText("Current Time/Date", header)
  743.                 centerText(cur["location"], mainText)
  744.                 centerText(cur["date"] .. " - " .. cur["time"], secondText)
  745.                 centerText("$$back", thirdText)
  746.                 while true do
  747.                     local e, msg = os.pullEvent("chat_command")
  748.                     msg = trimText(msg:lower())
  749.                     if (msg == "back") or (msg == "home") then
  750.                         resetScreen()
  751.                         return
  752.                     end
  753.                 end
  754.             elseif resp == "cancel" then
  755.                 centerText("Request Cancelled", secondText)
  756.                 return
  757.             elseif resp == "invalid" then
  758.                 centerText("Invalid location!", secondText)
  759.                 return
  760.             else
  761.                 centerText("Service not available", secondText)
  762.                 return
  763.             end
  764.         end
  765.  
  766.         local function getEnvs()
  767.             local newEnv = getfenv(0)
  768.             newEnv.secondText = secondText
  769.             newEnv.thirdText = thirdText
  770.             newEnv.forthText = forthText
  771.             newEnv.tempText = tempText
  772.             newEnv.mainText = mainText
  773.             newEnv.resetScreen = resetScreen
  774.             newEnv.squeezeScreen = squeezeScreen
  775.             newEnv.textScreen = textScreen
  776.             newEnv.slowText = slowText
  777.             newEnv.centerText = centerText
  778.             newEnv.plasticGet = plasticGet
  779.             newEnv.trimText = trimText
  780.             newEnv.header = header
  781.             newEnv.plastic = plastic
  782.             return newEnv
  783.         end
  784.  
  785.         local function home()
  786.             local function resetSecond()
  787.                 secondText.setText("")
  788.                 secondText.setColor(gColors.blue)
  789.                 secondText.setY(57)
  790.                 secondText.setScale(1)
  791.             end
  792.             thirdText.setText("")
  793.             header.setText("")
  794.             mainText.setText("")
  795.             mainText.setColor(gColors.text)
  796.             mainText.setScale(3)
  797.             mainText.setY(32)
  798.             secondText.setText("")
  799.             secondText.setColor(gColors.blue)
  800.             secondText.setY(57)
  801.             displayTime("00:00 --")
  802.             os.queueEvent("plastic_clock_manager", "show")
  803.             centerText("Welcome, " .. settings["name"], secondText)
  804.             while true do
  805.                 local skipAll = false
  806.                 local e, msg = os.pullEvent()
  807.                 if e == "chat_command" then
  808.                     msg = trimText(msg:lower())
  809.                     if searchArgs("root") then
  810.                         for k,v in pairs(rootApps) do
  811.                             local a = loadstring("local cmd = [[" .. msg .. "]]\n" .. v)
  812.                             if a then
  813.                                 local env = getEnvs()
  814.                                 setfenv(a, env)
  815.                                 if a() then
  816.                                     skipAll = true
  817.                                 end
  818.                             else
  819.                                 print("Failed to run application: ", k)
  820.                             end
  821.                         end
  822.                     end
  823.                     if not(skipAll) then
  824.                         if (msg:sub(1,1) == "=") then
  825.                             local banned = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
  826.                             "p", "q", "r", "s", "t", "u", "v", "w", "x","y", "z"}
  827.                             local formula = msg:sub(2, -1):lower()
  828.                             for k,v in pairs(banned) do
  829.                                 formula = formula:gsub(v, "")
  830.                             end
  831.                             local func = loadstring("return " .. formula)
  832.                             local e, resp = pcall(func)
  833.                             if e and ((type(resp) == "number") or (type(resp) == "string")) then
  834.                                 centerText("=" .. resp, secondText)
  835.                             else
  836.                                 centerText("Syntax Error", secondText)
  837.                             end
  838.                         elseif msg == "help" then
  839.                             squeezeScreen()
  840.                             header.setColor(gColors.blue)
  841.                             centerText("Help, Try: $$", header)
  842.                             centerText("=12*3, home, irl, restart,", mainText)
  843.                             centerText("igl, quit, update, weather,", secondText)
  844.                             centerText("time/weather for city,", thirdText)
  845.                             centerText("convert x to y (back)", forthText)
  846.                             while true do
  847.                                 local _, msg = os.pullEvent("chat_command")
  848.                                 msg = trimText(msg:lower())
  849.                                 if (msg == "back") or (msg == "home") then
  850.                                     resetScreen()
  851.                                     break
  852.                                 end
  853.                             end
  854.                         elseif msg == "about" then
  855.                             secondText.setX(32)
  856.                             slowText("Plastic B v0.11 by 1lann", secondText)
  857.                         elseif (msg:sub(1,8) == "weather ") or msg == "weather" then
  858.                             local location = nil
  859.                             if msg:sub(1,12) == "weather for " then
  860.                                 location = trimText(msg:sub(13, -1))
  861.                             elseif msg:sub(1,11) == "weather in " then
  862.                                 location = trimText(msg:sub(12, -1))
  863.                             elseif msg == "weather" then
  864.                                 location = ""
  865.                             else
  866.                                 location = trimText(msg:sub(9, -1))
  867.                             end
  868.                             if location == "" then
  869.                                 renderWeather()
  870.                             else
  871.                                 renderWeather(location)
  872.                             end
  873.                         elseif (msg:sub(1,8) == "time in ") or (msg:sub(1,9) == "time for ") or (msg:sub(1,9) == "date for ") then
  874.                             local location = nil
  875.                             if (msg:sub(1,8) == "time in ") then
  876.                                 location = msg:sub(9,-1)
  877.                             else
  878.                                 location = msg:sub(10, -1)
  879.                             end
  880.                             if location == "" then
  881.                                 centerText("No city speicifed!", secondText)
  882.                             else
  883.                                 renderDate(location)
  884.                             end
  885.                         elseif msg == "settings" then
  886.                             local exit = false
  887.                             while true do
  888.                                 local noSave = false
  889.                                 textScreen()
  890.                                 header.setColor(gColors.blue)
  891.                                 centerText("Change Settings", header)
  892.                                 centerText("Options: temperature,", mainText)
  893.                                 centerText("time format, name,", secondText)
  894.                                 centerText("location, back", thirdText)
  895.                                 while true do
  896.                                     local _, msg = os.pullEvent("chat_command")
  897.                                     msg = trimText(msg:lower())
  898.                                     if (msg == "back") or (msg == "home") then
  899.                                         resetScreen()
  900.                                         exit = true
  901.                                         break
  902.                                     elseif (msg == "temperature") then
  903.                                         mainText.setText("")
  904.                                         secondText.setText("")
  905.                                         thirdText.setText("")
  906.                                         header.setText("")
  907.                                         header.setColor(gColors.textGray)
  908.                                         centerText("Setup", header)
  909.                                         settings["temperature"] = setupTemperature()
  910.                                         noSave = false
  911.                                     elseif (msg == "time format") then
  912.                                         mainText.setText("")
  913.                                         secondText.setText("")
  914.                                         thirdText.setText("")
  915.                                         header.setText("")
  916.                                         header.setColor(gColors.textGray)
  917.                                         centerText("Setup", header)
  918.                                         settings["use12hour"] = setupTime()
  919.                                         noSave = false
  920.                                     elseif (msg == "name") then
  921.                                         mainText.setText("")
  922.                                         secondText.setText("")
  923.                                         thirdText.setText("")
  924.                                         header.setText("")
  925.                                         header.setColor(gColors.textGray)
  926.                                         centerText("Setup", header)
  927.                                         settings["name"] = setupName()
  928.                                         noSave = false
  929.                                     elseif (msg == "location") then
  930.                                         mainText.setText("")
  931.                                         secondText.setText("")
  932.                                         thirdText.setText("")
  933.                                         header.setText("")
  934.                                         header.setColor(gColors.textGray)
  935.                                         centerText("Setup", header)
  936.                                         settings["city"] = setupLocation()
  937.                                         noSave = false
  938.                                     else
  939.                                         noSave = true
  940.                                     end
  941.                                     if not(noSave) then
  942.                                         local f = io.open("/plasticOptions", "w")
  943.                                         f:write(textutils.serialize(settings))
  944.                                         f:close()
  945.                                         mainText.setText("")
  946.                                         secondText.setText("")
  947.                                         thirdText.setText("")
  948.                                         header.setText("")
  949.                                         mainText.setColor(gColors.green)
  950.                                         centerText("Settings saved!", mainText)
  951.                                         sleep(2)
  952.                                         break
  953.                                     end
  954.                                 end
  955.                                 if exit then break end
  956.                             end
  957.                         elseif (msg:sub(1,8) == "convert ") then
  958.                             os.queueEvent("plastic_clock_manager", "show")
  959.                             resetSecond()
  960.                             convert(msg)
  961.                         elseif msg == "irl" then
  962.                             if not(settings["showtime"] == "irl") then
  963.                                 secondText.setX(30)
  964.                                 slowText("Changing time... | cancel", secondText)
  965.                                 local resp, time = getTime(settings["city"])
  966.                                 if resp == "success" then
  967.                                     settings["showtime"] = "irl"
  968.                                     os.queueEvent("plastic_clock_manager", "force", time)
  969.                                     os.queueEvent("plastic_clock_manager", "show")
  970.                                     os.queueEvent("plastic_clock_manager", "irl")
  971.                                     displayTime(time)
  972.                                     local f = io.open("/plasticOptions", "w")
  973.                                     f:write(textutils.serialize(settings))
  974.                                     f:close()
  975.                                     centerText("Time is now IRL", secondText)
  976.                                 else
  977.                                     centerText("Could not get IRL time!", secondText)
  978.                                 end
  979.                             else
  980.                                 centerText("Time is already IRL!", secondText)
  981.                             end
  982.                         elseif msg == "ingame" or (msg == "igl") then
  983.                             if not(settings["showtime"] == "ingame") then
  984.                                 settings["showtime"] = "ingame"
  985.                                 os.queueEvent("plastic_clock_manager", "force", textutils.formatTime(os.time(), not(settings["use12hour"])))
  986.                                 os.queueEvent("plastic_clock_manager", "show")
  987.                                 os.queueEvent("plastic_clock_manager", "ingame")
  988.                                 local f = io.open("/plasticOptions", "w")
  989.                                 f:write(textutils.serialize(settings))
  990.                                 f:close()
  991.                                 centerText("Time is now in-game", secondText)
  992.                             else
  993.                                 secondText.setX(30)
  994.                                 slowText("Time is already in-game!", secondText)
  995.                             end
  996.                         elseif msg == "update" then
  997.                             secondText.setX(35)
  998.                             centerText("Updating... | cancel", secondText)
  999.                             local resp, data = plasticGet("http://pastebin.com/raw.php?i=43nHyKXU")
  1000.                             if resp == "success" then
  1001.                                 local f = io.open(plasticInstallation, "w")
  1002.                                 f:write(data)
  1003.                                 f:close()
  1004.                                 closeAnimation()
  1005.                                 reliableSleep(1)
  1006.                                 shell.run(plasticInstallation, "nodaemon", unpack(tArgs))
  1007.                                 error()
  1008.                             elseif resp == "failure" then
  1009.                                 centerText("Failed to update!", secondText)
  1010.                             elseif resp == "cancel" then
  1011.                                 centerText("Request Cancelled", secondText)
  1012.                             end
  1013.                         elseif (msg == "home") or (msg == "clock") or (msg == "time") then
  1014.                             resetScreen()
  1015.                         elseif (msg == "restart") then
  1016.                             closeAnimation()
  1017.                             reliableSleep(1)
  1018.                             shell.run(plasticInstallation, "nodaemon", unpack(tArgs))
  1019.                             error()
  1020.                         elseif (msg == "exit") or (msg == "quit") or (msg == "stop") then
  1021.                             closeAnimation()
  1022.                             error()
  1023.                         else
  1024.                             centerText("Unknown Command!", secondText)
  1025.                         end
  1026.                     end
  1027.                 end
  1028.             end
  1029.         end
  1030.  
  1031.         start()
  1032.         home()
  1033.     end
  1034.  
  1035.     local function updateWeather()
  1036.         if sensor then
  1037.             if worldSensor then
  1038.                 header.setY(22)
  1039.                 local data = worldSensor.getTargets()["CURRENT"]
  1040.                 if data["Thundering"] then
  1041.                     header.setColor(gColors.textGray)
  1042.                     header.setX(53)
  1043.                     header.setText("Thunderstorm")
  1044.                 elseif data["Raining"] then
  1045.                     header.setColor(gColors.rain)
  1046.                     header.setX(80)
  1047.                     header.setText("Rain")
  1048.                 elseif data["Daytime"] then
  1049.                     header.setColor(gColors.yellow)
  1050.                     header.setX(75)
  1051.                     header.setText("Sunny")
  1052.                 else
  1053.                     header.setColor(gColors.rain)
  1054.                     header.setX(59)
  1055.                     header.setText("Clear Night")
  1056.                 end
  1057.             else
  1058.                 header.setColor(gColors.textGray)
  1059.                 header.setX(35)
  1060.                 header.setText("Missing world sensor!")
  1061.             end
  1062.         end
  1063.     end
  1064.  
  1065.     local function weatherThread()
  1066.         local timer = os.startTimer(5)
  1067.         while true do
  1068.             local e, id = os.pullEvent()
  1069.             if e == "plastic_clock_manager" then
  1070.                 if id == "hide" then
  1071.                     showClock = false
  1072.                 elseif id == "show" then
  1073.                     updateWeather()
  1074.                     timer = os.startTimer(5)
  1075.                     showClock = true
  1076.                 end
  1077.             elseif (e == "timer") and (timer == id) and showClock then
  1078.                 updateWeather()
  1079.                 timer = os.startTimer(5)
  1080.             end
  1081.         end
  1082.     end
  1083.  
  1084.     local function backgroundThread()
  1085.         local webUpdate = 0
  1086.         local resp, time = nil
  1087.         local lastTimeUpdate = os.clock()
  1088.         local function updateTime(prevTime, city)
  1089.             if os.clock() >= lastTimeUpdate+60 then
  1090.                 webUpdate  = webUpdate + 1
  1091.                 if webUpdate < 60 then
  1092.                     if prevTime then
  1093.                         local hour,minute,ampm = prevTime:match("^(%d+):(%d+)(.-)$")
  1094.                         if ampm == " AM" then
  1095.                             if settings["use12hour"] == false then
  1096.                                 return getTime(city)
  1097.                             end
  1098.                             lastTimeUpdate = os.clock()
  1099.                             if minute == "59" then
  1100.                                 if hour == "11" then
  1101.                                     return "success","12:00 PM"
  1102.                                 elseif hour == "12" then
  1103.                                     return "success","1:00 AM"
  1104.                                 else
  1105.                                     return "success",tostring(tonumber(hour)+1)..":00 AM"
  1106.                                 end
  1107.                             else
  1108.                                 if #tostring(tonumber(minute)+1) > 1 then
  1109.                                     return "success",hour..":"..tostring(tonumber(minute)+1).." AM"
  1110.                                 else
  1111.                                     return "success",hour..":0"..tostring(tonumber(minute)+1).." AM"
  1112.                                 end
  1113.                             end
  1114.                         elseif ampm == " PM" then
  1115.                             if settings["use12hour"] == false then
  1116.                                 return getTime(city)
  1117.                             end
  1118.                             lastTimeUpdate = os.clock()
  1119.                             if minute == "59" then
  1120.                                 if hour == "11" then
  1121.                                     return "success","12:00 AM"
  1122.                                 elseif hour == "12" then
  1123.                                     return "success","1:00 PM"
  1124.                                 else
  1125.                                     return "success",tostring(tonumber(hour)+1)..":00 PM"
  1126.                                 end
  1127.                             else
  1128.                                 if #tostring(tonumber(minute)+1) > 1 then
  1129.                                     return "success",hour..":"..tostring(tonumber(minute)+1).." PM"
  1130.                                 else
  1131.                                     return "success",hour..":0"..tostring(tonumber(minute)+1).." PM"
  1132.                                 end
  1133.                             end
  1134.                         else
  1135.                             if settings["use12hour"] == true then
  1136.                                 return getTime(city)
  1137.                             end
  1138.                             lastTimeUpdate = os.clock()
  1139.                             if minute == "59" then
  1140.                                 if hour == "23" then
  1141.                                     return "success", "0:00"
  1142.                                 else
  1143.                                     return "success", tostring(tonumber(hour)+1)..":".."00"
  1144.                                 end
  1145.                             else
  1146.                                 if #tostring(tonumber(minute)+1) > 1 then
  1147.                                     return "success",hour..":"..tostring(tonumber(minute)+1)
  1148.                                 else
  1149.                                     return "success",hour..":0"..tostring(tonumber(minute)+1)
  1150.                                 end
  1151.                             end
  1152.                         end
  1153.                     else
  1154.                         return "failure"
  1155.                     end
  1156.                 else
  1157.                     return getTime(city)
  1158.                 end
  1159.             else
  1160.                 return "success",prevTime
  1161.             end
  1162.         end
  1163.         local clockType = settings["showtime"]
  1164.         local timerID = nil
  1165.         local updateTimer = nil
  1166.         local previousClock = nil
  1167.         local dynamicSleep = nil
  1168.         local resp = nil
  1169.         if settings["showtime"] == "irl" then
  1170.             resp, time = getTime(settings["city"])
  1171.             if resp == "success" then
  1172.                 settings["showtime"] = "irl"
  1173.                 os.queueEvent("plastic_clock_manager", "force", time)
  1174.                 os.queueEvent("plastic_clock_manager", "show")
  1175.                 os.queueEvent("plastic_clock_manager", "irl")
  1176.                 displayTime(time)
  1177.                 local f = io.open("/plasticOptions", "w")
  1178.                 f:write(textutils.serialize(settings))
  1179.                 f:close()
  1180.  
  1181.             else
  1182.  
  1183.             end
  1184.         end
  1185.         if clockType == "ingame" then
  1186.             dynamicSleep = 0.83
  1187.         else
  1188.             dynamicSleep = 60
  1189.         end
  1190.         timerID = os.clock() + dynamicSleep
  1191.         os.startTimer(0.83)
  1192.         updateTimer = 0.83+os.clock()
  1193.         while true do
  1194.             if os.clock() >= updateTimer then
  1195.                     os.startTimer(0.83)
  1196.                     updateTimer = 0.83+os.clock()
  1197.             end
  1198.             local e, command, param =  os.pullEvent()
  1199.             if e == "plastic_clock_manager" then
  1200.                 if command == "show" then
  1201.                     if time then
  1202.                         displayTime(time)
  1203.                     end
  1204.                     mainText.setColor(gColors.text)
  1205.                     mainText.setScale(3)
  1206.                     mainText.setY(32)
  1207.                     header.setText("")
  1208.                     showClock = true
  1209.                     timerID = os.clock()
  1210.                 elseif command == "hide" then
  1211.                     header.setText("")
  1212.                     mainText.setText("")
  1213.                     timerID = os.clock()+2
  1214.                     showClock = false
  1215.                 elseif command == "irl" then
  1216.                     clockType = "irl"
  1217.                     dynamicSleep = 60
  1218.                     timerID = os.clock() + dynamicSleep
  1219.                 elseif command == "ingame" then
  1220.                     clockType = "ingame"
  1221.                     dynamicSleep = 0.83
  1222.                     timerID = os.clock() + dynamicSleep
  1223.                 elseif command == "force" then
  1224.                     if param then
  1225.                         time = param
  1226.                     end
  1227.                 elseif command == "kill" then
  1228.                     sleep(100)
  1229.                 end
  1230.             elseif os.clock() >= timerID then
  1231.                 if showClock then
  1232.                     if clockType == "irl" then
  1233.                         resp, time = updateTime(time,settings["city"])
  1234.                         if resp ~= "success" then
  1235.                             displayTime("ERROR")
  1236.                             webUpdate = 60
  1237.                         else
  1238.                             displayTime(time)
  1239.                         end
  1240.                     elseif clockType == "ingame" then
  1241.                         time = textutils.formatTime(os.time(), not(settings["use12hour"]))
  1242.                         displayTime(time)
  1243.                     end
  1244.                 end
  1245.                 timerID = os.clock() + dynamicSleep
  1246.             end
  1247.         end
  1248.     end
  1249.  
  1250.     local eError, eResp = pcall(function() parallel.waitForAny(mainThread,backgroundThread,weatherThread) end)
  1251.     if eError then
  1252.         return
  1253.     elseif eResp then
  1254.         if not(fs.exists("/plasticLog")) then
  1255.             local f = io.open("/plasticLog", "w") f:write("-- Plastic Error Logs --\n") f:close()
  1256.         end
  1257.         local f = io.open("/plasticLog", "a")
  1258.         f:write(eResp .. "\n")
  1259.         f:close()
  1260.         mainText.setText("")
  1261.         secondText.setText("")
  1262.         thirdText.setText("")
  1263.         forthText.setText("")
  1264.         tempText.setText("")
  1265.         header.setText("")
  1266.         header.setY(25)
  1267.         header.setColor(gColors.red)
  1268.         centerText("Plastic has crashed", header)
  1269.         mainText.setY(37)
  1270.         mainText.setColor(gColors.yellow)
  1271.         secondText.setColor(gColors.yellow)
  1272.         thirdText.setColor(gColors.yellow)
  1273.         mainText.setScale(1)
  1274.         secondText.setScale(1)
  1275.         thirdText.setScale(1)
  1276.         centerText("and will now restart.", mainText)
  1277.         secondText.setY(47)
  1278.         centerText("See /plasticLog for", secondText)
  1279.         thirdText.setY(57)
  1280.         centerText("more information.", thirdText)
  1281.         reliableSleep(3)
  1282.         closeAnimation()
  1283.         reliableSleep(1)
  1284.         shell.run(plasticInstallation, "nodaemon", unpack(tArgs))
  1285.         error()
  1286.     end
  1287. end
  1288.  
  1289. local function plasticWrapper()
  1290.     pcall(runPlastic)
  1291. end
  1292.  
  1293. --[[function os.pullEvent(lookfor)
  1294.     local data = {os.pullEventRaw()}
  1295.     --if not(data[1] == "timer") and not(data[1] == "ocs_success") then
  1296.         print(os.clock(), data[1], tostring(data[2]))
  1297.     --end
  1298.     if not lookfor then
  1299.         return unpack(data)
  1300.     elseif data[1] == lookfor then
  1301.         return unpack(data)
  1302.     end
  1303. end]]
  1304.  
  1305. if not(searchArgs("nodaemon")) then
  1306.     parallel.waitForAny(plasticWrapper, function() shell.run("/rom/programs/shell") end)
  1307.     closeAnimation()
  1308.     term.clear()
  1309.     term.setCursorPos(1,1)
  1310.     print("Thank you for using Plastic Beta v0.11 by 1lann")
  1311. else
  1312.     runPlastic()
  1313.     closeAnimation()
  1314.     term.clear()
  1315.     term.setCursorPos(1,1)
  1316.     print("Thank you for using Plastic Beta v0.11 by 1lann")
  1317. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement