-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: hold middle-click to continuously upgrade buildings #3821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,6 +159,25 @@ export class UserSettings { | |
| return this.getBool("settings.leftClickOpensMenu", false); | ||
| } | ||
|
|
||
| holdMiddleClickUpgrade() { | ||
| return this.getBool("settings.holdMiddleClickUpgrade", true); | ||
| } | ||
|
|
||
| holdMiddleClickUpgradeSpeed(): number { | ||
| return this.getFloat("settings.holdMiddleClickUpgradeSpeed", 150); | ||
| } | ||
|
|
||
| toggleHoldMiddleClickUpgrade() { | ||
| this.setBool( | ||
| "settings.holdMiddleClickUpgrade", | ||
| !this.holdMiddleClickUpgrade(), | ||
| ); | ||
| } | ||
|
|
||
| setHoldMiddleClickUpgradeSpeed(value: number): void { | ||
| this.setFloat("settings.holdMiddleClickUpgradeSpeed", value); | ||
|
Comment on lines
+166
to
+178
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clamp the hold speed before persisting it. A negative or 🛠️ Suggested fix holdMiddleClickUpgradeSpeed(): number {
- return this.getFloat("settings.holdMiddleClickUpgradeSpeed", 150);
+ const raw = this.getFloat("settings.holdMiddleClickUpgradeSpeed", 150);
+ if (!Number.isFinite(raw)) return 150;
+ return Math.min(500, Math.max(50, Math.round(raw)));
}
@@
setHoldMiddleClickUpgradeSpeed(value: number): void {
- this.setFloat("settings.holdMiddleClickUpgradeSpeed", value);
+ const normalized = Number.isFinite(value) ? Math.round(value) : 150;
+ this.setFloat(
+ "settings.holdMiddleClickUpgradeSpeed",
+ Math.min(500, Math.max(50, normalized)),
+ );
}🤖 Prompt for AI Agents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🧠 Learnings usedFailed to handle agent chat message. Please try again. |
||
| } | ||
|
|
||
| territoryPatterns() { | ||
| return this.getBool("settings.territoryPatterns", true); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear the middle-click timers outside
pointeruptoo.If focus changes or the handler is torn down while the button is still held, these timer handles can survive and keep emitting
AutoUpgradeEvents in the background. Please route the cleanup through one helper and call it from blur/teardown as well.🔧 Suggested cleanup helper
Call it from the middle-button release path, the blur handler, and
destroy().🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evanpelle, here's the fix — a singleclearHoldUpgradeTimers()helper called from all three places:1. Replace the inline cleanup in
onPointerUp:onPointerUp(event: PointerEvent) { if (event.button === 1) { event.preventDefault(); - clearTimeout(this.holdUpgradeTimeout); - clearInterval(this.holdUpgradeInterval); - this.holdUpgradeTimeout = undefined; - this.holdUpgradeInterval = undefined; + this.clearHoldUpgradeTimers(); return; }2. Add cleanup in the
blurhandler (insideinitialize()):window.addEventListener("blur", () => { this.activeKeys.clear(); if (this.alternateView) { this.alternateView = false; this.eventBus.emit(new AlternateViewEvent(false)); } this.pointerDown = false; this.pointers.clear(); + this.clearHoldUpgradeTimers(); if (this.longPressTimer !== null) {3. Add cleanup in
destroy():destroy() { if (this.moveInterval !== null) { clearInterval(this.moveInterval); } + this.clearHoldUpgradeTimers(); this.activeKeys.clear(); }This keeps the logic in one place and makes sure the upgrade loop stops on focus loss or teardown — not just on mouse-up.
🧠 Learnings used
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!