mrWhiskasss

контроль 50 реакторов

Jul 29th, 2021
610
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local com = require("component")
  2. local term = require("term")
  3. local event = require("event")
  4. local gpu = com.gpu
  5.  
  6. local proxyReactors
  7.  
  8. local ResX, ResY = gpu.getResolution()
  9. local color = {
  10.  ["StartForeground"] = gpu.getForeground(), -- цвета для завершения проги
  11.  ["StartBackground"] = gpu.getBackground(), -- цвета для завершения проги
  12.  ["background"] = 0x161a1e, -- цвет фона
  13.  ["UpBar"] = 0x2a323b,      -- цвет фона вверхней полосы (бар)
  14.  ["foreground"] = 0xf5f5f5, -- цвет текста
  15.  ["reactorON"] = 0x00DD00,  -- цвет текста состояния реактора.
  16.  ["reactorOFF"] = 0xFF0000, -- цвет текста состояния реактора.
  17.  ["reactorNIL"] = 0x5c5c5c, -- цвет состояния, если реактор не найден
  18.  ["lastColor"] = 0x000000,  -- штука для хоть какойнить оптимизации
  19.  ["warningHeat"] = 0xffba00,
  20.  ["normalHeat"] = 0x66cc00,
  21.  ["backgroundReactorIcon"] = { -- таакс... а это цвета для выделения блоков. что бы не сливались
  22.   ["background_1"] = 0x777777,
  23.   ["background_2"] = 0x878787,
  24.   ["background_nil_1"] = 0x393939,
  25.   ["background_nil_2"] = 0x262626
  26.  },
  27.  ["ByColors"] = {0xffffff,0x66ff00,0xe0e0e0,0x0060ff,0xc2c2c2,0xff0000,0x999999}
  28. }
  29. local addresses = {
  30.  --1      2      3      4      5      6      7      8      9         реактор
  31. "7a1f8910-06a8-43a0-ba8c-6b27db6a6295", "6805d282-0578-4a82-9d62-f2c243e7348d", "db0b7d44-f548-4c18-a1bb-ddf15f33b026", "b588b706-b5d6-4abd-993d-9f9038861de1", "533ae447-2575-499e-a816-a0dc852aa255", "d20a9f91-7d30-4ae6-936b-f88d4b296aa9", "263f47df-289e-42bb-9333-d1483258315d", "39a94a0d-a159-4c6a-b2be-d7fa79002aaa", "686c16e2-35c1-4b99-a385-d9c5a65fe986", "75c6a04b-c8b1-42ae-ae4b-233c8e9cab5d", "f421709b-6a23-4fd5-8a9c-05a2e047c83a", "495822c7-5570-4b85-bc1c-af4dc5e9a473", "15cc5994-d357-4bd0-819b-3c0fede6d05d", "d5148f85-7920-43d3-a773-0997f12d2784", "712263df-ce76-46b1-804e-44a2364df712", "c2d9dc27-c1a7-4f84-856b-658fcbf70e7f", "74f86322-a4f6-4e63-937d-0210dd08f951", "df94b33e-d85a-4d4d-bf32-e86dec7bbbfe", "c81d3234-956d-4fc4-bb99-5fcd757f918e", "410cdc0c-6864-4619-8a62-a4a9930e3f3d", "5fcb98a1-e9d0-437e-97a0-5dcc9dcf4c6c", "27389320-99b7-42d1-a8da-16acf319e8d0", "bd022ad7-6d46-4b21-828b-cfb76c34e5fc", "6127ff23-8a0b-4b1c-b182-8f701663bb39", "2cf30389-494b-4721-a048-6656fe6a56ce", "fd043f5d-c561-4841-8e2a-f01bc917ed56", "a65f2b2b-9149-4409-9146-e3e66c86cd28", "6ccbb2f6-dcad-44ea-84a0-1bce69ba183b", "d298d943-b476-41a9-ad8c-75202b93e1d8", "8b4cc36a-1923-4bdf-a60a-1a10702c7581", "c3d402cb-1078-4f96-ba9f-48b7f957974d", "91c7373d-285b-4b51-9f8b-970a0bd0d7a1", "b01ef098-150b-4b00-b3b1-4dc8b76b481e", "96e570a1-36ac-41db-810f-2c6e158035bf", "b6a92b7d-4580-46cd-8177-bc4b76926061", "eecf8f06-f074-43c6-8107-d72ea137b12f", "98d44057-028d-4ce3-8774-431e5a10d11d", "80912358-f868-4dc9-8449-529991eaf8fc", "7a57a8d3-665e-4e42-a5dc-03c3395b650b", "bfd526fb-8c5b-446b-b2ae-0f636e9eda80", "a4e449ef-5db2-4cee-8e95-3a8f24533640", "6ebed09a-17bc-49f1-8446-c95e008003fb", "d53f0f90-f0e3-4987-a7d9-4e5a5ffef2b8", "d1c25ba7-38fd-4b58-b885-7739bc594108", "d3f05ca1-f84b-415f-bca5-c3ece7db3e3e", "f6e12279-9dae-4778-9600-f0c82ac3b976", "c86b5366-e612-48e0-a251-333b1e6ce758", "537a924d-0d2c-4d53-a5c6-c2b0ea3799d9", "20e02864-8aab-4965-bf03-c459657ef0a1", "1ef764ce-bfb7-42a3-97bf-1de7633a6a1e"
  32. }
  33.  
  34. local statusReactors = {}
  35.  
  36. local IDColorBy = 1
  37.  
  38. local ExitStatus = false
  39.  
  40. local function DrawBy()
  41.  local by = "by oGoOgO"
  42.  gpu.setBackground(color.UpBar)
  43.  gpu.setForeground(color.ByColors[IDColorBy])
  44.  lastColor = color.ByColors[IDColorBy]
  45.  gpu.set(ResX-#by+1, 1, by)
  46.  if IDColorBy+1 <= #color.ByColors then IDColorBy = IDColorBy + 1 else IDColorBy = 1 end
  47. end
  48.  
  49. local function GetComponentsReactors(addressesComponents)
  50.  local proxys = {}
  51.  for i = 1, #addressesComponents do
  52.   proxys[i] = com.proxy(addressesComponents[i]) or "?"
  53.  end
  54.  return proxys
  55. end
  56.  
  57. local function GetStatusReactors(reactors)
  58.  local result = {}
  59.  for i = 1, #reactors do
  60.   if com.get(reactors[i].address) ~= nil then
  61.     result[i] = {
  62.      math.floor(reactors[i].getReactorEUOutput()),
  63.      reactors[i].getHeat()/reactors[i].getMaxHeat()*100
  64.     }
  65.   end
  66.  end
  67.  return result
  68. end
  69.  
  70. local function GetColorBackgroundReactor(ID,color1,color2)
  71.  return ID%2==0 and color1 or color2
  72. end
  73.  
  74. local function GetColorStatusReactor(ID,color1,color2)
  75.  return statusReactors[ID][1]>0 and color1 or color2
  76. end
  77.  
  78. local function ChangeForegroundColor(color)
  79.  if lastColor ~= color then
  80.   gpu.setForeground(color); lastColor = color
  81.  end
  82. end
  83.  
  84. local function DrawBarsAndOther()
  85.  gpu.setBackground(color.background)
  86.  gpu.setForeground(color.foreground)
  87.  term.clear()
  88.  
  89.  gpu.setBackground(color.UpBar)
  90.  gpu.fill(1,1,160,3," ")
  91.  gpu.fill(5,1,1,50," ")
  92.  gpu.set(1,1,"X")
  93.  for i=1, 6 do
  94.   local XPos = 4+(i-1)*24+i
  95.   gpu.set((XPos*2+26)/2-3,2, "Блок "..i)
  96.   gpu.fill(30+((i-1)*25),3,1,48," ")
  97.  end
  98. end
  99.  
  100. local function DrawStatusReactors(STS)
  101.  local IDReactor = 1
  102.  local IBlocks = 1
  103.  for address=1, #addresses do
  104.   local EUOutput, HeatReactor = "?"
  105.   local StartX = 6+(IBlocks-1)*24+IBlocks
  106.   local StartY = 5+(IDReactor-1)*5
  107.   local EndX = 22
  108.   local EndY = 5
  109.   local positionIcon = {StartX, StartY, EndX, EndY}
  110.   local PositionText = {
  111.    (positionIcon[1]*2+positionIcon[3])/2,
  112.    (positionIcon[2]*2+positionIcon[4])/2
  113.   }
  114.  
  115.   if STS[address] ~= nil then
  116.    EUOutput =    tostring(STS[address][1]).." EU/t"
  117.    HeatReactor = tostring(STS[address][2]).."% Нагрев"
  118.    gpu.setBackground(GetColorBackgroundReactor(IDReactor,color.backgroundReactorIcon.background_1,color.backgroundReactorIcon.background_2))
  119.    ChangeForegroundColor(GetColorStatusReactor(address,color.reactorON,color.reactorOFF))
  120.   else
  121.    ChangeForegroundColor(color.reactorNIL)
  122.    gpu.setBackground(GetColorBackgroundReactor(IDReactor,color.backgroundReactorIcon.background_nil_1,color.backgroundReactorIcon.background_nil_2))
  123.   end
  124.   gpu.fill(positionIcon[1],positionIcon[2],positionIcon[3],positionIcon[4]," ")
  125.   gpu.set(PositionText[1]-5,PositionText[2],"Реактор N"..IDReactor)
  126.   gpu.set(StartX,PositionText[2]+2,EUOutput)
  127.  
  128.   ChangeForegroundColor(STS[address][2]>=50 and color.warningHeat or color.normalHeat)
  129.   gpu.set(StartX+EndX-#HeatReactor,PositionText[2]-2,HeatReactor)
  130.   if IDReactor+1 <= 9 then IDReactor = IDReactor + 1 else IDReactor = 1; IBlocks = IBlocks + 1 end
  131.  end
  132. end
  133.  
  134. local function HandlerTouch()
  135.  local _, _, x, y = event.pull(1,"touch")
  136.  ExitStatus = x == 1 and y == 1
  137. end
  138.  
  139. local function Init()
  140.  for i=1, #addresses do addresses[i] = com.get(addresses[i]) or "?" end
  141.  proxyReactors = GetComponentsReactors(addresses)
  142.  DrawBarsAndOther()
  143. end
  144.  
  145. local function Main()
  146.  while not ExitStatus do
  147.   statusReactors = GetStatusReactors(proxyReactors)
  148.   DrawStatusReactors(statusReactors)
  149.   DrawBy() -- и это тоже не трогай, иначе будет плохо...
  150.   HandlerTouch()
  151.  end
  152.  gpu.setBackground(color.StartBackground)
  153.  gpu.setForeground(color.StartForeground)
  154.  term.clear()
  155. end
  156.  
  157. Init()
  158. Main()
RAW Paste Data