Move the classes of the config items into the newly created config-items directory.

This commit is contained in:
László Monda
2016-03-29 02:05:59 +02:00
parent ecb9d6f73c
commit 03dbf3a142
5 changed files with 4 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
class KeyAction {
static fromJsObject(jsObject: any): KeyAction {
switch (jsObject.keyActionType) {
case KeystrokeAction.actionTypeString:
return new KeystrokeAction().fromJsObject(jsObject);
case KeyActionNone.actionTypeString:
return new KeyActionNone().fromJsObject(jsObject);
default:
throw 'Invalid KeyAction.keyActionType: "${jsObject.actionType}"';
}
}
static fromBinary(buffer: UhkBuffer): KeyAction {
let keyActionFirstByte = buffer.readUInt8();
buffer.backtrack();
if (KeystrokeAction.isScancodeValid(keyActionFirstByte)) {
return new KeystrokeAction().fromBinary(buffer);
} else if (keyActionFirstByte === KeyActionNone.keyActionNoneId) {
return new KeyActionNone().fromBinary(buffer);
} else {
throw 'Invalid KeyAction first byte "${keyActionFirstByte}"';
}
}
}

View File

@@ -0,0 +1,38 @@
class KeyActionNone extends KeyAction implements Serializable<KeyActionNone> {
static actionTypeString = 'none';
static keyActionNoneId = 0;
static keyActionNoneParam = 0;
fromJsObject(jsObject: any): KeyActionNone {
if (jsObject.keyActionType !== KeyActionNone.actionTypeString) {
throw 'Invalid KeyActionNone.keyActionType: "${jsObject.keyActionType}"';
}
return this;
}
fromBinary(buffer: UhkBuffer): KeyActionNone {
let keyActionId = buffer.readUInt8();
if (keyActionId !== KeyActionNone.keyActionNoneId) {
throw 'Invalid KeyActionNone.id: ${keyActionId}';
}
let keyActionParam = buffer.readUInt8();
if (keyActionParam !== KeyActionNone.keyActionNoneParam) {
throw 'Invalid KeyActionNone.param: ${keyActionParam}';
}
return this;
}
toJsObject(): any {
return {
keyActionType: KeyActionNone.actionTypeString
};
}
toBinary(buffer: UhkBuffer) {
buffer.writeUInt8(KeyActionNone.keyActionNoneId);
buffer.writeUInt8(KeyActionNone.keyActionNoneParam);
}
}

View File

@@ -0,0 +1,50 @@
class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction> {
static actionTypeString = 'keystroke';
static firstValidScancode = 1;
static lastValidScancode = 231;
_scancode: number;
modifierMask: number;
get scancode() {
return this._scancode;
}
set scancode(value) {
if (!KeystrokeAction.isScancodeValid(value)) {
throw 'Invalid KeystrokeAction.scancode: ${scancode}';
}
this._scancode = value;
}
static isScancodeValid(scancode) {
return KeystrokeAction.firstValidScancode <= scancode &&
scancode <= KeystrokeAction.lastValidScancode;
}
fromJsObject(jsObject: any): KeystrokeAction {
this.scancode = jsObject.scancode;
this.modifierMask = jsObject.modifierMask;
return this;
}
fromBinary(buffer: UhkBuffer): KeystrokeAction {
this.scancode = buffer.readUInt8();
this.modifierMask = buffer.readUInt8();
return this;
}
toJsObject(): any {
return {
keyActionType: KeystrokeAction.actionTypeString,
scancode: this.scancode,
modifierMask: this.modifierMask
};
}
toBinary(buffer: UhkBuffer) {
buffer.writeUInt8(this.scancode);
buffer.writeUInt8(this.modifierMask);
}
}

View File

@@ -0,0 +1,3 @@
/// <reference path="KeyAction.ts" />
/// <reference path="KeystrokeAction.ts" />
/// <reference path="KeyActionNone.ts" />