From ff22793f7c727c82b3cdbbf953788d9b511ad45d Mon Sep 17 00:00:00 2001 From: Kipstz <140314732+Kipstz@users.noreply.github.com> Date: Tue, 5 Aug 2025 04:48:11 +0200 Subject: [PATCH 01/99] Add auto-upgrade buildings feature with middle mouse click (#1597) ## Description: This PR implements a new feature allowing automatic upgrade of the nearest building using the middle mouse button. This feature greatly simplifies the upgrade process that previously required a right-click + building recreation. ## 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 - [x] I have read and accepted the CLA agreement (only required once). ## Please put your Discord username so you can be contacted if a bug or regression is found: Kipstzz --------- Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- resources/lang/en.json | 1 + src/client/ClientGameRunner.ts | 73 ++++++ src/client/HelpModal.ts | 8 + src/client/InputHandler.ts | 23 ++ tests/AutoUpgrade.test.ts | 155 +++++++++++++ tests/InputHandler.test.ts | 400 +++++++++++++++++++++++++++++++++ 6 files changed, 660 insertions(+) create mode 100644 tests/AutoUpgrade.test.ts create mode 100644 tests/InputHandler.test.ts diff --git a/resources/lang/en.json b/resources/lang/en.json index df37a229fc..e738a8d674 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -43,6 +43,7 @@ "action_move_camera": "Move camera", "action_ratio_change": "Decrease/Increase attack ratio", "action_reset_gfx": "Reset graphics", + "action_auto_upgrade": "Auto-upgrade nearest building", "ui_section": "Game UI", "ui_leaderboard": "Leaderboard", "ui_your_team": "Your team:", diff --git a/src/client/ClientGameRunner.ts b/src/client/ClientGameRunner.ts index b0c3150d8b..6d073fd307 100644 --- a/src/client/ClientGameRunner.ts +++ b/src/client/ClientGameRunner.ts @@ -26,6 +26,7 @@ import { loadTerrainMap, TerrainMapData } from "../core/game/TerrainMapLoader"; import { UserSettings } from "../core/game/UserSettings"; import { WorkerClient } from "../core/worker/WorkerClient"; import { + AutoUpgradeEvent, DoBoatAttackEvent, DoGroundAttackEvent, InputHandler, @@ -40,6 +41,7 @@ import { SendBoatAttackIntentEvent, SendHashEvent, SendSpawnIntentEvent, + SendUpgradeStructureIntentEvent, Transport, } from "./Transport"; import { createCanvas } from "./Utils"; @@ -248,6 +250,7 @@ export class ClientGameRunner { }, 20000); this.eventBus.on(MouseUpEvent, this.inputEvent.bind(this)); this.eventBus.on(MouseMoveEvent, this.onMouseMove.bind(this)); + this.eventBus.on(AutoUpgradeEvent, this.autoUpgradeEvent.bind(this)); this.eventBus.on( DoBoatAttackEvent, this.doBoatAttackUnderCursor.bind(this), @@ -424,6 +427,76 @@ export class ClientGameRunner { }); } + private autoUpgradeEvent(event: AutoUpgradeEvent) { + if (!this.isActive) { + return; + } + + const cell = this.renderer.transformHandler.screenToWorldCoordinates( + event.x, + event.y, + ); + if (!this.gameView.isValidCoord(cell.x, cell.y)) { + return; + } + + const tile = this.gameView.ref(cell.x, cell.y); + + if (this.myPlayer === null) { + const myPlayer = this.gameView.playerByClientID(this.lobby.clientID); + if (myPlayer === null) return; + this.myPlayer = myPlayer; + } + + if (this.gameView.inSpawnPhase()) { + return; + } + + this.findAndUpgradeNearestBuilding(tile); + } + + private findAndUpgradeNearestBuilding(clickedTile: TileRef) { + this.myPlayer!.actions(clickedTile).then((actions) => { + const upgradeUnits: { + unitId: number; + unitType: UnitType; + distance: number; + }[] = []; + + for (const bu of actions.buildableUnits) { + if (bu.canUpgrade !== false) { + const existingUnit = this.gameView + .units() + .find((unit) => unit.id() === bu.canUpgrade); + if (existingUnit) { + const distance = this.gameView.manhattanDist( + clickedTile, + existingUnit.tile(), + ); + + upgradeUnits.push({ + unitId: bu.canUpgrade, + unitType: bu.type, + distance: distance, + }); + } + } + } + + if (upgradeUnits.length > 0) { + upgradeUnits.sort((a, b) => a.distance - b.distance); + const bestUpgrade = upgradeUnits[0]; + + this.eventBus.emit( + new SendUpgradeStructureIntentEvent( + bestUpgrade.unitId, + bestUpgrade.unitType, + ), + ); + } + }); + } + private doBoatAttackUnderCursor(): void { const tile = this.getTileUnderCursor(); if (tile === null) { diff --git a/src/client/HelpModal.ts b/src/client/HelpModal.ts index 97e74be6de..2c9e33cbba 100644 --- a/src/client/HelpModal.ts +++ b/src/client/HelpModal.ts @@ -138,6 +138,14 @@ export class HelpModal extends LitElement {
Sourced from on-headers's releases.
1.1.0
Important
What's Changed
- Migrate CI pipeline to GitHub actions by
@βcarpasse
in jshttp/on-headers#12- fix README.md badges by
@βcarpasse
in jshttp/on-headers#13- add OSSF scorecard action by
@βcarpasse
in jshttp/on-headers#14- fix: use
ubuntu-latest
as ci runner by@βUlisesGascon
in jshttp/on-headers#19- ci: apply OSSF Scorecard security best practices by
@βUlisesGascon
in jshttp/on-headers#20- π· add upstream change detection by
@βctcpip
in jshttp/on-headers#31- β¨ add script to update known hashes by
@βctcpip
in jshttp/on-headers#32- π update CI - add newer node versions by
@βctcpip
in jshttp/on-headers#33New Contributors
@βcarpasse
made their first contribution in jshttp/on-headers#12@βUlisesGascon
made their first contribution in jshttp/on-headers#19@βctcpip
made their first contribution in jshttp/on-headers#31Full Changelog: https://github.com/jshttp/on-headers/compare/v1.0.2...v1.1.0
4b017af
1.1.0b636f2d
β»οΈ refactor header array code3e2c2d4
β¨ ignore falsy header keys, matching node behavior172eb41
β¨ support duplicate headersc6e3849
ποΈ fix array handling6893518
π update CI - add newer node versions56a345d
β¨ add script to update known hashes175ab21
π· add upstream change detection (#31)ce0b2c8
ci: apply OSSF Scorecard security best practices (#20)1a38c54
fix: use ubuntu-latest
as ci runner (#19)This version was pushed to npm by ulisesgascon, a new releaser for on-headers since your current version.
Sourced from compression's releases.
v1.8.1
What's Changed
- fix(docs): update multiple links from http to https by
@βPhillip9587
in expressjs/compression#222- ci: add dependabot for github actions by
@βbjohansebas
in expressjs/compression#207- build(deps): bump github/codeql-action from 2.23.2 to 3.28.15 by
@βdependabot
[bot] in expressjs/compression#228- build(deps): bump ossf/scorecard-action from 2.3.1 to 2.4.1 by
@βdependabot
[bot] in expressjs/compression#229- build(deps-dev): bump eslint-plugin-import from 2.26.0 to 2.31.0 by
@βdependabot
[bot] in expressjs/compression#230- build(deps-dev): bump supertest from 6.2.3 to 6.3.4 by
@βdependabot
[bot] in expressjs/compression#231- [StepSecurity] ci: Harden GitHub Actions by
@βstep-security-bot
in expressjs/compression#235- build(deps): bump github/codeql-action from 3.28.15 to 3.29.2 by
@βdependabot
[bot] in expressjs/compression#243- build(deps): bump actions/upload-artifact from 4.3.1 to 4.6.2 by
@βdependabot
[bot] in expressjs/compression#239- build(deps): bump ossf/scorecard-action from 2.4.1 to 2.4.2 by
@βdependabot
[bot] in expressjs/compression#240- build(deps): bump actions/checkout from 4.1.1 to 4.2.2 by
@βdependabot
[bot] in expressjs/compression#241- build(deps-dev): bump eslint-plugin-import from 2.31.0 to 2.32.0 by
@βdependabot
[bot] in expressjs/compression#244- deps: on-headers@1.1.0 by
@βUlisesGascon
in expressjs/compression#246- Release: 1.8.1 by
@βUlisesGascon
in expressjs/compression#247New Contributors
@βdependabot
[bot] made their first contribution in expressjs/compression#228@βstep-security-bot
made their first contribution in expressjs/compression#235Full Changelog: https://github.com/expressjs/compression/compare/1.8.0...v1.8.1
83a0c45
1.8.1ce62713
deps: on-headers@1.1.0 (#246)f4acb23
build(deps-dev): bump eslint-plugin-import from 2.31.0 to 2.32.0 (#244)6eaebe6
build(deps): bump actions/checkout from 4.1.1 to 4.2.2 (#241)37e0623
build(deps): bump ossf/scorecard-action from 2.4.1 to 2.4.2 (#240)bc436b2
build(deps): bump actions/upload-artifact from 4.3.1 to 4.6.2 (#239)2f9f572
build(deps): bump github/codeql-action from 3.28.15 to 3.29.2 (#243)5f13b14
[StepSecurity] ci: Harden GitHub Actions (#235)76e0945
build(deps-dev): bump supertest from 6.2.3 to 6.3.4 (#231)ae6ee80
build(deps-dev): bump eslint-plugin-import from 2.26.0 to 2.31.0 (#230)