changed kernel events to static class

This commit is contained in:
Djeeberjr 2023-07-27 20:30:39 +02:00
parent adc5ab1849
commit e1e0180502
12 changed files with 154 additions and 156 deletions

View File

@ -25,7 +25,7 @@ class Init {
public static function initKernel() { public static function initKernel() {
// Init singeltons here because haxe is confused about the order to create them. // Init singeltons here because haxe is confused about the order to create them.
Log.instance = new Log(); Log.instance = new Log();
KernelEvents.instance = new KernelEvents(); KernelEvents.init();
Peripheral.instance = new Peripheral(); Peripheral.instance = new Peripheral();
WindowManager.instance = new WindowManager(); WindowManager.instance = new WindowManager();
@ -44,8 +44,8 @@ class Init {
INS.instance = new INS(); INS.instance = new INS();
// Register default terminate handler // Register default terminate handler
KernelEvents.instance.onTerminate.handle(_->{ KernelEvents.onTerminate.handle(_->{
KernelEvents.instance.shutdown(); KernelEvents.shutdown();
}); });
Debug.printBuildInfo(); Debug.printBuildInfo();
@ -57,7 +57,7 @@ class Init {
} }
Init.mainEvent = MainLoop.add(()->{ Init.mainEvent = MainLoop.add(()->{
KernelEvents.instance.startEventLoop(); KernelEvents.startEventLoop();
}); });
ServiceManager.instance = new ServiceManager(); ServiceManager.instance = new ServiceManager();

View File

@ -18,124 +18,122 @@ class KernelEvents {
/** /**
Depends on: (Nothing) Depends on: (Nothing)
**/ **/
public static var instance:KernelEvents; public static var onAlarm(default, null):Signal<Int>;
public static var onChar(default, null):Signal<String>;
public final onAlarm:Signal<Int>; public static var onDisk(default, null):Signal<String>;
public final onChar:Signal<String>; public static var onDiskEject(default, null):Signal<String>;
public final onDisk:Signal<String>; public static var onHttpCheck(default, null):Signal<{url:String, success:Bool, failReason:Any}>;
public final onDiskEject:Signal<String>; public static var onHttpFailure(default, null):Signal<{url:String, failReason:String, handle:HTTPResponse}>;
public final onHttpCheck:Signal<{url:String, success:Bool, failReason:Any}>; public static var onHttpSuccess(default, null):Signal<{url:String, handle:HTTPResponse}>;
public final onHttpFailure:Signal<{url:String, failReason:String, handle:HTTPResponse}>; public static var onKey(default, null):Signal<{keyCode:Int, isHeld:Bool}>;
public final onHttpSuccess:Signal<{url:String, handle:HTTPResponse}>; public static var onKeyUp(default, null):Signal<Int>;
public final onKey:Signal<{keyCode:Int, isHeld:Bool}>; public static var onModemMessage(default, null):Signal<{
public final onKeyUp:Signal<Int>;
public final onModemMessage:Signal<{
addr:String, addr:String,
channel:Int, channel:Int,
replyChannel:Int, replyChannel:Int,
message:Dynamic, message:Dynamic,
distance:Null<Float> distance:Null<Float>
}>; }>;
public final onMonitorResize:Signal<String>; public static var onMonitorResize(default, null):Signal<String>;
public final onMonitorTouch:Signal<{addr:String, pos:Pos}>; public static var onMonitorTouch(default, null):Signal<{addr:String, pos:Pos}>;
public final onMouseClick:Signal<{button:ButtonType, pos:Pos}>; public static var onMouseClick(default, null):Signal<{button:ButtonType, pos:Pos}>;
public final onMouseDrag:Signal<{button:ButtonType, pos:Pos}>; public static var onMouseDrag(default, null):Signal<{button:ButtonType, pos:Pos}>;
public final onMouseScroll:Signal<{dir:Int, pos:Pos}>; public static var onMouseScroll(default, null):Signal<{dir:Int, pos:Pos}>;
public final onMouseUp:Signal<{button:ButtonType, pos:Pos}>; public static var onMouseUp(default, null):Signal<{button:ButtonType, pos:Pos}>;
public final onPaste:Signal<String>; public static var onPaste(default, null):Signal<String>;
public final onPeripheral:Signal<String>; public static var onPeripheral(default, null):Signal<String>;
public final onPeripheralDetach:Signal<String>; public static var onPeripheralDetach(default, null):Signal<String>;
public final onRedstone:Signal<Noise>; public static var onRedstone(default, null):Signal<Noise>;
public final onSpeakerAudioEmpty:Signal<String>; public static var onSpeakerAudioEmpty(default, null):Signal<String>;
public final onTaskComplete:Signal<{id:Int, success:Bool, failedReason:String}>; public static var onTaskComplete(default, null):Signal<{id:Int, success:Bool, failedReason:String}>;
public final onTermResize:Signal<Noise>; public static var onTermResize(default, null):Signal<Noise>;
public final onTerminate:Signal<Noise>; public static var onTerminate(default, null):Signal<Noise>;
public final onTimer:Signal<Int>; public static var onTimer(default, null):Signal<Int>;
public final onTurtleInventory:Signal<Noise>; public static var onTurtleInventory(default, null):Signal<Noise>;
public final onWebsocketClose:Signal<String>; public static var onWebsocketClose(default, null):Signal<String>;
public final onWebsocketFailure:Signal<{url:String, failReason:String}>; public static var onWebsocketFailure(default, null):Signal<{url:String, failReason:String}>;
public final onWebsocketMessage:Signal<{url:String, message:String, isBinary:Bool}>; public static var onWebsocketMessage(default, null):Signal<{url:String, message:String, isBinary:Bool}>;
public final onWebsocketSuccess:Signal<{url:String, handle:Any}>; public static var onWebsocketSuccess(default, null):Signal<{url:String, handle:Any}>;
private final onAlarmTrigger:SignalTrigger<Int> = Signal.trigger(); private static final onAlarmTrigger:SignalTrigger<Int> = Signal.trigger();
private final onCharTrigger:SignalTrigger<String> = Signal.trigger(); private static final onCharTrigger:SignalTrigger<String> = Signal.trigger();
private final onDiskTrigger:SignalTrigger<String> = Signal.trigger(); private static final onDiskTrigger:SignalTrigger<String> = Signal.trigger();
private final onDiskEjectTrigger:SignalTrigger<String> = Signal.trigger(); private static final onDiskEjectTrigger:SignalTrigger<String> = Signal.trigger();
private final onHttpCheckTrigger:SignalTrigger<{url:String, success:Bool, failReason:Any}> = Signal.trigger(); private static final onHttpCheckTrigger:SignalTrigger<{url:String, success:Bool, failReason:Any}> = Signal.trigger();
private final onHttpFailureTrigger:SignalTrigger<{url:String, failReason:String, handle:HTTPResponse}> = Signal.trigger(); private static final onHttpFailureTrigger:SignalTrigger<{url:String, failReason:String, handle:HTTPResponse}> = Signal.trigger();
private final onHttpSuccessTrigger:SignalTrigger<{url:String, handle:HTTPResponse}> = Signal.trigger(); private static final onHttpSuccessTrigger:SignalTrigger<{url:String, handle:HTTPResponse}> = Signal.trigger();
private final onKeyTrigger:SignalTrigger<{keyCode:Int, isHeld:Bool}> = Signal.trigger(); private static final onKeyTrigger:SignalTrigger<{keyCode:Int, isHeld:Bool}> = Signal.trigger();
private final onKeyUpTrigger:SignalTrigger<Int> = Signal.trigger(); private static final onKeyUpTrigger:SignalTrigger<Int> = Signal.trigger();
private final onModemMessageTrigger:SignalTrigger<{ private static final onModemMessageTrigger:SignalTrigger<{
addr:String, addr:String,
channel:Int, channel:Int,
replyChannel:Int, replyChannel:Int,
message:Dynamic, message:Dynamic,
distance:Null<Float> distance:Null<Float>
}> = Signal.trigger(); }> = Signal.trigger();
private final onMonitorResizeTrigger:SignalTrigger<String> = Signal.trigger(); private static final onMonitorResizeTrigger:SignalTrigger<String> = Signal.trigger();
private final onMonitorTouchTrigger:SignalTrigger<{addr:String, pos:Pos}> = Signal.trigger(); private static final onMonitorTouchTrigger:SignalTrigger<{addr:String, pos:Pos}> = Signal.trigger();
private final onMouseClickTrigger:SignalTrigger<{button:ButtonType, pos:Pos}> = Signal.trigger(); private static final onMouseClickTrigger:SignalTrigger<{button:ButtonType, pos:Pos}> = Signal.trigger();
private final onMouseDragTrigger:SignalTrigger<{button:ButtonType, pos:Pos}> = Signal.trigger(); private static final onMouseDragTrigger:SignalTrigger<{button:ButtonType, pos:Pos}> = Signal.trigger();
private final onMouseScrollTrigger:SignalTrigger<{dir:Int, pos:Pos}> = Signal.trigger(); private static final onMouseScrollTrigger:SignalTrigger<{dir:Int, pos:Pos}> = Signal.trigger();
private final onMouseUpTrigger:SignalTrigger<{button:ButtonType, pos:Pos}> = Signal.trigger(); private static final onMouseUpTrigger:SignalTrigger<{button:ButtonType, pos:Pos}> = Signal.trigger();
private final onPasteTrigger:SignalTrigger<String> = Signal.trigger(); private static final onPasteTrigger:SignalTrigger<String> = Signal.trigger();
private final onPeripheralTrigger:SignalTrigger<String> = Signal.trigger(); private static final onPeripheralTrigger:SignalTrigger<String> = Signal.trigger();
private final onPeripheralDetachTrigger:SignalTrigger<String> = Signal.trigger(); private static final onPeripheralDetachTrigger:SignalTrigger<String> = Signal.trigger();
private final onRednetMessageTrigger:SignalTrigger<{sender:Int, message:Any, protocol:Any}> = Signal.trigger(); private static final onRednetMessageTrigger:SignalTrigger<{sender:Int, message:Any, protocol:Any}> = Signal.trigger();
private final onRedstoneTrigger:SignalTrigger<Noise> = Signal.trigger(); private static final onRedstoneTrigger:SignalTrigger<Noise> = Signal.trigger();
private final onSpeakerAudioEmptyTrigger:SignalTrigger<String> = Signal.trigger(); private static final onSpeakerAudioEmptyTrigger:SignalTrigger<String> = Signal.trigger();
private final onTaskCompleteTrigger:SignalTrigger<{id:Int, success:Bool, failedReason:String}> = Signal.trigger(); private static final onTaskCompleteTrigger:SignalTrigger<{id:Int, success:Bool, failedReason:String}> = Signal.trigger();
private final onTermResizeTrigger:SignalTrigger<Noise> = Signal.trigger(); private static final onTermResizeTrigger:SignalTrigger<Noise> = Signal.trigger();
private final onTerminateTrigger:SignalTrigger<Noise> = Signal.trigger(); private static final onTerminateTrigger:SignalTrigger<Noise> = Signal.trigger();
private final onTimerTrigger:SignalTrigger<Int> = Signal.trigger(); private static final onTimerTrigger:SignalTrigger<Int> = Signal.trigger();
private final onTurtleInventoryTrigger:SignalTrigger<Noise> = Signal.trigger(); private static final onTurtleInventoryTrigger:SignalTrigger<Noise> = Signal.trigger();
private final onWebsocketCloseTrigger:SignalTrigger<String> = Signal.trigger(); private static final onWebsocketCloseTrigger:SignalTrigger<String> = Signal.trigger();
private final onWebsocketFailureTrigger:SignalTrigger<{url:String, failReason:String}> = Signal.trigger(); private static final onWebsocketFailureTrigger:SignalTrigger<{url:String, failReason:String}> = Signal.trigger();
private final onWebsocketMessageTrigger:SignalTrigger<{url:String, message:String, isBinary:Bool}> = Signal.trigger(); private static final onWebsocketMessageTrigger:SignalTrigger<{url:String, message:String, isBinary:Bool}> = Signal.trigger();
private final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger(); private static final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
private var stopLoop:Bool = false; private static var stopLoop:Bool = false;
@:allow(kernel.Init) @:allow(kernel.Init)
private function new() { private static function init() {
this.onAlarm = onAlarmTrigger.asSignal(); onAlarm = onAlarmTrigger.asSignal();
this.onChar = onCharTrigger.asSignal(); onChar = onCharTrigger.asSignal();
this.onDisk = onDiskTrigger.asSignal(); onDisk = onDiskTrigger.asSignal();
this.onDiskEject = onDiskEjectTrigger.asSignal(); onDiskEject = onDiskEjectTrigger.asSignal();
this.onHttpCheck = onHttpCheckTrigger.asSignal(); onHttpCheck = onHttpCheckTrigger.asSignal();
this.onHttpFailure = onHttpFailureTrigger.asSignal(); onHttpFailure = onHttpFailureTrigger.asSignal();
this.onHttpSuccess = onHttpSuccessTrigger.asSignal(); onHttpSuccess = onHttpSuccessTrigger.asSignal();
this.onKey = onKeyTrigger.asSignal(); onKey = onKeyTrigger.asSignal();
this.onKeyUp = onKeyUpTrigger.asSignal(); onKeyUp = onKeyUpTrigger.asSignal();
this.onModemMessage = onModemMessageTrigger.asSignal(); onModemMessage = onModemMessageTrigger.asSignal();
this.onMonitorResize = onMonitorResizeTrigger.asSignal(); onMonitorResize = onMonitorResizeTrigger.asSignal();
this.onMonitorTouch = onMonitorTouchTrigger.asSignal(); onMonitorTouch = onMonitorTouchTrigger.asSignal();
this.onMouseClick = onMouseClickTrigger.asSignal(); onMouseClick = onMouseClickTrigger.asSignal();
this.onMouseDrag = onMouseDragTrigger.asSignal(); onMouseDrag = onMouseDragTrigger.asSignal();
this.onMouseScroll = onMouseScrollTrigger.asSignal(); onMouseScroll = onMouseScrollTrigger.asSignal();
this.onMouseUp = onMouseUpTrigger.asSignal(); onMouseUp = onMouseUpTrigger.asSignal();
this.onPaste = onPasteTrigger.asSignal(); onPaste = onPasteTrigger.asSignal();
this.onPeripheral = onPeripheralTrigger.asSignal(); onPeripheral = onPeripheralTrigger.asSignal();
this.onPeripheralDetach = onPeripheralDetachTrigger.asSignal(); onPeripheralDetach = onPeripheralDetachTrigger.asSignal();
this.onRedstone = onRedstoneTrigger.asSignal(); onRedstone = onRedstoneTrigger.asSignal();
this.onSpeakerAudioEmpty = onSpeakerAudioEmptyTrigger.asSignal(); onSpeakerAudioEmpty = onSpeakerAudioEmptyTrigger.asSignal();
this.onTaskComplete = onTaskCompleteTrigger.asSignal(); onTaskComplete = onTaskCompleteTrigger.asSignal();
this.onTermResize = onTermResizeTrigger.asSignal(); onTermResize = onTermResizeTrigger.asSignal();
this.onTerminate = onTerminateTrigger.asSignal(); onTerminate = onTerminateTrigger.asSignal();
this.onTimer = onTimerTrigger.asSignal(); onTimer = onTimerTrigger.asSignal();
this.onTurtleInventory = onTurtleInventoryTrigger.asSignal(); onTurtleInventory = onTurtleInventoryTrigger.asSignal();
this.onWebsocketClose = onWebsocketCloseTrigger.asSignal(); onWebsocketClose = onWebsocketCloseTrigger.asSignal();
this.onWebsocketFailure = onWebsocketFailureTrigger.asSignal(); onWebsocketFailure = onWebsocketFailureTrigger.asSignal();
this.onWebsocketMessage = onWebsocketMessageTrigger.asSignal(); onWebsocketMessage = onWebsocketMessageTrigger.asSignal();
this.onWebsocketSuccess = onWebsocketSuccessTrigger.asSignal(); onWebsocketSuccess = onWebsocketSuccessTrigger.asSignal();
} }
/** /**
Start pulling events. Blocking. Start pulling events. Blocking.
**/ **/
@:allow(kernel.Init) @:allow(kernel.Init)
private function startEventLoop() { private static function startEventLoop() {
while (!stopLoop) { while (!stopLoop) {
var event:Table<Int, Dynamic> = pullEvents(); var event:Table<Int, Dynamic> = pullEvents();
@ -148,7 +146,7 @@ class KernelEvents {
} }
} }
public function shutdown() { public static function shutdown() {
// clearing screens // clearing screens
for (screen in Peripheral.instance.getAllScreens()) { for (screen in Peripheral.instance.getAllScreens()) {
@ -156,37 +154,37 @@ class KernelEvents {
} }
Log.info('Shutting down event loop'); Log.info('Shutting down event loop');
this.stopLoop = true; stopLoop = true;
MainTerm.instance.reset(); MainTerm.instance.reset();
Init.mainEvent.stop(); Init.mainEvent.stop();
} }
private function pullEvents():Table<Int, Dynamic> { private static function pullEvents():Table<Int, Dynamic> {
return cast TableTools.pack(Coroutine.yield(null)); return cast TableTools.pack(Coroutine.yield(null));
} }
private function fireSignal(eventName: String,event:Table<Int, Dynamic> ) { private static function fireSignal(eventName: String,event:Table<Int, Dynamic> ) {
switch eventName { switch eventName {
case "alarm": case "alarm":
this.onAlarmTrigger.trigger(event[2]); onAlarmTrigger.trigger(event[2]);
case "char": case "char":
this.onCharTrigger.trigger(event[2]); onCharTrigger.trigger(event[2]);
case "disk": case "disk":
this.onDiskTrigger.trigger(event[2]); onDiskTrigger.trigger(event[2]);
case "disk_eject": case "disk_eject":
this.onDiskEjectTrigger.trigger(event[2]); onDiskEjectTrigger.trigger(event[2]);
case "http_check": case "http_check":
this.onHttpCheckTrigger.trigger({url: event[2], success: event[3], failReason: event[4]}); onHttpCheckTrigger.trigger({url: event[2], success: event[3], failReason: event[4]});
case "http_failure": case "http_failure":
this.onHttpFailureTrigger.trigger({url: event[2], failReason: event[3], handle: event[4]}); onHttpFailureTrigger.trigger({url: event[2], failReason: event[3], handle: event[4]});
case "http_success": case "http_success":
this.onHttpSuccessTrigger.trigger({url: event[2], handle: event[3]}); onHttpSuccessTrigger.trigger({url: event[2], handle: event[3]});
case "key": case "key":
this.onKeyTrigger.trigger({keyCode: event[2], isHeld: event[3]}); onKeyTrigger.trigger({keyCode: event[2], isHeld: event[3]});
case "key_up": case "key_up":
this.onKeyUpTrigger.trigger(event[2]); onKeyUpTrigger.trigger(event[2]);
case "modem_message": case "modem_message":
this.onModemMessageTrigger.trigger({ onModemMessageTrigger.trigger({
addr: event[2], addr: event[2],
channel: event[3], channel: event[3],
replyChannel: event[4], replyChannel: event[4],
@ -194,45 +192,45 @@ class KernelEvents {
distance: event[6] distance: event[6]
}); });
case "monitor_resize": case "monitor_resize":
this.onMonitorResizeTrigger.trigger(event[2]); onMonitorResizeTrigger.trigger(event[2]);
case "monitor_touch": case "monitor_touch":
this.onMonitorTouchTrigger.trigger({addr: event[2], pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}}); onMonitorTouchTrigger.trigger({addr: event[2], pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}});
case "mouse_click": case "mouse_click":
this.onMouseClickTrigger.trigger({button: ccButtonToEnum(event[2]), pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}}); onMouseClickTrigger.trigger({button: ccButtonToEnum(event[2]), pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}});
case "mouse_drag": case "mouse_drag":
this.onMouseDragTrigger.trigger({button: ccButtonToEnum(event[2]), pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}}); onMouseDragTrigger.trigger({button: ccButtonToEnum(event[2]), pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}});
case "mouse_scroll": case "mouse_scroll":
this.onMouseScrollTrigger.trigger({dir: event[2], pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}}); onMouseScrollTrigger.trigger({dir: event[2], pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}});
case "mouse_up": case "mouse_up":
this.onMouseUpTrigger.trigger({button: ccButtonToEnum(event[2]), pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}}); onMouseUpTrigger.trigger({button: ccButtonToEnum(event[2]), pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}});
case "paste": case "paste":
this.onPasteTrigger.trigger(event[2]); onPasteTrigger.trigger(event[2]);
case "peripheral": case "peripheral":
this.onPeripheralTrigger.trigger(event[2]); onPeripheralTrigger.trigger(event[2]);
case "peripheral_detach": case "peripheral_detach":
this.onPeripheralDetachTrigger.trigger(event[2]); onPeripheralDetachTrigger.trigger(event[2]);
case "redstone": case "redstone":
this.onRedstoneTrigger.trigger(null); onRedstoneTrigger.trigger(null);
case "speaker_audio_empty": case "speaker_audio_empty":
this.onSpeakerAudioEmptyTrigger.trigger(event[2]); onSpeakerAudioEmptyTrigger.trigger(event[2]);
case "task_complete": case "task_complete":
this.onTaskCompleteTrigger.trigger({id: event[2], success: event[3], failedReason: event[4]}); onTaskCompleteTrigger.trigger({id: event[2], success: event[3], failedReason: event[4]});
case "term_resize": case "term_resize":
this.onTermResizeTrigger.trigger(null); onTermResizeTrigger.trigger(null);
case "terminate": case "terminate":
this.onTerminateTrigger.trigger(null); onTerminateTrigger.trigger(null);
case "timer": case "timer":
this.onTimerTrigger.trigger(event[2]); onTimerTrigger.trigger(event[2]);
case "turtle_inventory": case "turtle_inventory":
this.onTurtleInventoryTrigger.trigger(null); onTurtleInventoryTrigger.trigger(null);
case "websocket_closed": case "websocket_closed":
this.onWebsocketCloseTrigger.trigger(event[2]); onWebsocketCloseTrigger.trigger(event[2]);
case "websocket_failure": case "websocket_failure":
this.onWebsocketFailureTrigger.trigger({url: event[2], failReason: event[3]}); onWebsocketFailureTrigger.trigger({url: event[2], failReason: event[3]});
case "websocket_message": case "websocket_message":
this.onWebsocketMessageTrigger.trigger({url: event[2], message: event[3], isBinary: event[4]}); onWebsocketMessageTrigger.trigger({url: event[2], message: event[3], isBinary: event[4]});
case "websocket_success": case "websocket_success":
this.onWebsocketSuccessTrigger.trigger({url: event[2], handle: event[3]}); onWebsocketSuccessTrigger.trigger({url: event[2], handle: event[3]});
case "endofloop": case "endofloop":
EndOfLoop.run(); EndOfLoop.run();
default: default:
@ -254,7 +252,7 @@ class KernelEvents {
} }
@:allow(lib.Debug) @:allow(lib.Debug)
private function printListenerCount() { private static function printListenerCount() {
if (onAlarmTrigger.getLength() > 0) Log.debug("onAlarm: " + onAlarmTrigger.getLength()); if (onAlarmTrigger.getLength() > 0) Log.debug("onAlarm: " + onAlarmTrigger.getLength());
if (onCharTrigger.getLength() > 0) Log.debug("onChar: " + onCharTrigger.getLength()); if (onCharTrigger.getLength() > 0) Log.debug("onChar: " + onCharTrigger.getLength());
if (onDiskTrigger.getLength() > 0) Log.debug("onDisk: " + onDiskTrigger.getLength()); if (onDiskTrigger.getLength() > 0) Log.debug("onDisk: " + onDiskTrigger.getLength());

View File

@ -26,7 +26,7 @@ class MainTerm implements TermWriteable {
this.onResizeTrigger = Signal.trigger(); this.onResizeTrigger = Signal.trigger();
this.onResize = this.onResizeTrigger.asSignal(); this.onResize = this.onResizeTrigger.asSignal();
KernelEvents.instance.onTermResize.handle(_ -> { KernelEvents.onTermResize.handle(_ -> {
onResizeTrigger.trigger(getSize()); onResizeTrigger.trigger(getSize());
}); });
} }

View File

@ -19,7 +19,7 @@ class Timer {
timerID = OS.startTimer(timeout); timerID = OS.startTimer(timeout);
this.callback = callback; this.callback = callback;
timerLink = KernelEvents.instance.onTimer.handle(timerID -> { timerLink = KernelEvents.onTimer.handle(timerID -> {
if (this.timerID == timerID) { if (this.timerID == timerID) {
callback.invoke(null); callback.invoke(null);
timerLink.cancel(); timerLink.cancel();

View File

@ -8,13 +8,13 @@ using tink.CoreApi;
class Http { class Http {
public static function request(url:String,?body:String,?options: String):Future<Outcome<HTTPResponse,HTTPFailure>> { public static function request(url:String,?body:String,?options: String):Future<Outcome<HTTPResponse,HTTPFailure>> {
return new Future<Outcome<HTTPResponse,HTTPFailure>>((resolve) -> { return new Future<Outcome<HTTPResponse,HTTPFailure>>((resolve) -> {
KernelEvents.instance.onHttpFailure.handle((params)->{ KernelEvents.onHttpFailure.handle((params)->{
if (params.url == url){ if (params.url == url){
resolve(Failure(new HTTPFailure(params.failReason,params.handle))); resolve(Failure(new HTTPFailure(params.failReason,params.handle)));
} }
}); });
KernelEvents.instance.onHttpSuccess.handle((params) -> { KernelEvents.onHttpSuccess.handle((params) -> {
if (params.url == url){ if (params.url == url){
resolve(Success(new HTTPResponse(params.handle))); resolve(Success(new HTTPResponse(params.handle)));
} }

View File

@ -22,13 +22,13 @@ class Drive implements IPeripheral {
this.onDiskInsert = this.onDiskInsertTrigger.asSignal(); this.onDiskInsert = this.onDiskInsertTrigger.asSignal();
this.onDiskEject = this.onDiskEjectTrigger.asSignal(); this.onDiskEject = this.onDiskEjectTrigger.asSignal();
KernelEvents.instance.onDisk.handle((addr) ->{ KernelEvents.onDisk.handle((addr) ->{
if (addr == this.addr){ if (addr == this.addr){
this.onDiskInsertTrigger.trigger(null); this.onDiskInsertTrigger.trigger(null);
} }
}); });
KernelEvents.instance.onDiskEject.handle((addr)->{ KernelEvents.onDiskEject.handle((addr)->{
if (addr == this.addr){ if (addr == this.addr){
this.onDiskEjectTrigger.trigger(null); this.onDiskEjectTrigger.trigger(null);
} }

View File

@ -22,7 +22,7 @@ class Modem implements INetworkInterface implements IPeripheral {
this.native = Peripheral.wrap(addr); this.native = Peripheral.wrap(addr);
this.addr = addr; this.addr = addr;
KernelEvents.instance.onModemMessage.handle(params ->{ KernelEvents.onModemMessage.handle(params ->{
try{ try{
if (params.addr == this.addr){ if (params.addr == this.addr){
var pack:GenericPackage = { var pack:GenericPackage = {

View File

@ -63,7 +63,7 @@ class Redstone implements IPeripheral implements IExportable {
updateState(); updateState();
KernelEvents.instance.onRedstone.handle(()->{ KernelEvents.onRedstone.handle(()->{
if ((this.getAnalogInput() != this.analogInputState) || (this.bundleInputState != this.getBundledInput())){ if ((this.getAnalogInput() != this.analogInputState) || (this.bundleInputState != this.getBundledInput())){
updateState(); updateState();
this.onChangeTrigger.trigger(null); this.onChangeTrigger.trigger(null);

View File

@ -26,7 +26,7 @@ class Screen implements TermWriteable implements IPeripheral {
this.nativ = Peripheral.wrap(addr); this.nativ = Peripheral.wrap(addr);
this.addr = addr; this.addr = addr;
KernelEvents.instance.onMonitorResize.handle(addr -> { KernelEvents.onMonitorResize.handle(addr -> {
if (addr == this.addr) { if (addr == this.addr) {
onResizeTrigger.trigger(getSize()); onResizeTrigger.trigger(getSize());
} }

View File

@ -20,7 +20,7 @@ class WindowManager {
@:allow(kernel.Init) @:allow(kernel.Init)
private function new() { private function new() {
KernelEvents.instance.onKey.handle(params -> { KernelEvents.onKey.handle(params -> {
if (currentMainContext != null) { if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){ if (currentMainContext.eventDelegate != null){
var foo = currentMainContext.eventDelegate.getEventHandlers(); var foo = currentMainContext.eventDelegate.getEventHandlers();
@ -31,7 +31,7 @@ class WindowManager {
} }
}); });
KernelEvents.instance.onKeyUp.handle(keyCode -> { KernelEvents.onKeyUp.handle(keyCode -> {
if (currentMainContext != null) { if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){ if (currentMainContext.eventDelegate != null){
var foo = currentMainContext.eventDelegate.getEventHandlers(); var foo = currentMainContext.eventDelegate.getEventHandlers();
@ -42,7 +42,7 @@ class WindowManager {
} }
}); });
KernelEvents.instance.onMouseClick.handle(params -> { KernelEvents.onMouseClick.handle(params -> {
if (currentMainContext != null) { if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){ if (currentMainContext.eventDelegate != null){
var foo = currentMainContext.eventDelegate.getEventHandlers(); var foo = currentMainContext.eventDelegate.getEventHandlers();
@ -53,7 +53,7 @@ class WindowManager {
} }
}); });
KernelEvents.instance.onMouseDrag.handle(params -> { KernelEvents.onMouseDrag.handle(params -> {
if (currentMainContext != null) { if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){ if (currentMainContext.eventDelegate != null){
var foo = currentMainContext.eventDelegate.getEventHandlers(); var foo = currentMainContext.eventDelegate.getEventHandlers();
@ -64,7 +64,7 @@ class WindowManager {
} }
}); });
KernelEvents.instance.onMouseScroll.handle(params -> { KernelEvents.onMouseScroll.handle(params -> {
if (currentMainContext != null) { if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){ if (currentMainContext.eventDelegate != null){
var foo = currentMainContext.eventDelegate.getEventHandlers(); var foo = currentMainContext.eventDelegate.getEventHandlers();
@ -75,7 +75,7 @@ class WindowManager {
} }
}); });
KernelEvents.instance.onMouseUp.handle(params -> { KernelEvents.onMouseUp.handle(params -> {
if (currentMainContext != null) { if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){ if (currentMainContext.eventDelegate != null){
var foo = currentMainContext.eventDelegate.getEventHandlers(); var foo = currentMainContext.eventDelegate.getEventHandlers();
@ -86,7 +86,7 @@ class WindowManager {
} }
}); });
KernelEvents.instance.onPaste.handle(text -> { KernelEvents.onPaste.handle(text -> {
if (currentMainContext != null) { if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){ if (currentMainContext.eventDelegate != null){
var foo = currentMainContext.eventDelegate.getEventHandlers(); var foo = currentMainContext.eventDelegate.getEventHandlers();
@ -97,11 +97,11 @@ class WindowManager {
} }
}); });
KernelEvents.instance.onMonitorTouch.handle(params -> { KernelEvents.onMonitorTouch.handle(params -> {
// TODO // TODO
}); });
KernelEvents.instance.onChar.handle(char -> { KernelEvents.onChar.handle(char -> {
if (currentMainContext != null) { if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){ if (currentMainContext.eventDelegate != null){
var foo = currentMainContext.eventDelegate.getEventHandlers(); var foo = currentMainContext.eventDelegate.getEventHandlers();

View File

@ -39,7 +39,7 @@ class Debug {
#if Debug #if Debug
public static function printKernelEventsCount(){ public static function printKernelEventsCount(){
KernelEvents.instance.printListenerCount(); KernelEvents.printListenerCount();
} }
#end #end

View File

@ -54,7 +54,7 @@ class HomeContext {
requestRender(); requestRender();
// Register global key bindings to react to main terminal // Register global key bindings to react to main terminal
KernelEvents.instance.onKey.handle(e -> { KernelEvents.onKey.handle(e -> {
// Is HOME pressed? // Is HOME pressed?
// TODO: remove magic number // TODO: remove magic number
if (e.keyCode == 268) { if (e.keyCode == 268) {
@ -165,7 +165,7 @@ class HomeContext {
} }
children.push(new TextElement('Output: ${selectedOutput}',{ uiEvents:{ onClick: this.cycleOutput}})); children.push(new TextElement('Output: ${selectedOutput}',{ uiEvents:{ onClick: this.cycleOutput}}));
children.push(new TextElement('Exit', {style: {bgColor: Red}, uiEvents: {onClick: KernelEvents.instance.shutdown}})); children.push(new TextElement('Exit', {style: {bgColor: Red}, uiEvents: {onClick: KernelEvents.shutdown}}));
renderer.setChildren(children); renderer.setChildren(children);