Rename SwitchLayerAction.ts to SwitchKeymapAction.ts and vice versa, so that these files contain their relevant classes.
This commit is contained in:
@@ -1,99 +1,41 @@
|
|||||||
function assertUInt8(target: any, key: string) {
|
class SwitchKeymapAction extends KeyAction implements Serializable<SwitchKeymapAction> {
|
||||||
let val = this[key];
|
|
||||||
if (delete this[key]) {
|
|
||||||
Object.defineProperty(target, key, {
|
|
||||||
get: function () {
|
|
||||||
return val;
|
|
||||||
},
|
|
||||||
set: function (newVal) {
|
|
||||||
if (newVal < 0 || newVal > 255) {
|
|
||||||
throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not uint8`;
|
|
||||||
}
|
|
||||||
val = newVal;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertEnum<E>(enumerated: E) {
|
static keyActionTypeString = 'switchKeymap';
|
||||||
return function(target: any, key: string) {
|
|
||||||
let val = this[key];
|
|
||||||
if (delete this[key]) {
|
|
||||||
Object.defineProperty(target, key, {
|
|
||||||
get: function () {
|
|
||||||
return val;
|
|
||||||
},
|
|
||||||
set: function (newVal) {
|
|
||||||
if (enumerated[newVal] === undefined) {
|
|
||||||
throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not enum`;
|
|
||||||
}
|
|
||||||
val = newVal;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Layer {
|
private _keymapId: number;
|
||||||
mod,
|
|
||||||
fn,
|
|
||||||
mouse
|
|
||||||
}
|
|
||||||
|
|
||||||
class SwitchLayerAction extends KeyAction implements Serializable<SwitchLayerAction> {
|
get keymapId(): number {
|
||||||
|
return this._keymapId;
|
||||||
static keyActionTypeString = 'switchLayer';
|
|
||||||
static toggleFlag = 0x80;
|
|
||||||
|
|
||||||
isLayerToggleable: boolean;
|
|
||||||
|
|
||||||
@assertEnum(Layer)
|
|
||||||
private layer: Layer;
|
|
||||||
/*
|
|
||||||
get layer(): number {
|
|
||||||
return this._layer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set layer(value) {
|
set keymapId(value) {
|
||||||
if (!TypeChecker.isUInt8Valid(value)) {
|
if (!TypeChecker.isUInt8Valid(value)) {
|
||||||
throw 'Invalid SwitchLayerAction.layerId: ${value}';
|
throw `Invalid SwitchKeymapAction.keymapId: ${value}`;
|
||||||
}
|
}
|
||||||
this._layer = value;
|
this._keymapId = value;
|
||||||
}
|
|
||||||
*/
|
|
||||||
getToggleFlag() {
|
|
||||||
return this.isLayerToggleable ? SwitchLayerAction.toggleFlag : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJsObject(jsObject: any): SwitchLayerAction {
|
fromJsObject(jsObject: any): SwitchKeymapAction {
|
||||||
this.assertKeyActionType(jsObject, SwitchLayerAction.keyActionTypeString, 'SwitchLayerAction');
|
this.assertKeyActionType(jsObject, SwitchKeymapAction.keyActionTypeString, 'SwitchKeymapAction');
|
||||||
this.layer = jsObject.layerId;
|
this.keymapId = jsObject.keymapId;
|
||||||
this.isLayerToggleable = jsObject.toggle;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromBinary(buffer: UhkBuffer): SwitchLayerAction {
|
fromBinary(buffer: UhkBuffer): SwitchKeymapAction {
|
||||||
this.readAndAssertKeyActionId(buffer, KeyActionId.SwitchLayerAction, 'SwitchLayerAction');
|
this.readAndAssertKeyActionId(buffer, KeyActionId.SwitchKeymapAction, 'SwitchKeymapAction');
|
||||||
this.layer = buffer.readUInt8();
|
this.keymapId = buffer.readUInt8();
|
||||||
this.isLayerToggleable = (this.layer & SwitchLayerAction.toggleFlag) !== 0;
|
|
||||||
this.layer &= ~SwitchLayerAction.toggleFlag; // Clear toggle bit.
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: SwitchLayerAction.keyActionTypeString,
|
keyActionType: SwitchKeymapAction.keyActionTypeString,
|
||||||
layer: this.layer,
|
keymapId: this.keymapId
|
||||||
toggle: this.isLayerToggleable
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
toBinary(buffer: UhkBuffer) {
|
toBinary(buffer: UhkBuffer) {
|
||||||
buffer.writeUInt8(KeyActionId.SwitchLayerAction);
|
buffer.writeUInt8(KeyActionId.SwitchKeymapAction);
|
||||||
buffer.writeUInt8(this.layer | this.getToggleFlag());
|
buffer.writeUInt8(this.keymapId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,99 @@
|
|||||||
class SwitchKeymapAction extends KeyAction implements Serializable<SwitchKeymapAction> {
|
function assertUInt8(target: any, key: string) {
|
||||||
|
let val = this[key];
|
||||||
static keyActionTypeString = 'switchKeymap';
|
if (delete this[key]) {
|
||||||
|
Object.defineProperty(target, key, {
|
||||||
private _keymapId: number;
|
get: function () {
|
||||||
|
return val;
|
||||||
get keymapId(): number {
|
},
|
||||||
return this._keymapId;
|
set: function (newVal) {
|
||||||
|
if (newVal < 0 || newVal > 255) {
|
||||||
|
throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not uint8`;
|
||||||
|
}
|
||||||
|
val = newVal;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
set keymapId(value) {
|
function assertEnum<E>(enumerated: E) {
|
||||||
if (!TypeChecker.isUInt8Valid(value)) {
|
return function(target: any, key: string) {
|
||||||
throw `Invalid SwitchKeymapAction.keymapId: ${value}`;
|
let val = this[key];
|
||||||
|
if (delete this[key]) {
|
||||||
|
Object.defineProperty(target, key, {
|
||||||
|
get: function () {
|
||||||
|
return val;
|
||||||
|
},
|
||||||
|
set: function (newVal) {
|
||||||
|
if (enumerated[newVal] === undefined) {
|
||||||
|
throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not enum`;
|
||||||
|
}
|
||||||
|
val = newVal;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
this._keymapId = value;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Layer {
|
||||||
|
mod,
|
||||||
|
fn,
|
||||||
|
mouse
|
||||||
|
}
|
||||||
|
|
||||||
|
class SwitchLayerAction extends KeyAction implements Serializable<SwitchLayerAction> {
|
||||||
|
|
||||||
|
static keyActionTypeString = 'switchLayer';
|
||||||
|
static toggleFlag = 0x80;
|
||||||
|
|
||||||
|
isLayerToggleable: boolean;
|
||||||
|
|
||||||
|
@assertEnum(Layer)
|
||||||
|
private layer: Layer;
|
||||||
|
/*
|
||||||
|
get layer(): number {
|
||||||
|
return this._layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJsObject(jsObject: any): SwitchKeymapAction {
|
set layer(value) {
|
||||||
this.assertKeyActionType(jsObject, SwitchKeymapAction.keyActionTypeString, 'SwitchKeymapAction');
|
if (!TypeChecker.isUInt8Valid(value)) {
|
||||||
this.keymapId = jsObject.keymapId;
|
throw 'Invalid SwitchLayerAction.layerId: ${value}';
|
||||||
|
}
|
||||||
|
this._layer = value;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
getToggleFlag() {
|
||||||
|
return this.isLayerToggleable ? SwitchLayerAction.toggleFlag : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fromJsObject(jsObject: any): SwitchLayerAction {
|
||||||
|
this.assertKeyActionType(jsObject, SwitchLayerAction.keyActionTypeString, 'SwitchLayerAction');
|
||||||
|
this.layer = jsObject.layerId;
|
||||||
|
this.isLayerToggleable = jsObject.toggle;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromBinary(buffer: UhkBuffer): SwitchKeymapAction {
|
fromBinary(buffer: UhkBuffer): SwitchLayerAction {
|
||||||
this.readAndAssertKeyActionId(buffer, KeyActionId.SwitchKeymapAction, 'SwitchKeymapAction');
|
this.readAndAssertKeyActionId(buffer, KeyActionId.SwitchLayerAction, 'SwitchLayerAction');
|
||||||
this.keymapId = buffer.readUInt8();
|
this.layer = buffer.readUInt8();
|
||||||
|
this.isLayerToggleable = (this.layer & SwitchLayerAction.toggleFlag) !== 0;
|
||||||
|
this.layer &= ~SwitchLayerAction.toggleFlag; // Clear toggle bit.
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: SwitchKeymapAction.keyActionTypeString,
|
keyActionType: SwitchLayerAction.keyActionTypeString,
|
||||||
keymapId: this.keymapId
|
layer: this.layer,
|
||||||
|
toggle: this.isLayerToggleable
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
toBinary(buffer: UhkBuffer) {
|
toBinary(buffer: UhkBuffer) {
|
||||||
buffer.writeUInt8(KeyActionId.SwitchKeymapAction);
|
buffer.writeUInt8(KeyActionId.SwitchLayerAction);
|
||||||
buffer.writeUInt8(this.keymapId);
|
buffer.writeUInt8(this.layer | this.getToggleFlag());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user