Skip to content
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

Fix window resizing #320

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Fixed
- Resizing the editor while using multiple monitors [#319](https://github.com/CCDirectLink/crosscode-map-editor/issues/319)

## [1.6.0] 2024-06-28
### Fixed
- Keep filtered entities inactive when changing tabs [#301](https://github.com/CCDirectLink/crosscode-map-editor/issues/301)
Expand Down
20 changes: 10 additions & 10 deletions webapp/src/app/components/phaser/phaser.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AfterViewInit, Component, ElementRef, HostListener, ViewChild } from '@angular/core';
import * as Phaser from 'phaser';

import { MatSnackBar } from '@angular/material/snack-bar';
import { AutotileService } from '../../services/autotile/autotile.service';
import { GlobalEventsService } from '../../services/global-events.service';
import { Globals } from '../../services/globals';
Expand All @@ -10,19 +11,18 @@ import { MapLoaderService } from '../../services/map-loader.service';
import { EntityRegistryService } from '../../services/phaser/entities/registry/entity-registry.service';
import { MainScene } from '../../services/phaser/main-scene';
import { PhaserEventsService } from '../../services/phaser/phaser-events.service';
import { StateHistoryService } from '../dialogs/floating-window/history/state-history.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { SettingsService } from '../../services/settings.service';
import { StateHistoryService } from '../dialogs/floating-window/history/state-history.service';

@Component({
selector: 'app-phaser',
templateUrl: './phaser.component.html',
styleUrls: ['./phaser.component.scss']
})
export class PhaserComponent implements AfterViewInit {
@ViewChild('content', {static: true}) content!: ElementRef<HTMLElement>;

@ViewChild('content', { static: true }) content!: ElementRef<HTMLElement>;

constructor(
private element: ElementRef,
private mapLoader: MapLoaderService,
Expand All @@ -46,8 +46,8 @@ export class PhaserComponent implements AfterViewInit {
Globals.snackbar = snackbar;
Globals.settingsService = settingsService;
}


ngAfterViewInit() {
this.heightMap.init();
const scene = new MainScene();
Expand All @@ -70,20 +70,20 @@ export class PhaserComponent implements AfterViewInit {
});
Globals.scene = scene;
}

@HostListener('window:resize', ['$event'])
onResize() {
if (!Globals.game) {
return;
}
const scale = this.getScale();
Globals.game.scale.setZoom(1 / window.devicePixelRatio);
Globals.game.scale.resize(
scale.width,
scale.height
);
Globals.game.scale.setZoom(1 / window.devicePixelRatio);
}

private getScale() {
const rect = this.content.nativeElement.getBoundingClientRect();
return {
Expand Down
Loading