Advertisement
Ewgeniy

Untitled

Nov 2nd, 2021
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.09 KB | None | 0 0
  1. local c = require("component")
  2. local event = require("event")
  3. local geo, holo
  4. local gpu = c.gpu
  5. local ecs = require("ECSAPI")
  6. local palette = require("palette")
  7. local computer = require("computer")
  8.  
  9. local args = {...}
  10.  
  11. --Проверка на наличие нужных устройств
  12. if not c.isAvailable("geolyzer") or not c.isAvailable("hologram") then
  13.   ecs.error("Подключите геоанализатор и голографический проектор 2-ого уровня")
  14.   return
  15. else
  16.   geo = c.geolyzer
  17.   holo = c.hologram
  18. end
  19.  
  20. -------------------------
  21.  
  22. local massiv = {}
  23.  
  24. local yModifyer = -20
  25. local scales = {0.33, 0.75, 1, 1.5, 2, 2.5, 3}
  26. local currentScale = 1
  27. local countOfScales = #scales
  28.  
  29. local xScanFrom = tonumber(args[1]) or -24
  30. local xScanTo = tonumber(args[2]) or 23
  31. local zScanFrom, zScanTo = xScanFrom, xScanTo
  32.  
  33. local xSize, ySize = gpu.getResolution()
  34. local yCenter = math.floor(ySize / 2)
  35.  
  36. ---------------------------------------
  37.  
  38. local function clear()
  39.   holo.clear()
  40. end
  41.  
  42. local function getMemory()
  43.   local totalMemory = computer.totalMemory() /  1024
  44.   local freeMemory = computer.freeMemory() / 1024
  45.   local usedMemory = totalMemory - freeMemory
  46.  
  47.   local stro4ka = math.ceil(usedMemory).."/"..math.floor(totalMemory).."KB"
  48.  
  49.   totalMemory, freeMemory, usedMemory = nil, nil, nil
  50.  
  51.   return stro4ka
  52. end
  53.  
  54. local function changeScale()
  55.   if currentScale < countOfScales then
  56.     currentScale = currentScale + 1
  57.   else
  58.     currentScale = 1
  59.   end
  60.  
  61.   holo.setScale(scales[currentScale])
  62. end
  63.  
  64. local function displayRow(x, yModifyer, z,  tablica)
  65.   local color
  66.   for i = 1, #tablica do
  67.    
  68.     massiv[x][z][i] = math.ceil(massiv[x][z][i])
  69.      
  70.     if tablica[i] > 0 then
  71.      
  72.       color = 1
  73.  
  74.       if tablica[i] > 4 then
  75.         color = 2
  76.       end
  77.  
  78.       if tablica[i + yModifyer] then
  79.         holo.set(xScanTo - x + 1, i + yModifyer, zScanTo - z + 1, color)
  80.       end
  81.     end
  82.   end
  83.   color = nil
  84.   tablica = nil
  85. end
  86.  
  87. local function displayAllRows()
  88.   clear()
  89.   for x, val in pairs(massiv) do
  90.     for z, val2 in pairs(massiv[x]) do
  91.       displayRow(x, yModifyer, z, val2)
  92.     end
  93.   end
  94. end
  95.  
  96. local function scan()
  97.   clear()
  98.   ecs.clearScreen(0xffffff)
  99.   local barWidth = math.floor(xSize / 3 * 2)
  100.   local percent = 0
  101.   local xBar, yBar = math.floor(xSize/2 - barWidth / 2), yCenter
  102.   local countOfAll = (math.abs(xScanFrom) + math.abs(xScanTo) + 1) ^ 2
  103.  
  104.   local counter = 0
  105.   for x = xScanFrom, xScanTo do
  106.     massiv[x] = {}
  107.     for z = zScanFrom, zScanTo do
  108.  
  109.       massiv[x][z] = geo.scan(x, z, true)
  110.       for i = 1, #massiv[x][z] do
  111.         displayRow(x, yModifyer, z, massiv[x][z])
  112.       end
  113.       percent = counter / countOfAll * 100
  114.       ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, percent)
  115.       gpu.setForeground(0x444444)
  116.       gpu.setBackground(0xffffff)
  117.       ecs.centerText("x", yBar + 1, "   Сканирование стека на x = "..x..", z = "..z.."   ")
  118.       ecs.centerText("x", yBar + 3, "   "..math.floor(percent).."% завершено   ")
  119.       ecs.centerText("x", yBar + 2, "   "..getMemory().." RAM   ")
  120.       counter = counter + 1
  121.  
  122.     end
  123.   end
  124. end
  125.  
  126. local obj = {}
  127. local function newObj(class, name, ...)
  128.   obj[class] = obj[class] or {}
  129.   obj[class][name] = {...}
  130. end
  131.  
  132. local currentHoloColor = ecs.colors.lime
  133.  
  134. local function changeColorTo(color)
  135.   currentHoloColor = color
  136.   holo.setPaletteColor(1, color)
  137.   holo.setPaletteColor(2, 0xffffff - color)
  138. end
  139.  
  140.  
  141. local function main()
  142.   ecs.clearScreen(0xffffff)
  143.   local yPos = yCenter - 14
  144.   newObj("buttons", "Сканировать местность", ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Сканировать местность", 0x444444, 0xffffff)); yPos = yPos + 4
  145.   newObj("buttons", "Масштаб", ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Масштаб", 0x444444, 0xffffff)); yPos = yPos + 4
  146.   newObj("buttons", "Перерисовать голограмму", ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Перерисовать голограмму", 0x444444, 0xffffff)); yPos = yPos + 4
  147.   newObj("buttons", "+ 10 блоков", ecs.drawAdaptiveButton("auto", yPos, 3, 1, "+ 10 блоков", 0x444444, 0xffffff)); yPos = yPos + 4
  148.   newObj("buttons", "- 10 блоков", ecs.drawAdaptiveButton("auto", yPos, 3, 1, "- 10 блоков", 0x444444, 0xffffff)); yPos = yPos + 4
  149.   newObj("buttons", "Изменить цвет", ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Изменить цвет", currentHoloColor, 0xffffff)); yPos = yPos + 4
  150.   newObj("buttons", "Выйти", ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Выйти", 0x666666, 0xffffff)); yPos = yPos + 4
  151.   gpu.setBackground(0xffffff)
  152.   gpu.setForeground(0x444444)
  153.   ecs.centerText("x", yPos, "Модификатор высоты: "..yModifyer)
  154. end
  155.  
  156. ----------------------------
  157.  
  158. changeColorTo(0x009900)
  159. changeScale()
  160. main()
  161.  
  162. while true do
  163.   local e = {event.pull()}
  164.   if e[1] == "touch" then
  165.     for key, val in pairs(obj["buttons"]) do
  166.       if ecs.clickedAtArea(e[3], e[4], obj["buttons"][key][1], obj["buttons"][key][2], obj["buttons"][key][3], obj["buttons"][key][4]) then
  167.         ecs.drawAdaptiveButton(obj["buttons"][key][1], obj["buttons"][key][2], 3, 1, key, ecs.colors.green, 0xffffff)
  168.         os.sleep(0.3)
  169.         if key == "Сканировать местность" then
  170.           scan()
  171.         elseif key == "Масштаб" then
  172.           changeScale()
  173.         elseif key == "Перерисовать голограмму" then
  174.           displayAllRows()
  175.         elseif key == "+ 10 блоков" then
  176.           yModifyer = yModifyer - 10
  177.         elseif key == "- 10 блоков" then
  178.           yModifyer = yModifyer + 10
  179.         elseif key == "Выйти" then
  180.           ecs.prepareToExit()
  181.           return 0
  182.         elseif key == "Изменить цвет" then
  183.           local color = palette.draw("auto", "auto", currentHoloColor)
  184.           if color ~= nil then
  185.             changeColorTo(color)
  186.           end
  187.         end
  188.         main()
  189.         break
  190.       end
  191.     end
  192.   end
  193. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement