mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 22:51:57 +00:00
Center map on start (#1013)
## Description: - Adds logic to hard-set the transform handler directly to a new position, without a movement animation - Implements #1004    - removed a second initialization of the TransformHandler to prevent transformation desyncs between layers. Incidentally this probably fixes #62 ## 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 understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: demonessica --------- Co-authored-by: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com>
This commit is contained in:
@@ -265,11 +265,8 @@ export class GameRenderer {
|
||||
window.addEventListener("resize", () => this.resizeCanvas());
|
||||
this.resizeCanvas();
|
||||
|
||||
this.transformHandler = new TransformHandler(
|
||||
this.game,
|
||||
this.eventBus,
|
||||
this.canvas,
|
||||
);
|
||||
//show whole map on startup
|
||||
this.transformHandler.centerAll(0.9);
|
||||
|
||||
requestAnimationFrame(() => this.renderGame());
|
||||
}
|
||||
|
||||
@@ -257,4 +257,31 @@ export class TransformHandler {
|
||||
}
|
||||
this.target = null;
|
||||
}
|
||||
|
||||
override(x: number = 0, y: number = 0, s: number = 1) {
|
||||
//hardset view position
|
||||
this.clearTarget();
|
||||
this.offsetX = x;
|
||||
this.offsetY = y;
|
||||
this.scale = s;
|
||||
this.changed = true;
|
||||
}
|
||||
|
||||
centerAll(fit: number = 1) {
|
||||
//position entire map centered on the screen
|
||||
|
||||
const vpWidth = this.boundingRect().width;
|
||||
const vpHeight = this.boundingRect().height;
|
||||
const mapWidth = this.game.width();
|
||||
const mapHeight = this.game.height();
|
||||
|
||||
const scHor = (vpWidth / mapWidth) * fit;
|
||||
const scVer = (vpHeight / mapHeight) * fit;
|
||||
const tScale = Math.min(scHor, scVer);
|
||||
|
||||
const oHor = (mapWidth - vpWidth) / 2 / tScale;
|
||||
const oVer = (mapHeight - vpHeight) / 2 / tScale;
|
||||
|
||||
this.override(oHor, oVer, tScale);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user