sc4
Version:
A command line utility for automating SimCity 4 modding tasks & modifying savegames
64 lines (63 loc) • 1.92 kB
TypeScript
import type { TGILike, uint32 } from 'sc4/types';
import type { Class } from 'type-fest';
import Stream from './stream.js';
import type DBPF from './dbpf.js';
import type { DecodedFileTypeId, TypeIdToFile, DecodedFile, ReadResult } from './types.js';
import TGI from './tgi.js';
/**
* Returns a DBPF Entry type where the file type pointed to by the entry is
* inferred from the type id.
*
* @param A file type id.
*/
export type EntryFromType<T extends DecodedFileTypeId> = Entry<TypeIdToFile<T>>;
export type EntryJSON = {
tgi: uint32[];
size: number;
offset: number;
};
type EntryConstructorOptions = {
tgi?: TGILike;
dbpf?: DBPF;
size?: number;
offset?: number;
compressed?: boolean;
};
type EntryParseOptions = {
minor?: number;
buffer?: Uint8Array | null;
};
type AllowedEntryType = DecodedFile | Uint8Array;
export default class Entry<T extends AllowedEntryType = AllowedEntryType> {
#private;
tgi: TGI;
size: number;
offset: number;
compressed: boolean | undefined;
dbpf: DBPF;
raw: Uint8Array | null;
buffer: Uint8Array | null;
file: ReadResult<T> | null;
constructor(opts?: EntryConstructorOptions);
isType<T extends DecodedFileTypeId>(type: T): this is EntryFromType<T>;
isArrayType(): boolean;
get type(): number;
get group(): number;
get instance(): number;
get id(): string;
get isRead(): boolean;
isTouched(): boolean;
get fileConstructor(): Class<unknown> | undefined;
isKnownType(): this is Entry<DecodedFile>;
free(): this;
parse(rs: Stream, opts?: EntryParseOptions): this;
readRaw(): Uint8Array;
decompress(): Uint8Array;
read(): ReadResult<T>;
readRawAsync(): Promise<Uint8Array<ArrayBufferLike>>;
decompressAsync(): Promise<Uint8Array>;
readAsync(): Promise<ReadResult<T>>;
toBuffer(): Uint8Array;
toJSON(): EntryJSON;
}
export {};