UNPKG

sc4

Version:

A command line utility for automating SimCity 4 modding tasks & modifying savegames

31 lines (30 loc) 1.63 kB
import type { TGIQuery, TGILiteral, uint32, TGIArray } from 'sc4/types'; import BinaryIndex from './binary-tgi-index.js'; export type { TGIIndexJSON } from './mapped-tgi-index.js'; export type { TGIQuery, TGILiteral }; export type SingleResult<T> = T | undefined; export type ArrayResult<T> = T[]; type Predicate<T, S extends T = T> = ((entry: T, index?: number, ctx?: T[]) => unknown) | ((entry: T, index?: number, ctx?: T[]) => entry is S); export type TGIPredicate<T, S extends T = T> = Predicate<T, S>; export type FindParameters<T> = [type: uint32, group: uint32, instance: uint32] | [query: TGIQuery] | [query: TGIArray] | [predicate: TGIPredicate<T>, thisArg?: any]; export default class TGIIndex<T extends TGILiteral = TGILiteral> extends Array<T> { index: BinaryIndex; dirty: boolean; build(): this; load(buffer: Uint8Array): this; find(type: number, group: number, instance: number): SingleResult<T>; find(query: TGIQuery): SingleResult<T>; find(query: TGIArray): SingleResult<T>; find<S extends T = T>(predicate: TGIPredicate<T, S>, thisArg?: any): SingleResult<S>; findAll(type: number, group: number, instance: number): ArrayResult<T>; findAll(query: TGIQuery): ArrayResult<T>; findAll(query: TGIArray): ArrayResult<T>; findAll<S extends T = T>(predicate: TGIPredicate<T, S>, thisArg?: any): ArrayResult<S>; private expand; remove(fn: TGIPredicate<T>): number; remove(query: TGIQuery): number; remove(query: TGIArray): number; remove(type: number, group: number, instance: number): number; push(...tgis: T[]): number; add(...args: T[]): this; }