Hikooshi

Sorter

Aug 31st, 2021 (edited)
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 28.20 KB | None | 0 0
  1. local component = require("component")
  2. local gpu = component.gpu
  3. local transposer = component.transposer
  4. local term = require("term")
  5. local event = require("event")
  6. local unicode = require("unicode")
  7. local screen = component.screen
  8. local serialization = require("serialization")
  9. local sides = require("sides")
  10.  
  11.  
  12.  
  13. local waitTime = 10 --Время ожидания цикла
  14. local areas = {}
  15. local lists = {main = {x=2, y=6, width=40, height=16, content={}, limit=160, top = false, posF = 1, sb={0x0000FA, true, length=0, shift=0, work=false}, cFore = 0xFAFA00, cBack = 0x000000},
  16.                commands = {x=46, y=6, width=30, height=16, content={}, limit=160, top=true, posF = 1, sb={0x0000FA, true, length=0, shift=0, work=false}, cFore = 0xFAFA00, cBack = 0x000000},
  17.                states = {x=2, y=2, width=74, height=3, content={}, limit=160, top = true, posF = 1, sb={0x00FA00, true, length=0, shift=0, work=false}, cFore = 0xFAFA00, cBack = 0x000000}}
  18. local modemAddress = "1"
  19. local robotModemAddress = "2"
  20. local messages = {}
  21. local xCursor, yCursor, xCursorMove = 2, 23, 2
  22. local q = 0
  23. local rawLen = 13
  24. local funcs = {}
  25. local wScreen, hScreen = gpu.maxResolution()
  26. local matWl = {}
  27. local matBl = {"leather", "emerald", "lapislazuli", "slime"} --Черный список материалов
  28. local matBrn = {"chainmail"}
  29. local items = {"helmet", "chestplate", "leggings", "boots", "sword", "shovel", "axe"}
  30. local encList = {}
  31. local itemsBl = {["friender pearl"]=1, ["patient bag"]=2}
  32. local modsBl = {}
  33. local ignoreEncList = false
  34. local mainSearch = false
  35. local enchSearch = false
  36. local ignoreItemsBl = false
  37. local ignoreModsList = false
  38. local mstr = true
  39. local sd = "src"
  40. local smb = unicode.char(167)
  41. local mainID = 3
  42. local autoBl = false
  43. local autoEnc = false
  44. local sidesFlag = {"src", "loot"}
  45. local workSides = {src=5, loot=0, del=2, brn=3, enc=1, rep=4} --Стороны
  46. local tf = {["true"]=true, ["false"]=false}
  47. local wtm = 72*waitTime
  48. local tm1, tm2 = 0, 0
  49. local newSides = {[0]="Низ", [1]="Верх", [2]="Север", [3]="Юг", [4]="Запад", [5]="Восток"}
  50. local numbers = {i=1, ii=2, iii=3, iv=4, v=5, vi=6, "i", "ii", "iii", "iv", "v", "vi"}
  51. local slots = {src=39, loot=39}
  52. local slot = {src=1, loot=1}
  53. local sidesNames = {src = "Сторона для основного инвентаря", loot = "Сторона инвентаря для лутбоксов", del = "Сторона для уничтожения предметов", enc = "Сторона для сохранения зачарований", brn = "Сторона для сжигания предметов", rep = "Сторона для переплавки восстанавливаемых предметов"}
  54. local commandList = {"start",
  55.                      "Начать сортировку предметов",
  56.                      "    ",
  57.                      "F1",
  58.                      "Остановить сортировку предметов",
  59.                      "    ",
  60.                      "get src|loot line column",
  61.                      "Получить значение предмета в слоте",
  62.                      "src - основной инвентарь",
  63.                      "loot - инвентарь для лутбоксов",
  64.                      "line - строка в инвентаре",
  65.                      "column - столбец в инвентаре",
  66.                      "Столбец можно не указывать, но в этом случае в значение line нужно записывать номер слота",
  67.                      "    ",
  68.                      "side name newSide",
  69.                      "Указать новую сторону для инвентарей",
  70.                      "name: src, loot, rep, enc, del, brn",
  71.                      "src и loot аналогично; rep - сторона для ремонта и переплавки предметов; enc - сторона для сохранения зачарований; del - сторона для удаления предметов; brn - сторона для обычной переплавки предметов",
  72.                      "newSide: bottom, top, north, south, west, east",
  73.                      "    ",
  74.                      "bl nil|mod",
  75.                      "Запросить значения черного списка. При nil (само nil писать не надо) - черный список предметов, при mod - черный список модов",
  76.                      "bl add  src|loot  line  column|nil  nil|mod",
  77.                      "Добавить в черный список предмет или мод. Если последним аргументом ничего не указано, то добавится предмет, если указано слово 'mod', то добавится мод. Значения столбца можно указывать или не указывать по аналогии с функцией 'get'.",
  78.                      "Например, чтобы добавить предмет из 4 строки и 5 колонки основного инвентаря, запрос будет следующим:",
  79.                      "bl add src 4 5",
  80.                      "Или чтобы добавить предмет из 8 слота инвентаря для лутбоксов:",
  81.                      "bl add loot 8",
  82.                      "Но чтобы добавить мод из 16 слота инвентаря для лутбоксов:",
  83.                      "bl add loot 16 _ mod",
  84.                      "    ",
  85.                      "bl rmv  value  nil|mod",
  86.                      "Убрать из черного списка предмет или мод",
  87.                      "value - название предмета или его ID; nil|mod - по аналогии выше",
  88.                      "    ",
  89.                      "bl ignore nil|mod",
  90.                      "Игнорировать черный список предметов или модов",
  91.                      "    ",
  92.                      "bl save nil|mod",
  93.                      "Сохранить черный список предметов или модов",
  94.                      "    ",
  95.                      "bl asv  nil|true|false",
  96.                      "Автосохранение черных списков",
  97.                      "При nil - узнать текущее состояние; true или false - включить или выключить соответственно",
  98.                      "    ",
  99.                      "enc",
  100.                      "Получить список сохраненных зачарований",
  101.                      "    ",
  102.                      "enc add name",
  103.                      "Добавить в список зачарований имя зачарования. Силу указвать не требуется",
  104.                      "    ",
  105.                      "enc rmv value",
  106.                      "Удалить зачарование из списка зачарований. value - название, как в списке или ID",
  107.                      "    ",
  108.                      "enc list",
  109.                      "Переключает состояние поиска зачарований по списку на true или false",
  110.                      "    ",
  111.                      "enc search",
  112.                      "Включает или выключает поиск зачарований",
  113.                      "    ",
  114.                      "enc save",
  115.                      "Сохранить список зачарований в файл",
  116.                      "    ",
  117.                      "enc asv  nil|true|false",
  118.                      "Автосохранение списка зачарований в файл. Аналогично примерам выше",
  119.                      "    ",
  120.                      "exit",
  121.                      "Выход из программы"}
  122.  
  123. function add(list, data)
  124.  
  125. local wList = lists[list]
  126. local cPos, shift = 1, wList.width
  127. local totalLines = #wList.content
  128. if data then
  129. local count = math.ceil(unicode.wlen(data) / wList.width)
  130. if totalLines + count > 160 then
  131.   for i = 1, count do
  132.   table.remove(wList.content, 1)
  133.   end
  134. end
  135.       for i = 1, count do
  136.       table.insert(wList.content, unicode.sub(data, cPos, cPos+shift-1))
  137.       cPos = cPos + shift
  138.       end
  139. totalLines = #wList.content
  140.         if totalLines > wList.height and wList.top == false then
  141.         wList.posF = totalLines - wList.height + 1
  142.         end
  143. end
  144. if wList.sb then
  145. local length = 0
  146. local q = 0
  147.   if totalLines > wList.height then
  148.   length = math.floor(wList.height/totalLines*wList.height)
  149.   length = length > 0 and length or 1
  150.   q = (wList.height - 1 - length)/(totalLines - 1 - wList.height)
  151.   q = q > 0 and q or 1
  152.   wList.sb.q = q
  153. --  wList.sb.thumbPosition = math.ceil(math.abs(q*wlist.posF-realLength))
  154.   wList.sb.work = true
  155.   else
  156.   length = wList.height
  157.   q = 0
  158.   end
  159. wList.sb.q = q
  160. wList.sb.thumb = string.rep(" ", length)
  161. end
  162. if list == "main" then
  163. drawList(lists.main)
  164. end
  165.  
  166. end
  167.  
  168. function newID()
  169.  
  170. mainID = mainID + 1
  171. return mainID
  172.  
  173. end
  174.  
  175. function drawAreas(area)
  176.  
  177. gpu.setForeground(area.cFore or 0xFFFFFF)
  178. gpu.setBackground(area.cBack or 0x000000)
  179. gpu.fill(area.x, area.y, area.width, area.height, " ")
  180.   if area.sList then
  181.   drawList(area.sList)
  182.   end
  183.     if area.data then
  184.     local firstY = area.y
  185.       for i = 1, #area.data do
  186.       gpu.set(area.x, firstY, area.data[i])
  187.       firstY = firstY + 1
  188.       end
  189.         if area.data.outTbl then
  190.           for k,v in pairs(area.data.outTbl) do
  191.           gpu.set(area.x, firstY, tostring(k) .. " " .. tostring(v))
  192.           firstY = firstY + 1
  193.           end
  194.         end
  195.     end
  196. gpu.setBackground(0x000000)
  197.  
  198. end
  199.  
  200. function drawList(list)
  201.  
  202. gpu.setForeground(list.cFore)
  203. gpu.setBackground(list.cBack)
  204. local allLines = #list.content
  205. local linesCount = list.height
  206. gpu.fill(list.x, list.y, list.width, list.height, " ")
  207. local shiftF = -1
  208. local fLine = allLines > linesCount and linesCount or allLines
  209.   if not list.top and allLines < linesCount then
  210.   shiftF = linesCount - allLines - 1
  211.   end
  212.     for i = 1, fLine do
  213.     gpu.set(list.x, list.y+i+shiftF, list.content[i+list.posF-1])
  214.     end
  215.       if list.sb then
  216.       gpu.setBackground(0x000044)
  217.       gpu.fill(list.x+list.width, list.y, 1, list.height, " ")
  218.       gpu.setBackground(list.sb[1])
  219.       local thumbPosition = math.ceil(list.sb.q*(list.posF-1))
  220.       gpu.set(list.x+list.width, list.y+thumbPosition, list.sb.thumb, list.sb[2])
  221.       end
  222. gpu.setForeground(0xFAFA00)
  223. gpu.setBackground(0x000000)
  224.  
  225. end
  226.  
  227. function sidesInit()
  228.  
  229. local sidesFile = io.open("workSides", "r")
  230. if sidesFile then
  231.   for line in sidesFile:lines() do
  232.     for k,v in line:gmatch("(%w+)=(%d+)") do
  233.     workSides[k] = tonumber(v)
  234.     end
  235.   end
  236. sidesFile:close()
  237. else
  238. add("main", "[!]Файл с обозначением сторон не найден.")
  239. add("main", "Значения сторон будут взяты из внутренней таблицы")
  240. add("main", " ")
  241. end
  242.             for k,v in pairs(workSides) do
  243.               if v >= 0 and v < 6 then
  244.                 if not transposer.getInventorySize(v) then
  245.                 add("main", sidesNames[k].." -> не установлен инвентарь")
  246.                 end
  247.               add("main", sidesNames[k].." -> "..newSides[v])
  248.               else
  249.               add("main", sidesNames[k].." указана неверно")
  250.               end
  251.             add("main", " ")
  252.             end
  253. slots.src = transposer.getInventorySize(workSides.src)
  254. slots.loot = transposer.getInventorySize(workSides.loot)
  255. local fileBl = io.open("itemsBl", "r")
  256.   if fileBl then
  257.     itemsBl = {}
  258.     for line in fileBl:lines() do
  259.       for k,v in line:gmatch("(.+)=(%d+)") do itemsBl[k] = tonumber(v) end
  260.     end
  261.     mainID = getMaxValue(itemsBl)
  262.   fileBl:close()
  263.   add("main", "Значения черного списка загружены из файла")
  264.   else
  265.   add("main", "[!]Файл черного списка не найден")
  266.   end
  267. add("main", " ")
  268. local fileMods = io.open("modsBl", "r")
  269.   if fileMods then
  270.   modsBl = {}
  271.   for line in fileMods:lines() do
  272.     for k,v in line:gmatch("(%w+)=(%d+)") do modsBl[k] = tonumber(v) end
  273.   end
  274.   mainID = getMaxValue(modsBl)
  275.   fileMods:close()
  276.   add("main", "Значения черного списка модов загружены из файла")
  277.   else
  278.   add("main", "[!]Файл черного списка модов не найден")
  279.   end
  280. add("main", " ")
  281. local fileEnc = io.open("encList", "r")
  282.     if fileEnc then
  283.       encList = {}
  284.       for line in fileEnc:lines() do
  285.         for k,v in line:gmatch("(.+)=(%d+)") do encList[k] = tonumber(v) end
  286.       end
  287.       mainID = getMaxValue(encList)
  288.     fileEnc:close()
  289.     add("main", "Значения списка зачарований загружены из файла")
  290.     else
  291.     add("main", "[!]Файл списка зачарований не найден")
  292.     end
  293. add("main", " ")
  294. add("main", "Если стороны верны, то введите команду 'start', чтобы начать работу программы")
  295.  
  296. end
  297.  
  298. function saveData(tbl, name)
  299.  
  300. local file = io.open(name, "w")
  301. for k,v in pairs(tbl) do
  302. file:write(k .. "=" .. tostring(v) .. "\n")
  303. end
  304. file:close()
  305.  
  306. end
  307.  
  308. function funcs.bl(str)
  309.  
  310. local data = getArgs(str)
  311. local raw = tonumber(data[3]) or nil
  312. local column = tonumber(data[4]) or nil
  313. local wSlot = 0
  314. if data[1] == nil then
  315.   add("main", "Черный список:")
  316.   add("main", " ")
  317.   for k,v in pairs(itemsBl) do
  318.   add("main", tostring(v).." "..k)
  319.   end
  320.   add("main", " ")
  321. elseif data[1] == "add" then
  322.   if data[2] == "src" or data[2] == "loot" then
  323.         if raw and column then
  324.         wSlot = (raw-1)*rawLen+column
  325.         elseif raw and not column then
  326.         wSlot = raw
  327.         end
  328.     if wSlot > 0 and wSlot <= slots[data[2]] then
  329.       if data[5] == nil then
  330.       local lbl = unicode.lower(transposer.getStackInSlot(workSides[data[2]], wSlot).label)
  331.         if itemsBl[lbl] then
  332.         add("main", "Предмет "..lbl.." уже в черном списке")
  333.         else
  334.         itemsBl[lbl] = newID()
  335.           if autoBl then
  336.           saveData(itemsBl, "itemsBl")
  337.           end
  338.         add("main", "Предмет "..lbl.." добавлен в черный список")
  339.         end
  340.       elseif data[5] == "mod" then
  341.       local modName
  342.       local modTbl=transposer.getStackInSlot(workSides[data[2]], wSlot)
  343.         if modTbl then
  344.         modName = modTbl.name:match("%w+")
  345.           if modsBl[modName] then
  346.           add("main", "Мод " .. modName .. " уже в черном списке")
  347.           else
  348.           modsBl[modName] = newID()
  349.             if autoBl then
  350.             saveData(modsBl, "modsBl")
  351.             end
  352.           add("main", "Мод " .. modName .. " добавлен в черный список")
  353.           end
  354.         end
  355.       else
  356.       add("main", "Неверная команда")
  357.       end
  358.     else
  359.     add("main", "Слот указан не верно")
  360.     end
  361.   else
  362.   add("main", "Третье значение должно быть 'src' или 'loot'")
  363.   end
  364.   add("main", " ")
  365. elseif data[1] == "rmv" then
  366.   local wItem = ""
  367.   local mod = data[#data]
  368.   for i = 2, #data-(mod == "mod" and 1 or 0) do wItem = wItem .. " " .. data[i] end
  369.   local item = tonumber(wItem) or unicode.lower(wItem:sub(2))
  370.   local lbl
  371.     if type(item) == "number" then
  372.     local wTbl1 = mod == "mod" and modsBl or itemsBl
  373.       for k,v in pairs(wTbl1) do
  374.         if item == v then
  375.         lbl = k
  376.         wTbl1[lbl] = nil
  377.         break
  378.         end
  379.       end
  380.     elseif type(item) == "string" then
  381.     local wTbl2 = mod == "mod" and modsBl or itemsBl
  382.       for k,v in pairs(wTbl2) do
  383.         if k:match(item) then
  384.         lbl = k
  385.         wTbl2[lbl] = nil
  386.         break
  387.         end
  388.       end
  389.     end
  390. local wNm = mod == "mod" and "Мод" or "Предмет"
  391.         if lbl then
  392.           if autoBl then
  393.             if mod == "mod" then
  394.             saveData(modsBl, "modsBl")
  395.             else
  396.             saveData(itemsBl, "itemsBl")
  397.             end
  398.           end
  399.         add("main", wNm..lbl.." больше не в черном списке")
  400.         else
  401.         add("main", wNm.."не найден")
  402.         end
  403. elseif data[1] == "ignore" then
  404.   if data[2] == nil then
  405.   ignoreItemsBl = not ignoreItemsBl
  406.   add("main", "Парамерт 'Игнорировать Черный список' теперь "..tostring(ignoreItemsBl))
  407.   elseif data[2] == "mod" then
  408.   ignoreModsList = not ignoreModsList
  409.   add("main", "Параметр 'Игнорировать список модов' теперь "..tostring(ignoreModsList))
  410.   end
  411. setStates()
  412. elseif data[1] == "save" then
  413.   if data[2] == nil then
  414.   saveData(itemsBl, "itemsBl")
  415.   add("main", "Черный список сохранен в файл")
  416.   elseif data[2] == "mod" then
  417.   saveData(modsBl, "modsBl")
  418.   add("main", "Черный список модов сохранен в файл")
  419.   end
  420. elseif data[1] == "asv" then
  421.   if tf[data[2]] ~= nil then
  422.   autoBl = tf[data[2]]
  423.   end
  424.   add("main", "Автосохранение черного списка " .. (autoBl and "ON" or "OFF"))
  425. setStates()
  426. elseif data[1] == "mod" then
  427.   add("main", "Список модов:")
  428.   for k,v in pairs(modsBl) do
  429.   add("main", tostring(v) .. " " .. k)
  430.   end
  431.   add("main", " ")
  432. else
  433. add("main", "Неверная команда")
  434. end
  435.  
  436. end
  437.  
  438. function funcs.get(str)
  439.  
  440. local data = getArgs(str)
  441. local wSide = data[1]
  442. local raw = tonumber(data[2]) or nil
  443. local column = tonumber(data[3]) or nil
  444. local slot = 0
  445. if raw and column then
  446. slot = (raw-1)*rawLen+column
  447. elseif raw and not column then
  448. slot = raw
  449. end
  450.   if wSide == "src" or wSide == "loot" then
  451.     if slot > 0 and slot <= slots[wSide] then
  452.     local slotData = transposer.getStackInSlot(workSides[wSide], slot)
  453.     local label = slotData.label
  454.     local name = slotData.name
  455.     add("main", "В слоте "..tostring(slot).." находится:")
  456.     add("main", label)
  457.     add("main", name)
  458.     else
  459.     add("main", "Не верный слот")
  460.     end
  461.     add("main", " ")
  462.   else
  463.   add("main", "Сторона указана не верно")
  464.   end
  465.  
  466. end
  467.  
  468. function funcs.enc(str)
  469.  
  470. local data = getArgs(str)
  471. if data[1] == "add" then
  472. local wEnc = ""
  473. local result = false
  474.   for i = 2, #data do wEnc = wEnc .. " " .. data[i] end
  475.   wEnc = unicode.lower(wEnc:sub(2))
  476.     for k,v in pairs(encList) do
  477.       if wEnc == k then
  478.       result = true
  479.       break
  480.       end
  481.     end
  482.         if not result then
  483.         encList[wEnc] = newID()
  484.           if autoEnc then
  485.           saveData(encList, "encList")
  486.           end
  487.         add("main", "Зачарование добавлено в список")
  488.         else
  489.         add("main", "Зачарование уже в списке зачарований")
  490.         end
  491. elseif data[1] == nil then
  492. add("main", "Список зачарований:")
  493. add("main", " ")
  494.   for k,v in pairs(encList) do
  495.   add("main", k .. " " .. tostring(v))
  496.   end
  497. elseif data[1] == "rmv" then
  498. local wEnc = ""
  499. local enc
  500. local result = false
  501.   for i = 2, #data do wEnc = wEnc .. " " .. data[i] end
  502.   enc = tonumber(wEnc) or unicode.lower(wEnc:sub(2))
  503.     if type(enc) == "number" then
  504.       for k,v in pairs(encList) do
  505.         if v == enc then
  506.         encList[k] = nil
  507.         enc = k
  508.         result = true
  509.         break
  510.         end
  511.       end
  512.     elseif type(enc) == "string" then
  513.       for k,v in pairs(encList) do
  514.         if k == enc then
  515.         encList[k] = nil
  516.         result = true
  517.         break
  518.         end
  519.       end
  520.     end
  521.           if result then
  522.             if autoEnc then
  523.             saveData(encList, "encList")
  524.             end
  525.           add("main", "Зачарование " .. enc .. " удалено из списка")
  526.           else
  527.           add("main", "Такого зачарования нет в списке")
  528.           end
  529. elseif data[1] == "list" then
  530. ignoreEncList = not ignoreEncList
  531. add("main", "Состояние 'Игнорировать список зачарований' теперь " .. tostring(ignoreEncList))
  532. setStates()
  533. elseif data[1] == "search" then
  534. enchSearch = not enchSearch
  535. add("main", "Состояние 'Поиск зачарований' теперь " .. tostring(enchSearch))
  536. setStates()
  537. elseif data[1] == "save" then
  538. saveData(encList, "encList")
  539. add("main", "Список зачарований сохранен в файл")
  540. elseif data[1] == "asv" then
  541.   if tf[data[2]] ~= nil then
  542.   autoEnc = tf[data[2]]
  543.   end
  544. add("main", "Автосохранение списка зачарований " .. (autoEnc and "ON" or "OFF"))
  545. setStates()
  546. else
  547. add("main", "Неверная команда")
  548. end
  549.  
  550. end
  551.  
  552. function funcs.side(str)
  553.  
  554. local data = getArgs(str)
  555. local newSide = data[1]
  556. local nSide = sides[data[2]]
  557. if sidesNames[newSide] then
  558.   if nSide then
  559.   workSides[newSide] = nSide
  560.   add("main", sidesNames[newSide].." -> "..newSides[nSide])
  561.   else
  562.   add("main", "Такой стороны не существует")
  563.   end
  564. else
  565. add("main", "Инвентарь указан не верно")
  566. end
  567. local file = io.open("workSides", "w")
  568. for k,v in pairs(workSides) do
  569. file:write(k.."="..tostring(v).."\n")
  570. end
  571. file:close()
  572.  
  573. end
  574.  
  575. function main(strn)
  576.  
  577. local label, name, ench, count
  578. local s = workSides[sd]
  579. local allSlots = transposer.getAllStacks(workSides[sd])
  580. local slts = slots[sd]
  581. if allSlots then
  582.   for i = 1, slts do
  583. local result = false
  584. local resultSide = false
  585. local done = false
  586. label = unicode.lower(allSlots[i].label)
  587. name = allSlots[i].name
  588. ench = allSlots[i].enchantments
  589. count = allSlots[i].size
  590.         if ench and enchSearch then
  591.           if ignoreEncList then
  592.           done = transposer.transferItem(s, workSides.enc, _, i)
  593.           else
  594.             for e = 1, ench.n do
  595.                 local enc = unicode.lower(ench[e].label)
  596.                 local wEnc = ""
  597.                 local tEnc = {}
  598.                 for w in enc:gmatch("%S+") do table.insert(tEnc, w) end
  599.                   if numbers[tEnc[#tEnc]] then tEnc[#tEnc] = nil end
  600.                     for l = 1, #tEnc do wEnc = wEnc .. " " .. tEnc[l] end
  601.                     enc = wEnc:sub(2)
  602.               if encList[enc] then
  603.               done = transposer.transferItem(s, workSides.enc, _, i)
  604.               break
  605.               end
  606.             end
  607.           end
  608.         end
  609.                 if not done then
  610.                   if ignoreItemsBl == false then
  611.                       if itemsBl[label] then
  612.                       done = transposer.transferItem(s, workSides.del, _, i)
  613.                       end
  614.                    end
  615.                 end
  616.                     if not done then
  617.                       if not ignoreModsList then
  618.                         if modsBl[name:match("%w+")] then
  619.                         done = transposer.transferItem(s, workSides.del, _, i)
  620.                         end
  621.                       end
  622.                     end
  623.   if done == false then
  624.     for k,v in pairs(items) do
  625.       if name:match(v) then
  626.       result = true
  627.       break
  628.       end
  629.     end
  630.       if result then
  631.         for k1,v1 in pairs(matBl) do
  632.           if name:match(v1) then
  633.           resultSide = "del"
  634.           break
  635.           end
  636.         end
  637.         if resultSide == false then
  638.           for k2,v2 in pairs(matBrn) do
  639.             if name:match(v2) then
  640.             resultSide = "brn"
  641.             break
  642.             end
  643.           end
  644.         end
  645.         if not resultSide then
  646.           if not name:match("sword") then
  647.           resultSide = "rep"
  648.           else
  649.           resultSide = "del"
  650.           end
  651.         end
  652.           if resultSide then
  653.           transposer.transferItem(s, workSides[resultSide], _, i)
  654.           end
  655.       end
  656.   end
  657. end
  658. end
  659. if not mstr then tm1 = os.time() end
  660. mstr = not mstr
  661.  
  662. end
  663.  
  664. function getTableLength(tbl)
  665.  
  666. local length = 0
  667. for k,v in pairs(tbl) do
  668.   if k then length = length + 1 end
  669. end
  670. return length
  671.  
  672. end
  673.  
  674. function getMaxValue(tbl)
  675.  
  676. local mv = mainID
  677. for k,v in pairs(tbl) do
  678. mv = math.max(mv, v)
  679. end
  680. return mv
  681.  
  682. end
  683.  
  684. gpu.setResolution(80, 25)
  685. gpu.setBackground(0x444444)
  686. term.clear()
  687.  
  688. table.insert(areas, {x=lists.main.x, y=lists.main.y, width=lists.main.width, height=lists.main.height, sList=lists.main, cBack = lists.main.cBack})
  689. table.insert(areas, {x=lists.commands.x, y=lists.commands.y, width=lists.commands.width, height=lists.commands.height, sList=lists.commands, cBack = lists.commands.cBack})
  690. table.insert(areas, {x=lists.states.x, y=lists.states.y, width=lists.states.width, height=lists.states.height, sList=lists.states, cBack = lists.states.cBack})
  691. add("main")
  692. for i = 1, #commandList do
  693. add("commands", commandList[i])
  694. end
  695. add("states")
  696.  
  697. for k,v in pairs(areas) do
  698. drawAreas(v)
  699. end
  700. gpu.setForeground(0xFAFA00)
  701. gpu.setBackground(0x000000)
  702. gpu.fill(xCursor, yCursor, lists.main.width, 1, " ")
  703. term.setCursor(xCursor, yCursor)
  704. local str = ""
  705.  
  706. function getArgs(data)
  707.  
  708. local gArgs = {}
  709. for arg in data:gmatch("%S+") do table.insert(gArgs, arg) end
  710. table.remove(gArgs, 1)
  711. return gArgs
  712.  
  713. end
  714.  
  715. function funcs.exit()
  716.  
  717. gpu.setForeground(0xFFFFFF)
  718. gpu.setBackground(0x000000)
  719. term.clear()
  720. gpu.setResolution(wScreen, hScreen)
  721. os.exit()
  722.  
  723. end
  724.  
  725. sidesInit()
  726.  
  727. function funcs.start()
  728.  
  729. mainSearch = true
  730. tm1 = os.time()
  731. tm2 = os.time()+wtm
  732. add("main", "Сортировка предметов начата")
  733.  
  734. end
  735.  
  736. function setStates()
  737.  
  738. lists.states.content = {}
  739. add("states", "Поиск предметов по черному списку " .. (not ignoreItemsBl and "ON" or "OFF"))
  740. add("states", "Поиск модов по черному списку " .. (not ignoreModsList and "ON" or "OFF"))
  741. add("states", "Поиск зачарований " .. (enchSearch and "ON" or "OFF"))
  742. add("states", "Учитывать список зачарований " .. (not ignoreEncList and "ON" or "OFF"))
  743. add("states", "Автосохранение черного списка " .. (autoBl and "ON" or "OFF"))
  744. add("states", "Автосохранение списка зачарований " .. (autoEnc and "ON" or "OFF"))
  745. drawList(lists.states)
  746.  
  747. end
  748.  
  749. setStates()
  750.  
  751. while true do
  752. local event, address, char, port, distance, message, message1 = term.pull(0.5)
  753.   if event == "key_down" then
  754.   local addition = unicode.char(char):match("%C+") or ""
  755.   str = str .. addition
  756.   local newStr = unicode.sub(str, -40, unicode.wlen(str))
  757.   gpu.set(xCursor, yCursor, newStr)
  758.   xCursorMove = xCursorMove + (xCursorMove - xCursor < 40 and unicode.wlen(addition) or 0)
  759.   term.setCursor(xCursorMove, yCursor)
  760.     if char == 13 then
  761.     add("main", str)
  762.     drawList(lists.main)
  763.     gpu.setForeground(0xFAFA00)
  764.     gpu.setBackground(0x000000)
  765.     gpu.fill(xCursor, yCursor, 40, 1, " ")
  766.     xCursorMove = xCursor
  767.     term.setCursor(xCursor, yCursor)
  768.       local fnc = str:match("%w+")
  769.       if funcs[fnc] then funcs[fnc](str) end
  770.     str = ""
  771.     elseif char == 8 then
  772.     str = unicode.wtrunc(str, unicode.wlen(str))
  773.     gpu.fill(xCursor, yCursor, 40, 1, " ")
  774.     gpu.set(xCursor, yCursor, str)
  775.     xCursorMove = xCursorMove - (xCursorMove > xCursor and 1 or 0)
  776.     term.setCursor(xCursorMove, yCursor)
  777.     elseif char == 0 and port == 59 then
  778.     mainSearch = false
  779.     add("main", "Сортировка предметов остановлена")
  780.     end
  781.   elseif event == "scroll" then
  782.   local lst = false
  783.     for k,v in pairs(areas) do
  784.       if char >= v.x and char < v.x+v.width and port >= v.y and port < v.y+v.height and v.sList then
  785.       lst = v.sList
  786.       break
  787.       end
  788.     end
  789.         if lst and lst.sb.work then
  790.           if lst.content[(lst.posF - distance) + ((lst.height - 1) * ((1-distance)/2))] then
  791.           lst.posF = lst.posF - distance
  792.           end
  793.           drawList(lst)
  794.         end
  795.   end
  796.       if mainSearch then if tm2 - tm1 >= wtm then sd = sidesFlag[mstr and 1 or 2] main() end tm2=os.time() end
  797. end
Add Comment
Please, Sign In to add comment