Add KeyActionNone
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
|
/// <reference path="KeyActionNone.ts" />
|
||||||
/// <reference path="KeystrokeAction.ts" />
|
/// <reference path="KeystrokeAction.ts" />
|
||||||
|
|
||||||
class KeyAction {
|
class KeyAction {
|
||||||
|
|
||||||
static fromJsObject(jsObject: any): KeyAction {
|
static fromJsObject(jsObject: any): KeyAction {
|
||||||
switch (jsObject.actionType) {
|
switch (jsObject.actionType) {
|
||||||
|
case 'none':
|
||||||
|
let keyActionNone = new KeyActionNone();
|
||||||
|
keyActionNone.fromJsObject(jsObject);
|
||||||
|
return keyActionNone;
|
||||||
case 'keyStroke':
|
case 'keyStroke':
|
||||||
let keystrokeAction = new KeystrokeAction();
|
let keystrokeAction = new KeystrokeAction();
|
||||||
keystrokeAction.fromJsObject(jsObject);
|
keystrokeAction.fromJsObject(jsObject);
|
||||||
@@ -17,12 +22,14 @@ class KeyAction {
|
|||||||
let keyActionFirstByte = buffer.readUInt8();
|
let keyActionFirstByte = buffer.readUInt8();
|
||||||
buffer.backtrack();
|
buffer.backtrack();
|
||||||
|
|
||||||
if (KeystrokeAction.firstValidScancode <= keyActionFirstByte &&
|
if (KeystrokeAction.isScancodeValid(keyActionFirstByte)) {
|
||||||
keyActionFirstByte <= KeystrokeAction.lastValidScancode)
|
|
||||||
{
|
|
||||||
let keystrokeAction = new KeystrokeAction();
|
let keystrokeAction = new KeystrokeAction();
|
||||||
keystrokeAction.fromBinary(buffer);
|
keystrokeAction.fromBinary(buffer);
|
||||||
return keystrokeAction;
|
return keystrokeAction;
|
||||||
|
} else if (keyActionFirstByte === KeyActionNone.keyActionNoneId) {
|
||||||
|
let keyActionNone = new KeyActionNone();
|
||||||
|
keyActionNone.fromBinary(buffer);
|
||||||
|
return keyActionNone;
|
||||||
} else {
|
} else {
|
||||||
throw 'Unknown KeyAction first byte "${keyActionFirstByte}"';
|
throw 'Unknown KeyAction first byte "${keyActionFirstByte}"';
|
||||||
}
|
}
|
||||||
|
|||||||
36
model/KeyActionNone.ts
Normal file
36
model/KeyActionNone.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/// <reference path="KeyAction.ts" />
|
||||||
|
/// <reference path="Serializable.ts" />
|
||||||
|
|
||||||
|
class KeyActionNone extends KeyAction implements Serializable {
|
||||||
|
static keyActionNoneId = 0;
|
||||||
|
static keyActionNoneParam = 0;
|
||||||
|
|
||||||
|
fromJsObject(jsObject: any) {
|
||||||
|
if (jsObject.actionType !== 'none') {
|
||||||
|
throw 'KeyActionNone: The actionType is not "none"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fromBinary(buffer: UhkBuffer) {
|
||||||
|
let keyActionId = buffer.readUInt8();
|
||||||
|
if (keyActionId !== KeyActionNone.keyActionNoneId) {
|
||||||
|
throw 'KeyActionNone: id is ${keyActionId} instead of ${KeyActionNone.keyActionNoneId}';
|
||||||
|
}
|
||||||
|
|
||||||
|
let keyActionParam = buffer.readUInt8();
|
||||||
|
if (keyActionParam !== KeyActionNone.keyActionNoneParam) {
|
||||||
|
throw 'KeyActionNone: The param is ${keyActionParam} instead of ${KeyActionNone.keyActionNoneParam}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toJsObject(): any {
|
||||||
|
return {
|
||||||
|
actionType: 'none'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
toBinary(buffer: UhkBuffer) {
|
||||||
|
buffer.writeUInt8(KeyActionNone.keyActionNoneId);
|
||||||
|
buffer.writeUInt8(KeyActionNone.keyActionNoneParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
],
|
],
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
100
|
120
|
||||||
],
|
],
|
||||||
"no-trailing-whitespace": true,
|
"no-trailing-whitespace": true,
|
||||||
"trailing-comma": [
|
"trailing-comma": [
|
||||||
|
|||||||
Reference in New Issue
Block a user