FoxWorn3365

mkqlv3

Nov 15th, 2025 (edited)
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.60 KB | None | 0 0
  1. -- FILLEDBOX
  2. local function drawPixelInternal(xPos, yPos)
  3.     term.setCursorPos(xPos, yPos)
  4.     term.write(" ")
  5. end
  6.  
  7. local tColourLookup = {}
  8. for n = 1, 16 do
  9.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  10. end
  11.  
  12. function drawFilledBox(startX, startY, endX, endY, nColour)
  13.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  14.         "number" or type(endY) ~= "number" or
  15.         (nColour ~= nil and type(nColour) ~= "number") then
  16.         error("Expected startX, startY, endX, endY, colour", 2)
  17.     end
  18.  
  19.     startX = math.floor(startX)
  20.     startY = math.floor(startY)
  21.     endX = math.floor(endX)
  22.     endY = math.floor(endY)
  23.  
  24.     if nColour then term.setBackgroundColor(nColour) end
  25.     if startX == endX and startY == endY then
  26.         drawPixelInternal(startX, startY)
  27.         return
  28.     end
  29.  
  30.     local minX = math.min(startX, endX)
  31.     if minX == startX then
  32.         minY = startY
  33.         maxX = endX
  34.         maxY = endY
  35.     else
  36.         minY = endY
  37.         maxX = startX
  38.         maxY = startY
  39.     end
  40.  
  41.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  42. end
  43. -- CODE
  44.  
  45. -- Variables
  46. clicktocolor = {}
  47. itinerari = {}
  48.  
  49. -- Load data
  50. local h = fs.open("qlvdata-published", "r")
  51. data = textutils.unserialize(h.readAll())
  52. h.close()
  53.  
  54. function reset()
  55.     term.setBackgroundColor(colors.white)
  56.     term.clear()
  57.  
  58.     local qlv = paintutils.loadImage("qlv")
  59.     paintutils.drawImage(qlv, 2, 1)
  60.  
  61.     for k, v in ipairs(data) do
  62.         clicktocolor[v.position.x.."_"..v.position.y] = v.color
  63.  
  64.         local c = colors.lightGray
  65.         if v.type == "d" then
  66.             c = colors.gray
  67.         end
  68.  
  69.         term.setBackgroundColor(c)
  70.         drawPixelInternal(v.position.x, v.position.y)
  71.     end
  72.  
  73.     --term.setTextColor(colors.black)
  74.     --print(textutils.serialize(clicktocolor))
  75.  
  76.     term.setBackgroundColor(colors.white)
  77.     drawFilledBox(1, 1, 51, 1)
  78. end
  79.  
  80. while true do
  81.     reset()
  82.     term.setCursorPos(12, 1)
  83.     term.setTextColor(colors.black)
  84.     term.setBackgroundColor(colors.white)
  85.     term.write("CREA ITINERARIO")
  86.     term.setCursorPos(1, 2)
  87.     term.write("Nome:")
  88.     term.setCursorPos(7, 2)
  89.     local name = read()
  90.  
  91.     if name == "EXIT" then
  92.         break
  93.     end
  94.  
  95.     term.setCursorPos(5, 3)
  96.     term.write("Seleziona gli enti da attivare")
  97.     --print(textutils.serialize(clicktocolor))
  98.    
  99.     enti = {}
  100.     while true do
  101.         local ev, bt, x, y = os.pullEvent("mouse_click")
  102.    
  103.         if y > 17 then
  104.             break
  105.         end
  106.  
  107.         local pos = x.."_"..y
  108.         local cc = clicktocolor[pos]
  109.  
  110.         if cc ~= nil then
  111.             table.insert(enti, cc)
  112.  
  113.             term.setBackgroundColor(colors.red)
  114.             term.setCursorPos(x, y)
  115.             term.write(" ")
  116.             term.setBackgroundColor(colors.white)
  117.         end
  118.     end
  119.  
  120.     reset()
  121.     term.setCursorPos(12, 1)
  122.     term.setTextColor(colors.black)
  123.     term.setBackgroundColor(colors.white)
  124.     term.write("BLOCCA ITINERARIO")
  125.     term.setCursorPos(1, 2)
  126.     term.write("Dir. it (s/d):")
  127.     term.setCursorPos(20, 2)
  128.     local dir = read()
  129.     term.setCursorPos(5, 3)
  130.     term.write("Seleziona gli enti da BLOCCARE "..name)
  131.     --print(textutils.serialize(clicktocolor))
  132.    
  133.     enti_lock = {}
  134.     while true do
  135.         local ev, bt, x, y = os.pullEvent("mouse_click")
  136.    
  137.         if y > 17 then
  138.             break
  139.         end
  140.  
  141.         local pos = x.."_"..y
  142.         local cc = clicktocolor[pos]
  143.  
  144.         if cc ~= nil then
  145.             table.insert(enti_lock, cc)
  146.  
  147.             term.setBackgroundColor(colors.blue)
  148.             term.setCursorPos(x, y)
  149.             term.write(" ")
  150.             term.setBackgroundColor(colors.white)
  151.         end
  152.     end
  153.  
  154.     table.insert(itinerari, {name=name,enti=enti,lock=enti_lock,direction=dir})
  155. end
  156.  
  157. local h2 = fs.open("qlvd", "w")
  158. h2.write(textutils.serialize(itinerari))
  159. h2.close()
  160.  
  161. print("DONEEEE")
Advertisement
Add Comment
Please, Sign In to add comment