mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 11:30:43 +00:00
Restore world-stable name scaling
This commit is contained in:
@@ -25,8 +25,8 @@ import { NameLayerAssets } from "./NameLayerAssets";
|
||||
import {
|
||||
computeNameLayerFontSize,
|
||||
computeNameLayerLayout,
|
||||
computeNameLayerScale,
|
||||
computeNameLayerVisible,
|
||||
computeNameLayerWorldScale,
|
||||
computeTraitorFlashAlpha,
|
||||
replaceUnsupportedNameGlyphs,
|
||||
} from "./NameLayerLayout";
|
||||
@@ -347,11 +347,13 @@ export class NameLayer implements Layer {
|
||||
const screenPos = this.transformHandler.worldToCanvasCoordinates(
|
||||
render.location,
|
||||
);
|
||||
render.container.position.set(
|
||||
Math.round(screenPos.x),
|
||||
Math.round(screenPos.y),
|
||||
render.container.position.set(screenPos.x, screenPos.y);
|
||||
render.container.scale.set(
|
||||
computeNameLayerWorldScale(
|
||||
render.baseSize,
|
||||
this.transformHandler.scale,
|
||||
),
|
||||
);
|
||||
render.container.scale.set(computeNameLayerScale(render.baseSize));
|
||||
this.updateTraitorAlpha(render, now);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,13 @@ export function computeNameLayerScale(baseSize: number): number {
|
||||
return Math.min(baseSize * 0.25, 3);
|
||||
}
|
||||
|
||||
export function computeNameLayerWorldScale(
|
||||
baseSize: number,
|
||||
transformScale: number,
|
||||
): number {
|
||||
return computeNameLayerScale(baseSize) * transformScale;
|
||||
}
|
||||
|
||||
export function computeNameLayerFontSize(baseSize: number): number {
|
||||
return Math.max(4, Math.floor(baseSize * 0.4));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
} from "../src/client/graphics/PlayerIcons";
|
||||
import {
|
||||
computeNameLayerLayout,
|
||||
computeNameLayerWorldScale,
|
||||
computeTraitorFlashAlpha,
|
||||
computeTraitorFlashDurationSeconds,
|
||||
replaceUnsupportedNameGlyphs,
|
||||
@@ -96,6 +97,11 @@ describe("NameLayerLayout", () => {
|
||||
expect(layout.width).toBe(60);
|
||||
});
|
||||
|
||||
test("combines local label scale with camera scale for world-stable labels", () => {
|
||||
expect(computeNameLayerWorldScale(8, 2)).toBeCloseTo(4);
|
||||
expect(computeNameLayerWorldScale(20, 2)).toBeCloseTo(6);
|
||||
});
|
||||
|
||||
test("matches traitor flash duration thresholds and alpha extrema", () => {
|
||||
expect(computeTraitorFlashDurationSeconds(156)).toBeNull();
|
||||
expect(computeTraitorFlashDurationSeconds(150)).toBeCloseTo(1);
|
||||
|
||||
Reference in New Issue
Block a user