Advertisement
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
- 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
- count = 1
- if #args > 1 then
- count = assert(tonumber(args[2]), tostring(args[2]) .. " is not a valid count")
- end
- block = nil
- if #args > 2 then
- block = assert(tonumber(args[3]), tostring(args[3]) .. "Not valid block_number")
- end
- 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")
- local pIndex = 0
- local printer
- -- Loop all models in file
- local blockNumber = 1
- if block ~= nil then
- blockNumber = block
- else
- blockNumber = 1
- end
- while blockNumber <= #data1 do
- if block ~= nil then
- if blockNumber == block+1 then
- break
- end
- end
- -- Looking for idle printer
- pIndex = (pIndex+1)>#printers and 1 or pIndex+1
- printer = printers[pIndex]
- if printer.status() ~= "idle" then goto continue end
- if block ~= nil then
- if blockNumber == block then
- m = data1[block]
- end
- else
- m = data1[blockNumber]
- end
- printer.reset()
- if m.label then
- printer.setLabel(m.label)
- end
- if m.tooltip then
- printer.setTooltip(m.tooltip)
- else
- printer.setTooltip("["..blockNumber.."]")
- end
- if m.lightLevel and printer.setLightLevel then -- as of OC 1.5.7
- 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("Failed adding shape: " .. tostring(reason) .. "\n")
- end
- end
- cwrite(nil,"#"); cwrite(0x00ffff,blockNumber); cwrite(nil,"/") cwrite(0x00ffff,#data1); cwrite(nil,": ")
- cwrite(0xffffff, printer.getLabel() or "[no label]", " ")
- cwrite(0x555555, printer.getTooltip() or "[no tooltip]", " ")
- cwrite(nil,"Shape = "); cwrite(0xffff00, printer.getShapeCount()*1)
- local result, reason = printer.commit(count)
- if result then
- cwrite(0x00ff00," >> Печать..\n");
- blockNumber = blockNumber + 1
- os.sleep(0.5)
- else
- io.stderr:write("\nFailed committing job: " .. tostring(reason) .. "\n")
- end
- ::continue::
- end
- cwrite(nil,"Завершение печати")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement