added redstone interface
This commit is contained in:
parent
35be02dbe2
commit
a75f86cbc1
@ -20,12 +20,15 @@ class Peripheral {
|
||||
private var screens: Array<Screen> = [];
|
||||
private var modes: Array<Modem> = [];
|
||||
private var drives:Array<Drive> = [];
|
||||
private var redstone:Array<Redstone> = [];
|
||||
|
||||
@:allow(kernel.Init)
|
||||
private function new() {
|
||||
KernelEvents.instance.onPeripheral.handle(this.updatePeripherals);
|
||||
KernelEvents.instance.onPeripheralDetach.handle(this.updatePeripherals);
|
||||
updatePeripherals();
|
||||
|
||||
redstone = [ for(side in [Side.Top,Side.Right,Side.Left,Side.Front,Side.Bottom,Side.Back]) new Redstone(side) ];
|
||||
}
|
||||
|
||||
private function updatePeripherals() {
|
||||
@ -81,4 +84,8 @@ class Peripheral {
|
||||
var allDrives = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "drive");
|
||||
this.drives = allDrives.map(s -> return new Drive((cc.Peripheral.wrap(s) : Dynamic), s));
|
||||
}
|
||||
|
||||
public function getRedstone(side: String): Redstone {
|
||||
return this.redstone.find(item -> item.getAddr() == side);
|
||||
}
|
||||
}
|
||||
|
60
src/kernel/peripherals/Redstone.hx
Normal file
60
src/kernel/peripherals/Redstone.hx
Normal file
@ -0,0 +1,60 @@
|
||||
package kernel.peripherals;
|
||||
|
||||
import util.Color;
|
||||
|
||||
typedef BundleMask = Color;
|
||||
|
||||
class Redstone implements IPeripheral {
|
||||
|
||||
private final addr:Side;
|
||||
|
||||
@:allow(kernel.peripherals)
|
||||
private function new(side: Side) {
|
||||
this.addr = side;
|
||||
}
|
||||
|
||||
public function getAddr():String {
|
||||
return this.addr;
|
||||
}
|
||||
|
||||
public inline function setOutput(on:Bool):Void {
|
||||
cc.Redstone.setOutput(this.addr,on);
|
||||
}
|
||||
|
||||
public inline function getOutput(): Bool {
|
||||
return cc.Redstone.getOutput(this.addr);
|
||||
}
|
||||
|
||||
public inline function getInput(): Bool {
|
||||
return cc.Redstone.getInput(this.addr);
|
||||
}
|
||||
|
||||
public inline function setAnalogOutput(strength:Int): Void {
|
||||
cc.Redstone.setAnalogOutput(this.addr,strength);
|
||||
}
|
||||
|
||||
public inline function getAnalogOutput(): Int {
|
||||
return cc.Redstone.getAnalogOutput(this.addr);
|
||||
}
|
||||
|
||||
public inline function getAnalogInput(): Int {
|
||||
return cc.Redstone.getAnalogInput(this.addr);
|
||||
}
|
||||
|
||||
public inline function setBundledOutput(output: BundleMask) {
|
||||
cc.Redstone.setBundledOutput(this.addr,output);
|
||||
}
|
||||
|
||||
public inline function getBundledOutput():BundleMask {
|
||||
return cc.Redstone.getBundledOutput(this.addr);
|
||||
}
|
||||
|
||||
public inline function getBundledInput():BundleMask {
|
||||
return cc.Redstone.getBundledInput(this.addr);
|
||||
}
|
||||
|
||||
public inline function testBundledInput(mask: Color): Bool {
|
||||
return cc.Redstone.testBundledInput(this.addr,mask);
|
||||
}
|
||||
|
||||
}
|
10
src/kernel/peripherals/Side.hx
Normal file
10
src/kernel/peripherals/Side.hx
Normal file
@ -0,0 +1,10 @@
|
||||
package kernel.peripherals;
|
||||
|
||||
enum abstract Side(String) to String {
|
||||
var Top = "top";
|
||||
var Bottom = "bottom";
|
||||
var Left = "left";
|
||||
var Right = "right";
|
||||
var Front = "front";
|
||||
var Back = "back";
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package util;
|
||||
|
||||
import kernel.peripherals.Redstone.BundleMask;
|
||||
|
||||
enum abstract Color(Int) from cc.Colors.Color to cc.Colors.Color {
|
||||
var White = 0x1;
|
||||
var Orange = 0x2;
|
||||
@ -17,4 +19,9 @@ enum abstract Color(Int) from cc.Colors.Color to cc.Colors.Color {
|
||||
var Green = 0x2000;
|
||||
var Red = 0x4000;
|
||||
var Black = 0x8000;
|
||||
|
||||
@:op(A + B)
|
||||
public inline function combine(rhs: Color):BundleMask {
|
||||
return this + rhs;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user