Keymap data layer (#95)
This commit is contained in:
committed by
József Farkas
parent
fb8cd163ec
commit
b78bc5850f
@@ -5,9 +5,6 @@ import { Layers } from './Layers';
|
||||
|
||||
export class Keymap extends Serializable<Keymap> {
|
||||
|
||||
@assertUInt8
|
||||
id: number;
|
||||
|
||||
name: string;
|
||||
|
||||
description: string;
|
||||
@@ -23,7 +20,7 @@ export class Keymap extends Serializable<Keymap> {
|
||||
if (!keymap) {
|
||||
return;
|
||||
}
|
||||
this.id = keymap.id;
|
||||
|
||||
this.name = keymap.name;
|
||||
this.description = keymap.description;
|
||||
this.abbreviation = keymap.abbreviation;
|
||||
@@ -32,7 +29,6 @@ export class Keymap extends Serializable<Keymap> {
|
||||
}
|
||||
|
||||
_fromJsObject(jsObject: any): Keymap {
|
||||
this.id = jsObject.id;
|
||||
this.isDefault = jsObject.isDefault;
|
||||
this.abbreviation = jsObject.abbreviation;
|
||||
this.name = jsObject.name;
|
||||
@@ -42,7 +38,6 @@ export class Keymap extends Serializable<Keymap> {
|
||||
}
|
||||
|
||||
_fromBinary(buffer: UhkBuffer): Keymap {
|
||||
this.id = buffer.readUInt8();
|
||||
this.isDefault = buffer.readBoolean();
|
||||
this.abbreviation = buffer.readString();
|
||||
this.name = buffer.readString();
|
||||
@@ -53,7 +48,6 @@ export class Keymap extends Serializable<Keymap> {
|
||||
|
||||
_toJsObject(): any {
|
||||
return {
|
||||
id: this.id,
|
||||
isDefault: this.isDefault,
|
||||
abbreviation: this.abbreviation,
|
||||
name: this.name,
|
||||
@@ -63,7 +57,6 @@ export class Keymap extends Serializable<Keymap> {
|
||||
}
|
||||
|
||||
_toBinary(buffer: UhkBuffer): void {
|
||||
buffer.writeUInt8(this.id);
|
||||
buffer.writeBoolean(this.isDefault);
|
||||
buffer.writeString(this.abbreviation);
|
||||
buffer.writeString(this.name);
|
||||
@@ -72,6 +65,6 @@ export class Keymap extends Serializable<Keymap> {
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return `<Keymap id="${this.id}" name="${this.name}">`;
|
||||
return `<Keymap abbreviation="${this.abbreviation}" name="${this.name}">`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,10 +88,10 @@ export class UhkConfiguration extends Serializable<UhkConfiguration> {
|
||||
return `<UhkConfiguration signature="${this.signature}">`;
|
||||
}
|
||||
|
||||
getKeymap(keymapId: number): Keymap {
|
||||
getKeymap(keymapAbbreviation: string): Keymap {
|
||||
let keymaps: Keymap[] = this.keymaps.elements;
|
||||
for (let i = 0; i < keymaps.length; ++i) {
|
||||
if (keymapId === keymaps[i].id) {
|
||||
if (keymapAbbreviation === keymaps[i].abbreviation) {
|
||||
return keymaps[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,43 @@
|
||||
import { assertUInt8 } from '../../assert';
|
||||
import { UhkBuffer } from '../../UhkBuffer';
|
||||
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||
|
||||
export class SwitchKeymapAction extends KeyAction {
|
||||
|
||||
@assertUInt8
|
||||
keymapId: number;
|
||||
keymapAbbreviation: string;
|
||||
|
||||
constructor(other?: SwitchKeymapAction) {
|
||||
super();
|
||||
if (!other) {
|
||||
return;
|
||||
}
|
||||
this.keymapId = other.keymapId;
|
||||
this.keymapAbbreviation = other.keymapAbbreviation;
|
||||
}
|
||||
|
||||
_fromJsObject(jsObject: any): SwitchKeymapAction {
|
||||
this.assertKeyActionType(jsObject);
|
||||
this.keymapId = jsObject.keymapId;
|
||||
this.keymapAbbreviation = jsObject.keymapAbbreviation;
|
||||
return this;
|
||||
}
|
||||
|
||||
_fromBinary(buffer: UhkBuffer): SwitchKeymapAction {
|
||||
this.readAndAssertKeyActionId(buffer);
|
||||
this.keymapId = buffer.readUInt8();
|
||||
this.keymapAbbreviation = buffer.readString();
|
||||
return this;
|
||||
}
|
||||
|
||||
_toJsObject(): any {
|
||||
return {
|
||||
keyActionType: keyActionType.SwitchKeymapAction,
|
||||
keymapId: this.keymapId
|
||||
keymapAbbreviation: this.keymapAbbreviation
|
||||
};
|
||||
}
|
||||
|
||||
_toBinary(buffer: UhkBuffer) {
|
||||
buffer.writeUInt8(KeyActionId.SwitchKeymapAction);
|
||||
buffer.writeUInt8(this.keymapId);
|
||||
buffer.writeString(this.keymapAbbreviation);
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return `<SwitchKeymapAction keymapId="${this.keymapId}">`;
|
||||
return `<SwitchKeymapAction keymapAbbreviation="${this.keymapAbbreviation}">`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
{
|
||||
"keymaps": [
|
||||
{
|
||||
"id": 0,
|
||||
"isDefault": true,
|
||||
"isDefault": false,
|
||||
"abbreviation": "QTY",
|
||||
"name": "QWERTY",
|
||||
"description": "Maecenas sem dui, ullamcorper consequat pellentesque ut, mattis at velit. Duis scelerisque eleifend gravida. Aenean at mauris rhoncus, dictum mi vitae, semper eros. Quisque maximus est elit, at condimentum ligula consectetur vel. Aenean lorem felis, molestie id ex suscipit, sagittis mollis dui. Phasellus in felis in libero bibendum ornare. Duis vestibulum dolor sed diam tempor vulputate. Curabitur scelerisque pretium ipsum. Phasellus non orci vestibulum, vehicula lectus sit amet, lacinia velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In diam lacus, cursus at pretium vel, ullamcorper at ante.",
|
||||
@@ -381,7 +380,7 @@
|
||||
},
|
||||
{
|
||||
"keyActionType": "switchKeymap",
|
||||
"keymapId": 2
|
||||
"keymapAbbreviation": "VIM"
|
||||
},
|
||||
{
|
||||
"keyActionType": "none"
|
||||
@@ -791,7 +790,6 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"isDefault": false,
|
||||
"abbreviation": "VIM",
|
||||
"name": "VIM",
|
||||
@@ -813,7 +811,7 @@
|
||||
},
|
||||
{
|
||||
"keyActionType": "switchKeymap",
|
||||
"keymapId": 1
|
||||
"keymapAbbreviation": "QTY"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -879,7 +877,6 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"isDefault": false,
|
||||
"abbreviation": "DVR",
|
||||
"name": "DVR",
|
||||
@@ -14,7 +14,6 @@
|
||||
],
|
||||
"keymaps": [
|
||||
{
|
||||
"id": 0,
|
||||
"isDefault": true,
|
||||
"abbreviation": "QTY",
|
||||
"name": "QWERTY",
|
||||
@@ -394,7 +393,7 @@
|
||||
},
|
||||
{
|
||||
"keyActionType": "switchKeymap",
|
||||
"keymapId": 2
|
||||
"keymapAbbreviation": "VIM"
|
||||
},
|
||||
{
|
||||
"keyActionType": "none"
|
||||
@@ -809,7 +808,6 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"isDefault": false,
|
||||
"abbreviation": "VIM",
|
||||
"name": "VIM",
|
||||
@@ -831,7 +829,7 @@
|
||||
},
|
||||
{
|
||||
"keyActionType": "switchKeymap",
|
||||
"keymapId": 1
|
||||
"keymapAbbreviation": "QTY"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -912,7 +910,6 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"isDefault": false,
|
||||
"abbreviation": "DVR",
|
||||
"name": "DVR",
|
||||
|
||||
Reference in New Issue
Block a user