This commit is contained in:
Djeeberjr 2023-02-04 23:24:57 +01:00
parent dabc42ea25
commit 3e7d993662
2 changed files with 74 additions and 0 deletions

View File

@ -21,6 +21,7 @@ class Peripheral {
private var modes: Array<Modem> = [];
private var drives:Array<Drive> = [];
private var redstone:Array<Redstone> = [];
private var printers:Array<Printer> = [];
@: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<Printer> {
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));
}
}

View File

@ -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();
}
}