diff --git a/src/kernel/KernelEvents.hx b/src/kernel/KernelEvents.hx index 4bd6c17..b6d7ced 100644 --- a/src/kernel/KernelEvents.hx +++ b/src/kernel/KernelEvents.hx @@ -138,78 +138,82 @@ class KernelEvents { var eventName:String = event[1]; - switch eventName { - case "alarm": - this.onAlarmTrigger.trigger(event[2]); - case "char": - this.onCharTrigger.trigger(event[2]); - case "disk": - this.onDiskTrigger.trigger(event[2]); - case "disk_eject": - this.onDiskEjectTrigger.trigger(event[2]); - case "http_check": - this.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]}); - case "http_success": - this.onHttpSuccessTrigger.trigger({url: event[2], handle: event[3]}); - case "key": - this.onKeyTrigger.trigger({keyCode: event[2], isHeld: event[3]}); - case "key_up": - this.onKeyUpTrigger.trigger(event[2]); - case "modem_message": - this.onModemMessageTrigger.trigger({ - addr: event[2], - channel: event[3], - replyChannel: event[4], - message: event[5], - distance: event[6] - }); - case "monitor_resize": - this.onMonitorResizeTrigger.trigger(event[2]); - case "monitor_touch": - this.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}}); - case "mouse_drag": - this.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}}); - case "mouse_up": - this.onMouseUpTrigger.trigger({button: ccButtonToEnum(event[2]), pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}}); - case "paste": - this.onPasteTrigger.trigger(event[2]); - case "peripheral": - this.onPeripheralTrigger.trigger(event[2]); - case "peripheral_detach": - this.onPeripheralDetachTrigger.trigger(event[2]); - case "rednet_message": - this.onRednetMessageTrigger.trigger({sender: event[2], message: event[3], protocol: event[4]}); - case "redstone": - this.onRedstoneTrigger.trigger(null); - case "speaker_audio_empty": - this.onSpeakerAudioEmptyTrigger.trigger(event[2]); - case "task_complete": - this.onTaskCompleteTrigger.trigger({id: event[2], success: event[3], failedReason: event[4]}); - case "term_resize": - this.onTermResizeTrigger.trigger(null); - case "terminate": - this.onTerminateTrigger.trigger(null); - case "timer": - this.onTimerTrigger.trigger(event[2]); - case "turtle_inventory": - this.onTurtleInventoryTrigger.trigger(null); - case "websocket_closed": - this.onWebsocketCloseTrigger.trigger(event[2]); - case "websocket_failure": - this.onWebsocketFailureTrigger.trigger({url: event[2], failReason: event[3]}); - case "websocket_message": - this.onWebsocketMessageTrigger.trigger({url: event[2], message: event[3], isBinary: event[4]}); - case "websocket_success": - this.onWebsocketSuccessTrigger.trigger({url: event[2], handle: event[3]}); - default: - Log.error("Unknown cc event: " + eventName); - } + fireSignal(eventName,event); + } + } + + private function fireSignal(eventName: String,event:Table ) { + switch eventName { + case "alarm": + this.onAlarmTrigger.trigger(event[2]); + case "char": + this.onCharTrigger.trigger(event[2]); + case "disk": + this.onDiskTrigger.trigger(event[2]); + case "disk_eject": + this.onDiskEjectTrigger.trigger(event[2]); + case "http_check": + this.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]}); + case "http_success": + this.onHttpSuccessTrigger.trigger({url: event[2], handle: event[3]}); + case "key": + this.onKeyTrigger.trigger({keyCode: event[2], isHeld: event[3]}); + case "key_up": + this.onKeyUpTrigger.trigger(event[2]); + case "modem_message": + this.onModemMessageTrigger.trigger({ + addr: event[2], + channel: event[3], + replyChannel: event[4], + message: event[5], + distance: event[6] + }); + case "monitor_resize": + this.onMonitorResizeTrigger.trigger(event[2]); + case "monitor_touch": + this.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}}); + case "mouse_drag": + this.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}}); + case "mouse_up": + this.onMouseUpTrigger.trigger({button: ccButtonToEnum(event[2]), pos: {x: (event[3] : Int) - 1, y: (event[4] : Int) - 1}}); + case "paste": + this.onPasteTrigger.trigger(event[2]); + case "peripheral": + this.onPeripheralTrigger.trigger(event[2]); + case "peripheral_detach": + this.onPeripheralDetachTrigger.trigger(event[2]); + case "rednet_message": + this.onRednetMessageTrigger.trigger({sender: event[2], message: event[3], protocol: event[4]}); + case "redstone": + this.onRedstoneTrigger.trigger(null); + case "speaker_audio_empty": + this.onSpeakerAudioEmptyTrigger.trigger(event[2]); + case "task_complete": + this.onTaskCompleteTrigger.trigger({id: event[2], success: event[3], failedReason: event[4]}); + case "term_resize": + this.onTermResizeTrigger.trigger(null); + case "terminate": + this.onTerminateTrigger.trigger(null); + case "timer": + this.onTimerTrigger.trigger(event[2]); + case "turtle_inventory": + this.onTurtleInventoryTrigger.trigger(null); + case "websocket_closed": + this.onWebsocketCloseTrigger.trigger(event[2]); + case "websocket_failure": + this.onWebsocketFailureTrigger.trigger({url: event[2], failReason: event[3]}); + case "websocket_message": + this.onWebsocketMessageTrigger.trigger({url: event[2], message: event[3], isBinary: event[4]}); + case "websocket_success": + this.onWebsocketSuccessTrigger.trigger({url: event[2], handle: event[3]}); + default: + Log.error("Unknown cc event: " + eventName); } }