refactor: UhkConfiguration
This commit is contained in:
@@ -48,7 +48,7 @@ export class MacroComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
getMacro(id: number): Macro {
|
getMacro(id: number): Macro {
|
||||||
const config = this.uhkConfigurationService.getUhkConfiguration();
|
const config = this.uhkConfigurationService.getUhkConfiguration();
|
||||||
const macro: Macro = config.macros.elements.find(item => item.id === id);
|
const macro: Macro = config.macros.find(item => item.id === id);
|
||||||
if (macro) {
|
if (macro) {
|
||||||
// Clone macro for editing
|
// Clone macro for editing
|
||||||
return new Macro().fromJsObject(macro.toJsObject());
|
return new Macro().fromJsObject(macro.toJsObject());
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export class MacroTabComponent implements OnInit, Tab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.macros = this.uhkConfigurationService.getUhkConfiguration().macros.elements;
|
this.macros = this.uhkConfigurationService.getUhkConfiguration().macros;
|
||||||
|
|
||||||
this.macroOptions.push({
|
this.macroOptions.push({
|
||||||
id: '-1',
|
id: '-1',
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ import { assertUInt32, assertUInt8 } from '../assert';
|
|||||||
import { Serializable } from '../Serializable';
|
import { Serializable } from '../Serializable';
|
||||||
import { UhkBuffer } from '../UhkBuffer';
|
import { UhkBuffer } from '../UhkBuffer';
|
||||||
import { Keymap } from './Keymap';
|
import { Keymap } from './Keymap';
|
||||||
import { Keymaps } from './Keymaps';
|
|
||||||
import { Macro } from './Macro';
|
import { Macro } from './Macro';
|
||||||
import { Macros } from './Macros';
|
import { ModuleConfiguration } from './ModuleConfiguration';
|
||||||
import { ModuleConfigurations } from './ModuleConfigurations';
|
|
||||||
|
|
||||||
export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
||||||
|
|
||||||
@@ -23,11 +21,11 @@ export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
|||||||
@assertUInt8
|
@assertUInt8
|
||||||
brandId: number;
|
brandId: number;
|
||||||
|
|
||||||
moduleConfigurations: ModuleConfigurations;
|
moduleConfigurations: ModuleConfiguration[];
|
||||||
|
|
||||||
keymaps: Keymaps;
|
keymaps: Keymap[];
|
||||||
|
|
||||||
macros: Macros;
|
macros: Macro[];
|
||||||
|
|
||||||
@assertUInt32
|
@assertUInt32
|
||||||
epilogue: number;
|
epilogue: number;
|
||||||
@@ -38,9 +36,11 @@ export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
|||||||
this.prologue = jsObject.prologue;
|
this.prologue = jsObject.prologue;
|
||||||
this.hardwareId = jsObject.hardwareId;
|
this.hardwareId = jsObject.hardwareId;
|
||||||
this.brandId = jsObject.brandId;
|
this.brandId = jsObject.brandId;
|
||||||
this.moduleConfigurations = new ModuleConfigurations().fromJsObject(jsObject.moduleConfigurations);
|
this.moduleConfigurations = jsObject.moduleConfigurations.map((moduleConfiguration: any) => {
|
||||||
this.keymaps = new Keymaps().fromJsObject(jsObject.keymaps);
|
return new ModuleConfiguration().fromJsObject(moduleConfiguration);
|
||||||
this.macros = new Macros().fromJsObject(jsObject.macros);
|
});
|
||||||
|
this.keymaps = jsObject.keymaps.map((keymap: any) => new Keymap().fromJsObject(keymap));
|
||||||
|
this.macros = jsObject.macros.map((macro: any) => new Macro().fromJsObject(macro));
|
||||||
this.epilogue = jsObject.epilogue;
|
this.epilogue = jsObject.epilogue;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -51,9 +51,9 @@ export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
|||||||
this.prologue = buffer.readUInt32();
|
this.prologue = buffer.readUInt32();
|
||||||
this.hardwareId = buffer.readUInt8();
|
this.hardwareId = buffer.readUInt8();
|
||||||
this.brandId = buffer.readUInt8();
|
this.brandId = buffer.readUInt8();
|
||||||
this.moduleConfigurations = new ModuleConfigurations().fromBinary(buffer);
|
this.moduleConfigurations = buffer.readArray<ModuleConfiguration>(ModuleConfiguration);
|
||||||
this.keymaps = new Keymaps().fromBinary(buffer);
|
this.keymaps = buffer.readArray<Keymap>(Keymap);
|
||||||
this.macros = new Macros().fromBinary(buffer);
|
this.macros = buffer.readArray<Macro>(Macro);
|
||||||
this.epilogue = buffer.readUInt32();
|
this.epilogue = buffer.readUInt32();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -65,9 +65,9 @@ export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
|||||||
prologue: this.prologue,
|
prologue: this.prologue,
|
||||||
hardwareId: this.hardwareId,
|
hardwareId: this.hardwareId,
|
||||||
brandId: this.brandId,
|
brandId: this.brandId,
|
||||||
moduleConfigurations: this.moduleConfigurations.toJsObject(),
|
moduleConfigurations: this.moduleConfigurations.map(moduleConfiguration => moduleConfiguration.toJsObject()),
|
||||||
keymaps: this.keymaps.toJsObject(),
|
keymaps: this.keymaps.map(keymap => keymap.toJsObject()),
|
||||||
macros: this.macros.toJsObject(),
|
macros: this.macros.map(macro => macro.toJsObject()),
|
||||||
epilogue: this.epilogue
|
epilogue: this.epilogue
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -78,9 +78,9 @@ export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
|||||||
buffer.writeUInt32(this.prologue);
|
buffer.writeUInt32(this.prologue);
|
||||||
buffer.writeUInt8(this.hardwareId);
|
buffer.writeUInt8(this.hardwareId);
|
||||||
buffer.writeUInt8(this.brandId);
|
buffer.writeUInt8(this.brandId);
|
||||||
this.moduleConfigurations.toBinary(buffer);
|
buffer.writeArray(this.moduleConfigurations);
|
||||||
this.keymaps.toBinary(buffer);
|
buffer.writeArray(this.keymaps);
|
||||||
this.macros.toBinary(buffer);
|
buffer.writeArray(this.macros);
|
||||||
buffer.writeUInt32(this.epilogue);
|
buffer.writeUInt32(this.epilogue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,10 +89,10 @@ export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getKeymap(keymapAbbreviation: string): Keymap {
|
getKeymap(keymapAbbreviation: string): Keymap {
|
||||||
return this.keymaps.elements.find(keymap => keymapAbbreviation === keymap.abbreviation);
|
return this.keymaps.find(keymap => keymapAbbreviation === keymap.abbreviation);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMacro(macroId: number): Macro {
|
getMacro(macroId: number): Macro {
|
||||||
return this.macros.elements.find(macro => macroId === macro.id);
|
return this.macros.find(macro => macroId === macro.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ export class Local {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
keymaps: config.keymaps.elements,
|
keymaps: config.keymaps,
|
||||||
macros: config.macros.elements,
|
macros: config.macros,
|
||||||
presetKeymaps: presetAll.elements
|
presetKeymaps: presetAll.elements
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -51,13 +51,13 @@ export class Local {
|
|||||||
config = new UhkConfiguration().fromJsObject(
|
config = new UhkConfiguration().fromJsObject(
|
||||||
JSON.parse(localStorage.getItem('config'))
|
JSON.parse(localStorage.getItem('config'))
|
||||||
);
|
);
|
||||||
config.keymaps.elements = Object.values(nextState);
|
config.keymaps = Object.values(nextState);
|
||||||
localStorage.setItem('config', JSON.stringify(config.toJsObject()));
|
localStorage.setItem('config', JSON.stringify(config.toJsObject()));
|
||||||
} else if (action.type.startsWith(MacroActions.PREFIX) && state.length && state[0] instanceof Macro) {
|
} else if (action.type.startsWith(MacroActions.PREFIX) && state.length && state[0] instanceof Macro) {
|
||||||
config = new UhkConfiguration().fromJsObject(
|
config = new UhkConfiguration().fromJsObject(
|
||||||
JSON.parse(localStorage.getItem('config'))
|
JSON.parse(localStorage.getItem('config'))
|
||||||
);
|
);
|
||||||
config.macros.elements = Object.values(nextState);
|
config.macros = Object.values(nextState);
|
||||||
localStorage.setItem('config', JSON.stringify(config.toJsObject()));
|
localStorage.setItem('config', JSON.stringify(config.toJsObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user