Skip to content

Commit 4ab1cdf

Browse files
author
DavidQ
committed
BUILD PR: centralize network debug serialization helpers across exact network debug batch. V2
1 parent 4765b89 commit 4ab1cdf

4 files changed

Lines changed: 15 additions & 22 deletions

File tree

games/network_sample_a/debug/networkSampleADebug.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ networkSampleADebug.js
88
import { createNetworkDebugPluginDefinition } from "../../../engine/debug/network/index.js";
99
import { asArray, asObject } from "../../../src/engine/debug/inspectors/shared/inspectorUtils.js";
1010
import {
11+
asNumber,
1112
commandLinesForTrace,
1213
getCommandSnapshot,
1314
toNetworkSnapshot
@@ -19,10 +20,6 @@ function sanitizeText(value) {
1920
return typeof value === "string" ? value.trim() : "";
2021
}
2122

22-
function asNumber(value, fallback = 0) {
23-
return Number.isFinite(value) ? Number(value) : fallback;
24-
}
25-
2623
function toConnectionLines(snapshot) {
2724
const network = toNetworkSnapshot(snapshot, NETWORK_SAMPLE_KEY);
2825
const connection = asObject(network.connection);

games/network_sample_b/debug/networkSampleBDebug.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@ networkSampleBDebug.js
77

88
import { createNetworkDebugPluginDefinition } from "../../../engine/debug/network/index.js";
99
import { asArray, asObject } from "../../../src/engine/debug/inspectors/shared/inspectorUtils.js";
10-
import { toNetworkSnapshot } from "../../../src/shared/utils/networkDebugUtils.js";
10+
import { asNumber, toNetworkSnapshot } from "../../../src/shared/utils/networkDebugUtils.js";
1111

1212
const NETWORK_SAMPLE_KEY = "networkSampleB";
1313

1414
function sanitizeText(value) {
1515
return typeof value === "string" ? value.trim() : "";
1616
}
1717

18-
function asNumber(value, fallback = 0) {
19-
const numeric = Number(value);
20-
return Number.isFinite(numeric) ? numeric : fallback;
21-
}
22-
2318
function toHostStatusLines(snapshot) {
2419
const network = toNetworkSnapshot(snapshot, NETWORK_SAMPLE_KEY);
2520
const summary = asObject(network.summary);

games/network_sample_c/debug/networkSampleCDebug.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ networkSampleCDebug.js
88
import { createNetworkDebugPluginDefinition } from "../../../engine/debug/network/index.js";
99
import { asArray, asObject } from "../../../src/engine/debug/inspectors/shared/inspectorUtils.js";
1010
import {
11+
asNumber,
1112
commandLinesForTrace,
1213
getCommandSnapshot,
1314
toNetworkSnapshot
@@ -19,11 +20,6 @@ function sanitizeText(value) {
1920
return typeof value === "string" ? value.trim() : "";
2021
}
2122

22-
function asNumber(value, fallback = 0) {
23-
const numeric = Number(value);
24-
return Number.isFinite(numeric) ? numeric : fallback;
25-
}
26-
2723
function formatEntityLine(entity, options = {}) {
2824
const source = asObject(entity);
2925
const limit = Number.isFinite(Number(options.labelLimit))

src/shared/utils/networkDebugUtils.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,35 @@ function toSafeKey(value) {
1414
return sanitizeText(value);
1515
}
1616

17-
export function toNetworkSnapshot(snapshot, sampleKey) {
17+
export function asNumber(value, fallback = 0) {
18+
const numeric = Number(value);
19+
return Number.isFinite(numeric) ? numeric : fallback;
20+
}
21+
22+
export function toNetworkSnapshot(snapshot) {
23+
const sampleKey = arguments[1];
1824
const key = toSafeKey(sampleKey);
1925
if (!key) {
2026
return {};
2127
}
2228
return asObject(snapshot?.assets?.[key]);
2329
}
2430

25-
export function getCommandSnapshot(context, sampleKey) {
31+
export function getCommandSnapshot(context) {
32+
const sampleKey = arguments[1];
2633
const key = toSafeKey(sampleKey);
2734
if (!key) {
2835
return {};
2936
}
3037
return asObject(context?.assets?.[key]);
3138
}
3239

33-
export function commandLinesForTrace(context, args = [], options = {}) {
40+
export function commandLinesForTrace(context, args = []) {
41+
const options = asObject(arguments[2]);
3442
const sanitize = typeof options?.sanitizeText === "function" ? options.sanitizeText : sanitizeText;
3543
const formatNumber = typeof options?.formatNumber === "function"
3644
? options.formatNumber
37-
: (value, fallback = 0) => {
38-
const numeric = Number(value);
39-
return Number.isFinite(numeric) ? numeric : fallback;
40-
};
45+
: asNumber;
4146

4247
const snapshot = getCommandSnapshot(context, options?.sampleKey);
4348
const trace = asObject(snapshot.trace);

0 commit comments

Comments
 (0)