mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-24 09:35:03 +00:00
4cd22a9b5c
The render/ tree was the only place in the client still using kebab-case filenames. Brings ~80 files in line with the rest of src/client/ (BuildPreviewController, TransformHandler, etc.). Directories kept as they were (name-pass/, fx-pass/, passes/, utils/, debug/) since the codebase already mixes those. Two collisions surfaced and got resolved: render/types/ is a directory, not a file, so its imports kept the lowercase form; and the sed pass incidentally normalized core/pathfinding imports, which had to be reverted since that file is actually lowercase on disk despite some imports having referenced it as ./Types under macOS case-insensitive resolution.
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
/**
|
|
* Utilities for RenderSettings persistence — deep-assign, deep-diff.
|
|
*/
|
|
|
|
type Obj = Record<string, any>;
|
|
|
|
/** Recursively assign source values onto target, preserving target's structure. */
|
|
export function deepAssign(target: Obj, source: Obj): void {
|
|
for (const key of Object.keys(source)) {
|
|
if (
|
|
typeof source[key] === "object" &&
|
|
source[key] !== null &&
|
|
typeof target[key] === "object" &&
|
|
target[key] !== null
|
|
) {
|
|
deepAssign(target[key] as Obj, source[key] as Obj);
|
|
} else if (key in target) {
|
|
target[key] = source[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Compute a sparse deep-partial of values that differ from defaults.
|
|
* Returns `undefined` if nothing differs.
|
|
*/
|
|
export function deepDiff(defaults: Obj, current: Obj): Obj | undefined {
|
|
let result: Obj | undefined;
|
|
for (const key of Object.keys(defaults)) {
|
|
const dv = defaults[key];
|
|
const cv = current[key];
|
|
if (
|
|
typeof dv === "object" &&
|
|
dv !== null &&
|
|
typeof cv === "object" &&
|
|
cv !== null
|
|
) {
|
|
const sub = deepDiff(dv as Obj, cv as Obj);
|
|
if (sub !== undefined) {
|
|
result ??= {};
|
|
result[key] = sub;
|
|
}
|
|
} else if (dv !== cv) {
|
|
result ??= {};
|
|
result[key] = cv;
|
|
}
|
|
}
|
|
return result;
|
|
}
|