diff --git a/src/kernel/Init.hx b/src/kernel/Init.hx index c72a407..8afc324 100644 --- a/src/kernel/Init.hx +++ b/src/kernel/Init.hx @@ -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(); diff --git a/src/kernel/KernelEvents.hx b/src/kernel/KernelEvents.hx index 40498f7..1051d50 100644 --- a/src/kernel/KernelEvents.hx +++ b/src/kernel/KernelEvents.hx @@ -18,124 +18,122 @@ class KernelEvents { /** Depends on: (Nothing) **/ - public static var instance:KernelEvents; - - public final onAlarm:Signal; - public final onChar:Signal; - public final onDisk:Signal; - public final onDiskEject:Signal; - 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; - public final onModemMessage:Signal<{ + public static var onAlarm(default, null):Signal; + public static var onChar(default, null):Signal; + public static var onDisk(default, null):Signal; + public static var onDiskEject(default, null):Signal; + 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; + public static var onModemMessage(default, null):Signal<{ addr:String, channel:Int, replyChannel:Int, message:Dynamic, distance:Null }>; - public final onMonitorResize:Signal; - 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; - public final onPeripheral:Signal; - public final onPeripheralDetach:Signal; - public final onRedstone:Signal; - public final onSpeakerAudioEmpty:Signal; - public final onTaskComplete:Signal<{id:Int, success:Bool, failedReason:String}>; - public final onTermResize:Signal; - public final onTerminate:Signal; - public final onTimer:Signal; - public final onTurtleInventory:Signal; - public final onWebsocketClose:Signal; - 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; + 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; + public static var onPeripheral(default, null):Signal; + public static var onPeripheralDetach(default, null):Signal; + public static var onRedstone(default, null):Signal; + public static var onSpeakerAudioEmpty(default, null):Signal; + public static var onTaskComplete(default, null):Signal<{id:Int, success:Bool, failedReason:String}>; + public static var onTermResize(default, null):Signal; + public static var onTerminate(default, null):Signal; + public static var onTimer(default, null):Signal; + public static var onTurtleInventory(default, null):Signal; + public static var onWebsocketClose(default, null):Signal; + 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 = Signal.trigger(); - private final onCharTrigger:SignalTrigger = Signal.trigger(); - private final onDiskTrigger:SignalTrigger = Signal.trigger(); - private final onDiskEjectTrigger:SignalTrigger = 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 = Signal.trigger(); - private final onModemMessageTrigger:SignalTrigger<{ + private static final onAlarmTrigger:SignalTrigger = Signal.trigger(); + private static final onCharTrigger:SignalTrigger = Signal.trigger(); + private static final onDiskTrigger:SignalTrigger = Signal.trigger(); + private static final onDiskEjectTrigger:SignalTrigger = 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 = Signal.trigger(); + private static final onModemMessageTrigger:SignalTrigger<{ addr:String, channel:Int, replyChannel:Int, message:Dynamic, distance:Null }> = Signal.trigger(); - private final onMonitorResizeTrigger:SignalTrigger = 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 = Signal.trigger(); - private final onPeripheralTrigger:SignalTrigger = Signal.trigger(); - private final onPeripheralDetachTrigger:SignalTrigger = Signal.trigger(); - private final onRednetMessageTrigger:SignalTrigger<{sender:Int, message:Any, protocol:Any}> = Signal.trigger(); - private final onRedstoneTrigger:SignalTrigger = Signal.trigger(); - private final onSpeakerAudioEmptyTrigger:SignalTrigger = Signal.trigger(); - private final onTaskCompleteTrigger:SignalTrigger<{id:Int, success:Bool, failedReason:String}> = Signal.trigger(); - private final onTermResizeTrigger:SignalTrigger = Signal.trigger(); - private final onTerminateTrigger:SignalTrigger = Signal.trigger(); - private final onTimerTrigger:SignalTrigger = Signal.trigger(); - private final onTurtleInventoryTrigger:SignalTrigger = Signal.trigger(); - private final onWebsocketCloseTrigger:SignalTrigger = 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 = 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 = Signal.trigger(); + private static final onPeripheralTrigger:SignalTrigger = Signal.trigger(); + private static final onPeripheralDetachTrigger:SignalTrigger = Signal.trigger(); + private static final onRednetMessageTrigger:SignalTrigger<{sender:Int, message:Any, protocol:Any}> = Signal.trigger(); + private static final onRedstoneTrigger:SignalTrigger = Signal.trigger(); + private static final onSpeakerAudioEmptyTrigger:SignalTrigger = Signal.trigger(); + private static final onTaskCompleteTrigger:SignalTrigger<{id:Int, success:Bool, failedReason:String}> = Signal.trigger(); + private static final onTermResizeTrigger:SignalTrigger = Signal.trigger(); + private static final onTerminateTrigger:SignalTrigger = Signal.trigger(); + private static final onTimerTrigger:SignalTrigger = Signal.trigger(); + private static final onTurtleInventoryTrigger:SignalTrigger = Signal.trigger(); + private static final onWebsocketCloseTrigger:SignalTrigger = 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 = 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 { + private static function pullEvents():Table { return cast TableTools.pack(Coroutine.yield(null)); } - private function fireSignal(eventName: String,event:Table ) { + private static function fireSignal(eventName: String,event:Table ) { 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()); diff --git a/src/kernel/MainTerm.hx b/src/kernel/MainTerm.hx index 70282fd..1302161 100644 --- a/src/kernel/MainTerm.hx +++ b/src/kernel/MainTerm.hx @@ -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()); }); } diff --git a/src/kernel/Timer.hx b/src/kernel/Timer.hx index 4a36d58..c713b7d 100644 --- a/src/kernel/Timer.hx +++ b/src/kernel/Timer.hx @@ -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(); diff --git a/src/kernel/http/HTTPRequest.hx b/src/kernel/http/HTTPRequest.hx index 3b39b62..fe77c45 100644 --- a/src/kernel/http/HTTPRequest.hx +++ b/src/kernel/http/HTTPRequest.hx @@ -8,13 +8,13 @@ using tink.CoreApi; class Http { public static function request(url:String,?body:String,?options: String):Future> { return new Future>((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))); } diff --git a/src/kernel/peripherals/Drive.hx b/src/kernel/peripherals/Drive.hx index 5af591a..06f4c65 100644 --- a/src/kernel/peripherals/Drive.hx +++ b/src/kernel/peripherals/Drive.hx @@ -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); } diff --git a/src/kernel/peripherals/Modem.hx b/src/kernel/peripherals/Modem.hx index e53d046..61a6cf2 100644 --- a/src/kernel/peripherals/Modem.hx +++ b/src/kernel/peripherals/Modem.hx @@ -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 = { diff --git a/src/kernel/peripherals/Redstone.hx b/src/kernel/peripherals/Redstone.hx index 7b56b7c..23395f9 100644 --- a/src/kernel/peripherals/Redstone.hx +++ b/src/kernel/peripherals/Redstone.hx @@ -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); diff --git a/src/kernel/peripherals/Screen.hx b/src/kernel/peripherals/Screen.hx index db33221..8ce8173 100644 --- a/src/kernel/peripherals/Screen.hx +++ b/src/kernel/peripherals/Screen.hx @@ -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()); } diff --git a/src/kernel/ui/WindowManager.hx b/src/kernel/ui/WindowManager.hx index f78a9ac..fdeeb34 100644 --- a/src/kernel/ui/WindowManager.hx +++ b/src/kernel/ui/WindowManager.hx @@ -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(); diff --git a/src/lib/Debug.hx b/src/lib/Debug.hx index eb97cb8..aa3c39f 100644 --- a/src/lib/Debug.hx +++ b/src/lib/Debug.hx @@ -39,7 +39,7 @@ class Debug { #if Debug public static function printKernelEventsCount(){ - KernelEvents.instance.printListenerCount(); + KernelEvents.printListenerCount(); } #end diff --git a/src/lib/HomeContext.hx b/src/lib/HomeContext.hx index 77953ec..c5d8f52 100644 --- a/src/lib/HomeContext.hx +++ b/src/lib/HomeContext.hx @@ -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);