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 { Component, OnInit } from '@angular/core';
import { NoneAction } from '../../../../config-serializer/config-items/key-action';
import { Tab } from '../tab'; import { Tab } from '../tab';
@Component({ @Component({
@@ -21,8 +20,8 @@ export class NoneTabComponent implements OnInit, Tab {
return false; return false;
} }
toKeyAction(): NoneAction { toKeyAction(): undefined {
return new NoneAction(); return undefined;
} }
} }

View File

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

View File

@@ -1,7 +1,7 @@
import { assertEnum, assertUInt8 } from '../assert'; import { assertEnum, assertUInt8 } from '../assert';
import { Serializable } from '../Serializable'; import { Serializable } from '../Serializable';
import { UhkBuffer } from '../UhkBuffer'; import { UhkBuffer } from '../UhkBuffer';
import { Helper as KeyActionHelper, KeyAction } from './key-action'; import { Helper as KeyActionHelper, KeyAction, NoneAction } from './key-action';
enum PointerRole { enum PointerRole {
none, none,
@@ -61,7 +61,17 @@ export class Module extends Serializable<Module> {
_toBinary(buffer: UhkBuffer): void { _toBinary(buffer: UhkBuffer): void {
buffer.writeUInt8(this.id); buffer.writeUInt8(this.id);
buffer.writeUInt8(this.pointerRole); 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 { toString(): string {

View File

@@ -1,6 +1,12 @@
import { UhkBuffer } from '../../UhkBuffer'; import { UhkBuffer } from '../../UhkBuffer';
import { KeyAction, KeyActionId, keyActionType } from './KeyAction'; 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 { export class NoneAction extends KeyAction {
_fromJsObject(jsObject: any): NoneAction { _fromJsObject(jsObject: any): NoneAction {

View File

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

View File

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