refactor: Module
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
[coverages]="module.coverages"
|
||||
[keyboardKeys]="module.keyboardKeys"
|
||||
[attr.transform]="module.attributes.transform"
|
||||
[keyActions]="moduleConfig[i].keyActions.elements"
|
||||
[keyActions]="moduleConfig[i].keyActions"
|
||||
(keyClick)="onKeyClick(i, $event)"
|
||||
(keyHover)="onKeyHover($event.index, $event.event, $event.over, i)"
|
||||
/>
|
||||
|
||||
|
Before Width: | Height: | Size: 662 B After Width: | Height: | Size: 653 B |
@@ -130,7 +130,7 @@ export class SvgKeyboardWrapComponent implements OnChanges {
|
||||
onKeyClick(moduleId: number, keyId: number): void {
|
||||
if (!this.popoverShown && this.popoverEnabled) {
|
||||
this.keyEditConfig = {
|
||||
keyActions: this.layers[this.currentLayer].modules[moduleId].keyActions.elements,
|
||||
keyActions: this.layers[this.currentLayer].modules[moduleId].keyActions,
|
||||
keyId
|
||||
};
|
||||
|
||||
@@ -140,7 +140,7 @@ export class SvgKeyboardWrapComponent implements OnChanges {
|
||||
}
|
||||
|
||||
onKeyHover(moduleId: number, event: MouseEvent, over: boolean, keyId: number): void {
|
||||
let keyActionToEdit: KeyAction = this.layers[this.currentLayer].modules[moduleId].keyActions.elements[keyId];
|
||||
let keyActionToEdit: KeyAction = this.layers[this.currentLayer].modules[moduleId].keyActions[keyId];
|
||||
|
||||
if (this.tooltipEnabled) {
|
||||
if (over) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { assertEnum, assertUInt8 } from '../assert';
|
||||
import { Serializable } from '../Serializable';
|
||||
import { UhkBuffer } from '../UhkBuffer';
|
||||
import { KeyActions } from './key-action';
|
||||
import { Helper as KeyActionHelper, KeyAction } from './key-action';
|
||||
|
||||
enum PointerRole {
|
||||
none,
|
||||
@@ -14,32 +14,35 @@ export class Module extends Serializable<Module> {
|
||||
@assertUInt8
|
||||
id: number;
|
||||
|
||||
keyActions: KeyActions;
|
||||
keyActions: KeyAction[];
|
||||
|
||||
@assertEnum(PointerRole)
|
||||
private pointerRole: PointerRole;
|
||||
|
||||
constructor(moduleI?: Module) {
|
||||
constructor(other?: Module) {
|
||||
super();
|
||||
if (!moduleI) {
|
||||
if (!other) {
|
||||
return;
|
||||
}
|
||||
this.id = moduleI.id;
|
||||
this.keyActions = new KeyActions(moduleI.keyActions);
|
||||
this.pointerRole = moduleI.pointerRole;
|
||||
this.id = other.id;
|
||||
this.keyActions = other.keyActions.map(keyAction => KeyActionHelper.createKeyAction(keyAction));
|
||||
this.pointerRole = other.pointerRole;
|
||||
}
|
||||
|
||||
_fromJsObject(jsObject: any): Module {
|
||||
this.id = jsObject.id;
|
||||
this.pointerRole = PointerRole[<string>jsObject.pointerRole];
|
||||
this.keyActions = new KeyActions().fromJsObject(jsObject.keyActions);
|
||||
this.keyActions = jsObject.keyActions.map((keyAction: any) => KeyActionHelper.createKeyAction(keyAction));
|
||||
return this;
|
||||
}
|
||||
|
||||
_fromBinary(buffer: UhkBuffer): Module {
|
||||
this.id = buffer.readUInt8();
|
||||
this.pointerRole = buffer.readUInt8();
|
||||
this.keyActions = new KeyActions().fromBinary(buffer);
|
||||
let keyActionsLength: number = buffer.readCompactLength();
|
||||
this.keyActions = [];
|
||||
for (let i = 0; i < keyActionsLength; ++i) {
|
||||
this.keyActions.push(KeyActionHelper.createKeyAction(buffer));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -47,14 +50,14 @@ export class Module extends Serializable<Module> {
|
||||
return {
|
||||
id: this.id,
|
||||
pointerRole: PointerRole[this.pointerRole],
|
||||
keyActions: this.keyActions.toJsObject()
|
||||
keyActions: this.keyActions.map(keyAction => keyAction.toJsObject())
|
||||
};
|
||||
}
|
||||
|
||||
_toBinary(buffer: UhkBuffer): void {
|
||||
buffer.writeUInt8(this.id);
|
||||
buffer.writeUInt8(this.pointerRole);
|
||||
this.keyActions.toBinary(buffer);
|
||||
buffer.writeArray(this.keyActions);
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
|
||||
Reference in New Issue
Block a user