Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local shell = require("shell")
- local gpu = component.gpu
- local x , y = gpu.getResolution()
- local function setColor(c)
- if c and gpu.getForeground() ~= c then
- gpu.setForeground(c)
- end
- end
- local function cwrite(c, ...)
- local oldCol = gpu.getForeground()
- setColor(c)
- io.write(...)
- setColor(oldCol)
- end
- local args = shell.parse(...)
- if #args < 1 then
- io.write("Используйте: printAll FILE [Количество] [Номер блока]\n")
- os.exit(0)
- end
- local count = tonumber(args[2]) or 1
- local block = tonumber(args[3]) or nil
- -- Загружаем файл
- local file, reason = io.open(args[1], "r")
- if not file then
- io.stderr:write("Ошибка при открытии файла: " .. reason .. "\n")
- os.exit(1)
- end
- local rawdata = file:read("*all")
- file:close()
- local data, reason = load("return " .. rawdata)
- if not data then
- io.stderr:write("Ошибка загрузки модели: " .. reason .. "\n")
- os.exit(2)
- end
- -- Фильтруем модели
- local data1 = {}
- for _, i in pairs({data()}) do
- if (#i.shapes > 0) then
- table.insert(data1, i)
- end
- end
- cwrite(nil,"Блоков найдено: ")
- cwrite(0x00ffff, #data1, "\n")
- -- Получаем список принтеров
- local printers = {}
- for addr in component.list("printer3d") do
- table.insert(printers, component.proxy(addr))
- end
- cwrite(nil,"Принтеров найдено: ")
- cwrite(0x00ffff, #printers, "\n")
- if #printers == 0 then
- io.stderr:write("Нет доступных принтеров!\n")
- os.exit(3)
- end
- -- Очередь печати
- local blockNumber = block or 1
- while blockNumber <= #data1 do
- for _, printer in ipairs(printers) do
- if blockNumber > #data1 then break end
- if printer.status() == "idle" then
- local m = data1[blockNumber]
- printer.reset()
- printer.setLabel(m.label or ("Block "..blockNumber))
- printer.setTooltip(m.tooltip or ("["..blockNumber.."]"))
- if m.lightLevel and printer.setLightLevel then
- printer.setLightLevel(m.lightLevel)
- end
- if m.emitRedstone then
- printer.setRedstoneEmitter(m.emitRedstone)
- end
- if m.buttonMode then
- printer.setButtonMode(m.buttonMode)
- end
- for _, shape in ipairs(m.shapes) do
- local result, reason = printer.addShape(
- shape[1], shape[2], shape[3], shape[4], shape[5], shape[6],
- shape.texture, shape.state, shape.tint
- )
- if not result then
- io.write("Ошибка добавления фигуры: " .. tostring(reason) .. "\n")
- end
- end
- local result, reason = printer.commit(count)
- if result then
- cwrite(0x00ff00,"Принтер "..tostring(printer.address).." печатает блок "..blockNumber.."\n")
- blockNumber = blockNumber + 1
- else
- io.stderr:write("Ошибка печати: " .. tostring(reason) .. "\n")
- end
- end
- end
- os.sleep(1) -- проверяем принтеры несколько раз в секунду
- end
- cwrite(nil,"Все задания отправлены на печать\n")
Advertisement
Add Comment
Please, Sign In to add comment