Use ids in key actions instead of references (#239)
Partially reverts e48fdea
This commit is contained in:
@@ -59,7 +59,8 @@ export class KeymapTabComponent implements OnInit, OnChanges, Tab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const switchKeymapAction: SwitchKeymapAction = <SwitchKeymapAction>keyAction;
|
const switchKeymapAction: SwitchKeymapAction = <SwitchKeymapAction>keyAction;
|
||||||
this.selectedKeymap = switchKeymapAction.keymap;
|
this.selectedKeymap = this.keymaps
|
||||||
|
.find((keymap: Keymap) => keymap.abbreviation === switchKeymapAction.keymapAbbreviation);
|
||||||
}
|
}
|
||||||
|
|
||||||
toKeyAction(): SwitchKeymapAction {
|
toKeyAction(): SwitchKeymapAction {
|
||||||
@@ -68,7 +69,7 @@ export class KeymapTabComponent implements OnInit, OnChanges, Tab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const keymapAction = new SwitchKeymapAction();
|
const keymapAction = new SwitchKeymapAction();
|
||||||
keymapAction.keymap = this.selectedKeymap;
|
keymapAction.keymapAbbreviation = this.selectedKeymap.abbreviation;
|
||||||
return keymapAction;
|
return keymapAction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export class MacroTabComponent implements OnInit, OnChanges, OnDestroy, Tab {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const playMacroAction: PlayMacroAction = <PlayMacroAction>keyAction;
|
const playMacroAction: PlayMacroAction = <PlayMacroAction>keyAction;
|
||||||
this.selectedMacroIndex = this.macros.findIndex(macro => playMacroAction.macro === macro);
|
this.selectedMacroIndex = this.macros.findIndex(macro => playMacroAction.macroId === macro.id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ export class MacroTabComponent implements OnInit, OnChanges, OnDestroy, Tab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const keymapAction = new PlayMacroAction();
|
const keymapAction = new PlayMacroAction();
|
||||||
keymapAction.macro = this.macros[this.selectedMacroIndex];
|
keymapAction.macroId = this.macros[this.selectedMacroIndex].id;
|
||||||
return keymapAction;
|
return keymapAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -283,13 +283,14 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
} else if (this.keyAction instanceof SwitchKeymapAction) {
|
} else if (this.keyAction instanceof SwitchKeymapAction) {
|
||||||
let keyAction: SwitchKeymapAction = this.keyAction as SwitchKeymapAction;
|
let keyAction: SwitchKeymapAction = this.keyAction as SwitchKeymapAction;
|
||||||
this.labelType = LabelTypes.SwitchKeymap;
|
this.labelType = LabelTypes.SwitchKeymap;
|
||||||
this.labelSource = keyAction.keymap.abbreviation;
|
this.labelSource = keyAction.keymapAbbreviation;
|
||||||
} else if (this.keyAction instanceof PlayMacroAction) {
|
} else if (this.keyAction instanceof PlayMacroAction) {
|
||||||
let keyAction: PlayMacroAction = this.keyAction as PlayMacroAction;
|
let keyAction: PlayMacroAction = this.keyAction as PlayMacroAction;
|
||||||
|
const macro: Macro = this.macros.find((macro: Macro) => macro.id === keyAction.macroId);
|
||||||
this.labelType = LabelTypes.IconText;
|
this.labelType = LabelTypes.IconText;
|
||||||
this.labelSource = {
|
this.labelSource = {
|
||||||
icon: this.mapper.getIcon('macro'),
|
icon: this.mapper.getIcon('macro'),
|
||||||
text: keyAction.macro.name
|
text: macro.name
|
||||||
};
|
};
|
||||||
} else if (this.keyAction instanceof MouseAction) {
|
} else if (this.keyAction instanceof MouseAction) {
|
||||||
this.labelType = LabelTypes.MouseKey;
|
this.labelType = LabelTypes.MouseKey;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
>
|
>
|
||||||
<div class="tooltip-arrow"></div>
|
<div class="tooltip-arrow"></div>
|
||||||
<div class="tooltip-inner">
|
<div class="tooltip-inner">
|
||||||
<p *ngFor="let item of tooltipData.content">
|
<p *ngFor="let item of tooltipData.content | async">
|
||||||
{{ item.name }}: {{ item.value }}
|
{{ item.name }}: {{ item.value }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import {
|
|||||||
SimpleChanges
|
SimpleChanges
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import 'rxjs/add/observable/of';
|
||||||
|
import 'rxjs/add/operator/map';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
|
|
||||||
import { MapperService } from '../../../services/mapper.service';
|
import { MapperService } from '../../../services/mapper.service';
|
||||||
@@ -35,6 +38,11 @@ import { AppState } from '../../../store';
|
|||||||
import { KeymapActions } from '../../../store/actions';
|
import { KeymapActions } from '../../../store/actions';
|
||||||
import { PopoverComponent } from '../../popover';
|
import { PopoverComponent } from '../../popover';
|
||||||
|
|
||||||
|
interface NameValuePair {
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'svg-keyboard-wrap',
|
selector: 'svg-keyboard-wrap',
|
||||||
template: require('./svg-keyboard-wrap.component.html'),
|
template: require('./svg-keyboard-wrap.component.html'),
|
||||||
@@ -46,14 +54,19 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
|
|||||||
@Input() popoverEnabled: boolean = true;
|
@Input() popoverEnabled: boolean = true;
|
||||||
@Input() tooltipEnabled: boolean = false;
|
@Input() tooltipEnabled: boolean = false;
|
||||||
|
|
||||||
@ViewChild(PopoverComponent, { read: ElementRef}) popover: ElementRef;
|
@ViewChild(PopoverComponent, { read: ElementRef }) popover: ElementRef;
|
||||||
|
|
||||||
private popoverShown: boolean;
|
private popoverShown: boolean;
|
||||||
private keyEditConfig: { moduleId: number, keyId: number };
|
private keyEditConfig: { moduleId: number, keyId: number };
|
||||||
private popoverInitKeyAction: KeyAction;
|
private popoverInitKeyAction: KeyAction;
|
||||||
private keybindAnimationEnabled: boolean;
|
private keybindAnimationEnabled: boolean;
|
||||||
private currentLayer: number = 0;
|
private currentLayer: number = 0;
|
||||||
private tooltipData: { posTop: number, posLeft: number, content: { name: string, value: string }[], show: boolean };
|
private tooltipData: {
|
||||||
|
posTop: number,
|
||||||
|
posLeft: number,
|
||||||
|
content: Observable<NameValuePair[]>,
|
||||||
|
show: boolean
|
||||||
|
};
|
||||||
private layers: Layer[];
|
private layers: Layer[];
|
||||||
private keyPosition: ClientRect;
|
private keyPosition: ClientRect;
|
||||||
private wrapPosition: ClientRect;
|
private wrapPosition: ClientRect;
|
||||||
@@ -89,7 +102,7 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
|
|||||||
this.tooltipData = {
|
this.tooltipData = {
|
||||||
posTop: 0,
|
posTop: 0,
|
||||||
posLeft: 0,
|
posLeft: 0,
|
||||||
content: [],
|
content: Observable.of([]),
|
||||||
show: false
|
show: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -139,7 +152,7 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onCapture(moduleId: number, keyId: number, captured: {code: number, left: boolean[], right: boolean[]}): void {
|
onCapture(moduleId: number, keyId: number, captured: { code: number, left: boolean[], right: boolean[] }): void {
|
||||||
let keystrokeAction: KeystrokeAction = new KeystrokeAction();
|
let keystrokeAction: KeystrokeAction = new KeystrokeAction();
|
||||||
const modifiers = captured.left.concat(captured.right).map(x => x ? 1 : 0);
|
const modifiers = captured.left.concat(captured.right).map(x => x ? 1 : 0);
|
||||||
|
|
||||||
@@ -194,13 +207,30 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
|
|||||||
posTop = position.top + position.height;
|
posTop = position.top + position.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
let content: {
|
this.tooltipData = {
|
||||||
name: string,
|
posLeft: posLeft,
|
||||||
value: string
|
posTop: posTop,
|
||||||
}[] = [];
|
content: this.getKeyActionContent(keyAction),
|
||||||
|
show: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
hideTooltip() {
|
||||||
|
this.tooltipData.show = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
hidePopover(): void {
|
||||||
|
this.popoverShown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectLayer(index: number): void {
|
||||||
|
this.currentLayer = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getKeyActionContent(keyAction: KeyAction): Observable<NameValuePair[]> {
|
||||||
if (keyAction instanceof KeystrokeAction) {
|
if (keyAction instanceof KeystrokeAction) {
|
||||||
const keystrokeAction: KeystrokeAction = keyAction;
|
const keystrokeAction: KeystrokeAction = keyAction;
|
||||||
|
const content: NameValuePair[] = [];
|
||||||
content.push({
|
content.push({
|
||||||
name: 'Action type',
|
name: 'Action type',
|
||||||
value: 'Keystroke'
|
value: 'Keystroke'
|
||||||
@@ -231,71 +261,79 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
|
|||||||
value: LongPressAction[keystrokeAction.longPressAction]
|
value: LongPressAction[keystrokeAction.longPressAction]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return Observable.of(content);
|
||||||
} else if (keyAction instanceof MouseAction) {
|
} else if (keyAction instanceof MouseAction) {
|
||||||
const mouseAction: MouseAction = keyAction;
|
const mouseAction: MouseAction = keyAction;
|
||||||
content.push({
|
const content: NameValuePair[] =
|
||||||
name: 'Action type',
|
[
|
||||||
value: 'Mouse'
|
{
|
||||||
});
|
name: 'Action type',
|
||||||
content.push({
|
value: 'Mouse'
|
||||||
name: 'Action',
|
},
|
||||||
value: camelCaseToSentence(MouseActionParam[mouseAction.mouseAction])
|
{
|
||||||
});
|
name: 'Action',
|
||||||
|
value: camelCaseToSentence(MouseActionParam[mouseAction.mouseAction])
|
||||||
|
}
|
||||||
|
];
|
||||||
|
return Observable.of(content);
|
||||||
} else if (keyAction instanceof PlayMacroAction) {
|
} else if (keyAction instanceof PlayMacroAction) {
|
||||||
const playMacroAction: PlayMacroAction = keyAction;
|
const playMacroAction: PlayMacroAction = keyAction;
|
||||||
content.push({
|
return this.store
|
||||||
name: 'Action type',
|
.select(appState => appState.macros)
|
||||||
value: 'Play macro'
|
.map(macroState => macroState.entities.find(macro => {
|
||||||
});
|
return macro.id === playMacroAction.macroId;
|
||||||
|
}).name)
|
||||||
content.push({
|
.map(macroName => {
|
||||||
name: 'Macro name',
|
const content: NameValuePair[] = [
|
||||||
value: playMacroAction.macro.name.toString()
|
{
|
||||||
});
|
name: 'Action type',
|
||||||
|
value: 'Play macro'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Macro name',
|
||||||
|
value: macroName
|
||||||
|
}
|
||||||
|
];
|
||||||
|
return content;
|
||||||
|
});
|
||||||
} else if (keyAction instanceof SwitchKeymapAction) {
|
} else if (keyAction instanceof SwitchKeymapAction) {
|
||||||
const switchKeymapAction: SwitchKeymapAction = keyAction;
|
const switchKeymapAction: SwitchKeymapAction = keyAction;
|
||||||
content.push({
|
return this.store
|
||||||
name: 'Action type',
|
.select(appState => appState.keymaps.entities)
|
||||||
value: 'Switch keymap'
|
.map(keymaps => keymaps.find(keymap => keymap.abbreviation === switchKeymapAction.keymapAbbreviation).name)
|
||||||
});
|
.map(keymapName => {
|
||||||
content.push({
|
const content: NameValuePair[] = [
|
||||||
name: 'Keymap',
|
{
|
||||||
value: switchKeymapAction.keymap.name
|
name: 'Action type',
|
||||||
});
|
value: 'Switch keymap'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Keymap',
|
||||||
|
value: keymapName
|
||||||
|
}
|
||||||
|
];
|
||||||
|
return content;
|
||||||
|
});
|
||||||
} else if (keyAction instanceof SwitchLayerAction) {
|
} else if (keyAction instanceof SwitchLayerAction) {
|
||||||
const switchLayerAction: SwitchLayerAction = keyAction;
|
const switchLayerAction: SwitchLayerAction = keyAction;
|
||||||
content.push({
|
const content: NameValuePair[] =
|
||||||
name: 'Action type',
|
[
|
||||||
value: 'Switch layer'
|
{
|
||||||
});
|
name: 'Action type',
|
||||||
content.push({
|
value: 'Switch layer'
|
||||||
name: 'Layer',
|
},
|
||||||
value: capitalizeFirstLetter(LayerName[switchLayerAction.layer])
|
{
|
||||||
});
|
name: 'Layer',
|
||||||
content.push({
|
value: capitalizeFirstLetter(LayerName[switchLayerAction.layer])
|
||||||
name: 'Toogle',
|
},
|
||||||
value: switchLayerAction.isLayerToggleable ? 'On' : 'Off'
|
{
|
||||||
});
|
name: 'Toogle',
|
||||||
|
value: switchLayerAction.isLayerToggleable ? 'On' : 'Off'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
return Observable.of(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tooltipData = {
|
return Observable.of([]);
|
||||||
posLeft: posLeft,
|
|
||||||
posTop: posTop,
|
|
||||||
content,
|
|
||||||
show: true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
hideTooltip() {
|
|
||||||
this.tooltipData.show = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
hidePopover(): void {
|
|
||||||
this.popoverShown = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
selectLayer(index: number): void {
|
|
||||||
this.currentLayer = index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class Keymap extends Serializable<Keymap> {
|
|||||||
|
|
||||||
layers: Layer[];
|
layers: Layer[];
|
||||||
|
|
||||||
constructor(keymap?: Keymap, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro) {
|
constructor(keymap?: Keymap) {
|
||||||
super();
|
super();
|
||||||
if (!keymap) {
|
if (!keymap) {
|
||||||
return;
|
return;
|
||||||
@@ -25,25 +25,25 @@ export class Keymap extends Serializable<Keymap> {
|
|||||||
this.description = keymap.description;
|
this.description = keymap.description;
|
||||||
this.abbreviation = keymap.abbreviation;
|
this.abbreviation = keymap.abbreviation;
|
||||||
this.isDefault = keymap.isDefault;
|
this.isDefault = keymap.isDefault;
|
||||||
this.layers = keymap.layers.map(layer => new Layer(layer, getKeymap, getMacro));
|
this.layers = keymap.layers.map(layer => new Layer(layer));
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJsonObject(jsonObject: any, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro): Keymap {
|
fromJsonObject(jsonObject: any): Keymap {
|
||||||
this.isDefault = jsonObject.isDefault;
|
this.isDefault = jsonObject.isDefault;
|
||||||
this.abbreviation = jsonObject.abbreviation;
|
this.abbreviation = jsonObject.abbreviation;
|
||||||
this.name = jsonObject.name;
|
this.name = jsonObject.name;
|
||||||
this.description = jsonObject.description;
|
this.description = jsonObject.description;
|
||||||
this.layers = jsonObject.layers.map((layer: any) => new Layer().fromJsonObject(layer, getKeymap, getMacro));
|
this.layers = jsonObject.layers.map((layer: any) => new Layer().fromJsonObject(layer));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromBinary(buffer: UhkBuffer, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro): Keymap {
|
fromBinary(buffer: UhkBuffer): Keymap {
|
||||||
this.abbreviation = buffer.readString();
|
this.abbreviation = buffer.readString();
|
||||||
this.isDefault = buffer.readBoolean();
|
this.isDefault = buffer.readBoolean();
|
||||||
this.name = buffer.readString();
|
this.name = buffer.readString();
|
||||||
this.description = buffer.readString();
|
this.description = buffer.readString();
|
||||||
this.layers = buffer.readArray<Layer>(uhkBuffer => {
|
this.layers = buffer.readArray<Layer>(uhkBuffer => {
|
||||||
return new Layer().fromBinary(uhkBuffer, getKeymap, getMacro);
|
return new Layer().fromBinary(uhkBuffer);
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,22 +8,22 @@ export class Layer extends Serializable<Layer> {
|
|||||||
|
|
||||||
modules: Module[];
|
modules: Module[];
|
||||||
|
|
||||||
constructor(layers?: Layer, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro) {
|
constructor(layers?: Layer) {
|
||||||
super();
|
super();
|
||||||
if (!layers) {
|
if (!layers) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.modules = layers.modules.map(module => new Module(module, getKeymap, getMacro));
|
this.modules = layers.modules.map(module => new Module(module));
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJsonObject(jsonObject: any, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro): Layer {
|
fromJsonObject(jsonObject: any): Layer {
|
||||||
this.modules = jsonObject.modules.map((module: any) => new Module().fromJsonObject(module, getKeymap, getMacro));
|
this.modules = jsonObject.modules.map((module: any) => new Module().fromJsonObject(module));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromBinary(buffer: UhkBuffer, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro): Layer {
|
fromBinary(buffer: UhkBuffer): Layer {
|
||||||
this.modules = buffer.readArray<Module>(uhkBuffer => {
|
this.modules = buffer.readArray<Module>(uhkBuffer => {
|
||||||
return new Module().fromBinary(uhkBuffer, getKeymap, getMacro);
|
return new Module().fromBinary(uhkBuffer);
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,32 +21,32 @@ export class Module extends Serializable<Module> {
|
|||||||
@assertEnum(PointerRole)
|
@assertEnum(PointerRole)
|
||||||
pointerRole: PointerRole;
|
pointerRole: PointerRole;
|
||||||
|
|
||||||
constructor(other?: Module, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro) {
|
constructor(other?: Module) {
|
||||||
super();
|
super();
|
||||||
if (!other) {
|
if (!other) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.id = other.id;
|
this.id = other.id;
|
||||||
this.keyActions = other.keyActions.map(keyAction => KeyActionHelper.createKeyAction(keyAction, getKeymap, getMacro));
|
this.keyActions = other.keyActions.map(keyAction => KeyActionHelper.createKeyAction(keyAction));
|
||||||
this.pointerRole = other.pointerRole;
|
this.pointerRole = other.pointerRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJsonObject(jsonObject: any, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro): Module {
|
fromJsonObject(jsonObject: any): Module {
|
||||||
this.id = jsonObject.id;
|
this.id = jsonObject.id;
|
||||||
this.pointerRole = PointerRole[<string>jsonObject.pointerRole];
|
this.pointerRole = PointerRole[<string>jsonObject.pointerRole];
|
||||||
this.keyActions = jsonObject.keyActions.map((keyAction: any) => {
|
this.keyActions = jsonObject.keyActions.map((keyAction: any) => {
|
||||||
return KeyActionHelper.createKeyAction(keyAction, getKeymap, getMacro);
|
return KeyActionHelper.createKeyAction(keyAction);
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromBinary(buffer: UhkBuffer, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro): Module {
|
fromBinary(buffer: UhkBuffer): Module {
|
||||||
this.id = buffer.readUInt8();
|
this.id = buffer.readUInt8();
|
||||||
this.pointerRole = buffer.readUInt8();
|
this.pointerRole = buffer.readUInt8();
|
||||||
let keyActionsLength: number = buffer.readCompactLength();
|
let keyActionsLength: number = buffer.readCompactLength();
|
||||||
this.keyActions = [];
|
this.keyActions = [];
|
||||||
for (let i = 0; i < keyActionsLength; ++i) {
|
for (let i = 0; i < keyActionsLength; ++i) {
|
||||||
this.keyActions.push(KeyActionHelper.createKeyAction(buffer, getKeymap, getMacro));
|
this.keyActions.push(KeyActionHelper.createKeyAction(buffer));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,18 +40,7 @@ export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
|||||||
return new ModuleConfiguration().fromJsonObject(moduleConfiguration);
|
return new ModuleConfiguration().fromJsonObject(moduleConfiguration);
|
||||||
});
|
});
|
||||||
this.macros = jsonObject.macros.map((macro: any) => new Macro().fromJsonObject(macro));
|
this.macros = jsonObject.macros.map((macro: any) => new Macro().fromJsonObject(macro));
|
||||||
this.keymaps = jsonObject.keymaps.map((keymap: any) => {
|
this.keymaps = jsonObject.keymaps.map((keymap: any) => new Keymap().fromJsonObject(keymap));
|
||||||
const newKeymap = new Keymap();
|
|
||||||
newKeymap.abbreviation = keymap.abbreviation;
|
|
||||||
return newKeymap;
|
|
||||||
});
|
|
||||||
for (let i = 0; i < this.keymaps.length; ++i) {
|
|
||||||
this.keymaps[i].fromJsonObject(
|
|
||||||
jsonObject.keymaps[i],
|
|
||||||
abbrevation => this.getKeymap(abbrevation, true),
|
|
||||||
this.getMacro.bind(this)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.epilogue = jsonObject.epilogue;
|
this.epilogue = jsonObject.epilogue;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -66,10 +55,7 @@ export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
|||||||
return new ModuleConfiguration().fromBinary(uhkBuffer);
|
return new ModuleConfiguration().fromBinary(uhkBuffer);
|
||||||
});
|
});
|
||||||
this.macros = buffer.readArray<Macro>(uhkBuffer => new Macro().fromBinary(uhkBuffer));
|
this.macros = buffer.readArray<Macro>(uhkBuffer => new Macro().fromBinary(uhkBuffer));
|
||||||
this.keymaps = [];
|
this.keymaps = buffer.readArray<Keymap>(uhkBuffer => new Keymap().fromBinary(uhkBuffer));
|
||||||
this.keymaps = buffer.readArray<Keymap>(uhkBuffer => {
|
|
||||||
return new Keymap().fromBinary(uhkBuffer, abbrevation => this.getKeymap(abbrevation, true), this.getMacro.bind(this));
|
|
||||||
});
|
|
||||||
this.epilogue = buffer.readUInt32();
|
this.epilogue = buffer.readUInt32();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -104,14 +90,8 @@ export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
|||||||
return `<UhkConfiguration signature="${this.signature}">`;
|
return `<UhkConfiguration signature="${this.signature}">`;
|
||||||
}
|
}
|
||||||
|
|
||||||
getKeymap(keymapAbbreviation: string, createIfNotExist = false): Keymap {
|
getKeymap(keymapAbbreviation: string): Keymap {
|
||||||
let resultKeymap = this.keymaps.find(keymap => keymapAbbreviation === keymap.abbreviation);
|
return this.keymaps.find(keymap => keymapAbbreviation === keymap.abbreviation);
|
||||||
if (createIfNotExist && !resultKeymap) {
|
|
||||||
resultKeymap = new Keymap();
|
|
||||||
resultKeymap.abbreviation = keymapAbbreviation;
|
|
||||||
this.keymaps.push(resultKeymap);
|
|
||||||
}
|
|
||||||
return resultKeymap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getMacro(macroId: number): Macro {
|
getMacro(macroId: number): Macro {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
|
import { assertUInt8 } from '../../assert';
|
||||||
import { UhkBuffer } from '../../UhkBuffer';
|
import { UhkBuffer } from '../../UhkBuffer';
|
||||||
import { Macro } from '../Macro';
|
import { Macro } from '../Macro';
|
||||||
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||||
|
|
||||||
export class PlayMacroAction extends KeyAction {
|
export class PlayMacroAction extends KeyAction {
|
||||||
|
|
||||||
macro: Macro;
|
@assertUInt8
|
||||||
|
macroId: number;
|
||||||
|
|
||||||
constructor(parameter?: PlayMacroAction | Macro) {
|
constructor(parameter?: PlayMacroAction | Macro) {
|
||||||
super();
|
super();
|
||||||
@@ -12,38 +14,37 @@ export class PlayMacroAction extends KeyAction {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (parameter instanceof PlayMacroAction) {
|
if (parameter instanceof PlayMacroAction) {
|
||||||
this.macro = parameter.macro;
|
this.macroId = parameter.macroId;
|
||||||
} else {
|
} else {
|
||||||
this.macro = parameter;
|
this.macroId = parameter.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJsonObject(jsonObject: any, getMacro: (macroId: number) => Macro): PlayMacroAction {
|
fromJsonObject(jsonObject: any): PlayMacroAction {
|
||||||
this.assertKeyActionType(jsonObject);
|
this.assertKeyActionType(jsonObject);
|
||||||
this.macro = getMacro(jsonObject.macroId);
|
this.macroId = jsonObject.macroId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromBinary(buffer: UhkBuffer, getMacro: (macroId: number) => Macro): PlayMacroAction {
|
fromBinary(buffer: UhkBuffer): PlayMacroAction {
|
||||||
this.readAndAssertKeyActionId(buffer);
|
this.readAndAssertKeyActionId(buffer);
|
||||||
const macroId = buffer.readUInt8();
|
this.macroId = buffer.readUInt8();
|
||||||
this.macro = getMacro(macroId);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
_toJsonObject(): any {
|
_toJsonObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: keyActionType.PlayMacroAction,
|
keyActionType: keyActionType.PlayMacroAction,
|
||||||
macroId: this.macro.id
|
macroId: this.macroId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_toBinary(buffer: UhkBuffer) {
|
_toBinary(buffer: UhkBuffer) {
|
||||||
buffer.writeUInt8(KeyActionId.PlayMacroAction);
|
buffer.writeUInt8(KeyActionId.PlayMacroAction);
|
||||||
buffer.writeUInt8(this.macro.id);
|
buffer.writeUInt8(this.macroId);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
return `<PlayMacroAction macroId="${this.macro.id}">`;
|
return `<PlayMacroAction macroId="${this.macroId}">`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
|||||||
|
|
||||||
export class SwitchKeymapAction extends KeyAction {
|
export class SwitchKeymapAction extends KeyAction {
|
||||||
|
|
||||||
keymap: Keymap;
|
keymapAbbreviation: string;
|
||||||
|
|
||||||
constructor(parameter?: SwitchKeymapAction | Keymap) {
|
constructor(parameter?: SwitchKeymapAction | Keymap) {
|
||||||
super();
|
super();
|
||||||
@@ -12,38 +12,37 @@ export class SwitchKeymapAction extends KeyAction {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (parameter instanceof SwitchKeymapAction) {
|
if (parameter instanceof SwitchKeymapAction) {
|
||||||
this.keymap = parameter.keymap;
|
this.keymapAbbreviation = parameter.keymapAbbreviation;
|
||||||
} else {
|
} else {
|
||||||
this.keymap = parameter;
|
this.keymapAbbreviation = parameter.abbreviation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJsonObject(jsonObject: any, getKeymap: (abbrevation: string) => Keymap): SwitchKeymapAction {
|
fromJsonObject(jsonObject: any): SwitchKeymapAction {
|
||||||
this.assertKeyActionType(jsonObject);
|
this.assertKeyActionType(jsonObject);
|
||||||
this.keymap = getKeymap(jsonObject.keymapAbbreviation);
|
this.keymapAbbreviation = jsonObject.keymapAbbreviation;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromBinary(buffer: UhkBuffer, getKeymap: (abbrevation: string) => Keymap): SwitchKeymapAction {
|
fromBinary(buffer: UhkBuffer): SwitchKeymapAction {
|
||||||
this.readAndAssertKeyActionId(buffer);
|
this.readAndAssertKeyActionId(buffer);
|
||||||
const keymapAbbreviation = buffer.readString();
|
this.keymapAbbreviation = buffer.readString();
|
||||||
this.keymap = getKeymap(keymapAbbreviation);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
_toJsonObject(): any {
|
_toJsonObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: keyActionType.SwitchKeymapAction,
|
keyActionType: keyActionType.SwitchKeymapAction,
|
||||||
keymapAbbreviation: this.keymap.abbreviation
|
keymapAbbreviation: this.keymapAbbreviation
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_toBinary(buffer: UhkBuffer) {
|
_toBinary(buffer: UhkBuffer) {
|
||||||
buffer.writeUInt8(KeyActionId.SwitchKeymapAction);
|
buffer.writeUInt8(KeyActionId.SwitchKeymapAction);
|
||||||
buffer.writeString(this.keymap.abbreviation);
|
buffer.writeString(this.keymapAbbreviation);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
return `<SwitchKeymapAction keymapAbbreviation="${this.keymap.abbreviation}">`;
|
return `<SwitchKeymapAction keymapAbbreviation="${this.keymapAbbreviation}">`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,25 +15,17 @@ import { Macro } from '../Macro';
|
|||||||
|
|
||||||
export class Helper {
|
export class Helper {
|
||||||
|
|
||||||
static createKeyAction(
|
static createKeyAction(source: KeyAction | UhkBuffer | any): KeyAction {
|
||||||
source: KeyAction | UhkBuffer | any,
|
|
||||||
getKeymap?: (abbrevation: string) => Keymap,
|
|
||||||
getMacro?: (macroId: number) => Macro
|
|
||||||
): KeyAction {
|
|
||||||
if (source instanceof KeyAction) {
|
if (source instanceof KeyAction) {
|
||||||
return Helper.fromKeyAction(source);
|
return Helper.fromKeyAction(source);
|
||||||
} else if (source instanceof UhkBuffer) {
|
} else if (source instanceof UhkBuffer) {
|
||||||
return Helper.fromUhkBuffer(source, getKeymap, getMacro);
|
return Helper.fromUhkBuffer(source);
|
||||||
} else {
|
} else {
|
||||||
return Helper.fromJSONObject(source, getKeymap, getMacro);
|
return Helper.fromJSONObject(source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static fromUhkBuffer(
|
private static fromUhkBuffer(buffer: UhkBuffer): KeyAction {
|
||||||
buffer: UhkBuffer,
|
|
||||||
getKeymap?: (abbrevation: string) => Keymap,
|
|
||||||
getMacro?: (macroId: number) => Macro
|
|
||||||
): KeyAction {
|
|
||||||
let keyActionFirstByte = buffer.readUInt8();
|
let keyActionFirstByte = buffer.readUInt8();
|
||||||
buffer.backtrack();
|
buffer.backtrack();
|
||||||
|
|
||||||
@@ -48,11 +40,11 @@ export class Helper {
|
|||||||
case KeyActionId.SwitchLayerAction:
|
case KeyActionId.SwitchLayerAction:
|
||||||
return new SwitchLayerAction().fromBinary(buffer);
|
return new SwitchLayerAction().fromBinary(buffer);
|
||||||
case KeyActionId.SwitchKeymapAction:
|
case KeyActionId.SwitchKeymapAction:
|
||||||
return new SwitchKeymapAction().fromBinary(buffer, getKeymap);
|
return new SwitchKeymapAction().fromBinary(buffer);
|
||||||
case KeyActionId.MouseAction:
|
case KeyActionId.MouseAction:
|
||||||
return new MouseAction().fromBinary(buffer);
|
return new MouseAction().fromBinary(buffer);
|
||||||
case KeyActionId.PlayMacroAction:
|
case KeyActionId.PlayMacroAction:
|
||||||
return new PlayMacroAction().fromBinary(buffer, getMacro);
|
return new PlayMacroAction().fromBinary(buffer);
|
||||||
default:
|
default:
|
||||||
throw `Invalid KeyAction first byte: ${keyActionFirstByte}`;
|
throw `Invalid KeyAction first byte: ${keyActionFirstByte}`;
|
||||||
}
|
}
|
||||||
@@ -74,11 +66,7 @@ export class Helper {
|
|||||||
return newKeyAction;
|
return newKeyAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static fromJSONObject(
|
private static fromJSONObject(keyAction: any): KeyAction {
|
||||||
keyAction: any,
|
|
||||||
getKeymap?: (abbrevation: string) => Keymap,
|
|
||||||
getMacro?: (macroId: number) => Macro
|
|
||||||
): KeyAction {
|
|
||||||
if (!keyAction) {
|
if (!keyAction) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -89,11 +77,11 @@ export class Helper {
|
|||||||
case keyActionType.SwitchLayerAction:
|
case keyActionType.SwitchLayerAction:
|
||||||
return new SwitchLayerAction().fromJsonObject(keyAction);
|
return new SwitchLayerAction().fromJsonObject(keyAction);
|
||||||
case keyActionType.SwitchKeymapAction:
|
case keyActionType.SwitchKeymapAction:
|
||||||
return new SwitchKeymapAction().fromJsonObject(keyAction, getKeymap);
|
return new SwitchKeymapAction().fromJsonObject(keyAction);
|
||||||
case keyActionType.MouseAction:
|
case keyActionType.MouseAction:
|
||||||
return new MouseAction().fromJsonObject(keyAction);
|
return new MouseAction().fromJsonObject(keyAction);
|
||||||
case keyActionType.PlayMacroAction:
|
case keyActionType.PlayMacroAction:
|
||||||
return new PlayMacroAction().fromJsonObject(keyAction, getMacro);
|
return new PlayMacroAction().fromJsonObject(keyAction);
|
||||||
default:
|
default:
|
||||||
throw `Invalid KeyAction.keyActionType: "${keyAction.keyActionType}"`;
|
throw `Invalid KeyAction.keyActionType: "${keyAction.keyActionType}"`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,14 +83,7 @@ export class DataStorage {
|
|||||||
initUHKJson() {
|
initUHKJson() {
|
||||||
this.uhkConfiguration = new UhkConfiguration().fromJsonObject(require('json!../../config-serializer/uhk-config.json'));
|
this.uhkConfiguration = new UhkConfiguration().fromJsonObject(require('json!../../config-serializer/uhk-config.json'));
|
||||||
this.uhkPresets = (<any[]>require('json!../../config-serializer/preset-keymaps.json'))
|
this.uhkPresets = (<any[]>require('json!../../config-serializer/preset-keymaps.json'))
|
||||||
/* TODO: Remove passing getters, because there shouldn't be any SwitchKeymapAction or PlayMacroAction in presets,
|
.map(keymap => new Keymap().fromJsonObject(keymap));
|
||||||
* so they shouldn't be needed.
|
|
||||||
*/
|
|
||||||
.map(keymap => new Keymap().fromJsonObject(
|
|
||||||
keymap,
|
|
||||||
this.uhkConfiguration.getKeymap.bind(this.uhkConfiguration),
|
|
||||||
this.uhkConfiguration.getMacro.bind(this.uhkConfiguration)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getConfiguration(): UhkConfiguration {
|
getConfiguration(): UhkConfiguration {
|
||||||
|
|||||||
Reference in New Issue
Block a user