SHOW:
|
|
- or go back to the newest paste.
| 1 | - | local component = require("component") |
| 1 | + | local component = require("component")
|
| 2 | - | local fs = require("filesystem") |
| 2 | + | local fs = require("filesystem")
|
| 3 | - | local shell = require("shell") |
| 3 | + | local shell = require("shell")
|
| 4 | - | local event = require("event") |
| 4 | + | local event = require("event")
|
| 5 | - | local unicode = require("unicode") |
| 5 | + | local unicode = require("unicode")
|
| 6 | - | local term = require("term") |
| 6 | + | local term = require("term")
|
| 7 | - | local g = component.gpu |
| 7 | + | local g = component.gpu |
| 8 | - | local me = component.me_interface |
| 8 | + | local me = component.me_interface |
| 9 | - | |
| 9 | + | |
| 10 | - | if not fs.exists("/lib/oc.lua") then |
| 10 | + | if not fs.exists("/lib/oc.lua") then
|
| 11 | - | shell.execute("wget https://www.dropbox.com/s/cgfytt8g174a6vs/libPrecraft.lua?dl=1 /lib/oc.lua") |
| 11 | + | shell.execute("wget https://www.dropbox.com/s/cgfytt8g174a6vs/libPrecraft.lua?dl=1 /lib/oc.lua")
|
| 12 | end | |
| 13 | - | local oc = require("oc") |
| 13 | + | local oc = require("oc")
|
| 14 | - | |
| 14 | + | |
| 15 | - | if not fs.exists("/home/BD.txt") then |
| 15 | + | if not fs.exists("/home/BD.txt") then
|
| 16 | - | oc.savef("BD.txt", {}) |
| 16 | + | oc.savef("BD.txt", {})
|
| 17 | end | |
| 18 | - | |
| 18 | + | |
| 19 | - | --------------------Настройки-------------------- |
| 19 | + | --------------------Настройки-------------------- |
| 20 | - | local CBUTTON, CDRAW, CTEXT = 0x00ffff, 0x004575, 0xD38FFE -- текст кнопок, рамки, осн текст |
| 20 | + | local CBUTTON, CDRAW, CTEXT = 0x00ffff, 0x004575, 0xD38FFE -- текст кнопок, рамки, осн текст |
| 21 | - | local debug = true -- вкл дебаг (меню с недостающими крафтами и нехватной ресурсов) |
| 21 | + | local debug = true -- вкл дебаг (меню с недостающими крафтами и нехватной ресурсов) |
| 22 | - | local ADM = {['KReaTlVNuY']=true, ['4ertik_']=true} -- доступы к нажатиям |
| 22 | + | local ADM = {['KReaTlVNuY']=true, ['4ertik_']=true} -- доступы к нажатиям
|
| 23 | - | local scroll = 1 -- начало скролла |
| 23 | + | local scroll = 1 -- начало скролла |
| 24 | - | local precraft = true -- флаг осн цикла |
| 24 | + | local precraft = true -- флаг осн цикла |
| 25 | - | local go = true -- включить идет ли проверка вещей |
| 25 | + | local go = true -- включить идет ли проверка вещей |
| 26 | - | local WIDTH, HEIGHT = 80, 50 |
| 26 | + | local WIDTH, HEIGHT = 80, 50 |
| 27 | - | --------------------Настройки-------------------- |
| 27 | + | --------------------Настройки-------------------- |
| 28 | - | local inputFind = "" |
| 28 | + | local inputFind = "" |
| 29 | - | local guiPath, debugLog1, debugLog2 = {}, {}, {} |
| 29 | + | local guiPath, debugLog1, debugLog2 = {}, {}, {}
|
| 30 | - | if debug then WIDTH, HEIGHT = 160, 50 end |
| 30 | + | if debug then WIDTH, HEIGHT = 160, 50 end |
| 31 | - | g.setResolution(WIDTH,HEIGHT) |
| 31 | + | g.setResolution(WIDTH,HEIGHT) |
| 32 | - | g.setForeground(CTEXT) |
| 32 | + | g.setForeground(CTEXT) |
| 33 | - | |
| 33 | + | |
| 34 | - | local function Clear() g.setBackground(0x000000) g.setForeground(0xD38FFE) g.fill(1,4,WIDTH,HEIGHT-4," ") end |
| 34 | + | local function Clear() g.setBackground(0x000000) g.setForeground(0xD38FFE) g.fill(1,4,WIDTH,HEIGHT-4," ") end |
| 35 | - | |
| 35 | + | |
| 36 | - | local function DrawScrollContent() |
| 36 | + | local function DrawScrollContent() |
| 37 | - | if guiPath[#guiPath]=="start" or guiPath[#guiPath] == "stop" or guiPath[#guiPath] == "go" then |
| 37 | + | if guiPath[#guiPath]=="start" or guiPath[#guiPath] == "stop" or guiPath[#guiPath] == "go" then |
| 38 | - | for i = scroll, maxscroll do |
| 38 | + | for i = scroll, maxscroll do |
| 39 | - | if content[i] then |
| 39 | + | if content[i] then |
| 40 | - | local k = i - scroll |
| 40 | + | local k = i - scroll |
| 41 | - | if i == posSelect then |
| 41 | + | if i == posSelect then |
| 42 | - | g.setBackground(0x1e1e1e) |
| 42 | + | g.setBackground(0x1e1e1e) |
| 43 | - | g.fill(11, 7 k, 58, 1, " ") |
| 43 | + | g.fill(11, 7 k, 58, 1, " ") |
| 44 | - | g.set(13,7 k, tostring(i.. ". "..content[i].name)) |
| 44 | + | g.set(13,7 k, tostring(i.. ". "..content[i].name)) |
| 45 | - | g.set(45, 7 k, tostring(content[i].count)) |
| 45 | + | g.set(45, 7 k, tostring(content[i].count)) |
| 46 | - | g.set(60, 7 k, tostring(content[i].craftSize)) |
| 46 | + | g.set(60, 7 k, tostring(content[i].craftSize)) |
| 47 | - | g.setBackground(0x000000) |
| 47 | + | g.setBackground(0x000000) |
| 48 | - | else |
| 48 | + | else |
| 49 | - | g.setBackground(0x000000) |
| 49 | + | g.setBackground(0x000000) |
| 50 | - | g.fill(11, 7 k, 58, 1, " ") |
| 50 | + | g.fill(11, 7 k, 58, 1, " ") |
| 51 | - | g.set(13,7 k, tostring(i.. ". "..content[i].name)) |
| 51 | + | g.set(13,7 k, tostring(i.. ". "..content[i].name)) |
| 52 | - | g.set(45, 7 k, tostring(content[i].count)) |
| 52 | + | g.set(45, 7 k, tostring(content[i].count)) |
| 53 | - | g.set(60, 7 k, tostring(content[i].craftSize)) |
| 53 | + | g.set(60, 7 k, tostring(content[i].craftSize)) |
| 54 | - | end |
| 54 | + | end |
| 55 | - | end |
| 55 | + | end |
| 56 | - | end |
| 56 | + | end |
| 57 | - | end |
| 57 | + | end |
| 58 | end | |
| 59 | - | |
| 59 | + | |
| 60 | - | local function ScrollContent() |
| 60 | + | local function ScrollContent() |
| 61 | - | local cont = {} |
| 61 | + | local cont = {}
|
| 62 | - | if inputFind ~= nil and inputFind ~= "" then |
| 62 | + | if inputFind ~= nil and inputFind ~= "" then |
| 63 | - | for key, data in pairs(content) do |
| 63 | + | for key, data in pairs(content) do |
| 64 | - | if unicode.lower(data.name):find(unicode.lower(inputFind)) then |
| 64 | + | if unicode.lower(data.name):find(unicode.lower(inputFind)) then |
| 65 | - | table.insert(cont, content[key]) |
| 65 | + | table.insert(cont, content[key]) |
| 66 | - | end |
| 66 | + | end |
| 67 | - | end |
| 67 | + | end |
| 68 | - | return cont |
| 68 | + | return cont |
| 69 | - | else |
| 69 | + | else |
| 70 | - | return content |
| 70 | + | return content |
| 71 | - | end |
| 71 | + | end |
| 72 | end | |
| 73 | - | |
| 73 | + | |
| 74 | - | local function eScroll(_,_,_,_,zs,nick) |
| 74 | + | local function eScroll(_,_,_,_,zs,nick) |
| 75 | - | if ADM[nick] then |
| 75 | + | if ADM[nick] then |
| 76 | - | for key in pairs(scrolls) do |
| 76 | + | for key in pairs(scrolls) do |
| 77 | - | for i = 1, #scrolls[key].ScrollIn do |
| 77 | + | for i = 1, #scrolls[key].ScrollIn do |
| 78 | - | if scrolls[key].ScrollIn[i] == guiPath[#guiPath] then |
| 78 | + | if scrolls[key].ScrollIn[i] == guiPath[#guiPath] then |
| 79 | - | if not zs then |
| 79 | + | if not zs then |
| 80 | - | scroll = 1 |
| 80 | + | scroll = 1 |
| 81 | - | elseif zs == 1 and scroll > 1 then |
| 81 | + | elseif zs == 1 and scroll > 1 then |
| 82 | - | scroll = scroll - 1 |
| 82 | + | scroll = scroll - 1 |
| 83 | - | elseif zs == -1 and maxscroll < #content then |
| 83 | + | elseif zs == -1 and maxscroll < #content then |
| 84 | - | scroll = scroll 1 |
| 84 | + | scroll = scroll 1 |
| 85 | - | end |
| 85 | + | end |
| 86 | - | maxscroll = scroll scrolls[key].h - 1 |
| 86 | + | maxscroll = scroll scrolls[key].h - 1 |
| 87 | - | scrolls[key].action() |
| 87 | + | scrolls[key].action() |
| 88 | - | content = ScrollContent() |
| 88 | + | content = ScrollContent() |
| 89 | - | oc.drawscroll(scrolls[key].x, scrolls[key].y, scrolls[key].w, scrolls[key].h, scroll, #content, 0x1e1e1e, 0x004575) |
| 89 | + | oc.drawscroll(scrolls[key].x, scrolls[key].y, scrolls[key].w, scrolls[key].h, scroll, #content, 0x1e1e1e, 0x004575) |
| 90 | - | g.fill(scrolls[key].xGui 1,scrolls[key].yGui 1,scrolls[key].wGui-4,scrolls[key].hGui-2, " ") |
| 90 | + | g.fill(scrolls[key].xGui 1,scrolls[key].yGui 1,scrolls[key].wGui-4,scrolls[key].hGui-2, " ") |
| 91 | - | DrawScrollContent() |
| 91 | + | DrawScrollContent() |
| 92 | - | end |
| 92 | + | end |
| 93 | - | end |
| 93 | + | end |
| 94 | - | end |
| 94 | + | end |
| 95 | - | end |
| 95 | + | end |
| 96 | end | |
| 97 | - | |
| 97 | + | |
| 98 | - | local function Main() |
| 98 | + | local function Main() |
| 99 | - | if guiPath[#guiPath] == "start" or guiPath[#guiPath] == "stop" or guiPath[#guiPath] == "go" then |
| 99 | + | if guiPath[#guiPath] == "start" or guiPath[#guiPath] == "stop" or guiPath[#guiPath] == "go" then |
| 100 | - | g.set(13, 5, "Название предмета:") |
| 100 | + | g.set(13, 5, "Название предмета:") |
| 101 | - | g.set(45, 5, "Кол-во:") |
| 101 | + | g.set(45, 5, "Кол-во:") |
| 102 | - | g.set(60, 5, "Крафт:") |
| 102 | + | g.set(60, 5, "Крафт:") |
| 103 | - | g.set(20,43, "Для поиска введите название..") |
| 103 | + | g.set(20,43, "Для поиска введите название..") |
| 104 | - | oc.right(71,50, "Всего "..#dataItems.. " крафтов") |
| 104 | + | oc.right(71,50, "Всего "..#dataItems.. " крафтов") |
| 105 | - | g.fill(85,1, 75, 51, " ") |
| 105 | + | g.fill(85,1, 75, 51, " ") |
| 106 | - | for i = 1, #debugLog1 do |
| 106 | + | for i = 1, #debugLog1 do |
| 107 | - | g.set(85, 4 i, tostring(debugLog1[i])) |
| 107 | + | g.set(85, 4 i, tostring(debugLog1[i])) |
| 108 | - | end |
| 108 | + | end |
| 109 | - | for i = 1, #debugLog2 do |
| 109 | + | for i = 1, #debugLog2 do |
| 110 | - | g.set(85, 26 i, tostring(debugLog2[i])) |
| 110 | + | g.set(85, 26 i, tostring(debugLog2[i])) |
| 111 | - | end |
| 111 | + | end |
| 112 | - | elseif guiPath[#guiPath] == "change" then |
| 112 | + | elseif guiPath[#guiPath] == "change" then |
| 113 | - | g.set(13, 10, "Название предмета: "..dataItems[posSelect].name) |
| 113 | + | g.set(13, 10, "Название предмета: "..dataItems[posSelect].name) |
| 114 | - | g.set(13, 12, "id предмета: "..tostring(dataItems[posSelect].id)) |
| 114 | + | g.set(13, 12, "id предмета: "..tostring(dataItems[posSelect].id)) |
| 115 | - | g.set(13, 14, "dmg предмета: "..tostring(dataItems[posSelect].dmg)) |
| 115 | + | g.set(13, 14, "dmg предмета: "..tostring(dataItems[posSelect].dmg)) |
| 116 | - | g.set(13, 16, "Количество поддержания: "..tostring(dataItems[posSelect].count)) |
| 116 | + | g.set(13, 16, "Количество поддержания: "..tostring(dataItems[posSelect].count)) |
| 117 | - | g.set(13, 18, "Размер крафта: "..tostring(dataItems[posSelect].craftSize)) |
| 117 | + | g.set(13, 18, "Размер крафта: "..tostring(dataItems[posSelect].craftSize)) |
| 118 | - | end |
| 118 | + | end |
| 119 | end | |
| 120 | - | |
| 120 | + | |
| 121 | - | local function DrawScrolls() |
| 121 | + | local function DrawScrolls() |
| 122 | - | for key in pairs(scrolls) do |
| 122 | + | for key in pairs(scrolls) do |
| 123 | - | for i = 1, #scrolls[key].ScrollIn do |
| 123 | + | for i = 1, #scrolls[key].ScrollIn do |
| 124 | - | if scrolls[key].ScrollIn[i] == guiPath[#guiPath] then |
| 124 | + | if scrolls[key].ScrollIn[i] == guiPath[#guiPath] then |
| 125 | - | scrolls[key].action() |
| 125 | + | scrolls[key].action() |
| 126 | - | eScroll(_,_,_,_,nil,"KReaTlVNuY") |
| 126 | + | eScroll(_,_,_,_,nil,"KReaTlVNuY") |
| 127 | - | oc.drawscroll(scrolls[key].x, scrolls[key].y, scrolls[key].w, scrolls[key].h, scroll, #content, 0x1e1e1e, 0x004575) |
| 127 | + | oc.drawscroll(scrolls[key].x, scrolls[key].y, scrolls[key].w, scrolls[key].h, scroll, #content, 0x1e1e1e, 0x004575) |
| 128 | - | oc.drawbutton(scrolls[key].xGui,scrolls[key].yGui,scrolls[key].wGui,scrolls[key].hGui,CBUTTON,CDRAW,"") |
| 128 | + | oc.drawbutton(scrolls[key].xGui,scrolls[key].yGui,scrolls[key].wGui,scrolls[key].hGui,CBUTTON,CDRAW,"") |
| 129 | - | end |
| 129 | + | end |
| 130 | - | end |
| 130 | + | end |
| 131 | - | end |
| 131 | + | end |
| 132 | end | |
| 133 | - | |
| 133 | + | |
| 134 | - | local function DrawButtons() |
| 134 | + | local function DrawButtons() |
| 135 | - | for button in pairs(buttons) do |
| 135 | + | for button in pairs(buttons) do |
| 136 | - | for i = 1, #buttons[button].ButtonIn do |
| 136 | + | for i = 1, #buttons[button].ButtonIn do |
| 137 | - | if buttons[button].ButtonIn[i] == guiPath[#guiPath] and buttons[button].visible then |
| 137 | + | if buttons[button].ButtonIn[i] == guiPath[#guiPath] and buttons[button].visible then |
| 138 | - | oc.drawbutton(buttons[button].x,buttons[button].y,buttons[button].w, buttons[button].h, buttons[button].ctext, buttons[button].cbutton, buttons[button].text) |
| 138 | + | oc.drawbutton(buttons[button].x,buttons[button].y,buttons[button].w, buttons[button].h, buttons[button].ctext, buttons[button].cbutton, buttons[button].text) |
| 139 | - | end |
| 139 | + | end |
| 140 | - | end |
| 140 | + | end |
| 141 | - | end |
| 141 | + | end |
| 142 | end | |
| 143 | - | |
| 143 | + | |
| 144 | - | local function toGui(gui, clear) |
| 144 | + | local function toGui(gui, clear) |
| 145 | - | if clear then |
| 145 | + | if clear then |
| 146 | - | guiPath[#guiPath] = nil |
| 146 | + | guiPath[#guiPath] = nil |
| 147 | - | end |
| 147 | + | end |
| 148 | - | if guiPath[#guiPath] ~= gui then |
| 148 | + | if guiPath[#guiPath] ~= gui then |
| 149 | - | guiPath[#guiPath 1] = gui |
| 149 | + | guiPath[#guiPath 1] = gui |
| 150 | - | end |
| 150 | + | end |
| 151 | - | dataq, dataItems = nil, nil |
| 151 | + | dataq, dataItems = nil, nil |
| 152 | - | dataItems = oc.loadf("BD.txt") |
| 152 | + | dataItems = oc.loadf("BD.txt")
|
| 153 | - | Clear() |
| 153 | + | Clear() |
| 154 | - | Main() |
| 154 | + | Main() |
| 155 | - | DrawButtons() |
| 155 | + | DrawButtons() |
| 156 | - | DrawScrolls() |
| 156 | + | DrawScrolls() |
| 157 | end | |
| 158 | - | |
| 158 | + | |
| 159 | - | local function Back(to) |
| 159 | + | local function Back(to) |
| 160 | - | if to then |
| 160 | + | if to then |
| 161 | - | if to <= #guiPath then for i = 1, to do table.remove(guiPath, #guiPath) end end |
| 161 | + | if to <= #guiPath then for i = 1, to do table.remove(guiPath, #guiPath) end end |
| 162 | - | else |
| 162 | + | else |
| 163 | - | table.remove(guiPath, #guiPath) |
| 163 | + | table.remove(guiPath, #guiPath) |
| 164 | - | end |
| 164 | + | end |
| 165 | - | posSelect = nil |
| 165 | + | posSelect = nil |
| 166 | - | Clear() |
| 166 | + | Clear() |
| 167 | - | Main() |
| 167 | + | Main() |
| 168 | - | DrawButtons() |
| 168 | + | DrawButtons() |
| 169 | - | DrawScrolls() |
| 169 | + | DrawScrolls() |
| 170 | end | |
| 171 | - | |
| 171 | + | |
| 172 | - | local function AddLogs(nameTable, log) |
| 172 | + | local function AddLogs(nameTable, log) |
| 173 | - | if nameTable == "ore" then |
| 173 | + | if nameTable == "ore" then |
| 174 | - | if #debugLog1 > 19 then table.remove(debugLog1, 1) end |
| 174 | + | if #debugLog1 > 19 then table.remove(debugLog1, 1) end |
| 175 | - | table.insert(debugLog1, log) |
| 175 | + | table.insert(debugLog1, log) |
| 176 | - | else |
| 176 | + | else |
| 177 | - | if #debugLog2 > 19 then table.remove(debugLog2, 1) end |
| 177 | + | if #debugLog2 > 19 then table.remove(debugLog2, 1) end |
| 178 | - | table.insert(debugLog2, log) |
| 178 | + | table.insert(debugLog2, log) |
| 179 | - | end |
| 179 | + | end |
| 180 | - | Main() |
| 180 | + | Main() |
| 181 | end | |
| 182 | - | |
| 182 | + | |
| 183 | - | local function Check() |
| 183 | + | local function Check() |
| 184 | - | for i = 1, #dataq do |
| 184 | + | for i = 1, #dataq do |
| 185 | - | if not go then break end |
| 185 | + | if not go then break end |
| 186 | - | if not dataq[i].craft or dataq[i].craft.isDone() or dataq[i].craft.isCanceled() then |
| 186 | + | if not dataq[i].craft or dataq[i].craft.isDone() or dataq[i].craft.isCanceled() then |
| 187 | - | dataq[i].craft = nil |
| 187 | + | dataq[i].craft = nil |
| 188 | - | local itemsMe = me.getItemDetail({id = dataq[i].id, dmg = dataq[i].dmg}) |
| 188 | + | local itemsMe = me.getItemDetail({id = dataq[i].id, dmg = dataq[i].dmg})
|
| 189 | - | if itemsMe then |
| 189 | + | if itemsMe then |
| 190 | - | local delta = dataq[i].count - itemsMe.basic().qty |
| 190 | + | local delta = dataq[i].count - itemsMe.basic().qty |
| 191 | - | if delta > dataq[i].craftSize then delta = dataq[i].craftSize end |
| 191 | + | if delta > dataq[i].craftSize then delta = dataq[i].craftSize end |
| 192 | - | if delta > 0 then |
| 192 | + | if delta > 0 then |
| 193 | - | local cpus = me.getCpus() |
| 193 | + | local cpus = me.getCpus() |
| 194 | - | for j = 1, #cpus do |
| 194 | + | for j = 1, #cpus do |
| 195 | - | if not cpus[j].busy and cpus[j].storage == dataq[i].cpu then |
| 195 | + | if not cpus[j].busy and cpus[j].storage == dataq[i].cpu then |
| 196 | - | local craftables = me.getCraftables({name = dataq[i].id, damage = dataq[i].dmg}) |
| 196 | + | local craftables = me.getCraftables({name = dataq[i].id, damage = dataq[i].dmg})
|
| 197 | - | if craftables.n >= 1 then |
| 197 | + | if craftables.n >= 1 then |
| 198 | - | dataq[i].craft = craftables[1].request(delta, false, tostring(dataq[i].cpu)) |
| 198 | + | dataq[i].craft = craftables[1].request(delta, false, tostring(dataq[i].cpu)) |
| 199 | - | --AddLogs("ore", delta.. " "..dataq[i].count) |
| 199 | + | --AddLogs("ore", delta.. " "..dataq[i].count)
|
| 200 | - | if debug then |
| 200 | + | if debug then |
| 201 | - | local cancel, cancelmsg = dataq[i].craft.isCanceled() |
| 201 | + | local cancel, cancelmsg = dataq[i].craft.isCanceled() |
| 202 | - | if not cancel and cancelmsg then |
| 202 | + | if not cancel and cancelmsg then |
| 203 | - | if cancelmsg == "computing" then |
| 203 | + | if cancelmsg == "computing" then |
| 204 | - | AddLogs("ore", dataq[i].name.. " не хватает ресурсов " .. cancelmsg) |
| 204 | + | AddLogs("ore", dataq[i].name.. " не хватает ресурсов " .. cancelmsg)
|
| 205 | - | end |
| 205 | + | end |
| 206 | - | elseif cancelmsg == "request failed (missing resources?)" then |
| 206 | + | elseif cancelmsg == "request failed (missing resources?)" then |
| 207 | - | AddLogs("ore", dataq[i].name.. " не хватает ресурсов " .. cancelmsg) |
| 207 | + | AddLogs("ore", dataq[i].name.. " не хватает ресурсов " .. cancelmsg)
|
| 208 | - | elseif cancelmsg then |
| 208 | + | elseif cancelmsg then |
| 209 | - | AddLogs("ore", dataq[i].name .. " ".. cancelmsg) |
| 209 | + | AddLogs("ore", dataq[i].name .. " ".. cancelmsg)
|
| 210 | - | end |
| 210 | + | end |
| 211 | - | os.sleep(0.5) |
| 211 | + | os.sleep(0.5) |
| 212 | - | break |
| 212 | + | break |
| 213 | - | end |
| 213 | + | end |
| 214 | - | elseif debug then |
| 214 | + | elseif debug then |
| 215 | - | AddLogs("recipe", dataq[i].name.. " не имеет рецепта") |
| 215 | + | AddLogs("recipe", dataq[i].name.. " не имеет рецепта")
|
| 216 | - | end |
| 216 | + | end |
| 217 | - | break |
| 217 | + | break |
| 218 | - | end |
| 218 | + | end |
| 219 | - | end |
| 219 | + | end |
| 220 | - | end |
| 220 | + | end |
| 221 | - | end |
| 221 | + | end |
| 222 | - | end |
| 222 | + | end |
| 223 | - | end |
| 223 | + | end |
| 224 | - | os.sleep(1) |
| 224 | + | os.sleep(1) |
| 225 | - | AddLogs("ore", " ") |
| 225 | + | AddLogs("ore", " ")
|
| 226 | - | AddLogs("recipe", " ") |
| 226 | + | AddLogs("recipe", " ")
|
| 227 | end | |
| 228 | - | |
| 228 | + | |
| 229 | - | local function AddItem() |
| 229 | + | local function AddItem() |
| 230 | - | changeitem = true |
| 230 | + | changeitem = true |
| 231 | - | if me.getStackInSlot(1) then |
| 231 | + | if me.getStackInSlot(1) then |
| 232 | - | g.fill(1,43, WIDTH, 1, " ") |
| 232 | + | g.fill(1,43, WIDTH, 1, " ") |
| 233 | - | g.set(14,43,"Введите название предмета:") term.setCursor(40,43) |
| 233 | + | g.set(14,43,"Введите название предмета:") term.setCursor(40,43) |
| 234 | - | local name = tostring(io.read()) g.fill(1,43,80,1, " ") |
| 234 | + | local name = tostring(io.read()) g.fill(1,43,80,1, " ") |
| 235 | - | g.set(14,43,"Введите кол-во поддержания:") term.setCursor(41,43) |
| 235 | + | g.set(14,43,"Введите кол-во поддержания:") term.setCursor(41,43) |
| 236 | - | local count = tonumber(io.read()) g.fill(1,43,80,1, " ") |
| 236 | + | local count = tonumber(io.read()) g.fill(1,43,80,1, " ") |
| 237 | - | g.set(14,43,"Введите макс. объём крафта:") term.setCursor(41,43) |
| 237 | + | g.set(14,43,"Введите макс. объём крафта:") term.setCursor(41,43) |
| 238 | - | local craftSize = tonumber(io.read()) g.fill(1,43,80,1, " ") |
| 238 | + | local craftSize = tonumber(io.read()) g.fill(1,43,80,1, " ") |
| 239 | - | table.insert(dataItems, {name=name, id = me.getStackInSlot(1).id,dmg = me.getStackInSlot(1).dmg, count = count, craftSize = craftSize, cpu = 65536}) |
| 239 | + | table.insert(dataItems, {name=name, id = me.getStackInSlot(1).id,dmg = me.getStackInSlot(1).dmg, count = count, craftSize = craftSize, cpu = 65536})
|
| 240 | - | oc.savef("BD.txt", dataItems) |
| 240 | + | oc.savef("BD.txt", dataItems)
|
| 241 | - | else |
| 241 | + | else |
| 242 | - | g.set(14, 43, "Предмет не установлен в 1-й слот интерфейса") |
| 242 | + | g.set(14, 43, "Предмет не установлен в 1-й слот интерфейса") |
| 243 | - | os.sleep(2) |
| 243 | + | os.sleep(2) |
| 244 | - | g.fill(1, 43, WIDTH, 1, " ") |
| 244 | + | g.fill(1, 43, WIDTH, 1, " ") |
| 245 | - | end |
| 245 | + | end |
| 246 | - | Main() |
| 246 | + | Main() |
| 247 | - | changeitem = false |
| 247 | + | changeitem = false |
| 248 | end | |
| 249 | - | |
| 249 | + | |
| 250 | - | local function RemoveItem() |
| 250 | + | local function RemoveItem() |
| 251 | - | if posSelect and dataItems then |
| 251 | + | if posSelect and dataItems then |
| 252 | - | for i = 1, #dataItems do |
| 252 | + | for i = 1, #dataItems do |
| 253 | - | if dataItems[i].name == content[posSelect].name then |
| 253 | + | if dataItems[i].name == content[posSelect].name then |
| 254 | - | table.remove(dataItems, i) |
| 254 | + | table.remove(dataItems, i) |
| 255 | - | oc.savef("BD.txt", dataItems) |
| 255 | + | oc.savef("BD.txt", dataItems)
|
| 256 | - | eScroll(_,_,_,_,nil,"KReaTlVNuY") |
| 256 | + | eScroll(_,_,_,_,nil,"KReaTlVNuY") |
| 257 | - | posSelect = nil |
| 257 | + | posSelect = nil |
| 258 | - | return true |
| 258 | + | return true |
| 259 | - | end |
| 259 | + | end |
| 260 | - | end |
| 260 | + | end |
| 261 | - | end |
| 261 | + | end |
| 262 | end | |
| 263 | - | |
| 263 | + | |
| 264 | - | local function EditItem() |
| 264 | + | local function EditItem() |
| 265 | - | if posSelect and dataItems then |
| 265 | + | if posSelect and dataItems then |
| 266 | - | for i = 1, #dataItems do |
| 266 | + | for i = 1, #dataItems do |
| 267 | - | if dataItems[i].name == content[posSelect].name then |
| 267 | + | if dataItems[i].name == content[posSelect].name then |
| 268 | - | posSelect = i |
| 268 | + | posSelect = i |
| 269 | - | toGui("change") |
| 269 | + | toGui("change")
|
| 270 | - | return true |
| 270 | + | return true |
| 271 | - | end |
| 271 | + | end |
| 272 | - | end |
| 272 | + | end |
| 273 | - | end |
| 273 | + | end |
| 274 | end | |
| 275 | - | |
| 275 | + | |
| 276 | - | local function ChangeItem(action) |
| 276 | + | local function ChangeItem(action) |
| 277 | - | if posSelect and dataItems then |
| 277 | + | if posSelect and dataItems then |
| 278 | - | g.fill(1,45, WIDTH, 1, " ") |
| 278 | + | g.fill(1,45, WIDTH, 1, " ") |
| 279 | - | if action == "changeName" then |
| 279 | + | if action == "changeName" then |
| 280 | - | g.set(14,45,"Введите название предмета:") term.setCursor(40,45) |
| 280 | + | g.set(14,45,"Введите название предмета:") term.setCursor(40,45) |
| 281 | - | dataItems[posSelect].name = tostring(io.read()) |
| 281 | + | dataItems[posSelect].name = tostring(io.read()) |
| 282 | - | elseif action == "changeCount" then |
| 282 | + | elseif action == "changeCount" then |
| 283 | - | g.set(14,45,"Введите кол-во поддержания:") term.setCursor(41,45) |
| 283 | + | g.set(14,45,"Введите кол-во поддержания:") term.setCursor(41,45) |
| 284 | - | dataItems[posSelect].count = tonumber(io.read()) |
| 284 | + | dataItems[posSelect].count = tonumber(io.read()) |
| 285 | - | elseif action == "changeCraftSize" then |
| 285 | + | elseif action == "changeCraftSize" then |
| 286 | - | g.set(14,45,"Введите макс. объём крафта:") term.setCursor(41,45) |
| 286 | + | g.set(14,45,"Введите макс. объём крафта:") term.setCursor(41,45) |
| 287 | - | dataItems[posSelect].craftSize = tonumber(io.read()) |
| 287 | + | dataItems[posSelect].craftSize = tonumber(io.read()) |
| 288 | - | end |
| 288 | + | end |
| 289 | - | oc.savef("BD.txt", dataItems) |
| 289 | + | oc.savef("BD.txt", dataItems)
|
| 290 | - | g.fill(1, 45, WIDTH, 1, " ") |
| 290 | + | g.fill(1, 45, WIDTH, 1, " ") |
| 291 | - | Main() |
| 291 | + | Main() |
| 292 | - | end |
| 292 | + | end |
| 293 | end | |
| 294 | - | |
| 294 | + | |
| 295 | - | local function eButton(_,_,x,y,_, nick) |
| 295 | + | local function eButton(_,_,x,y,_, nick) |
| 296 | - | if ADM[nick] then |
| 296 | + | if ADM[nick] then |
| 297 | - | for button in pairs(buttons) do |
| 297 | + | for button in pairs(buttons) do |
| 298 | - | if x >= buttons[button].x and x <= buttons[button].endX and y >= buttons[button].y and y <= buttons[button].endY then |
| 298 | + | if x >= buttons[button].x and x <= buttons[button].endX and y >= buttons[button].y and y <= buttons[button].endY then |
| 299 | - | for i = 1, #buttons[button].ButtonIn do |
| 299 | + | for i = 1, #buttons[button].ButtonIn do |
| 300 | - | if buttons[button].ButtonIn[i] == guiPath[#guiPath] then |
| 300 | + | if buttons[button].ButtonIn[i] == guiPath[#guiPath] then |
| 301 | - | yTouch = y |
| 301 | + | yTouch = y |
| 302 | - | buttons[button].action() |
| 302 | + | buttons[button].action() |
| 303 | - | return true |
| 303 | + | return true |
| 304 | - | end |
| 304 | + | end |
| 305 | - | end |
| 305 | + | end |
| 306 | - | |
| 306 | + | |
| 307 | - | end |
| 307 | + | end |
| 308 | - | end |
| 308 | + | end |
| 309 | - | end |
| 309 | + | end |
| 310 | end | |
| 311 | - | |
| 311 | + | |
| 312 | - | local function InputWrite(_,_,key1, key2,nick) |
| 312 | + | local function InputWrite(_,_,key1, key2,nick) |
| 313 | - | if ADM[nick] and not changeitem then |
| 313 | + | if ADM[nick] and not changeitem then |
| 314 | - | for key in pairs(scrolls) do |
| 314 | + | for key in pairs(scrolls) do |
| 315 | - | for i = 1, #scrolls[key].ScrollIn do |
| 315 | + | for i = 1, #scrolls[key].ScrollIn do |
| 316 | - | if scrolls[key].ScrollIn[i] == guiPath[#guiPath] then |
| 316 | + | if scrolls[key].ScrollIn[i] == guiPath[#guiPath] then |
| 317 | - | local y = scrolls[key].iwY |
| 317 | + | local y = scrolls[key].iwY |
| 318 | - | g.fill(20,y, 30, 1, " ") |
| 318 | + | g.fill(20,y, 30, 1, " ") |
| 319 | - | if key1 == 8 then -- backspace |
| 319 | + | if key1 == 8 then -- backspace |
| 320 | - | inputFind = unicode.sub(inputFind, 1, -2) |
| 320 | + | inputFind = unicode.sub(inputFind, 1, -2) |
| 321 | - | elseif key1 == 0 and key2 == 211 then -- delete |
| 321 | + | elseif key1 == 0 and key2 == 211 then -- delete |
| 322 | - | inputFind = "" |
| 322 | + | inputFind = "" |
| 323 | - | elseif key1 ~= 0 then -- keyboard |
| 323 | + | elseif key1 ~= 0 then -- keyboard |
| 324 | - | if inputFind == nil or inputFind == "" then |
| 324 | + | if inputFind == nil or inputFind == "" then |
| 325 | - | inputFind = unicode.char(key1) |
| 325 | + | inputFind = unicode.char(key1) |
| 326 | - | elseif unicode.len(inputFind) < 49 then |
| 326 | + | elseif unicode.len(inputFind) < 49 then |
| 327 | - | inputFind = inputFind .. unicode.char(key1) |
| 327 | + | inputFind = inputFind .. unicode.char(key1) |
| 328 | - | end |
| 328 | + | end |
| 329 | - | end |
| 329 | + | end |
| 330 | - | if unicode.len(inputFind) < 30 and unicode.len(inputFind) > 0 then |
| 330 | + | if unicode.len(inputFind) < 30 and unicode.len(inputFind) > 0 then |
| 331 | - | g.set(20,y, tostring(inputFind)) |
| 331 | + | g.set(20,y, tostring(inputFind)) |
| 332 | - | elseif unicode.len(inputFind) >= 30 then |
| 332 | + | elseif unicode.len(inputFind) >= 30 then |
| 333 | - | g.set(20,y, tostring(inputFind:sub(unicode.len(inputFind)-29, unicode.len(inputFind))))-- отображение последних 20 символов |
| 333 | + | g.set(20,y, tostring(inputFind:sub(unicode.len(inputFind)-29, unicode.len(inputFind))))-- отображение последних 20 символов |
| 334 | - | else |
| 334 | + | else |
| 335 | - | g.set(20,y, "Для поиска введите название..") |
| 335 | + | g.set(20,y, "Для поиска введите название..") |
| 336 | - | end |
| 336 | + | end |
| 337 | - | eScroll(_,_,_,_,nil,"KReaTlVNuY") |
| 337 | + | eScroll(_,_,_,_,nil,"KReaTlVNuY") |
| 338 | - | end |
| 338 | + | end |
| 339 | - | end |
| 339 | + | end |
| 340 | - | end |
| 340 | + | end |
| 341 | - | end |
| 341 | + | end |
| 342 | end | |
| 343 | - | |
| 343 | + | |
| 344 | - | local function initButtons() |
| 344 | + | local function initButtons() |
| 345 | - | for button in pairs(buttons) do |
| 345 | + | for button in pairs(buttons) do |
| 346 | - | buttons[button].endX = buttons[button].x buttons[button].w - 1 |
| 346 | + | buttons[button].endX = buttons[button].x buttons[button].w - 1 |
| 347 | - | buttons[button].endY = buttons[button].y buttons[button].h - 1 |
| 347 | + | buttons[button].endY = buttons[button].y buttons[button].h - 1 |
| 348 | - | end |
| 348 | + | end |
| 349 | end | |
| 350 | - | |
| 350 | + | |
| 351 | - | local function LoadSystem() |
| 351 | + | local function LoadSystem() |
| 352 | - | g.fill(1,1,WIDTH, HEIGHT, " ") |
| 352 | + | g.fill(1,1,WIDTH, HEIGHT, " ") |
| 353 | - | dataItems = oc.loadf("BD.txt") |
| 353 | + | dataItems = oc.loadf("BD.txt")
|
| 354 | - | initButtons() |
| 354 | + | initButtons() |
| 355 | - | etouch = event.listen("touch", eButton) |
| 355 | + | etouch = event.listen("touch", eButton)
|
| 356 | - | escroll = event.listen("scroll", eScroll) |
| 356 | + | escroll = event.listen("scroll", eScroll)
|
| 357 | - | ekeydown = event.listen("key_down", InputWrite) |
| 357 | + | ekeydown = event.listen("key_down", InputWrite)
|
| 358 | - | toGui("start") |
| 358 | + | toGui("start")
|
| 359 | - | dataq = dataItems |
| 359 | + | dataq = dataItems |
| 360 | - | |
| 360 | + | |
| 361 | - | return true |
| 361 | + | return true |
| 362 | end | |
| 363 | - | |
| 363 | + | |
| 364 | - | buttons = { |
| 364 | + | buttons = {
|
| 365 | - | LOGO = {ButtonIn = {"start", "go", "stop", "change"}, visible = true, x = 10, y = 1, w = 62, h = 3, cbutton = 0x004575, ctext = 0x00ffff, text = "PreCraft", action = function() end}, |
| 365 | + | LOGO = {ButtonIn = {"start", "go", "stop", "change"}, visible = true, x = 10, y = 1, w = 62, h = 3, cbutton = 0x004575, ctext = 0x00ffff, text = "PreCraft", action = function() end},
|
| 366 | - | Exit = {ButtonIn = {"start", "go","stop", "change"}, visible = false, x = 1, y = 1, w = 1, h = 1, cbutton = 0x004575, ctext = 0x00ffff, text = "", action = function() g.setResolution(160,50) event.cancel(etouch) event.cancel(ekeydown) event.cancel(escroll) precraft = false end}, |
| 366 | + | Exit = {ButtonIn = {"start", "go","stop", "change"}, visible = false, x = 1, y = 1, w = 1, h = 1, cbutton = 0x004575, ctext = 0x00ffff, text = "", action = function() g.setResolution(160,50) event.cancel(etouch) event.cancel(ekeydown) event.cancel(escroll) precraft = false end},
|
| 367 | - | |
| 367 | + | |
| 368 | - | Select = {ButtonIn = {"stop"}, visible = false, x = 11, y = 7, w = 60, h = 35, text = "", action = function() posSelect = yTouch scroll - 7 DrawScrollContent() end}, |
| 368 | + | Select = {ButtonIn = {"stop"}, visible = false, x = 11, y = 7, w = 60, h = 35, text = "", action = function() posSelect = yTouch scroll - 7 DrawScrollContent() end},
|
| 369 | - | Go = {ButtonIn = {"start","go"}, visible = true, x = 14, y = 47, w = 24, h = 3, cbutton = 0x28C730, ctext = 0x28C730, text = "Go", action = function() end}, |
| 369 | + | Go = {ButtonIn = {"start","go"}, visible = true, x = 14, y = 47, w = 24, h = 3, cbutton = 0x28C730, ctext = 0x28C730, text = "Go", action = function() end},
|
| 370 | - | GoTrue = {ButtonIn = {"stop"}, visible = true, x = 14, y = 47, w = 24, h = 3, cbutton = 0x00ffff, ctext = 0x00ffff, text = "Go", action = function() toGui("go") dataq = nil dataq = dataItems go = true end}, |
| 370 | + | GoTrue = {ButtonIn = {"stop"}, visible = true, x = 14, y = 47, w = 24, h = 3, cbutton = 0x00ffff, ctext = 0x00ffff, text = "Go", action = function() toGui("go") dataq = nil dataq = dataItems go = true end},
|
| 371 | - | |
| 371 | + | |
| 372 | - | Stop = {ButtonIn = {"stop"}, visible = true, x = 43, y = 47, w = 24, h = 3, cbutton = 0xff0000, ctext = 0xff0000, text = "Stop", action = function() end}, |
| 372 | + | Stop = {ButtonIn = {"stop"}, visible = true, x = 43, y = 47, w = 24, h = 3, cbutton = 0xff0000, ctext = 0xff0000, text = "Stop", action = function() end},
|
| 373 | - | StopTrue = {ButtonIn = {"start", "go"}, visible = true, x = 43, y = 47, w = 24, h = 3, cbutton = 0x00ffff, ctext = 0x00ffff,text = "Stop", action = function() toGui("stop") go = false end}, |
| 373 | + | StopTrue = {ButtonIn = {"start", "go"}, visible = true, x = 43, y = 47, w = 24, h = 3, cbutton = 0x00ffff, ctext = 0x00ffff,text = "Stop", action = function() toGui("stop") go = false end},
|
| 374 | - | |
| 374 | + | |
| 375 | - | Add = {ButtonIn = {"stop"}, visible = true, x = 20, y = 45, w = 10, h = 1, cbutton = nil, ctext = 0x00ffff, text = "[Добавить]", action = function() AddItem() end}, |
| 375 | + | Add = {ButtonIn = {"stop"}, visible = true, x = 20, y = 45, w = 10, h = 1, cbutton = nil, ctext = 0x00ffff, text = "[Добавить]", action = function() AddItem() end},
|
| 376 | - | Change = {ButtonIn = {"stop"}, visible = true, x = 36, y = 45, w = 10, h = 1, cbutton = nil, ctext = 0x00ffff, text = "[Изменить]", action = function() EditItem() end}, |
| 376 | + | Change = {ButtonIn = {"stop"}, visible = true, x = 36, y = 45, w = 10, h = 1, cbutton = nil, ctext = 0x00ffff, text = "[Изменить]", action = function() EditItem() end},
|
| 377 | - | Remove = {ButtonIn = {"stop"}, visible = true, x = 54, y = 45, w = 9, h = 1, cbutton = nil, ctext = 0x00ffff, text = "[Удалить]", action = function() RemoveItem() end}, |
| 377 | + | Remove = {ButtonIn = {"stop"}, visible = true, x = 54, y = 45, w = 9, h = 1, cbutton = nil, ctext = 0x00ffff, text = "[Удалить]", action = function() RemoveItem() end},
|
| 378 | - | -- сhange |
| 378 | + | -- сhange |
| 379 | - | changeName = {ButtonIn = {"change"}, visible = true, x = 14, y = 35, w = 53, h = 3, cbutton = 0x004575, ctext = 0x00ffff, text = "Изменить название", action = function() ChangeItem("changeName") end}, |
| 379 | + | changeName = {ButtonIn = {"change"}, visible = true, x = 14, y = 35, w = 53, h = 3, cbutton = 0x004575, ctext = 0x00ffff, text = "Изменить название", action = function() ChangeItem("changeName") end},
|
| 380 | - | changeCount = {ButtonIn = {"change"}, visible = true, x = 14, y = 38, w = 53, h = 3, cbutton = 0x004575, ctext = 0x00ffff, text = "Изменить количество поддержания", action = function() ChangeItem("changeCount") end}, |
| 380 | + | changeCount = {ButtonIn = {"change"}, visible = true, x = 14, y = 38, w = 53, h = 3, cbutton = 0x004575, ctext = 0x00ffff, text = "Изменить количество поддержания", action = function() ChangeItem("changeCount") end},
|
| 381 | - | changeCraftSize = {ButtonIn = {"change"}, visible = true, x = 14, y = 41, w = 53, h = 3, cbutton = 0x004575, ctext = 0x00ffff, text = "Изменит размер крафта", action = function() ChangeItem("changeCraftSize") end}, |
| 381 | + | changeCraftSize = {ButtonIn = {"change"}, visible = true, x = 14, y = 41, w = 53, h = 3, cbutton = 0x004575, ctext = 0x00ffff, text = "Изменит размер крафта", action = function() ChangeItem("changeCraftSize") end},
|
| 382 | - | changeBack = {ButtonIn = {"change"}, visible = true, x = 14, y = 47, w = 53, h = 3, cbutton = 0x004575, ctext = 0x00ffff, text = "Назад", action = function() Back() end}, |
| 382 | + | changeBack = {ButtonIn = {"change"}, visible = true, x = 14, y = 47, w = 53, h = 3, cbutton = 0x004575, ctext = 0x00ffff, text = "Назад", action = function() Back() end},
|
| 383 | - | } |
| 383 | + | } |
| 384 | - | |
| 384 | + | |
| 385 | - | scrolls = { |
| 385 | + | scrolls = {
|
| 386 | - | Buy = {ScrollIn = {"start", "go", "stop"},iwY = 43, xGui = 10 , yGui = 6, wGui = 62, hGui = 37, x = 70, y = 7, w = 1, h = 35, action = function() content = dataItems end}, |
| 386 | + | Buy = {ScrollIn = {"start", "go", "stop"},iwY = 43, xGui = 10 , yGui = 6, wGui = 62, hGui = 37, x = 70, y = 7, w = 1, h = 35, action = function() content = dataItems end},
|
| 387 | - | } |
| 387 | + | } |
| 388 | - | |
| 388 | + | |
| 389 | - | function loop() |
| 389 | + | function loop() |
| 390 | - | if LoadSystem() then |
| 390 | + | if LoadSystem() then |
| 391 | - | while precraft do |
| 391 | + | while precraft do |
| 392 | - | if go then |
| 392 | + | if go then |
| 393 | - | g.set(1,1,"check") |
| 393 | + | g.set(1,1,"check") |
| 394 | - | Check() |
| 394 | + | Check() |
| 395 | - | else |
| 395 | + | else |
| 396 | - | g.set(1,1,"sleep") |
| 396 | + | g.set(1,1,"sleep") |
| 397 | - | end |
| 397 | + | end |
| 398 | - | os.sleep(1) |
| 398 | + | os.sleep(1) |
| 399 | - | end |
| 399 | + | end |
| 400 | - | end |
| 400 | + | end |
| 401 | end | |
| 402 | - | |
| 402 | + | |
| 403 | - | ok, err = pcall(loop) |
| 403 | + | ok, err = pcall(loop) |
| 404 | - | |
| 404 | + | |
| 405 | - | |
| 405 | + | |
| 406 | - | if not ok then |
| 406 | + | if not ok then |
| 407 | - | event.cancel(etouch) |
| 407 | + | event.cancel(etouch) |
| 408 | - | event.cancel(escroll) |
| 408 | + | event.cancel(escroll) |
| 409 | - | event.cancel(ekeydown) |
| 409 | + | event.cancel(ekeydown) |
| 410 | - | computer.shutdown(true) |
| 410 | + | computer.shutdown(true) |
| 411 | end |