Remove SwitchLayerActions from non base layers

Closes #286
This commit is contained in:
József Farkas
2017-04-08 21:28:17 +02:00
parent 4b99fb213e
commit 3952e3347a

View File

@@ -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<Layer>(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;
});
}
}
}
}