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