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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@ class WindowManager {
@:allow(kernel.Init)
private function new() {
KernelEvents.instance.onKey.handle(params -> {
KernelEvents.onKey.handle(params -> {
if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){
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.eventDelegate != null){
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.eventDelegate != null){
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.eventDelegate != null){
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.eventDelegate != null){
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.eventDelegate != null){
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.eventDelegate != null){
var foo = currentMainContext.eventDelegate.getEventHandlers();
@ -97,11 +97,11 @@ class WindowManager {
}
});
KernelEvents.instance.onMonitorTouch.handle(params -> {
KernelEvents.onMonitorTouch.handle(params -> {
// TODO
});
KernelEvents.instance.onChar.handle(char -> {
KernelEvents.onChar.handle(char -> {
if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){
var foo = currentMainContext.eventDelegate.getEventHandlers();

View File

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

View File

@ -54,7 +54,7 @@ class HomeContext {
requestRender();
// Register global key bindings to react to main terminal
KernelEvents.instance.onKey.handle(e -> {
KernelEvents.onKey.handle(e -> {
// Is HOME pressed?
// TODO: remove magic number
if (e.keyCode == 268) {
@ -165,7 +165,7 @@ class HomeContext {
}
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);