mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Merge pull request #347 from dengr1065/debug-info
Improved debug info (position and version)
This commit is contained in:
commit
c4d7e65d9f
@ -9,4 +9,11 @@
|
|||||||
line-height: 15px;
|
line-height: 15px;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
|
||||||
|
&:not([data-mode="detailed"]) {
|
||||||
|
.mousePosition,
|
||||||
|
.cameraPosition {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,10 @@ import { BaseHUDPart } from "../base_hud_part";
|
|||||||
import { makeDiv, round3Digits, round2Digits } from "../../../core/utils";
|
import { makeDiv, round3Digits, round2Digits } from "../../../core/utils";
|
||||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||||
|
import { Vector } from "../../../core/vector";
|
||||||
|
|
||||||
|
/** @enum {string} */
|
||||||
|
export const enumDebugOverlayMode = { disabled: "disabled", regular: "regular", detailed: "detailed" };
|
||||||
|
|
||||||
export class HUDDebugInfo extends BaseHUDPart {
|
export class HUDDebugInfo extends BaseHUDPart {
|
||||||
createElements(parent) {
|
createElements(parent) {
|
||||||
@ -9,26 +13,62 @@ export class HUDDebugInfo extends BaseHUDPart {
|
|||||||
|
|
||||||
this.tickRateElement = makeDiv(this.element, null, ["tickRate"], "Ticks /s: 120");
|
this.tickRateElement = makeDiv(this.element, null, ["tickRate"], "Ticks /s: 120");
|
||||||
this.fpsElement = makeDiv(this.element, null, ["fps"], "FPS: 60");
|
this.fpsElement = makeDiv(this.element, null, ["fps"], "FPS: 60");
|
||||||
this.tickDurationElement = makeDiv(this.element, null, ["tickDuration"], "Update time: 0.5ms");
|
this.tickDurationElement = makeDiv(this.element, null, ["tickDuration"], "Tick dur: 0.5ms");
|
||||||
|
this.mousePositionElement = makeDiv(this.element, null, ["mousePosition"], "Pos: 0 0");
|
||||||
|
this.cameraPositionElement = makeDiv(this.element, null, ["cameraPosition"], "Center: 0 0");
|
||||||
|
this.versionElement = makeDiv(this.element, null, ["version"], "version unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
this.lastTick = 0;
|
this.lastTick = 0;
|
||||||
|
|
||||||
this.visible = false;
|
this.mode = enumDebugOverlayMode.disabled;
|
||||||
this.domAttach = new DynamicDomAttach(this.root, this.element);
|
this.domAttach = new DynamicDomAttach(this.root, this.element);
|
||||||
|
|
||||||
this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.toggleFPSInfo).add(() => this.toggle());
|
this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.toggleFPSInfo).add(() => this.toggle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateFullText() {
|
||||||
|
this.element.setAttribute("data-mode", this.mode);
|
||||||
|
|
||||||
|
let version = `version ${G_BUILD_VERSION}`;
|
||||||
|
if (this.full) {
|
||||||
|
version += ` @ ${G_APP_ENVIRONMENT} @ ${G_BUILD_COMMIT_HASH}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.versionElement.innerText = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePositions() {
|
||||||
|
let mousePos = this.root.app.mousePosition || new Vector(0, 0);
|
||||||
|
mousePos = this.root.camera.screenToWorld(mousePos).toTileSpace();
|
||||||
|
const cameraPos = this.root.camera.center.toTileSpace();
|
||||||
|
|
||||||
|
this.mousePositionElement.innerText = `Pos: ${mousePos.x} ${mousePos.y}`;
|
||||||
|
this.cameraPositionElement.innerText = `Center: ${cameraPos.x} ${cameraPos.y}`;
|
||||||
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
this.visible = !this.visible;
|
switch (this.mode) {
|
||||||
this.domAttach.update(this.visible);
|
case enumDebugOverlayMode.detailed:
|
||||||
|
this.mode = enumDebugOverlayMode.disabled;
|
||||||
|
break;
|
||||||
|
case enumDebugOverlayMode.regular:
|
||||||
|
this.mode = enumDebugOverlayMode.detailed;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.mode = enumDebugOverlayMode.regular;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.updateFullText();
|
||||||
|
this.domAttach.update(this.mode !== enumDebugOverlayMode.disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
const now = this.root.time.realtimeNow();
|
const now = this.root.time.realtimeNow();
|
||||||
if (now - this.lastTick > 0.25 && this.visible) {
|
if (!this.visible) return;
|
||||||
|
|
||||||
|
if (now - this.lastTick > 0.25) {
|
||||||
this.lastTick = now;
|
this.lastTick = now;
|
||||||
this.tickRateElement.innerText = "Tickrate: " + this.root.dynamicTickrate.currentTickRate;
|
this.tickRateElement.innerText = "Tickrate: " + this.root.dynamicTickrate.currentTickRate;
|
||||||
this.fpsElement.innerText =
|
this.fpsElement.innerText =
|
||||||
@ -40,5 +80,7 @@ export class HUDDebugInfo extends BaseHUDPart {
|
|||||||
this.tickDurationElement.innerText =
|
this.tickDurationElement.innerText =
|
||||||
"Tick Dur: " + round3Digits(this.root.dynamicTickrate.averageTickDuration) + "ms";
|
"Tick Dur: " + round3Digits(this.root.dynamicTickrate.averageTickDuration) + "ms";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.updatePositions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user