Refactor: Replace NoneAction with null in JSON representation

This commit is contained in:
Farkas József
2016-11-26 20:54:11 +01:00
parent c42cff71ae
commit 6bbcacfbe6
8 changed files with 290 additions and 812 deletions

View File

@@ -1,6 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { NoneAction } from '../../../../config-serializer/config-items/key-action';
import { Tab } from '../tab';
@Component({
@@ -21,8 +20,8 @@ export class NoneTabComponent implements OnInit, Tab {
return false;
}
toKeyAction(): NoneAction {
return new NoneAction();
toKeyAction(): undefined {
return undefined;
}
}

View File

@@ -28,7 +28,6 @@ import {
LayerName,
MouseAction,
MouseActionParam,
NoneAction,
PlayMacroAction,
SwitchKeymapAction,
SwitchLayerAction
@@ -165,7 +164,7 @@ export class SvgKeyboardWrapComponent implements OnChanges {
showTooltip(keyAction: KeyAction, event: MouseEvent): void {
if (keyAction instanceof NoneAction || keyAction === undefined) {
if (keyAction === undefined) {
return;
}

View File

@@ -1,7 +1,7 @@
import { assertEnum, assertUInt8 } from '../assert';
import { Serializable } from '../Serializable';
import { UhkBuffer } from '../UhkBuffer';
import { Helper as KeyActionHelper, KeyAction } from './key-action';
import { Helper as KeyActionHelper, KeyAction, NoneAction } from './key-action';
enum PointerRole {
none,
@@ -61,7 +61,17 @@ export class Module extends Serializable<Module> {
_toBinary(buffer: UhkBuffer): void {
buffer.writeUInt8(this.id);
buffer.writeUInt8(this.pointerRole);
buffer.writeArray(this.keyActions);
const noneAction = new NoneAction();
const keyActions: KeyAction[] = this.keyActions.map(keyAction => {
if (keyAction) {
return keyAction;
}
return noneAction;
});
buffer.writeArray(keyActions);
}
toString(): string {

View File

@@ -1,6 +1,12 @@
import { UhkBuffer } from '../../UhkBuffer';
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
/**
* NoneAction is only intended for binary serialization of undefined key actions
* DO NOT use it as a real KeyAction
*
*/
export class NoneAction extends KeyAction {
_fromJsObject(jsObject: any): NoneAction {

View File

@@ -4,7 +4,6 @@ import {
KeyActionId,
KeystrokeAction,
MouseAction,
NoneAction,
PlayMacroAction,
SwitchKeymapAction,
SwitchLayerAction,
@@ -33,7 +32,8 @@ export class Helper {
switch (keyActionFirstByte) {
case KeyActionId.NoneAction:
return new NoneAction().fromBinary(buffer);
buffer.readUInt8(); // Read type just to skip it
return undefined;
case KeyActionId.SwitchLayerAction:
return new SwitchLayerAction().fromBinary(buffer);
case KeyActionId.SwitchKeymapAction:
@@ -59,8 +59,6 @@ export class Helper {
newKeyAction = new MouseAction(keyAction);
} else if (keyAction instanceof PlayMacroAction) {
newKeyAction = new PlayMacroAction(keyAction);
} else {
newKeyAction = new NoneAction();
}
return newKeyAction;
}
@@ -71,8 +69,6 @@ export class Helper {
}
switch (keyAction.keyActionType) {
case keyActionType.NoneAction:
return new NoneAction().fromJsObject(keyAction);
case keyActionType.KeystrokeAction:
return new KeystrokeAction().fromJsObject(keyAction);
case keyActionType.SwitchLayerAction:

View File

@@ -34,12 +34,14 @@
"keyActions": {
"type": "array",
"items": {
"type": "object",
"type": [
"null",
"object"
],
"properties": {
"keyActionType": {
"type": "string",
"enum": [
"none",
"keystroke",
"switchLayer",
"switchKeymap",
@@ -51,7 +53,7 @@
"required": [
"keyActionType"
],
"oneOf": [
"anyOf": [
{
"properties": {
"keyActionType": {
@@ -137,16 +139,6 @@
"type": "integer"
}
}
},
{
"properties": {
"keyActionType": {
"type": "string",
"enum": [
"none"
]
}
}
}
]
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff