-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSporeAssetFinder.ts
35 lines (26 loc) · 1.2 KB
/
SporeAssetFinder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as WebApi from "./SporeWebApiClient.js";
import DwrClient from "./SporeDwrApiClient.js";
const DwrApi = new DwrClient();
/** Returns a list of asset IDs that are used in the specified adventure. */
export async function getAdventureAssets(adventureAssetId: number) {
const xmlModel = await WebApi.getXmlModel(adventureAssetId);
const assets: number[] = [];
// Trim out just the contents of assets tag
const assetsString = xmlModel.split("<assets><asset>")[1]?.split("</asset></assets>")[0];
assetsString?.split("</asset><asset>").forEach(element => {
assets.push(parseInt(element));
});
return assets;
}
/** Returns a list of assets in the specified asset's lineage. The list will be sorted newest to oldest, and will not include the specified asset. */
export async function getParentAssets(assetId: number) {
const asset = await DwrApi.getAsset(assetId);
const assetLineage = await DwrApi.getAssetLineage(assetId);
const parentIds: number[] = [];
const parentId = asset?.parentId ?? assetLineage?.parent?.id;
if (parentId) {
parentIds.push(parentId);
parentIds.push(...await getParentAssets(parentId));
}
return parentIds;
}