From 386882e1c60acda8c46e6ae0b37293a35a1ed64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Thu, 31 Mar 2016 11:30:50 +0200 Subject: [PATCH] Rename SwitchLayerAction.ts to SwitchKeymapAction.ts and vice versa, so that these files contain their relevant classes. --- .../config-items/SwitchKeymapAction.ts | 94 ++++------------ .../config-items/SwitchLayerAction.ts | 102 ++++++++++++++---- 2 files changed, 98 insertions(+), 98 deletions(-) diff --git a/config-serializer/config-items/SwitchKeymapAction.ts b/config-serializer/config-items/SwitchKeymapAction.ts index 66f2e632..bce92189 100644 --- a/config-serializer/config-items/SwitchKeymapAction.ts +++ b/config-serializer/config-items/SwitchKeymapAction.ts @@ -1,99 +1,41 @@ -function assertUInt8(target: any, key: string) { - let val = this[key]; - if (delete this[key]) { - Object.defineProperty(target, key, { - get: function () { - return val; - }, - set: function (newVal) { - if (newVal < 0 || newVal > 255) { - throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not uint8`; - } - val = newVal; - }, - enumerable: true, - configurable: true - }); - } -} +class SwitchKeymapAction extends KeyAction implements Serializable { -function assertEnum(enumerated: E) { - return function(target: any, key: string) { - let val = this[key]; - if (delete this[key]) { - Object.defineProperty(target, key, { - get: function () { - return val; - }, - set: function (newVal) { - if (enumerated[newVal] === undefined) { - throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not enum`; - } - val = newVal; - }, - enumerable: true, - configurable: true - }); - } - } -} + static keyActionTypeString = 'switchKeymap'; -enum Layer { - mod, - fn, - mouse -} + private _keymapId: number; -class SwitchLayerAction extends KeyAction implements Serializable { - - static keyActionTypeString = 'switchLayer'; - static toggleFlag = 0x80; - - isLayerToggleable: boolean; - - @assertEnum(Layer) - private layer: Layer; -/* - get layer(): number { - return this._layer; + get keymapId(): number { + return this._keymapId; } - set layer(value) { + set keymapId(value) { if (!TypeChecker.isUInt8Valid(value)) { - throw 'Invalid SwitchLayerAction.layerId: ${value}'; + throw `Invalid SwitchKeymapAction.keymapId: ${value}`; } - this._layer = value; - } -*/ - getToggleFlag() { - return this.isLayerToggleable ? SwitchLayerAction.toggleFlag : 0; + this._keymapId = value; } - fromJsObject(jsObject: any): SwitchLayerAction { - this.assertKeyActionType(jsObject, SwitchLayerAction.keyActionTypeString, 'SwitchLayerAction'); - this.layer = jsObject.layerId; - this.isLayerToggleable = jsObject.toggle; + fromJsObject(jsObject: any): SwitchKeymapAction { + this.assertKeyActionType(jsObject, SwitchKeymapAction.keyActionTypeString, 'SwitchKeymapAction'); + this.keymapId = jsObject.keymapId; return this; } - fromBinary(buffer: UhkBuffer): SwitchLayerAction { - this.readAndAssertKeyActionId(buffer, KeyActionId.SwitchLayerAction, 'SwitchLayerAction'); - this.layer = buffer.readUInt8(); - this.isLayerToggleable = (this.layer & SwitchLayerAction.toggleFlag) !== 0; - this.layer &= ~SwitchLayerAction.toggleFlag; // Clear toggle bit. + fromBinary(buffer: UhkBuffer): SwitchKeymapAction { + this.readAndAssertKeyActionId(buffer, KeyActionId.SwitchKeymapAction, 'SwitchKeymapAction'); + this.keymapId = buffer.readUInt8(); return this; } toJsObject(): any { return { - keyActionType: SwitchLayerAction.keyActionTypeString, - layer: this.layer, - toggle: this.isLayerToggleable + keyActionType: SwitchKeymapAction.keyActionTypeString, + keymapId: this.keymapId }; } toBinary(buffer: UhkBuffer) { - buffer.writeUInt8(KeyActionId.SwitchLayerAction); - buffer.writeUInt8(this.layer | this.getToggleFlag()); + buffer.writeUInt8(KeyActionId.SwitchKeymapAction); + buffer.writeUInt8(this.keymapId); } } diff --git a/config-serializer/config-items/SwitchLayerAction.ts b/config-serializer/config-items/SwitchLayerAction.ts index bce92189..66f2e632 100644 --- a/config-serializer/config-items/SwitchLayerAction.ts +++ b/config-serializer/config-items/SwitchLayerAction.ts @@ -1,41 +1,99 @@ -class SwitchKeymapAction extends KeyAction implements Serializable { - - static keyActionTypeString = 'switchKeymap'; - - private _keymapId: number; - - get keymapId(): number { - return this._keymapId; +function assertUInt8(target: any, key: string) { + let val = this[key]; + if (delete this[key]) { + Object.defineProperty(target, key, { + get: function () { + return val; + }, + set: function (newVal) { + if (newVal < 0 || newVal > 255) { + throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not uint8`; + } + val = newVal; + }, + enumerable: true, + configurable: true + }); } +} - set keymapId(value) { - if (!TypeChecker.isUInt8Valid(value)) { - throw `Invalid SwitchKeymapAction.keymapId: ${value}`; +function assertEnum(enumerated: E) { + return function(target: any, key: string) { + let val = this[key]; + if (delete this[key]) { + Object.defineProperty(target, key, { + get: function () { + return val; + }, + set: function (newVal) { + if (enumerated[newVal] === undefined) { + throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not enum`; + } + val = newVal; + }, + enumerable: true, + configurable: true + }); } - this._keymapId = value; + } +} + +enum Layer { + mod, + fn, + mouse +} + +class SwitchLayerAction extends KeyAction implements Serializable { + + static keyActionTypeString = 'switchLayer'; + static toggleFlag = 0x80; + + isLayerToggleable: boolean; + + @assertEnum(Layer) + private layer: Layer; +/* + get layer(): number { + return this._layer; } - fromJsObject(jsObject: any): SwitchKeymapAction { - this.assertKeyActionType(jsObject, SwitchKeymapAction.keyActionTypeString, 'SwitchKeymapAction'); - this.keymapId = jsObject.keymapId; + set layer(value) { + if (!TypeChecker.isUInt8Valid(value)) { + throw 'Invalid SwitchLayerAction.layerId: ${value}'; + } + this._layer = value; + } +*/ + getToggleFlag() { + return this.isLayerToggleable ? SwitchLayerAction.toggleFlag : 0; + } + + fromJsObject(jsObject: any): SwitchLayerAction { + this.assertKeyActionType(jsObject, SwitchLayerAction.keyActionTypeString, 'SwitchLayerAction'); + this.layer = jsObject.layerId; + this.isLayerToggleable = jsObject.toggle; return this; } - fromBinary(buffer: UhkBuffer): SwitchKeymapAction { - this.readAndAssertKeyActionId(buffer, KeyActionId.SwitchKeymapAction, 'SwitchKeymapAction'); - this.keymapId = buffer.readUInt8(); + fromBinary(buffer: UhkBuffer): SwitchLayerAction { + this.readAndAssertKeyActionId(buffer, KeyActionId.SwitchLayerAction, 'SwitchLayerAction'); + this.layer = buffer.readUInt8(); + this.isLayerToggleable = (this.layer & SwitchLayerAction.toggleFlag) !== 0; + this.layer &= ~SwitchLayerAction.toggleFlag; // Clear toggle bit. return this; } toJsObject(): any { return { - keyActionType: SwitchKeymapAction.keyActionTypeString, - keymapId: this.keymapId + keyActionType: SwitchLayerAction.keyActionTypeString, + layer: this.layer, + toggle: this.isLayerToggleable }; } toBinary(buffer: UhkBuffer) { - buffer.writeUInt8(KeyActionId.SwitchKeymapAction); - buffer.writeUInt8(this.keymapId); + buffer.writeUInt8(KeyActionId.SwitchLayerAction); + buffer.writeUInt8(this.layer | this.getToggleFlag()); } }