Skip to content

Commit 70767d2

Browse files
authored
Fluentslider rapid-fire bug fix (openfrontio#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
1 parent af0b8a8 commit 70767d2

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/client/LocalServer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ export class LocalServer {
132132
if (!this.lobbyConfig.gameRecord) {
133133
if (clientMsg.turnNumber % 100 === 0) {
134134
// In singleplayer, only store hash every 100 turns to reduce size of game record.
135-
this.turns[clientMsg.turnNumber].hash = clientMsg.hash;
135+
const turn = this.turns[clientMsg.turnNumber];
136+
if (turn) {
137+
turn.hash = clientMsg.hash;
138+
}
136139
}
137140
return;
138141
}

src/client/components/FluentSlider.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class FluentSlider extends LitElement {
8484
this.dispatchValueChange();
8585
}
8686

87-
private handleNumberChange(e: Event) {
87+
private handleNumberInput(e: Event) {
8888
const target = e.target as HTMLInputElement;
8989
let val = target.valueAsNumber;
9090
if (isNaN(val)) {
@@ -93,11 +93,19 @@ export class FluentSlider extends LitElement {
9393
if (val < this.min) val = this.min;
9494
if (val > this.max) val = this.max;
9595
this.value = val;
96+
// Don't dispatch value change on every input - only on blur/enter
97+
}
98+
99+
private handleNumberComplete() {
100+
// Dispatch the value change when editing is complete
96101
this.dispatchValueChange();
97102
}
98103

99104
private handleNumberKeyDown(e: KeyboardEvent) {
100-
if (e.key === "Enter") this.isEditing = false;
105+
if (e.key === "Enter") {
106+
this.isEditing = false;
107+
this.handleNumberComplete();
108+
}
101109
}
102110

103111
private enableEditing() {
@@ -125,8 +133,11 @@ export class FluentSlider extends LitElement {
125133
.min=${this.min}
126134
.max=${this.max}
127135
.valueAsNumber=${this.value}
128-
@input=${this.handleNumberChange}
129-
@blur=${() => (this.isEditing = false)}
136+
@input=${this.handleNumberInput}
137+
@blur=${() => {
138+
this.isEditing = false;
139+
this.handleNumberComplete();
140+
}}
130141
@keydown=${this.handleNumberKeyDown}
131142
/>`
132143
: html`<span

0 commit comments

Comments
 (0)