From ee1d8ec59e0cdca1b15941fc973e3834cbee9107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Farkas=20J=C3=B3zsef?= Date: Sat, 24 Sep 2016 22:12:46 +0200 Subject: [PATCH] cleanup: Remove unused ClassArray classes --- src/config-serializer/ClassArray.ts | 54 ------------ src/config-serializer/README.md | 2 - src/config-serializer/config-items/Keymaps.ts | 15 ---- src/config-serializer/config-items/Layers.ts | 23 ----- src/config-serializer/config-items/Macros.ts | 15 ---- .../config-items/ModuleConfigurations.ts | 15 ---- src/config-serializer/config-items/Modules.ts | 23 ----- .../config-items/key-action/KeyActions.ts | 84 ------------------ .../config-items/key-action/index.ts | 1 - .../config-items/macro-action/MacroActions.ts | 87 ------------------- .../config-items/macro-action/index.ts | 1 - 11 files changed, 320 deletions(-) delete mode 100644 src/config-serializer/ClassArray.ts delete mode 100644 src/config-serializer/config-items/Keymaps.ts delete mode 100644 src/config-serializer/config-items/Layers.ts delete mode 100644 src/config-serializer/config-items/Macros.ts delete mode 100644 src/config-serializer/config-items/ModuleConfigurations.ts delete mode 100644 src/config-serializer/config-items/Modules.ts delete mode 100644 src/config-serializer/config-items/key-action/KeyActions.ts delete mode 100644 src/config-serializer/config-items/macro-action/MacroActions.ts diff --git a/src/config-serializer/ClassArray.ts b/src/config-serializer/ClassArray.ts deleted file mode 100644 index 354bff48..00000000 --- a/src/config-serializer/ClassArray.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Serializable } from './Serializable'; -import { UhkBuffer } from './UhkBuffer'; - -export abstract class ClassArray> extends Serializable> { - - elements: T[] = []; - - _fromJsObject(jsObjects: any): ClassArray { - for (let jsObject of jsObjects) { - this.elements.push(this.jsObjectToClass(jsObject)); - } - return this; - } - - _fromBinary(buffer: UhkBuffer): ClassArray { - let arrayLength = buffer.readCompactLength(); - - if (buffer.enableDump) { - buffer.enableDump = false; - } - - for (let i = 0; i < arrayLength; i++) { - this.elements.push(this.binaryToClass(buffer)); - } - return this; - } - - _toJsObject(): any { - let array: any[] = []; - for (let element of this.elements) { - array.push(element.toJsObject()); - } - return array; - } - - _toBinary(buffer: UhkBuffer) { - buffer.writeCompactLength(this.elements.length); - - if (buffer.enableDump) { - buffer.enableDump = false; - } - - for (let element of this.elements) { - element.toBinary(buffer); - } - } - - toString(): string { - return `<${this.constructor.name} length="${this.elements.length}">`; - } - - abstract jsObjectToClass(jsObject: any): T; - abstract binaryToClass(buffer: UhkBuffer): T; -} diff --git a/src/config-serializer/README.md b/src/config-serializer/README.md index a405a48e..fd375140 100644 --- a/src/config-serializer/README.md +++ b/src/config-serializer/README.md @@ -26,8 +26,6 @@ Each configuration item belongs to a specific type. The following types are avai **Compound types** are composed of primitive types, and/or compound types. All compound types must descend from the [Serializable](Serializable.ts) class, and saved into the [config-items](config-items) directory. -**Array type** is a special compound type which is composed of a sequence of items of a specific type. Array items must descend from the [ClassArray](ClassArray.ts) class. - ## Dumping serialization The serialization of configuration items is a complicated business, and many things can go wrong. That's the exact reason why serialization can be dumped to ease debugging. All you have to do is to set `Serializable.enableDump` to `true`, and you'll see something like the following upon serialization actions: diff --git a/src/config-serializer/config-items/Keymaps.ts b/src/config-serializer/config-items/Keymaps.ts deleted file mode 100644 index 4fddea44..00000000 --- a/src/config-serializer/config-items/Keymaps.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { ClassArray } from '../ClassArray'; -import { UhkBuffer } from '../UhkBuffer'; -import { Keymap } from './Keymap'; - -export class Keymaps extends ClassArray { - - jsObjectToClass(jsObject: any): Keymap { - return new Keymap().fromJsObject(jsObject); - } - - binaryToClass(buffer: UhkBuffer): Keymap { - return new Keymap().fromBinary(buffer); - } - -} diff --git a/src/config-serializer/config-items/Layers.ts b/src/config-serializer/config-items/Layers.ts deleted file mode 100644 index 24ec978c..00000000 --- a/src/config-serializer/config-items/Layers.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ClassArray } from '../ClassArray'; -import { UhkBuffer } from '../UhkBuffer'; -import { Layer } from './Layer'; - -export class Layers extends ClassArray { - - constructor(layers?: Layers) { - super(); - if (!layers) { - return; - } - layers.elements.forEach(layer => this.elements.push(new Layer(layer))); - } - - jsObjectToClass(jsObject: any): Layer { - return new Layer().fromJsObject(jsObject); - } - - binaryToClass(buffer: UhkBuffer): Layer { - return new Layer().fromBinary(buffer); - } - -} diff --git a/src/config-serializer/config-items/Macros.ts b/src/config-serializer/config-items/Macros.ts deleted file mode 100644 index e4baf036..00000000 --- a/src/config-serializer/config-items/Macros.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { ClassArray } from '../ClassArray'; -import { UhkBuffer } from '../UhkBuffer'; -import { Macro } from './Macro'; - -export class Macros extends ClassArray { - - jsObjectToClass(jsObject: any): Macro { - return new Macro().fromJsObject(jsObject); - } - - binaryToClass(buffer: UhkBuffer): Macro { - return new Macro().fromBinary(buffer); - } - -} diff --git a/src/config-serializer/config-items/ModuleConfigurations.ts b/src/config-serializer/config-items/ModuleConfigurations.ts deleted file mode 100644 index 8d49f1a6..00000000 --- a/src/config-serializer/config-items/ModuleConfigurations.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { ClassArray } from '../ClassArray'; -import { UhkBuffer } from '../UhkBuffer'; -import { ModuleConfiguration } from './ModuleConfiguration'; - -export class ModuleConfigurations extends ClassArray { - - jsObjectToClass(jsObject: any): ModuleConfiguration { - return new ModuleConfiguration().fromJsObject(jsObject); - } - - binaryToClass(buffer: UhkBuffer): ModuleConfiguration { - return new ModuleConfiguration().fromBinary(buffer); - } - -} diff --git a/src/config-serializer/config-items/Modules.ts b/src/config-serializer/config-items/Modules.ts deleted file mode 100644 index e19db206..00000000 --- a/src/config-serializer/config-items/Modules.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ClassArray } from '../ClassArray'; -import { UhkBuffer } from '../UhkBuffer'; -import { Module } from './Module'; - -export class Modules extends ClassArray { - - constructor(modules?: Modules) { - super(); - if (!modules) { - return; - } - modules.elements.forEach(module => this.elements.push(new Module(module))); - } - - jsObjectToClass(jsObject: any): Module { - return new Module().fromJsObject(jsObject); - } - - binaryToClass(buffer: UhkBuffer): Module { - return new Module().fromBinary(buffer); - } - -} diff --git a/src/config-serializer/config-items/key-action/KeyActions.ts b/src/config-serializer/config-items/key-action/KeyActions.ts deleted file mode 100644 index e11f4075..00000000 --- a/src/config-serializer/config-items/key-action/KeyActions.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { ClassArray } from '../../ClassArray'; -import { UhkBuffer } from '../../UhkBuffer'; -import { KeyAction, KeyActionId, keyActionType } from './KeyAction'; -import { KeystrokeAction } from './KeystrokeAction'; -import { MouseAction } from './MouseAction'; -import { NoneAction } from './NoneAction'; -import { PlayMacroAction } from './PlayMacroAction'; -import { SwitchKeymapAction } from './SwitchKeymapAction'; -import { SwitchLayerAction } from './SwitchLayerAction'; - -export class KeyActions extends ClassArray { - - constructor(other?: KeyActions) { - super(); - if (!other) { - return; - } - other.elements.forEach(keyAction => { - let newKeyAction: KeyAction; - if (keyAction instanceof KeystrokeAction) { - newKeyAction = new KeystrokeAction(keyAction); - } else if (keyAction instanceof SwitchLayerAction) { - newKeyAction = new SwitchLayerAction(keyAction); - } else if (keyAction instanceof SwitchKeymapAction) { - newKeyAction = new SwitchKeymapAction(keyAction); - } else if (keyAction instanceof MouseAction) { - newKeyAction = new MouseAction(keyAction); - } else if (keyAction instanceof PlayMacroAction) { - newKeyAction = new PlayMacroAction(keyAction); - } else { - newKeyAction = new NoneAction(); - } - this.elements.push(newKeyAction); - }); - } - - jsObjectToClass(jsObject: any): KeyAction { - switch (jsObject.keyActionType) { - case keyActionType.NoneAction: - return new NoneAction().fromJsObject(jsObject); - case keyActionType.KeystrokeAction: - return new KeystrokeAction().fromJsObject(jsObject); - case keyActionType.SwitchLayerAction: - return new SwitchLayerAction().fromJsObject(jsObject); - case keyActionType.SwitchKeymapAction: - return new SwitchKeymapAction().fromJsObject(jsObject); - case keyActionType.MouseAction: - return new MouseAction().fromJsObject(jsObject); - case keyActionType.PlayMacroAction: - return new PlayMacroAction().fromJsObject(jsObject); - default: - throw `Invalid KeyAction.keyActionType: "${jsObject.keyActionType}"`; - } - } - - binaryToClass(buffer: UhkBuffer): KeyAction { - let keyActionFirstByte = buffer.readUInt8(); - buffer.backtrack(); - - if (buffer.enableDump) { - process.stdout.write(']\n'); - buffer.enableDump = false; - } - - if (keyActionFirstByte >= KeyActionId.KeystrokeAction && keyActionFirstByte < KeyActionId.LastKeystrokeAction) { - return new KeystrokeAction().fromBinary(buffer); - } - - switch (keyActionFirstByte) { - case KeyActionId.NoneAction: - return new NoneAction().fromBinary(buffer); - case KeyActionId.SwitchLayerAction: - return new SwitchLayerAction().fromBinary(buffer); - case KeyActionId.SwitchKeymapAction: - return new SwitchKeymapAction().fromBinary(buffer); - case KeyActionId.MouseAction: - return new MouseAction().fromBinary(buffer); - case KeyActionId.PlayMacroAction: - return new PlayMacroAction().fromBinary(buffer); - default: - throw `Invalid KeyAction first byte: ${keyActionFirstByte}`; - } - } -} diff --git a/src/config-serializer/config-items/key-action/index.ts b/src/config-serializer/config-items/key-action/index.ts index c79a8104..4788014b 100644 --- a/src/config-serializer/config-items/key-action/index.ts +++ b/src/config-serializer/config-items/key-action/index.ts @@ -1,5 +1,4 @@ export * from './KeyAction'; -export * from './KeyActions'; export * from './KeystrokeAction'; export * from './MouseAction'; export * from './NoneAction'; diff --git a/src/config-serializer/config-items/macro-action/MacroActions.ts b/src/config-serializer/config-items/macro-action/MacroActions.ts deleted file mode 100644 index 981b9af9..00000000 --- a/src/config-serializer/config-items/macro-action/MacroActions.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { ClassArray } from '../../ClassArray'; -import { UhkBuffer } from '../../UhkBuffer'; -import { DelayMacroAction } from './DelayMacroAction'; -import { KeyMacroAction } from './KeyMacroAction'; -import { MacroAction, MacroActionId, macroActionType } from './MacroAction'; -import { MouseButtonMacroAction } from './MouseButtonMacroAction'; -import { MoveMouseMacroAction } from './MoveMouseMacroAction'; -import { ScrollMouseMacroAction } from './ScrollMouseMacroAction'; -import { TextMacroAction } from './TextMacroAction'; - -export class MacroActions extends ClassArray { - - constructor(other?: MacroActions) { - super(); - if (!other) { - return; - } - other.elements.forEach(macroAction => { - let newMacroAction: MacroAction; - if (macroAction instanceof KeyMacroAction) { - newMacroAction = new KeyMacroAction(macroAction); - } else if (macroAction instanceof MouseButtonMacroAction) { - newMacroAction = new MouseButtonMacroAction(macroAction); - } else if (macroAction instanceof MoveMouseMacroAction) { - newMacroAction = new MoveMouseMacroAction(macroAction); - } else if (macroAction instanceof ScrollMouseMacroAction) { - newMacroAction = new ScrollMouseMacroAction(macroAction); - } else if (macroAction instanceof DelayMacroAction) { - newMacroAction = new DelayMacroAction(macroAction); - } else if (macroAction instanceof TextMacroAction) { - newMacroAction = new TextMacroAction(macroAction); - } - - this.elements.push(newMacroAction); - }); - } - - jsObjectToClass(jsObject: any): MacroAction { - switch (jsObject.macroActionType) { - case macroActionType.KeyMacroAction: - return new KeyMacroAction().fromJsObject(jsObject); - case macroActionType.MouseButtonMacroAction: - return new MouseButtonMacroAction().fromJsObject(jsObject); - case macroActionType.MoveMouseMacroAction: - return new MoveMouseMacroAction().fromJsObject(jsObject); - case macroActionType.ScrollMouseMacroAction: - return new ScrollMouseMacroAction().fromJsObject(jsObject); - case macroActionType.DelayMacroAction: - return new DelayMacroAction().fromJsObject(jsObject); - case macroActionType.TextMacroAction: - return new TextMacroAction().fromJsObject(jsObject); - default: - throw `Invalid MacroAction.macroActionType: "${jsObject.macroActionType}"`; - } - } - - binaryToClass(buffer: UhkBuffer): MacroAction { - let macroActionFirstByte = buffer.readUInt8(); - buffer.backtrack(); - - if (buffer.enableDump) { - process.stdout.write(']\n'); - buffer.enableDump = false; - } - - if (macroActionFirstByte >= MacroActionId.KeyMacroAction && macroActionFirstByte <= MacroActionId.LastKeyMacroAction) { - return new KeyMacroAction().fromBinary(buffer); - } else if ( - macroActionFirstByte >= MacroActionId.MouseButtonMacroAction && - macroActionFirstByte <= MacroActionId.LastMouseButtonMacroAction - ) { - return new MouseButtonMacroAction().fromBinary(buffer); - } - switch (macroActionFirstByte) { - case MacroActionId.MoveMouseMacroAction: - return new MoveMouseMacroAction().fromBinary(buffer); - case MacroActionId.ScrollMouseMacroAction: - return new ScrollMouseMacroAction().fromBinary(buffer); - case MacroActionId.DelayMacroAction: - return new DelayMacroAction().fromBinary(buffer); - case MacroActionId.TextMacroAction: - return new TextMacroAction().fromBinary(buffer); - default: - throw `Invalid MacroAction first byte: ${macroActionFirstByte}`; - } - } -} diff --git a/src/config-serializer/config-items/macro-action/index.ts b/src/config-serializer/config-items/macro-action/index.ts index d8d454a6..464ae627 100644 --- a/src/config-serializer/config-items/macro-action/index.ts +++ b/src/config-serializer/config-items/macro-action/index.ts @@ -2,7 +2,6 @@ export * from './DelayMacroAction'; export * from './EditableMacroAction'; export * from './KeyMacroAction'; export * from './MacroAction'; -export * from './MacroActions'; export * from './MoveMouseMacroAction'; export * from './MouseButtonMacroAction'; export * from './ScrollMouseMacroAction';