Add KeyActionNone
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
/// <reference path="KeyActionNone.ts" />
|
||||
/// <reference path="KeystrokeAction.ts" />
|
||||
|
||||
class KeyAction {
|
||||
|
||||
static fromJsObject(jsObject: any): KeyAction {
|
||||
switch (jsObject.actionType) {
|
||||
case 'none':
|
||||
let keyActionNone = new KeyActionNone();
|
||||
keyActionNone.fromJsObject(jsObject);
|
||||
return keyActionNone;
|
||||
case 'keyStroke':
|
||||
let keystrokeAction = new KeystrokeAction();
|
||||
keystrokeAction.fromJsObject(jsObject);
|
||||
@@ -17,12 +22,14 @@ class KeyAction {
|
||||
let keyActionFirstByte = buffer.readUInt8();
|
||||
buffer.backtrack();
|
||||
|
||||
if (KeystrokeAction.firstValidScancode <= keyActionFirstByte &&
|
||||
keyActionFirstByte <= KeystrokeAction.lastValidScancode)
|
||||
{
|
||||
if (KeystrokeAction.isScancodeValid(keyActionFirstByte)) {
|
||||
let keystrokeAction = new KeystrokeAction();
|
||||
keystrokeAction.fromBinary(buffer);
|
||||
return keystrokeAction;
|
||||
} else if (keyActionFirstByte === KeyActionNone.keyActionNoneId) {
|
||||
let keyActionNone = new KeyActionNone();
|
||||
keyActionNone.fromBinary(buffer);
|
||||
return keyActionNone;
|
||||
} else {
|
||||
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": [
|
||||
true,
|
||||
100
|
||||
120
|
||||
],
|
||||
"no-trailing-whitespace": true,
|
||||
"trailing-comma": [
|
||||
|
||||
Reference in New Issue
Block a user