Advertisement
N1nt3nd0

DreamfinityDynmapChecker

Jun 24th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.14 KB | None | 0 0
  1. local c = require('component')
  2. local ser = require('serialization')
  3. local fs = require('filesystem')
  4. local comp = require('computer')
  5. local ev = require('event')
  6. local term = require('term')
  7. local u = require('unicode')
  8. local keyb = require('keyboard')
  9. local g = c.gpu
  10.  
  11. local wOld, hOld = g.getResolution()
  12. local w, h = 80, 25
  13. local factionsCount = 0
  14. local totalY = 65
  15. local work = true
  16.  
  17. local folder = '/factionsFinder'
  18. local scriptInfo = { label = 'Dreamfinity Factions Finder', version = '1.0', copyright = '(c) N1nt3nd0' }
  19. local paths = { factionsList = folder..'/factions.list', config = folder..'/config.cfg', backup = folder..'/factions_backup.list' }
  20. local urls = { dynmap = 'http://mc.dreamfinity.org:8122/up/world/tcracy/' }
  21. local colors = { general = 0x6699FF, gray = 0x333333, green = 0x00ff45, text = 0xCCCCCC, white = 0xFFFFFF, red = 0xFF0000, black = 0x000000 }
  22. local factionsListPoses = { x = 2, y = 7, w = 41, h = 18, startId = 1, selectedId = 1, pointer = '┴', pointerColor = colors.gray }
  23. local glassesListPoses = { x = 47, y = 7, w = 32, max = 8, pointer = '├─', pointerColor = colors.general }
  24. local rgbs = { {0,1,0}, {0,0,1}, {1,0,1}, {1,0,0}, {1,1,0}, {0,1,1}, {1,1,1}, {0,0,0} }
  25. local status = { x = 2, y = 2, label = 'Статус:', on = 'Online. ', off = 'Offline.' }
  26. local config = { x = 0, y = 0, z = 0, sortId = 1, sortDir = true, lastWarp = false }
  27. local scrollFactionsListTable = {  }
  28. local glassesList = {  }
  29. local factionsList = {  }
  30.  
  31. local buttons = { ['Выход'] = { x = w-7, y = 2, color = colors.general, action = 'stopkran()' },
  32.                   ['Обновления  приватов'] = { x = 46, y = 17, color = colors.general, action = 'checkAreaupdates()' },
  33.                   ['Поиск по базе данных'] = { x = 46, y = 18, color = colors.general, action = 'databaseSearch()' },
  34.                   ['Бэкапы  базы  данных'] = { x = 46, y = 19, color = colors.general, action = 'createBackupDialog()' },
  35.                   ['Ввести X'] = { x = 48, y = 22, color = colors.general, action = 'enterX()' },
  36.                   ['Ввести Y'] = { x = 48, y = 23, color = colors.general, action = 'enterY()' },
  37.                   ['Ввести Z'] = { x = 48, y = 24, color = colors.general, action = 'enterZ()' },
  38.                   ['алфв'] = { x = 2, y = 5, color = colors.general, action = 'sortScrollTable(1) drawFactionsList()' },
  39.                   ['дист'] = { x = 8, y = 5, color = colors.general, action = 'sortScrollTable(4) drawFactionsList()' },
  40.                   ['дата'] = { x = 14, y = 5, color = colors.general, action = 'sortScrollTable(5) drawFactionsList()' },
  41.                   ['▴'] = { x = 20, y = 5, color = colors.general, action = 'switchSortDir(true)' },
  42.                   ['▾'] = { x = 23, y = 5, color = colors.general, action = 'switchSortDir(false)' },
  43.                   ['COMP'] = { x = 73, y = 16, color = colors.general, coords = {}, action = 'setWarpCoords("COMP")' },
  44.                   ['1'] = { x = 73, y = 17, color = colors.general, coords = {-9000, 240, -6000}, action = 'setWarpCoords("1")' },
  45.                   ['2'] = { x = 73, y = 18, color = colors.general, coords = {1000, 240, -6000}, action = 'setWarpCoords("2")' },
  46.                   ['3'] = { x = 73, y = 19, color = colors.general, coords = {9000, 240, -6000}, action = 'setWarpCoords("3")' },
  47.                   ['4'] = { x = 73, y = 20, color = colors.general, coords = {-9000, 240, 0}, action = 'setWarpCoords("4")' },
  48.                   ['5'] = { x = 73, y = 21, color = colors.general, coords = {0, 240, 0}, action = 'setWarpCoords("5")' },
  49.                   ['6'] = { x = 73, y = 22, color = colors.general, coords = {9000, 240, 0}, action = 'setWarpCoords("6")' },
  50.                   ['7'] = { x = 73, y = 23, color = colors.general, coords = {-9000, 240, 6000}, action = 'setWarpCoords("7")' },
  51.                   ['8'] = { x = 73, y = 24, color = colors.general, coords = {0, 240, 6000}, action = 'setWarpCoords("8")' },
  52.                   ['9'] = { x = 73, y = 25, color = colors.general, coords = {9000, 240, 6000}, action = 'setWarpCoords("9")' } }
  53.  
  54. function drawGui()
  55.     g.setForeground(colors.black)
  56.     term.clear()
  57.     g.setResolution(w,h)
  58.     drawGuiElement(1,1,w,3,scriptInfo.label..' '..scriptInfo.version,colors.general)
  59.     drawGuiElement(46,4,35,12,'Выводимые на очки координаты',colors.general)
  60.     drawGuiElement(1,4,44,22,'Фракции:',colors.general,9)
  61.     -- drawBox(46,18,26,8,colors.gray)
  62.     setText(status.x,status.y,status.label,colors.general)
  63.     setText(79,5,'x',colors.general)
  64.     setText(61,2,scriptInfo.copyright,colors.red)
  65.     drawBox(46,21,21,5,colors.gray)
  66.     drawGlassesList()
  67.     toGlassesFromList()
  68.     convertFactionsTable()
  69.     sortScrollTable(config.sortId)
  70.     drawFactionsList()
  71.     for label in pairs(buttons) do
  72.         drawButton(label)
  73.     end
  74.     if config.lastWarp then
  75.         setWarpCoords(config.lastWarp)
  76.     else
  77.         drawCoordArea()
  78.     end
  79. end
  80.  
  81. function drawGuiElement(x,y,width,height,label,col,xCor)
  82.     local labelPosX = x + width/2 - u.len(label)/2
  83.     if xCor then
  84.         labelPosX = labelPosX + xCor
  85.     end
  86.     drawLine(x,y+2,width,colors.gray)
  87.     drawBox(x,y,width,height,colors.general)
  88.     setText(labelPosX,y+1,label,col)
  89. end
  90.  
  91. function drawButton(label)
  92.     local but = buttons[label]
  93.     setText(but.x, but.y, '['..string.rep(' ',u.len(label))..']',colors.gray)
  94.     setText(but.x + 1, but.y, label, but.color)
  95. end
  96.  
  97. function drawBox(x,y,width,height,col)
  98.     g.setForeground(col)
  99.     g.fill(x,y,1,height,'│')
  100.     g.fill(x+width-1,y,1,height,'│')
  101.     g.set(x,y,'┌'..string.rep('─',width-2)..'┐')
  102.     g.set(x,y+height-1,'└'..string.rep('─',width-2)..'┘')
  103. end
  104.  
  105. function drawLine(x,y,lenght,col,isVert)
  106.     g.setForeground(col)
  107.     if isVert then
  108.         g.fill(x,y,1,lenght,'│')
  109.     else
  110.         g.fill(x,y,lenght,1,'─')
  111.     end
  112. end
  113.  
  114. function setText(x,y,text,col)
  115.     g.setForeground(col)
  116.     g.set(x,y,text)
  117. end
  118.  
  119. function clearArea(x,y,width,height)
  120.     g.fill(x,y,width,height,' ')
  121. end
  122.  
  123. function setStatus(boolean)
  124.     if boolean then
  125.         setText(status.x+u.len(status.label)+1,status.y,status.on,colors.green)
  126.     else
  127.         setText(status.x+u.len(status.label)+1,status.y,status.off,colors.red)
  128.     end
  129. end
  130.  
  131. function press(act)
  132.     if act == 'lock' then
  133.         ev.ignore('touch',clicker)
  134.         ev.ignore('scroll',clicker)
  135.         ev.ignore('key_down',clicker)
  136.     else
  137.         ev.listen('touch',clicker)
  138.         ev.listen('scroll',clicker)
  139.         ev.listen('key_down',clicker)
  140.     end
  141. end
  142.  
  143. function link(label)
  144.     comp.beep(1500)
  145.     setText(buttons[label].x+1,buttons[label].y,label,colors.red)
  146.     os.sleep(0.2)
  147.     drawButton(label)
  148. end
  149.  
  150. function conf_S()
  151.     io.open(paths.factionsList,'w'):write(ser.serialize(factionsList,false)):flush():close()
  152.     io.open(paths.config,'w'):write(ser.serialize(config,false)):flush():close()
  153. end
  154.  
  155. function conf_R()
  156.     local cFile = io.open(paths.config,'r')
  157.     config = ser.unserialize(cFile:read(fs.size(paths.config))) cFile:close()
  158. end
  159.  
  160. function factionsList_R()
  161.     local fFile = io.open(paths.factionsList,'r')
  162.     factionsList = ser.unserialize(fFile:read(fs.size(paths.factionsList))) fFile:close()
  163. end
  164.  
  165. function getAreaUpdates()
  166.     local out = {  }
  167.     local json = ""
  168.     local result, response = pcall(internet.request,urls.dynmap)
  169.     setStatus(result)
  170.     if not result then
  171.         return out
  172.     end
  173.     for chunk in response do
  174.         json = json .. chunk
  175.     end
  176.     while json:find('areaupdated') do
  177.         json = json:sub(json:find('areaupdated')+12)
  178.         local x = ser.unserialize('{'..json:sub(json:find('"x": %[')+6,json:find('%]')-1)..'}')[1]
  179.         json = json:sub(json:find('%]')+1)
  180.         local z = ser.unserialize('{'..json:sub(json:find('"z": %[')+6,json:find('%]')-1)..'}')[1]
  181.         local _,labelStartCut = json:find('"label": ".')
  182.         local label = json:sub(labelStartCut,labelStartCut+json:sub(labelStartCut):find('"')-2)
  183.         out[label] = {x,z}
  184.     end
  185.     return out
  186. end
  187.  
  188. function checkMap()
  189.     local updated = false
  190.     local upd = getAreaUpdates()
  191.     for label,poses in pairs(upd) do
  192.         if factionsList[label] == nil or factionsList[label][1] + factionsList[label][2] ~= poses[1] + poses[2] then
  193.             factionsCount = factionsCount + 1
  194.             factionsList[label] = {poses[1],poses[2],factionsCount}
  195.             updated = true
  196.         end
  197.     end
  198.     if updated then
  199.         convertFactionsTable()
  200.         sortScrollTable(config.sortId)
  201.         drawFactionsList()
  202.     end
  203. end
  204.  
  205. function checkScroll(scrollDir)
  206.     factionsListPoses.startId = factionsListPoses.startId + -scrollDir
  207.     if factionsListPoses.startId > #scrollFactionsListTable - factionsListPoses.h + 1 then
  208.         factionsListPoses.startId = #scrollFactionsListTable - factionsListPoses.h + 1
  209.     end
  210.     if factionsListPoses.startId <= 0 then
  211.         factionsListPoses.startId = 1
  212.     end
  213.     drawFactionsList()
  214. end
  215.  
  216. function subber(label,coords,width)
  217.     return label:sub(1,width-u.len(coords))..string.rep(' ',width-u.len(label)-u.len(coords))..coords
  218. end
  219.  
  220. function drawFactionsList()
  221.     local counter = 0
  222.     drawLine(2,6,25,colors.gray)
  223.     if config.sortId == 1 then
  224.         setText(4,6,factionsListPoses.pointer,factionsListPoses.pointerColor)
  225.     elseif config.sortId == 4 then
  226.         setText(10,6,factionsListPoses.pointer,factionsListPoses.pointerColor)
  227.     elseif config.sortId == 5 then
  228.         setText(16,6,factionsListPoses.pointer,factionsListPoses.pointerColor)
  229.     end
  230.     if config.sortDir then
  231.         setText(21,6,factionsListPoses.pointer,factionsListPoses.pointerColor)
  232.     else
  233.         setText(24,6,factionsListPoses.pointer,factionsListPoses.pointerColor)
  234.     end
  235.     for i = factionsListPoses.startId, #scrollFactionsListTable do
  236.         local outString = subber(i..'. '..scrollFactionsListTable[i][1],' ['..scrollFactionsListTable[i][2]..','..scrollFactionsListTable[i][3]..']['..scrollFactionsListTable[i][4]..']', factionsListPoses.w+1)
  237.         if i == factionsListPoses.selectedId then
  238.             selectColor = colors.general
  239.         else
  240.             selectColor = colors.gray
  241.         end
  242.         setText(factionsListPoses.x,counter+factionsListPoses.y,outString,selectColor)
  243.         counter = counter + 1
  244.         if counter >= factionsListPoses.h then
  245.             break
  246.         end
  247.     end
  248.     setText(37,5,'-'..#scrollFactionsListTable..'-',colors.green)
  249. end
  250.  
  251. function debug(text)
  252.     setText(47,h,text..'  ',colors.gray)
  253. end
  254.  
  255. function removeFromGlassesList(id)
  256.     local i = 1
  257.     for label in pairs(glassesList) do
  258.         if i == id then
  259.             glassesList[label] = nil
  260.             break
  261.         end
  262.         i = i + 1
  263.     end
  264. end
  265.  
  266. function drawGlassesList()
  267.     local i = 0
  268.     clearArea(glassesListPoses.x,glassesListPoses.y,glassesListPoses.w+1,glassesListPoses.max)
  269.     for label, poses in pairs(glassesList) do
  270.         local outString = subber(label,' ['..poses[3]..']['..poses[4]..']',glassesListPoses.w)
  271.         local y = glassesListPoses.y+i
  272.         setText(glassesListPoses.x,y,outString,colors.gray)
  273.         setText(glassesListPoses.x+glassesListPoses.w,y,'x',colors.general)
  274.         i = i + 1
  275.     end
  276. end
  277.  
  278. function checkAreaupdates()
  279.     glassesList = {  }
  280.     glassesListMessage('Сканирую...')
  281.     local upd = getAreaUpdates()
  282.     for label, poses in pairs(upd) do
  283.         addToGlassesList(label,poses[1],poses[2])
  284.     end
  285.     drawGlassesList()
  286.     toGlassesFromList()
  287. end
  288.  
  289. function clearGlassesList()
  290.     glassesList = {  }
  291.     drawGlassesList()
  292.     toGlassesFromList()
  293. end
  294.  
  295. function glassesListMessage(txt)
  296.     local messagePosX = glassesListPoses.x + glassesListPoses.w/2 - u.len(txt)/2
  297.     clearArea(glassesListPoses.x,glassesListPoses.y,glassesListPoses.w+1,glassesListPoses.max)
  298.     setText(messagePosX+1,8,txt,colors.gray)
  299.     os.sleep(1.5)
  300. end
  301.  
  302. function input(x,y,width,button)
  303.     press('lock')
  304.     local str, S = '', ''
  305.     local wCorr = width - 4
  306.     clearArea(x,y,width-1,1)
  307.     setText(x,y,'[]',colors.gray)
  308.     while true do
  309.         evName,_,un,code = ev.pull(0.1)
  310.         if evName == 'key_down' then
  311.             if un ~= nil and un > 0 and code ~= keyb.keys.tab then
  312.                 if code == keyb.keys.enter then
  313.                     clearArea(x,y,width-1,1)
  314.                     press()
  315.                     if button then
  316.                         drawButton(button)
  317.                     else
  318.                         clearArea(x,y,width-1,1)
  319.                     end
  320.                     return str
  321.                 elseif code == keyb.keys.back then
  322.                     str = u.sub(str,1,-2)
  323.                 elseif un == 38 then
  324.                     str = str..u.char(167)
  325.                 else
  326.                     str = str..u.char(un)
  327.                 end
  328.                 if u.len(str) >= wCorr then
  329.                     S = u.sub(str,-wCorr)
  330.                 else
  331.                     S = str
  332.                 end
  333.                 setText(x+1,y,S,colors.general)
  334.                 setText(x+u.len(S)+1,y,'] ',colors.gray)
  335.             end
  336.         elseif evName == 'touch' then
  337.             press()
  338.             if button then
  339.                 drawButton(button)
  340.             else
  341.                 clearArea(x,y,width-1,1)
  342.             end
  343.             sad()
  344.             return false
  345.         end
  346.     end
  347. end
  348.  
  349. function sad()
  350.     comp.beep(300)
  351. end
  352.  
  353. function databaseSearch()
  354.     local bLabel = 'Поиск по базе данных'
  355.     local toFind = input(buttons[bLabel].x,buttons[bLabel].y,24,bLabel)
  356.     if toFind and tofind ~= "" then
  357.         for label, poses in pairs(factionsList) do
  358.             if label:upper():match(toFind:upper()) then
  359.                 addToGlassesList(label,poses[1],poses[2])
  360.             end
  361.         end
  362.         drawGlassesList()
  363.         toGlassesFromList()
  364.     end
  365. end
  366.  
  367. function enterX()
  368.     local bLabel = 'Ввести X'
  369.     local newX = input(buttons[bLabel].x,buttons[bLabel].y,12,bLabel)
  370.     if newX then
  371.         local num = checkNum(newX)
  372.         if num then
  373.             config.lastWarp = false
  374.             config.x = num
  375.             drawCoordArea()
  376.         end
  377.     end
  378.     convertFactionsTable()
  379.     sortScrollTable(config.sortId)
  380.     drawFactionsList()
  381. end
  382.  
  383. function enterY()
  384.     local bLabel = 'Ввести Y'
  385.     local newY = input(buttons[bLabel].x,buttons[bLabel].y,12,bLabel)
  386.     if newY then
  387.         local num = checkNum(newY)
  388.         if num then
  389.             config.lastWarp = false
  390.             config.y = num
  391.             drawCoordArea()
  392.         end
  393.     end
  394. end
  395.  
  396. function enterZ()
  397.     local bLabel = 'Ввести Z'
  398.     local newZ = input(buttons[bLabel].x,buttons[bLabel].y,12,bLabel)
  399.     if newZ then
  400.         local num = checkNum(newZ)
  401.         if num then
  402.             config.lastWarp = false
  403.             config.z = num
  404.             drawCoordArea()
  405.         end
  406.     end
  407.     convertFactionsTable()
  408.     sortScrollTable(config.sortId)
  409.     drawFactionsList()
  410. end
  411.  
  412. function drawCoordArea(isWarp)
  413.     local x = config.x..'     '
  414.     local y = config.y..'     '
  415.     local z = config.z..'     '
  416.     clearArea(68,16,5,10)
  417.     drawLine(71,16,10,colors.gray,true)
  418.     drawLine(66,23,5,colors.gray)
  419.     setText(66,23,glassesListPoses.pointer,colors.gray)
  420.     setText(71,23,'┤',colors.gray)
  421.     setText(59,22,x:sub(1,6),colors.text)
  422.     setText(59,23,y:sub(1,6),colors.text)
  423.     setText(59,24,z:sub(1,6),colors.text)
  424.     if isWarp then
  425.         setText(71,buttons[isWarp].y,glassesListPoses.pointer,glassesListPoses.pointerColor)
  426.     end
  427. end
  428.  
  429. function checkNum(int)
  430.     local try = tonumber(int)
  431.     if try then
  432.         if not (try < -30000) and not (try > 30000) then
  433.             return try
  434.         end
  435.     end
  436.     sad()
  437.     return false
  438. end
  439.  
  440. function getDistanse(x,z,x2,z2)
  441.     return math.floor(math.sqrt((x - x2)^2+(z - z2)^2))
  442. end
  443.  
  444. function switchSortDir(dir)
  445.     config.sortDir = dir
  446.     sortScrollTable(config.sortId)
  447.     drawFactionsList()
  448. end
  449.  
  450. function sorter(a,b)
  451.     if config.sortDir then
  452.         if config.sortId == 5 then
  453.             return b[config.sortId] < a[config.sortId]
  454.         else
  455.             return a[config.sortId] < b[config.sortId]
  456.         end
  457.     else
  458.         if config.sortId == 5 then
  459.             return b[config.sortId] > a[config.sortId]
  460.         else
  461.             return a[config.sortId] > b[config.sortId]
  462.         end
  463.     end
  464. end
  465.  
  466. function sortScrollTable(id)
  467.     config.sortId = id
  468.     table.sort(scrollFactionsListTable,sorter)
  469. end
  470.  
  471. function convertFactionsTable()
  472.     scrollFactionsListTable = {  }
  473.     local i = 1
  474.     for label, poses in pairs(factionsList) do
  475.         scrollFactionsListTable[i] = {label,poses[1],poses[2],getDistanse(poses[1],poses[2],config.x,config.z),poses[3]}
  476.         i = i + 1
  477.     end
  478. end
  479.  
  480. function getFactionsCount()
  481.     for _ in pairs(factionsList) do
  482.         factionsCount = factionsCount + 1
  483.     end
  484. end
  485.  
  486. function setWarpCoords(label)
  487.     local coords = buttons[label].coords
  488.     config.lastWarp = label
  489.     config.x = coords[1]
  490.     config.y = coords[2]
  491.     config.z = coords[3]
  492.     convertFactionsTable()
  493.     sortScrollTable(config.sortId)
  494.     drawFactionsList()
  495.     drawCoordArea(label)
  496. end
  497.  
  498. function addToGlassesList(label,x,z)
  499.     local sortTable = {  }
  500.     local i = 1
  501.     for _ in pairs(glassesList) do
  502.         if i >= glassesListPoses.max then
  503.             return
  504.         end
  505.         i = i + 1
  506.     end
  507.     for warp, data in pairs(buttons) do
  508.         local warpCoords = data.coords
  509.         if warpCoords then
  510.             local dist = getDistanse(x,z,warpCoords[1],warpCoords[3])
  511.             table.insert(sortTable,{dist,warp,warpCoords[1],warpCoords[2],warpCoords[3]})
  512.         end
  513.     end
  514.     table.sort(sortTable,function(a,b) if a[1] < b[1] then return true end return false end)
  515.     glassesList[label] = {x,z,sortTable[1][1],sortTable[1][2],sortTable[1][3],sortTable[1][4],sortTable[1][5]}
  516. end
  517.  
  518. function toGlassesFromList()
  519.     local i = 1
  520.     glasses.removeAll()
  521.     for label, poses in pairs(glassesList) do
  522.         local outString = i..'. '..label..' ['..poses[1]..', '..poses[2]..'] ['..poses[3]..'] ['..poses[4]..']'
  523.         local vertexes = getVertexes(poses[1],poses[2],poses[5],poses[6],poses[7])
  524.         local cube = glasses.addCube3D()
  525.         local r,g,b = rgbs[i][1],rgbs[i][2],rgbs[i][3]
  526.         cube.setColor(r,g,b)
  527.         cube.setAlpha(1)
  528.         cube.setViewDistance(30000)
  529.         cube.setVisibleThroughObjects(true)
  530.         cube.set3DPos(vertexes[4],vertexes[5],vertexes[6])
  531.         local line = glasses.addLine3D()
  532.         line.setScale(3)
  533.         line.setAlpha(1)
  534.         line.setColor(r,g,b)
  535.         line.setVertex(1,vertexes[1]+0.5,vertexes[2]+0.5,vertexes[3]+0.5)
  536.         line.setVertex(2,vertexes[4]+0.5,vertexes[5]+0.5,vertexes[6]+0.5)
  537.         local text = glasses.addTextLabel()
  538.         text.setScale(1)
  539.         text.setAlpha(0.8)
  540.         text.setColor(r,g,b)
  541.         text.setPosition(2,i*9-5)
  542.         text.setText(outString)
  543.         i = i + 1
  544.     end
  545. end
  546.  
  547. function getVertexes(factX,factZ,warpX,warpY,warpZ)
  548.     local compPos = buttons['COMP'].coords
  549.     local xStart = warpX - compPos[1]
  550.     local yStart = warpY - compPos[2]
  551.     local zStart = warpZ - compPos[3]
  552.     local xEnd = factX - compPos[1]
  553.     local yEnd = totalY - compPos[2]
  554.     local zEnd = factZ - compPos[3]
  555.     return { xStart, yStart, zStart, xEnd, yEnd, zEnd }
  556. end
  557.  
  558. function createBackup()
  559.     if fs.size(paths.factionsList) > fs.size(paths.backup) then
  560.         fs.copy(paths.factionsList,paths.backup)
  561.     end
  562. end
  563.  
  564. function createBackupDialog()
  565.     press('lock')
  566.     term.clear()
  567.     g.setForeground(colors.general)
  568.     print('Расположение бэкапа базы данных: '..paths.backup..'.\n')
  569.     print('Нажать "1" - сохранить базу данных в бэкап (также сохраняется при выходе)')
  570.     print('Нажать "2" - загрузить базу данных из бэкапа.')
  571.     print('Нажать "3" - загрузить базу данных на pastebin.\n')
  572.     print('Или любую кнопку для отмены...\n')
  573.     local _,_,_,key = ev.pull('key_down')
  574.     if key == 2 then
  575.         createBackup()
  576.     elseif key == 3 then
  577.         fs.copy(paths.backup,paths.factionsList)
  578.         factionsList_R()
  579.     elseif key == 4 then
  580.         g.setForeground(colors.white)
  581.         os.execute('pastebin put '..paths.factionsList)
  582.         print('\n')
  583.         g.setForeground(colors.general)
  584.         print('Для продолжения нажмите любую кнопку...')
  585.         ev.pull('key_down')
  586.     end
  587.     press()
  588.     drawGui()
  589. end
  590.  
  591. function install()
  592.     fs.makeDirectory(folder)
  593.     io.open(paths.backup,'w'):write('{}'):flush():close()
  594.     conf_S()
  595. end
  596.  
  597. function clicker(evName,_,curX,curY,scrollDir,touchNick)
  598.     if evName == 'touch' then
  599.         -- debug('x:'..curX..', y:'..curY) -- для теста позиции курсора
  600.         if curX >= factionsListPoses.x and curX <= factionsListPoses.x + factionsListPoses.w + 1 and curY >= factionsListPoses.y and curY < factionsListPoses.y + factionsListPoses.h then
  601.                 factionsListPoses.selectedId = curY + factionsListPoses.startId - factionsListPoses.y
  602.                 drawFactionsList()
  603.                 if ev.pull(0.15,'touch') then
  604.                     local toAdd = scrollFactionsListTable[factionsListPoses.selectedId]
  605.                     addToGlassesList(toAdd[1],toAdd[2],toAdd[3])
  606.                     drawGlassesList()
  607.                     toGlassesFromList()
  608.                 end
  609.             return
  610.         elseif curX == glassesListPoses.x + glassesListPoses.w and curY >= glassesListPoses.y and curY <= glassesListPoses.y + glassesListPoses.max - 1 then
  611.             local id = (curY - glassesListPoses.y) + 1
  612.                 removeFromGlassesList(id)
  613.                 drawGlassesList()
  614.                 toGlassesFromList()
  615.             return
  616.         elseif curX == 79 and curY == 5 then
  617.             clearGlassesList()
  618.             return
  619.         end
  620.         for label,button in pairs(buttons) do
  621.             if curX >= button.x and curX <= button.x + u.len(label) + 1 and curY == button.y then
  622.                 link(label)
  623.                 load(button.action)()
  624.                 break
  625.             end
  626.         end
  627.     elseif evName == 'scroll' then
  628.         if curX >= factionsListPoses.x and curX <= factionsListPoses.x + factionsListPoses.w and curY >= factionsListPoses.y and curY < factionsListPoses.y + factionsListPoses.h then
  629.             checkScroll(scrollDir)
  630.         end
  631.     elseif evName == 'key_down' then
  632.         if curY == 199 then
  633.             factionsListPoses.startId = 1
  634.             factionsListPoses.selectedId = 1
  635.             drawFactionsList()
  636.         elseif curY == 207 then
  637.             if #scrollFactionsListTable > factionsListPoses.h then
  638.                 factionsListPoses.startId = #scrollFactionsListTable - factionsListPoses.h + 1
  639.                 factionsListPoses.selectedId = #scrollFactionsListTable
  640.                 drawFactionsList()
  641.             else
  642.                 factionsListPoses.selectedId = #scrollFactionsListTable
  643.                 drawFactionsList()
  644.             end
  645.         elseif curY == 63 then
  646.             checkAreaupdates()
  647.         end
  648.     end
  649. end
  650.  
  651. function start()
  652.     if not c.isAvailable('internet') then
  653.         print(scriptInfo.label..': Интернет карта не подключена!')
  654.     elseif g.getDepth() == 1 then
  655.         print(scriptInfo.label..': Монитор и видеокарта 1 уровня не поддерживаются!')
  656.     elseif not c.isAvailable('glasses') then
  657.         print(scriptInfo.label..': Glasses Terminal не подключен!')
  658.     elseif not c.isAvailable('os_entdetector') then
  659.     print(scriptInfo.label..': Entity Detector не подключен!')
  660.     else
  661.         if fs.exists(folder) then
  662.             conf_R()
  663.             factionsList_R()
  664.         else
  665.             install()
  666.         end
  667.         internet = require('internet')
  668.         glasses = c.glasses
  669.         glasses.removeAll()
  670.         buttons['COMP'].coords = {c.os_entdetector.getLoc()}
  671.         autosaveTimer = ev.timer(30,conf_S,math.huge)
  672.         press()
  673.         drawGui()
  674.         getFactionsCount()
  675.         while work do
  676.             checkMap()
  677.             os.sleep(2)
  678.         end
  679.         exit()
  680.     end
  681. end
  682.  
  683. function stopkran()
  684.     press('lock')
  685.     glassesListMessage('-Завершение работы-')
  686.     work = false
  687. end
  688.  
  689. function exit()
  690.     conf_S()
  691.     createBackup()
  692.     term.clear()
  693.     glasses.removeAll()
  694.     ev.cancel(autosaveTimer)
  695.     g.setForeground(colors.white)
  696.     g.setResolution(wOld,hOld)
  697.     os.sleep(0.1)
  698. end
  699.  
  700. function ev.shouldInterrupt()
  701.     return false
  702. end
  703.  
  704. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement