diff --git a/packages/uhk-common/src/config-serializer/assert.ts b/packages/uhk-common/src/config-serializer/assert.ts index 75482050758..da685b2689f 100644 --- a/packages/uhk-common/src/config-serializer/assert.ts +++ b/packages/uhk-common/src/config-serializer/assert.ts @@ -1,31 +1,41 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +export const INT8_MIN = -0x80; +export const INT8_MAX = 0x7F; +export const INT16_MIN = -0x8000; +export const INT16_MAX = 0x7FFF; +export const INT32_MIN = -0x80000000; +export const INT32_MAX = 0x7FFFFFFF; +export const UINT8_MAX = 0xFF; +export const UINT16_MAX = 0xFFFF; +export const UINT32_MAX = 0xFFFFFFFF; + export function assertUInt8(target: any, key: string) { - return assertInteger(target, key, 0, 0xFF); + return assertInteger(target, key, 0, UINT8_MAX); } export function assertInt8(target: any, key: string) { - return assertInteger(target, key, -0x80, 0x7F); + return assertInteger(target, key, INT8_MIN, INT8_MAX); } export function assertUInt16(target: any, key: string) { - return assertInteger(target, key, 0, 0xFFFF); + return assertInteger(target, key, 0, UINT16_MAX); } export function assertInt16(target: any, key: string) { - return assertInteger(target, key, -0x8000, 0x7FFF); + return assertInteger(target, key, INT16_MIN, INT16_MAX); } export function assertUInt32(target: any, key: string) { - return assertInteger(target, key, 0, 0xFFFFFFFF); + return assertInteger(target, key, 0, UINT32_MAX); } export function assertInt32(target: any, key: string) { - return assertInteger(target, key, -0x80000000, 0x7FFFFFFF); + return assertInteger(target, key, INT32_MIN, INT32_MAX); } export function assertFloat(target: any, key: string) { - return assertInteger(target, key, -0x80000000, 0x7FFFFFFF); + return assertInteger(target, key, INT32_MIN, INT32_MAX); } export function assertCompactLength(target: any, key: string) { diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.html b/packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.html index f9ba3799f39..43f727bd2b8 100644 --- a/packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.html +++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.html @@ -10,12 +10,12 @@

Delay

+ (ngModelChange)="setDelay(macroDelayInput.valueAsNumber)"> seconds diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.ts b/packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.ts index 20d243e288e..e3f110ec3c4 100644 --- a/packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.ts +++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.ts @@ -4,11 +4,12 @@ import { Input, OnInit } from '@angular/core'; -import { DelayMacroAction } from 'uhk-common'; +import { DelayMacroAction, UINT16_MAX } from 'uhk-common'; import { MacroBaseComponent } from '../macro-base.component'; const INITIAL_DELAY = 0.5; // In seconds +const MAX_DELAY_SECONDS = UINT16_MAX / 1000; @Component({ selector: 'macro-delay-tab', @@ -21,6 +22,7 @@ const INITIAL_DELAY = 0.5; // In seconds export class MacroDelayTabComponent extends MacroBaseComponent implements OnInit { @Input() macroAction: DelayMacroAction; + maxDelaySeconds = MAX_DELAY_SECONDS; presets: number[] = [0.1, 0.5, 1, 5, 10]; get delay(): number { @@ -44,11 +46,15 @@ export class MacroDelayTabComponent extends MacroBaseComponent implements OnInit } setDelay(value: number): void { - this._delay = Math.min(value, 65); - this.macroAction.delay = this._delay * 1000; - this.validate(); + if (Number.isNaN(value)) { + return; + } + + const delayMs = Math.min(Math.max(Math.round(value * 1000), 0), UINT16_MAX); + this.macroAction.delay = delayMs; + this.delay = delayMs / 1000; } - isMacroValid = () => this.macroAction.delay !== 0; + isMacroValid = () => this.macroAction.delay > 0 && this.macroAction.delay <= UINT16_MAX; } diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.html b/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.html index 7720d59ab71..191006f83a0 100644 --- a/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.html +++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.html @@ -42,22 +42,22 @@

Move mouse pointer

pixels + [ngModel]="macroAction['x']" + (ngModelChange)="setCoordinate('x', $event)" + [min]="INT16_MIN" + [max]="INT16_MAX" + maxlength="6"> pixels
pixels + [ngModel]="macroAction['y']" + (ngModelChange)="setCoordinate('y', $event)" + [min]="INT16_MIN" + [max]="INT16_MAX" + maxlength="6"> pixels
@@ -69,22 +69,22 @@

Scroll with mouse

pixels + [ngModel]="macroAction['x']" + (ngModelChange)="setCoordinate('x', $event)" + [min]="INT16_MIN" + [max]="INT16_MAX" + maxlength="6"> pixels
pixels + [ngModel]="macroAction['y']" + (ngModelChange)="setCoordinate('y', $event)" + [min]="INT16_MIN" + [max]="INT16_MAX" + maxlength="6"> pixels
diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts b/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts index 96e7fac2ea4..f3151a36226 100644 --- a/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts +++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts @@ -2,6 +2,8 @@ import { Component, Input, OnChanges, OnInit } from '@angular/core'; import { faArrowsAlt, faArrowsAltV, faHandPaper, faHandRock, faMousePointer } from '@fortawesome/free-solid-svg-icons'; import { + INT16_MAX, + INT16_MIN, MacroMouseSubAction, MouseButtons, MouseButtonMacroAction, @@ -33,6 +35,8 @@ enum TabName { export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit, OnChanges { @Input() macroAction: MouseMacroAction; + INT16_MAX = INT16_MAX; + INT16_MIN = INT16_MIN; MouseButtons = MouseButtons; TabName = TabName; activeTab: TabName; @@ -114,6 +118,17 @@ export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit } } + setCoordinate(axis: 'x' | 'y', value: number | string): void { + const numericValue = Number(value); + if (Number.isNaN(numericValue)) { + return; + } + + const action = this.macroAction as MoveMouseMacroAction | ScrollMouseMacroAction; + action[axis] = Math.min(Math.max(Math.round(numericValue), INT16_MIN), INT16_MAX); + this.validate(); + } + getTabName(action: MouseMacroAction): TabName { if (action instanceof MouseButtonMacroAction) { if (!action.action || action.isOnlyClickAction()) { @@ -137,7 +152,9 @@ export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit case ScrollMouseMacroAction: { const { x, y } = this.macroAction as MoveMouseMacroAction; return x !== undefined && x !== null && y !== undefined && y !== null && - (x !== 0 || y !== 0) && x < 10000 && x > -10000 && y < 10000 && y > -10000; + (x !== 0 || y !== 0) && + x >= INT16_MIN && x <= INT16_MAX && + y >= INT16_MIN && y <= INT16_MAX; } case MouseButtonMacroAction: {