hyndgrinder

Snuff

Jul 31st, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI('usr/mobController/Prison.lua')
  2. os.loadAPI('usr/getPeripheral.lua')
  3. textScale=0.5
  4. screen = term.current()
  5. chest = getPeripheral.findByName('copper')
  6. function p2Update(panel)
  7.     t= term.current()
  8.     term.redirect(panel)
  9.     term.clear()
  10.     term.setCursorPos(1,1)
  11.     print('     Mobs    ')
  12.     for k, v in pairs(prisons) do
  13.         if string.find(v.meta.displayName, 'blizz')  then
  14.             displayName = 'Blizz'
  15.         else
  16.             displayName = v.meta.displayName:gsub('Mob Imprisonment Tool ', '')
  17.             displayName = displayName:gsub('[()]', '')
  18.         end    
  19.         print(displayName)
  20.     end
  21.     p2x, p2y = term.getSize()
  22.     term.setCursorPos(p2x/2-3, p2y-#hdr)
  23.     print('reset')
  24.     term.redirect(t)
  25. end
  26.  
  27. function p2touch(periph, x,y)
  28.     t = term.current()
  29.     term.redirect(panel3)
  30.     prison = prisons[y-(#hdr+1)]
  31.     if not prison then
  32.         print('No prison selected')
  33.     else
  34.         term.clear()
  35.         term.setCursorPos(1,1)
  36.         Prison.pullPrison(chest)
  37.         scs, put_prison = Prison.putPrison(chest, prison)
  38.         if scs then
  39.             print(prison.meta.displayName)
  40.             print(prison.slot)
  41.         end
  42.     end
  43.     term.redirect(t)
  44. end
  45.  
  46.  
  47. hdr={
  48.    [[ _____ _              __  __ ]],
  49.    [[/  ___( )            / _|/ _|]],
  50.    [[\ `--.|/ _ __  _   _| |_| |_ ]],
  51.    [[ `--. \ | '_ \| | | |  _|  _|]],
  52.    [[/\__/ / | | | | |_| | | | |  ]],
  53.    [[\____/  |_| |_|\__,_|_| |_|  ]],
  54.     }
  55. --------initialize windows---------
  56. --wrap monitor
  57. mon = peripheral.wrap('top')
  58. mon.setTextScale(textScale)
  59.  
  60. --define windows based on monitor size
  61. monX, monY = mon.getSize()
  62. panel1 = window.create(mon, 1, 1, monX, #hdr)
  63. panel2 = window.create(mon, 1, #hdr+1, monX*0.3333, monY)
  64. panel3 = window.create(mon, monX*0.3333+1, #hdr+1, monX, monY)
  65.  
  66. panels={panel1, panel2, panel3}
  67.  
  68. --define css properties for each window
  69. panel_props = {
  70.     {panel=panel1, background = colors.lightGray, textColor=colors.blue},
  71.     {panel=panel2, background = colors.blue, textColor=colors.white},
  72.     {panel=panel3, background = colors.gray, textColor=colors.white},
  73. }
  74.  
  75. --draw windows
  76. term.redirect(panel1)
  77. term.setBackgroundColor(panel_props[1].background)
  78. term.setTextColor(panel_props[1].textColor)
  79. term.clear()
  80. for k,v in pairs(hdr) do
  81. print(v)
  82. end
  83.  
  84. for k,v in pairs(panels) do
  85.     for a,b in pairs(panel_props) do
  86.         if b.panel == v and v~=panel1 then
  87.             term.redirect(v)
  88.             term.setBackgroundColor(b.background)
  89.             term.setTextColor(b.textColor)
  90.             term.setCursorPos(1,1)
  91.             term.clear()
  92.         end
  93.     end
  94. end
  95. mon.setCursorPos(1,1)
  96.  
  97.  
  98. ----------MAIN LOOP----------
  99. while true do
  100.     scs, prisons = Prison.getPrisons()
  101.     if not scs then
  102.         scs, prisons = Prison.readChest(chest)
  103.     end
  104.     t = term.current()
  105.     p2Update(panel2)
  106.    
  107.     event, periph, x, y  = os.pullEvent('monitor_touch')
  108.     if event then
  109.         if x<monX*0.33 and y>#hdr+1 and y<=#hdr+1+#prisons then
  110.             p2touch(chest, x,y)
  111.         elseif x<monX*0.33 and y==monY then
  112.             Prison.resetPrisons(chest)
  113.         end
  114.     elseif event == 'key' then
  115.         if periph == keys.q then
  116.             term.redirect(screen)
  117.             print('quitting')
  118.             break
  119.         end
  120.    end    
  121. end
Add Comment
Please, Sign In to add comment