feat: scaffold workspace with search, fetch, and extract packages
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import type { TTSMod, TTSObject } from '@tts/shared';
|
||||
import { markParent, traverseMod } from './traverse.js';
|
||||
|
||||
/**
|
||||
* Flatten all objects in a save into an array.
|
||||
* Ensures parent links are set before returning.
|
||||
*/
|
||||
export function flattenObjects(mod: TTSMod): TTSObject[] {
|
||||
for (const state of mod.ObjectStates) {
|
||||
markParent(state);
|
||||
}
|
||||
return [...traverseMod(mod)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter objects by a predicate (name, GUID, type, etc.).
|
||||
*/
|
||||
export function filterObjects(
|
||||
mod: TTSMod,
|
||||
predicate: (o: TTSObject) => boolean,
|
||||
): TTSObject[] {
|
||||
return flattenObjects(mod).filter(predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a single object by GUID.
|
||||
*/
|
||||
export function findObject(mod: TTSMod, guid: string): TTSObject | undefined {
|
||||
return flattenObjects(mod).find((o) => o.GUID === guid);
|
||||
}
|
||||
|
||||
export { markParent, traverseMod } from './traverse.js';
|
||||
Reference in New Issue
Block a user