Revenge/src/ui/assets.ts
2023-01-07 23:06:36 +00:00

26 lines
No EOL
944 B
TypeScript

import { Asset, Indexable, } from "@types";
import { after } from "@lib/patcher";
import { assets } from "@metro/common";
export const all: Indexable<Asset> = {};
export default function patchAssets() {
try {
after("registerAsset", assets, (args: Asset[], id: number) => {
const asset = args[0];
all[asset.name] = { ...asset, id: id };
});
for (let id = 1; ; id++) {
const asset = assets.getAssetByID(id);
if (!asset) break;
if (all[asset.name]) continue;
all[asset.name] = { ...asset, id: id };
};
} catch {};
}
export const find = (filter: (a: any) => void): Asset | null | undefined => Object.values(all).find(filter);
export const getAssetByName = (name: string): Asset => all[name];
export const getAssetByID = (id: number): Asset => assets.getAssetByID(id);
export const getAssetIDByName = (name: string) => all[name]?.id;