Skip to content

Commit

Permalink
refactor+fix: user another camera full fullscreen map
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Jul 17, 2023
1 parent 5733e65 commit 3932559
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions client/src/scripts/scenes/minimapScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class MinimapScene extends Phaser.Scene {

renderTexture!: Phaser.GameObjects.RenderTexture;

fullScreenCamera!: Phaser.Cameras.Scene2D.Camera;

constructor() {
super("minimap");
}
Expand All @@ -38,15 +40,17 @@ export class MinimapScene extends Phaser.Scene {
this.gasNewPosCircle = this.add.circle(0, 0, 0).setStrokeStyle(3, 0xffffff).setDepth(15);
this.gasToCenterLine = this.add.line(0, 0, 0, 0, 0, 0).setStrokeStyle(12, 0x00ffff).setDepth(14);

this.fullScreenCamera = this.cameras.add();

this.gasRect = this.add.rectangle(MAP_WIDTH / 2 * MINIMAP_SCALE,
MAP_HEIGHT / 2 * MINIMAP_SCALE,
(MAP_WIDTH * 1.5) * MINIMAP_SCALE,
(MAP_HEIGHT * 1.5) * MINIMAP_SCALE,
GAS_COLOR, GAS_ALPHA).setDepth(10).setMask(this.gasMask);

this.scale.on("resize", (): void => {
if (this.isExpanded) this.resizeBigMap();
else this.resizeSmallMap();
this.resizeBigMap();
this.resizeSmallMap();
});

if (core.game?.playerManager.isMobile) {
Expand Down Expand Up @@ -83,14 +87,14 @@ export class MinimapScene extends Phaser.Scene {
}

resizeBigMap(): void {
if (this.cameras.main === undefined) return;
if (this.fullScreenCamera === undefined) return;
const screenWidth = window.innerWidth;
const screenHeight = window.innerHeight;
this.cameras.main.setZoom((0.85 * screenHeight) / (MAP_HEIGHT * MINIMAP_SCALE));
this.fullScreenCamera.setZoom((0.85 * screenHeight) / (MAP_HEIGHT * MINIMAP_SCALE));
// noinspection JSSuspiciousNameCombination
this.cameras.main.setSize(screenHeight, screenHeight);
this.cameras.main.setPosition(screenWidth / 2 - screenHeight / 2, 0);
this.cameras.main.centerOn(MAP_WIDTH / 2 * MINIMAP_SCALE, (MAP_HEIGHT * 1.1) / 2 * MINIMAP_SCALE);
this.fullScreenCamera.setSize(screenHeight, screenHeight);
this.fullScreenCamera.setPosition(screenWidth / 2 - screenHeight / 2, 0);
this.fullScreenCamera.centerOn(MAP_WIDTH / 2 * MINIMAP_SCALE, (MAP_HEIGHT * 1.1) / 2 * MINIMAP_SCALE);
$("#scopes-container").hide();
this.updateTransparency();
}
Expand All @@ -114,25 +118,27 @@ export class MinimapScene extends Phaser.Scene {

switchToBigMap(): void {
if (this.cameras.main === undefined) return;
this.cameras.main.setVisible(true);
this.fullScreenCamera.setVisible(true);
this.isExpanded = true;
this.cameras.main.stopFollow();
this.resizeBigMap();
this.cameras.main.setVisible(false);
$("#minimap-border").hide();
}

switchToSmallMap(): void {
if (this.cameras.main === undefined) return;
this.isExpanded = false;
this.fullScreenCamera.setVisible(false);
this.cameras.main.setVisible(this.visible);
this.resizeSmallMap();
$("#minimap-border").toggle(this.visible);
}

updateTransparency(): void {
if (this.cameras.main === undefined) return;
const alpha = this.isExpanded ? localStorageInstance.config.bigMapTransparency : localStorageInstance.config.minimapTransparency;
this.cameras.main.setBackgroundColor({ ...GRASS_RGB, a: alpha * 255 });
this.cameras.main.setAlpha(alpha);
this.cameras.main.setBackgroundColor({ ...GRASS_RGB, a: localStorageInstance.config.minimapTransparency * 255 });
this.cameras.main.setAlpha(localStorageInstance.config.minimapTransparency);
this.fullScreenCamera.setBackgroundColor({ ...GRASS_RGB, a: localStorageInstance.config.bigMapTransparency * 255 });
this.fullScreenCamera.setAlpha(localStorageInstance.config.bigMapTransparency);
}
}

0 comments on commit 3932559

Please sign in to comment.