From 3952e3347a364df97222d111bfcc87929f311b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Farkas?= Date: Sat, 8 Apr 2017 21:28:17 +0200 Subject: [PATCH] Remove SwitchLayerActions from non base layers Closes #286 --- .../config-serializer/config-items/Keymap.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/shared/src/config-serializer/config-items/Keymap.ts b/shared/src/config-serializer/config-items/Keymap.ts index bddda741..ed4ccb51 100644 --- a/shared/src/config-serializer/config-items/Keymap.ts +++ b/shared/src/config-serializer/config-items/Keymap.ts @@ -1,6 +1,7 @@ import { UhkBuffer } from '../UhkBuffer'; import { Layer } from './Layer'; import { Macro } from './Macro'; +import { SwitchLayerAction } from './key-action'; export class Keymap { @@ -32,6 +33,7 @@ export class Keymap { this.name = jsonObject.name; this.description = jsonObject.description; this.layers = jsonObject.layers.map((layer: any) => new Layer().fromJsonObject(layer, macros)); + this.normalize(); return this; } @@ -43,6 +45,7 @@ export class Keymap { this.layers = buffer.readArray(uhkBuffer => { return new Layer().fromBinary(uhkBuffer, macros); }); + this.normalize(); return this; } @@ -91,4 +94,18 @@ export class Keymap { return this; } + private normalize() { + // Removes all the SwitchLayerActions from any non base layer + for (let i = 1; i < this.layers.length; ++i) { + for (const module of this.layers[i].modules) { + module.keyActions = module.keyActions.map(keyAction => { + if (keyAction instanceof SwitchLayerAction) { + return undefined; + } + return keyAction; + }); + } + } + } + }