redstone bundle mask improvement
This commit is contained in:
		
							parent
							
								
									57bf49bea9
								
							
						
					
					
						commit
						a1bb41f8a2
					
				@ -1,10 +1,45 @@
 | 
			
		||||
package kernel.peripherals;
 | 
			
		||||
 | 
			
		||||
import haxe.ds.ReadOnlyArray;
 | 
			
		||||
import util.Color;
 | 
			
		||||
 | 
			
		||||
using tink.CoreApi;
 | 
			
		||||
 | 
			
		||||
typedef BundleMask = Color;
 | 
			
		||||
abstract BundleMask(Int) from cc.Colors.Color to cc.Colors.Color  {
 | 
			
		||||
	public inline function new(i:Int) {
 | 
			
		||||
		this = i;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@:from
 | 
			
		||||
	public static function fromColor(c: Color) {
 | 
			
		||||
		return new BundleMask(c);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@:op(A + B)
 | 
			
		||||
	@:op(A | B)
 | 
			
		||||
	public inline function combine(rhs: BundleMask):BundleMask {
 | 
			
		||||
		return this | rhs;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@:op(A + B)
 | 
			
		||||
	@:op(A | B)
 | 
			
		||||
	public inline function combineWithColor(rhs: Color):BundleMask {
 | 
			
		||||
		return this | rhs;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getComponents(): ReadOnlyArray<Color> {
 | 
			
		||||
		var components: Array<Color> = [];
 | 
			
		||||
		var mask = 1;
 | 
			
		||||
		for (i in 0...16){
 | 
			
		||||
			if ((this & mask) > 0 ){
 | 
			
		||||
				components.push(mask);
 | 
			
		||||
			}
 | 
			
		||||
			mask = mask << 1;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return components;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Redstone implements IPeripheral {
 | 
			
		||||
 | 
			
		||||
@ -22,16 +57,19 @@ class Redstone implements IPeripheral {
 | 
			
		||||
		this.addr = side;
 | 
			
		||||
		this.onChange = this.onChangeTrigger.asSignal();
 | 
			
		||||
 | 
			
		||||
		updateState();
 | 
			
		||||
 | 
			
		||||
		KernelEvents.instance.onRedstone.handle(()->{
 | 
			
		||||
			if ((this.getAnalogInput() != this.analogInputState) || (this.bundleInputState == this.getBundledInput())){
 | 
			
		||||
			if ((this.getAnalogInput() != this.analogInputState) || (this.bundleInputState != this.getBundledInput())){
 | 
			
		||||
				updateState();
 | 
			
		||||
				this.onChangeTrigger.trigger(null);
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAddr():String {
 | 
			
		||||
		return this.addr;
 | 
			
		||||
		updateState();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function updateState() {
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,8 @@ enum abstract Color(Int) from cc.Colors.Color to cc.Colors.Color {
 | 
			
		||||
	var Black = 0x8000;
 | 
			
		||||
 | 
			
		||||
	@:op(A + B)
 | 
			
		||||
	@:op(A | B)
 | 
			
		||||
	public inline function combine(rhs: Color):BundleMask {
 | 
			
		||||
		return this + rhs;
 | 
			
		||||
		return this | rhs;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user