mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 09:14:09 +00:00
Fluentslider rapid-fire bug fix (#2778)
## Description: Describe the PR. Modified FluentSlider(my code) to split number input handle to visual update(NumberInput) and dispatch value(NumberComplete) updated the event flow to match them, will fix rapid-fire updates that seemed to glitch bots out. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: jackochess
This commit is contained in:
@@ -132,7 +132,10 @@ export class LocalServer {
|
|||||||
if (!this.lobbyConfig.gameRecord) {
|
if (!this.lobbyConfig.gameRecord) {
|
||||||
if (clientMsg.turnNumber % 100 === 0) {
|
if (clientMsg.turnNumber % 100 === 0) {
|
||||||
// In singleplayer, only store hash every 100 turns to reduce size of game record.
|
// In singleplayer, only store hash every 100 turns to reduce size of game record.
|
||||||
this.turns[clientMsg.turnNumber].hash = clientMsg.hash;
|
const turn = this.turns[clientMsg.turnNumber];
|
||||||
|
if (turn) {
|
||||||
|
turn.hash = clientMsg.hash;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export class FluentSlider extends LitElement {
|
|||||||
this.dispatchValueChange();
|
this.dispatchValueChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleNumberChange(e: Event) {
|
private handleNumberInput(e: Event) {
|
||||||
const target = e.target as HTMLInputElement;
|
const target = e.target as HTMLInputElement;
|
||||||
let val = target.valueAsNumber;
|
let val = target.valueAsNumber;
|
||||||
if (isNaN(val)) {
|
if (isNaN(val)) {
|
||||||
@@ -93,11 +93,19 @@ export class FluentSlider extends LitElement {
|
|||||||
if (val < this.min) val = this.min;
|
if (val < this.min) val = this.min;
|
||||||
if (val > this.max) val = this.max;
|
if (val > this.max) val = this.max;
|
||||||
this.value = val;
|
this.value = val;
|
||||||
|
// Don't dispatch value change on every input - only on blur/enter
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleNumberComplete() {
|
||||||
|
// Dispatch the value change when editing is complete
|
||||||
this.dispatchValueChange();
|
this.dispatchValueChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleNumberKeyDown(e: KeyboardEvent) {
|
private handleNumberKeyDown(e: KeyboardEvent) {
|
||||||
if (e.key === "Enter") this.isEditing = false;
|
if (e.key === "Enter") {
|
||||||
|
this.isEditing = false;
|
||||||
|
this.handleNumberComplete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enableEditing() {
|
private enableEditing() {
|
||||||
@@ -125,8 +133,11 @@ export class FluentSlider extends LitElement {
|
|||||||
.min=${this.min}
|
.min=${this.min}
|
||||||
.max=${this.max}
|
.max=${this.max}
|
||||||
.valueAsNumber=${this.value}
|
.valueAsNumber=${this.value}
|
||||||
@input=${this.handleNumberChange}
|
@input=${this.handleNumberInput}
|
||||||
@blur=${() => (this.isEditing = false)}
|
@blur=${() => {
|
||||||
|
this.isEditing = false;
|
||||||
|
this.handleNumberComplete();
|
||||||
|
}}
|
||||||
@keydown=${this.handleNumberKeyDown}
|
@keydown=${this.handleNumberKeyDown}
|
||||||
/>`
|
/>`
|
||||||
: html`<span
|
: html`<span
|
||||||
|
|||||||
Reference in New Issue
Block a user