cleanup: Remove unused ClassArray classes
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
import { Serializable } from './Serializable';
|
||||
import { UhkBuffer } from './UhkBuffer';
|
||||
|
||||
export abstract class ClassArray<T extends Serializable<T>> extends Serializable<ClassArray<T>> {
|
||||
|
||||
elements: T[] = [];
|
||||
|
||||
_fromJsObject(jsObjects: any): ClassArray<T> {
|
||||
for (let jsObject of jsObjects) {
|
||||
this.elements.push(this.jsObjectToClass(jsObject));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
_fromBinary(buffer: UhkBuffer): ClassArray<T> {
|
||||
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;
|
||||
}
|
||||
@@ -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:
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ClassArray } from '../ClassArray';
|
||||
import { UhkBuffer } from '../UhkBuffer';
|
||||
import { Keymap } from './Keymap';
|
||||
|
||||
export class Keymaps extends ClassArray<Keymap> {
|
||||
|
||||
jsObjectToClass(jsObject: any): Keymap {
|
||||
return new Keymap().fromJsObject(jsObject);
|
||||
}
|
||||
|
||||
binaryToClass(buffer: UhkBuffer): Keymap {
|
||||
return new Keymap().fromBinary(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { ClassArray } from '../ClassArray';
|
||||
import { UhkBuffer } from '../UhkBuffer';
|
||||
import { Layer } from './Layer';
|
||||
|
||||
export class Layers extends ClassArray<Layer> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ClassArray } from '../ClassArray';
|
||||
import { UhkBuffer } from '../UhkBuffer';
|
||||
import { Macro } from './Macro';
|
||||
|
||||
export class Macros extends ClassArray<Macro> {
|
||||
|
||||
jsObjectToClass(jsObject: any): Macro {
|
||||
return new Macro().fromJsObject(jsObject);
|
||||
}
|
||||
|
||||
binaryToClass(buffer: UhkBuffer): Macro {
|
||||
return new Macro().fromBinary(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ClassArray } from '../ClassArray';
|
||||
import { UhkBuffer } from '../UhkBuffer';
|
||||
import { ModuleConfiguration } from './ModuleConfiguration';
|
||||
|
||||
export class ModuleConfigurations extends ClassArray<ModuleConfiguration> {
|
||||
|
||||
jsObjectToClass(jsObject: any): ModuleConfiguration {
|
||||
return new ModuleConfiguration().fromJsObject(jsObject);
|
||||
}
|
||||
|
||||
binaryToClass(buffer: UhkBuffer): ModuleConfiguration {
|
||||
return new ModuleConfiguration().fromBinary(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { ClassArray } from '../ClassArray';
|
||||
import { UhkBuffer } from '../UhkBuffer';
|
||||
import { Module } from './Module';
|
||||
|
||||
export class Modules extends ClassArray<Module> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<KeyAction> {
|
||||
|
||||
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}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from './KeyAction';
|
||||
export * from './KeyActions';
|
||||
export * from './KeystrokeAction';
|
||||
export * from './MouseAction';
|
||||
export * from './NoneAction';
|
||||
|
||||
@@ -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<MacroAction> {
|
||||
|
||||
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}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user