From 2d83994771dafb12191d34bf6622d1bdc81c1c51 Mon Sep 17 00:00:00 2001 From: dengr1065 Date: Tue, 30 Jun 2020 04:53:06 +0300 Subject: [PATCH 1/8] More debug info (toggle) --- src/css/ingame_hud/debug_info.scss | 7 +++++ src/js/game/hud/parts/debug_info.js | 41 +++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/css/ingame_hud/debug_info.scss b/src/css/ingame_hud/debug_info.scss index f370d04e..24bd856f 100644 --- a/src/css/ingame_hud/debug_info.scss +++ b/src/css/ingame_hud/debug_info.scss @@ -9,4 +9,11 @@ line-height: 15px; flex-direction: column; color: #fff; + + &:not(.debugFull) { + .mousePosition, + .cameraPosition { + display: none; + } + } } diff --git a/src/js/game/hud/parts/debug_info.js b/src/js/game/hud/parts/debug_info.js index 46ec2dcf..79004d8e 100644 --- a/src/js/game/hud/parts/debug_info.js +++ b/src/js/game/hud/parts/debug_info.js @@ -2,6 +2,7 @@ import { BaseHUDPart } from "../base_hud_part"; import { makeDiv, round3Digits, round2Digits } from "../../../core/utils"; import { DynamicDomAttach } from "../dynamic_dom_attach"; import { KEYMAPPINGS } from "../../key_action_mapper"; +import { Vector } from "../../../core/vector"; export class HUDDebugInfo extends BaseHUDPart { createElements(parent) { @@ -9,20 +10,54 @@ export class HUDDebugInfo extends BaseHUDPart { this.tickRateElement = makeDiv(this.element, null, ["tickRate"], "Ticks /s: 120"); 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() { this.lastTick = 0; this.visible = false; + this.full = false; this.domAttach = new DynamicDomAttach(this.root, this.element); this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.toggleFPSInfo).add(() => this.toggle()); } + updateFullText() { + this.element.classList.toggle("debugFull", this.full); + + 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() { - this.visible = !this.visible; + if (this.visible) { + if (this.full) { + this.visible = false; + this.full = false; + } else { + this.full = true; + } + } else { + this.visible = true; + } + this.updateFullText(); this.domAttach.update(this.visible); } @@ -40,5 +75,7 @@ export class HUDDebugInfo extends BaseHUDPart { this.tickDurationElement.innerText = "Tick Dur: " + round3Digits(this.root.dynamicTickrate.averageTickDuration) + "ms"; } + + this.updatePositions(); } } From 6769e9c9b8ce2f822de14b28e0d53ae71c130920 Mon Sep 17 00:00:00 2001 From: dengr1065 Date: Wed, 1 Jul 2020 23:53:51 +0300 Subject: [PATCH 2/8] Use enum for debug overlay --- src/js/game/hud/parts/debug_info.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/js/game/hud/parts/debug_info.js b/src/js/game/hud/parts/debug_info.js index 79004d8e..d4baa18a 100644 --- a/src/js/game/hud/parts/debug_info.js +++ b/src/js/game/hud/parts/debug_info.js @@ -4,6 +4,8 @@ import { DynamicDomAttach } from "../dynamic_dom_attach"; import { KEYMAPPINGS } from "../../key_action_mapper"; import { Vector } from "../../../core/vector"; +export const enumDebugOverlayMode = { disabled: 'disabled', regular: 'regular', detailed: 'detailed'}; + export class HUDDebugInfo extends BaseHUDPart { createElements(parent) { this.element = makeDiv(parent, "ingame_HUD_DebugInfo", []); @@ -19,8 +21,7 @@ export class HUDDebugInfo extends BaseHUDPart { initialize() { this.lastTick = 0; - this.visible = false; - this.full = false; + this.mode = enumDebugOverlayMode.disabled; this.domAttach = new DynamicDomAttach(this.root, this.element); this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.toggleFPSInfo).add(() => this.toggle()); @@ -47,18 +48,19 @@ export class HUDDebugInfo extends BaseHUDPart { } toggle() { - if (this.visible) { - if (this.full) { - this.visible = false; - this.full = false; - } else { - this.full = true; - } - } else { - this.visible = true; + switch (this.mode) { + 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.visible); + this.domAttach.update(this.mode != enumDebugOverlayMode.disabled); } update() { From 4bbbdafbb9c9ca84d9ae827b36891db3f61af104 Mon Sep 17 00:00:00 2001 From: dengr1065 Date: Thu, 2 Jul 2020 00:41:01 +0300 Subject: [PATCH 3/8] Fix copy-pasted code i hate myself --- src/js/game/hud/parts/debug_info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/game/hud/parts/debug_info.js b/src/js/game/hud/parts/debug_info.js index d4baa18a..d79dd0a1 100644 --- a/src/js/game/hud/parts/debug_info.js +++ b/src/js/game/hud/parts/debug_info.js @@ -4,7 +4,7 @@ import { DynamicDomAttach } from "../dynamic_dom_attach"; import { KEYMAPPINGS } from "../../key_action_mapper"; import { Vector } from "../../../core/vector"; -export const enumDebugOverlayMode = { disabled: 'disabled', regular: 'regular', detailed: 'detailed'}; +export const enumDebugOverlayMode = { disabled: "disabled", regular: "regular", detailed: "detailed" }; export class HUDDebugInfo extends BaseHUDPart { createElements(parent) { From c29b505ef0d1ce0f06884a4ca8f1d38ddb0ebded Mon Sep 17 00:00:00 2001 From: dengr1065 Date: Thu, 2 Jul 2020 01:05:25 +0300 Subject: [PATCH 4/8] Add consistent enum comment --- src/js/game/hud/parts/debug_info.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/game/hud/parts/debug_info.js b/src/js/game/hud/parts/debug_info.js index d79dd0a1..33644f33 100644 --- a/src/js/game/hud/parts/debug_info.js +++ b/src/js/game/hud/parts/debug_info.js @@ -4,6 +4,7 @@ import { DynamicDomAttach } from "../dynamic_dom_attach"; 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 { From 6546c023a6bca3bec49183fd0535c569ed696e17 Mon Sep 17 00:00:00 2001 From: dengr1065 Date: Mon, 6 Jul 2020 12:00:40 +0300 Subject: [PATCH 5/8] debug info css - prepare for attribute usage --- src/css/ingame_hud/debug_info.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/css/ingame_hud/debug_info.scss b/src/css/ingame_hud/debug_info.scss index 24bd856f..dc3e7221 100644 --- a/src/css/ingame_hud/debug_info.scss +++ b/src/css/ingame_hud/debug_info.scss @@ -10,7 +10,7 @@ flex-direction: column; color: #fff; - &:not(.debugFull) { + &:not([data-mode="full"]) { .mousePosition, .cameraPosition { display: none; From f4c9c663541a2196de17a352980df9eb78d64099 Mon Sep 17 00:00:00 2001 From: dengr1065 Date: Mon, 6 Jul 2020 12:02:31 +0300 Subject: [PATCH 6/8] debug info fixes --- src/js/game/hud/parts/debug_info.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/js/game/hud/parts/debug_info.js b/src/js/game/hud/parts/debug_info.js index 33644f33..bdce3071 100644 --- a/src/js/game/hud/parts/debug_info.js +++ b/src/js/game/hud/parts/debug_info.js @@ -29,7 +29,7 @@ export class HUDDebugInfo extends BaseHUDPart { } updateFullText() { - this.element.classList.toggle("debugFull", this.full); + this.element.setAttribute("data-mode", this.mode); let version = `version ${G_BUILD_VERSION}`; if (this.full) { @@ -61,12 +61,14 @@ export class HUDDebugInfo extends BaseHUDPart { break; } this.updateFullText(); - this.domAttach.update(this.mode != enumDebugOverlayMode.disabled); + this.domAttach.update(this.mode !== enumDebugOverlayMode.disabled); } update() { 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.tickRateElement.innerText = "Tickrate: " + this.root.dynamicTickrate.currentTickRate; this.fpsElement.innerText = From b61e0aac73ef6941966ff4f35da3a4afadd2f3fd Mon Sep 17 00:00:00 2001 From: dengr1065 Date: Mon, 6 Jul 2020 12:07:46 +0300 Subject: [PATCH 7/8] debug info - fix lint fail github editor sucks without built-in prettier --- src/js/game/hud/parts/debug_info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/game/hud/parts/debug_info.js b/src/js/game/hud/parts/debug_info.js index bdce3071..bfa09b1e 100644 --- a/src/js/game/hud/parts/debug_info.js +++ b/src/js/game/hud/parts/debug_info.js @@ -67,7 +67,7 @@ export class HUDDebugInfo extends BaseHUDPart { update() { const now = this.root.time.realtimeNow(); if (!this.visible) return; - + if (now - this.lastTick > 0.25) { this.lastTick = now; this.tickRateElement.innerText = "Tickrate: " + this.root.dynamicTickrate.currentTickRate; From b3c9c186d318792f22b52aec8babc7a174def431 Mon Sep 17 00:00:00 2001 From: dengr1065 Date: Mon, 6 Jul 2020 14:17:58 +0300 Subject: [PATCH 8/8] debug info - use "detailed" instead of "full" i'm retarded pls help --- src/css/ingame_hud/debug_info.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/css/ingame_hud/debug_info.scss b/src/css/ingame_hud/debug_info.scss index dc3e7221..de69a4f9 100644 --- a/src/css/ingame_hud/debug_info.scss +++ b/src/css/ingame_hud/debug_info.scss @@ -10,7 +10,7 @@ flex-direction: column; color: #fff; - &:not([data-mode="full"]) { + &:not([data-mode="detailed"]) { .mousePosition, .cameraPosition { display: none;