Revenge/src/ui/assets.ts

26 lines
906 B
TypeScript
Raw Normal View History

import { Asset, Indexable } from "@types";
2023-01-07 03:13:16 +00:00
import { assets } from "@metro/common";
2023-02-26 22:56:36 +00:00
import { after } from "@lib/patcher";
2022-10-22 22:26:06 +00:00
2023-01-07 23:06:36 +00:00
export const all: Indexable<Asset> = {};
2022-10-22 22:26:06 +00:00
2023-01-08 23:24:00 +00:00
export function patchAssets() {
const unpatch = after("registerAsset", assets, (args: Asset[], id: number) => {
const asset = args[0];
all[asset.name] = { ...asset, id: id };
});
2022-10-22 22:26:06 +00:00
for (let id = 1; ; id++) {
const asset = assets.getAssetByID(id);
if (!asset) break;
if (all[asset.name]) continue;
all[asset.name] = { ...asset, id: id };
};
return unpatch;
2022-10-22 22:26:06 +00:00
}
export const find = (filter: (a: any) => void): Asset | null | undefined => Object.values(all).find(filter);
export const getAssetByName = (name: string): Asset => all[name];
2023-01-07 03:13:16 +00:00
export const getAssetByID = (id: number): Asset => assets.getAssetByID(id);
2022-10-22 22:43:51 +00:00
export const getAssetIDByName = (name: string) => all[name]?.id;