Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if fs.exists("dark") == false then -- load darkAPI
- print("Missing DarkAPI")
- sleep(2)
- print("Attempting to download...")
- getGit = http.get("https://github.com/darkrising/darkprograms/raw/darkprograms/darksecurity/dark")
- getGit = getGit.readAll()
- file = fs.open("dark", "w")
- file.write(getGit)
- file.close()
- os.reboot()
- else
- os.loadAPI("dark")
- end
- local mon = peripheral.wrap("back")
- mon.setTextScale(1)
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- Side = "bottom"
- c = colors.combine()
- local button = {}
- local clockTimer = -1
- local clockOffsetX,clockOffsetY=0,0
- local clockAutoCenter = true
- local clockUpdateRate = 0.08
- do
- local mW,mH = mon.getSize()
- clockOffsetY = mH-1
- if clockAutoCenter then
- clockOffsetX = (mW/2)-5
- end
- end
- function saveState()
- dark.db.save("State", button)
- end
- function LoadStuff()
- if fs.exists("State") == true then
- button = dark.db.load("State")
- end
- for name, data in pairs(button) do
- if data["active"] == true then
- c = colors.combine(c, data["color"])
- rs.setBundledOutput(Side, c)
- end
- end
- end
- function setTable(name, xmin, xmax, ymin, ymax, RScolor)
- xmax = xmax or mon.getSize()
- if not button[name] then
- button[name] = {}
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- button[name]["color"] = RScolor
- end
- end
- function fillTable()
- setTable("Arrow Dispensers", 1, nil,2 ,6, colors.white)
- setTable("Defense Station", 1, nil, 8, 12, colors.orange)
- setTable("Lights", 1, nil, 14, 18, colors.magenta)
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then currColor = colors.lime else currColor = colors.red end
- fill(name, currColor, data)
- end
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- data["active"] = not data["active"]
- if data["active"] == true then
- c = colors.combine(c, data["color"])
- else
- c = colors.subtract(c, data["color"])
- end
- rs.setBundledOutput(Side, c)
- print(name)
- end
- end
- end
- end
- function heading(text)
- w, h = mon.getSize()
- mon.setCursorPos((w-string.len(text))/2+1, 1)
- mon.write(text)
- end
- function updateClock()
- mon.setCursorPos(1+clockOffsetX,1+clockOffsetY)
- mon.clearLine()
- local time = os.time()
- local hours = math.floor(time)
- local minutes = math.floor( (time - hours)*60)
- local ampm = "am"
- if hours > 11 then
- ampm = "pm"
- if hours > 12 then
- hours = hours - 12
- end
- elseif hours == 0 then hours = 12
- end
- mon.write(string.format("%s:%s",(hours<10 and "0"..hours or hours),(minutes<10 and "0"..minutes or minutes)).. " " .. ampm)
- clockTimer = os.startTimer(clockUpdateRate)
- end
- fillTable()
- LoadStuff()
- updateClock()
- mon.clear()
- heading("Castle Controls V1.0")
- screen()
- while true do
- local evData = { os.pullEvent() }
- if evData[1] == "monitor_touch" then
- local e,side,x,y = unpack(evData)
- print(x..":"..y)
- checkxy(x,y)
- saveState()
- sleep(.1)
- mon.clear()
- heading("Castle Controls V1.0")
- screen()
- updateClock()
- elseif evData[1] == "timer" then
- if evData[2] == clockTimer then
- updateClock()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement