diff --git a/src/kernel/peripherals/Peripherals.hx b/src/kernel/peripherals/Peripherals.hx index ec3ce38..7b330c3 100644 --- a/src/kernel/peripherals/Peripherals.hx +++ b/src/kernel/peripherals/Peripherals.hx @@ -21,6 +21,7 @@ class Peripheral { private var modes: Array = []; private var drives:Array = []; private var redstone:Array = []; + private var printers:Array = []; @:allow(kernel.Init) private function new() { @@ -85,7 +86,24 @@ class Peripheral { this.drives = allDrives.map(s -> return new Drive((cc.Peripheral.wrap(s) : Dynamic), s)); } + /** + Get redstone peripheral. + **/ public function getRedstone(side: String): Redstone { return this.redstone.find(item -> item.getAddr() == side); } + + /** + Get all connected printers. + **/ + + public function getPrinters():ReadOnlyArray { + return this.printers; + } + + private function findPrinters() { + var allPrinters = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "printer"); + this.printers = allPrinters.map(s -> return new Printer((cc.Peripheral.wrap(s) : Dynamic), s)); + } + } diff --git a/src/kernel/peripherals/Printer.hx b/src/kernel/peripherals/Printer.hx new file mode 100644 index 0000000..7958d34 --- /dev/null +++ b/src/kernel/peripherals/Printer.hx @@ -0,0 +1,56 @@ +package kernel.peripherals; + +import lib.Rect; +import lib.Pos; + +class Printer implements IPeripheral { + + private final native:cc.periphs.Printer.Printer; + private final addr:String; + + public function new(native: cc.periphs.Printer.Printer, addr: String) { + this.native = native; + this.addr = addr; + } + + public function getAddr():String { + return addr; + } + + public function write(text: String){ + + } + + public function getCurserPos(): Pos { + return new Pos({x: 0, y: 0}); + } + + public function setCurserPos(pos: Pos){ + this.native.setCursorPos(pos.x, pos.y); + } + + public function getPageSize(): Rect { + var pos = this.native.getPageSize(); + return new Rect({x: 0, y: 0}, {x: pos.x, y: pos.y}); + } + + public function newPage(): Bool{ + return this.native.newPage(); + } + + public function endPage(): Bool{ + return this.native.endPage(); + } + + public function setPageTitle(title: String){ + this.native.setPageTitle(title); + } + + public function getInkLevel(): Float{ + return this.native.getInkLevel(); + } + + public function getPaperLevel():Int { + return this.native.getPaperLevel(); + } +}