api.gameData
GameDataApi
Which set of game files the editor draws from — the game's own or a mod's — and installing, switching and removing sets.
The game data as a whole: which set of files the editor draws from, and installing,
switching and removing sets — the plugin side of Help ▸ Game Data…. What is in the
files is data (the tables), tileset (the graphics), graphics (the pictures) and
names (the labels, which follow the loaded set: a unit, weapon, upgrade or
technology a mod renamed shows its new name, and the rest keep StarEdit's).
A data set is a name over files in the game's own formats, at whatever width they
have: a units.dat of more than 228 types gives the palette more types (named by
rez\unitnames.tbl and pictured by unit\cmdbtns\uniticons.grp where the data set has
them), a tileset of more than 2,048 groups draws its extended tiles. Installing lays the
files over the game's two archives, as a loader does, or over a copy already here (base).
Members
source
source(): GameDataSource | null;
The session's source, or null while it is still being resolved at startup.
profiles
profiles(): Promise<GameDataProfile[]>;
Every data set with a copy here, the game's own first.
install
install(profile: GameDataProfile, files: GameDataFiles, progress?: (fraction: number, label: string) => void): Promise<GameDataSource>;
Extract a data set from its files, store it under profile.id and switch to it. The
archives must include the game's own two; the promise rejects with the reason when
they do not or the extraction fails. progress is 0–1 with a label, as the dialog's bar.
select
select(id: string): Promise<GameDataSource>;
Switch to a data set. Everything decoded from the previous one is dropped and the viewport redraws from the new files; a set with no copy here falls back to the game's own. Resolves with the source in use afterwards.
remove
remove(id: string): Promise<boolean>;
Remove a data set's copy (never the game's bundled files). True when there was one.
read
read(path: string, options?: GameDataReadOptions): Promise<Uint8Array | null>;
One file of the data set in use, by its path in the extracted copy: the archive path in
lower case with forward slashes (arr/units.dat, tileset/jungle.cv5,
unit/zerg/drone.grp). tileset/manifest.json and unit/manifest.json list what was
extracted. Null when the copy has no such file, or there is no game data.
// A mod's units.dat against the game's beneath it, while the mod is attached.
const mine = await api.gameData.read("arr/units.dat");
const theirs = await api.gameData.read("arr/units.dat", { under: true });Try itstoredPath
storedPath(member: string): string;
Where a copy keeps a file the game's archives name member — the path read and a
GameDataReader take: arr\units.dat is arr/units.dat, rez\stat_txt.tbl is
tileset/stat_txt.tbl, tileset\jungle\ofire.pcx is tileset/jungle.ofire.pcx. Any case,
either slash.
attach
attach(profile: GameDataProfile, read: GameDataReader, options?: { hash?: string; }): Promise<GameDataSource>;
Draw from a data set that is a function in memory: every file is asked of read first,
and what it leaves (null) comes from the data set in use now. Nothing is stored and the
choice is not remembered — select, install or a reload leave it. The table and
picture editor's loop: change a file, reload(), see the map drawn with it. Units'
Remastered pictures are not drawn from such a data set (what it changed is not known).
options.hash is what a map saved with the set records and Test Map hands on (sixteen
hex digits by the rule of GameDataSource.hash); it can follow later with rehash.
Attaching reads everything again, even with the same profile and function.
Resolves with the source in use afterwards.
// Try a units.dat edit on the open map without installing anything.
const edited = new Map<string, Uint8Array>([["arr/units.dat", myUnitsDat]]);
await api.gameData.attach({ id: "draft", name: "Draft" }, (path) => edited.get(path) ?? null);
// … later, after changing the bytes in `edited`:
api.gameData.reload();
reload
reload(): void;
Read the data set in use afresh: everything decoded from it (tables, tilesets, pictures,
names) is dropped and the map is drawn again — after the files behind attach changed.
rehash
rehash(hash: string | null): GameDataSource | null;
Give the set in memory in use (attach) a new hash, or none with null, without reading
anything again: for a hash worked out after the files were attached or redrawn. What a
map saved from then on records and what Test Map hands on change; nothing is decoded
afresh. The "gameData" event fires. Returns the source, or null (and nothing
changes) when no set in memory is in use.
// Draw from the edit at once, and name it when its digest is ready.
api.gameData.reload();
api.gameData.rehash(await modHashOfTheFiles());
races
races(): DataSetRace[];
The races the data set in use adds; empty for the game's own or when none is declared.
Absent in an editor from before races a data set adds: call it as
api.gameData.races?.() ?? [].
setRaces
setRaces(races: readonly DataSetRace[], id?: string): GameDataSource | null;
Declare the races a data set adds, replacing its table: the data set in use by default,
or the profile id. Kept with the profile's id (it survives a new release of the mod and
a re-attach). Rows are normalized: sorted by id, a row with an id outside 8–255, an id an
earlier row has, or no name (or one over 40 characters) dropped; an empty list forgets
them. The game's own data set (and a Remastered installation's) takes none: returns null.
For the set in use, returns its source with the races, and fires what a change of the
data set fires (the "gameData" event), so open panels repaint; for another set, keeps
them for when it is used and returns null.
api.gameData.setRaces?.([{ id: 9, name: "Hivemind Remnant", letter: "h", like: 0 }]);
api.names.race(9); // "Hivemind Remnant"Try itraceCandidates
raceCandidates(): Promise<{ names: string[]; letters: string[]; }>;
What the data set in use suggests about races it adds, for a person naming them: names,
the strings its rez\network.tbl has past the game's own table, and letters, the
letters other than z, t, p and n with a game\<letter>console.pcx or
rez\statbtn<letter>.bin of its own. Names and letters already declared are left out;
empty for the game's own data set. These are hints a person confirms, never names to fill
in. A set in memory (attach) is asked through its function; a stored copy keeps none of
these files, so it gives none. Absent in an editor from before it
(api.gameData.raceCandidates?.()).
Types
Declarations only this group names.
GameDataProfileinterface
interface GameDataProfile
A data set: one set of game files the editor draws from. The default is the game's
own; any other is installed under an id of its own, the same formats with some of the
files replaced — its tables at any width (the game's, DatExtend's expanded layout or
GPTP's .datex), its tilesets at any size.
id: string | Lower-case letters, digits and hyphens, up to 40 characters. |
|---|---|
name: string | What the dialog and the status line call it. |
url?: string | Where the data set's makers publish it, an |
races?: DataSetRace[] | The races the data set adds to the game's own, when they are declared (no game file says
what a mod's races are called). Kept with the id: a profile handed to |
GameDataSourceinterface
interface GameDataSource
Where the session's game data comes from.
kind: "bundled" | "stored" | "reader" | "none" |
|
|---|---|
label: string | One line, as Help ▸ Game Data… shows it. |
profile: GameDataProfile | The data set the files belong to. |
desktop: boolean | Set when the desktop app extracted the files from a StarCraft installation. |
hash?: string | The data set's hash, where one is known: what a map saved with it records. The mod's
hash, as the play page and |
base?: string | The data set this one was laid over, when it was: |
GameDataBytestype
type GameDataBytes = Blob | Uint8Array;
Bytes for an install: a File / Blob, or already an array.
GameDataFilesinterface
interface GameDataFiles
What a data set is installed from.
archives: readonly { name: string; data: GameDataBytes; }[] | The archives, |
|---|---|
files?: readonly { path: string; data: GameDataBytes; }[] | Loose files by member path ( |
base?: string | Lay the files over the copy of this data set (an id from |
GameDataReadContextinterface
interface GameDataReadContext
What a GameDataReader is told beside the path it is asked for.
member: string | null | The file as the game's archives name it, in lower case with backslashes:
|
|---|---|
under(path: string): Promise<Uint8Array | null> | A file of the data set the reader was attached over, by its path in the extracted copy:
the game's own file beneath a mod's, to compare with or to answer from. Null when that
set has no such file. The same as |
GameDataReadertype
type GameDataReader = (path: string, file: GameDataReadContext) => Uint8Array | null | undefined | Promise<Uint8Array | null | undefined>;
A data set that is a function in memory (gameData.attach): asked for a file by its path
in the extracted copy (arr/units.dat, unit/zerg/drone.grp), it answers the bytes, or
null to leave the file to the data set underneath. It may answer at once or with a promise.
file names the same file as the game does and reads the set underneath.
It need not answer unit/manifest.json: when it answers null the editor takes the list
of the set underneath and works out from the reader's own files which tables are in
GPTP's .datex layout and whether it brings unit names (rez/unitnames.tbl) and command
card pictures (unit/cmdbtns/uniticons.grp). A reader that answers one is taken at its word.
GameDataReadOptionsinterface
interface GameDataReadOptions
How gameData.read reads.
under?: boolean | Read the data set under the one in use: when a set in memory is attached
( |
|---|