Advertisement
Guest User

elevator.lua

a guest
Jun 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. API = require("buttonAPI")
  2. local component = require("component")
  3. local sides = require("sides")
  4. local event = require("event")
  5. local keyboard = require("keyboard")
  6. local gpu = component.gpu
  7.  
  8. local colors = {
  9.   blue = 0x4286F4,
  10.   purple = 0xB673d6,
  11.   red = 0xC14141,
  12.   green = 0xDA841,
  13.   black = 0x000000,
  14.   white = 0xFFFFFF,
  15.   gray = 0x47494C,
  16.   lightGray = 0xBBBBBB
  17. }
  18.  
  19. local sections = {
  20.   buttons = { x = 1, y = 1, width = 50, height = 20, title = "  CONTROLS  "},
  21.   position = { x = 53, y = 1, width = 26, height = 20, title = "  POSITION  "}
  22. }
  23.  
  24. -- List floor (components)
  25. local floors = {
  26.   main = "c88",
  27.   first = "495",
  28.   second = "425"
  29. }
  30.  
  31. local screens = {
  32.   main = "180",
  33.  first = "380",
  34.  second = "39b"
  35. }
  36.  
  37. local floorComponents = {}
  38. local elevatorPosition = nil
  39.  
  40. function moveTo(floor)
  41.   floorComponents[floor].setOutput(sides.east, 15)
  42.   floorComponents[floor].setOutput(sides.east, 0)
  43.   elevatorPosition = floor
  44. end
  45.  
  46. function moveToMain()
  47.   moveTo(floors.main)
  48. end
  49.  
  50. function moveToFirst()
  51.   moveTo(floors.first)
  52. end
  53.  
  54. local maxWidth, maxHeight = component.gpu.maxResolution()
  55.  
  56. function clear()
  57.   gpu.fill(1, 1, maxWidth, maxHeight, " ")
  58. end
  59.  
  60. function setButtons()
  61.   for k,v in pairs(screens) do
  62.     gpu.bind(component.get(v))
  63.     API.screen()
  64.     API.setTable(k, moveToMain, 0, 0, 10, 10, "Call", {on = colors.green, off = colors.green})
  65.   end
  66.  
  67.   -- Set the first screen as default again
  68.   gpu.bind(component.get(screens.main))
  69. end
  70.  
  71. function printBorders(sectionName)
  72.   local s = sections[sectionName]
  73.  
  74.    -- set border
  75.   gpu.setBackground(colors.gray)
  76.   gpu.fill(s.x, s.y, s.width, 1, " ")
  77.   gpu.fill(s.x, s.y, 1, s.height, " ")
  78.   gpu.fill(s.x, s.y + s.height, s.width, 1, " ")
  79.   gpu.fill(s.x + s.width, s.y, 1, s.height + 1, " ")
  80.    
  81.   -- set title
  82.   gpu.setBackground(colors.black)
  83.   gpu.set(s.x + 2, s.y, s.title)
  84. end
  85.  
  86. -- Initialize components and move to bottom floor
  87. function init()
  88.   API.screen()
  89.  
  90.   event.listen("touch", API.checkxy)
  91.  
  92.   for k,v in pairs(floors) do
  93.     floorComponents[v] = component.redstone
  94.     floorComponents[v].address = component.proxy(component.get(v))
  95.   end
  96.  
  97.  
  98.   for k,v in pairs(screens) do
  99.     gpu.bind(component.get(v))
  100.     clear()
  101.  
  102.     for section,settings in pairs(sections) do
  103.       printBorders(section)
  104.       print(section)
  105.     end
  106.   end
  107.   component.bind(component.get(screens.main))
  108.   setButtons()
  109. end
  110.  
  111. function draw()
  112. --  for k,v in pairs(screens) do
  113.   --  gpu.bind(component.get(v))
  114. --  end
  115. end
  116.  
  117. while event.pull(0.05, "interrupted") == nil do
  118.   local event, address, arg1, arg2, arg3 = event.pull(1)
  119.   if type(address) == "string" and component.isPrimary(address) then
  120.     if event == "key_down" and arg2 == keyboard.keys.q then    
  121.       os.exit(1)
  122.     end
  123.   end
  124.   draw()
  125.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement