Class DataPackageManager
Methods
exportPackage
- export
Package (): DataPackage Export a DataPackage object for local caching purposes.
Returns DataPackage
Remarks
It is recommended to export/import any data packages ahead of time to reduce unnecessary calls to DataPackageManager.fetchPackage and reduce connection startup time and lighten network overhead. See below for an example.
Example: Node.js
import fs from "node:fs";
import { Client } from "archipelago.js";
// ... misc client code (connecting and fetching data package).
// Save data package to a local file.
const data = client.package.exportPackage();
fs.writeFileSync("path/to/cache/datapackage_cache.json", JSON.stringify(data), "utf8");
fetchPackage
- fetch
Package (games?, update?): Promise<DataPackage> Fetches and returns the DataPackage from the server, if the games are not locally cached or checksums do not match.
Parameters
- games: string[] = []
A list of game packages to fetch. If omitted, will fetch all available game packages from the current room.
- update: boolean = true
If
true
, after fetching the data package, any changes will automatically be updated without needing to manually call DataPackageManager.importPackage.
Returns Promise<DataPackage>
- games: string[] = []
findPackage
- find
Package (game): null | PackageMetadata Returns the package metadata helper object for a specified game. If game package does not exist in cache, returns
null
instead.Parameters
- game: string
The specific game package to look up.
Returns null | PackageMetadata
- game: string
importPackage
- import
Package (dataPackage): void Import a DataPackage object to prepopulate local cache.
Parameters
- dataPackage: DataPackage
The package to import.
Returns void
Remarks
It is recommended to export/import any data packages ahead of time to reduce unnecessary calls to DataPackageManager.fetchPackage and reduce connection startup time and lighten network overhead. See below for an example.
Example: Node.js
import fs from "node:fs";
import { Client } from "archipelago.js";
const data = fs.readFileSync("path/to/cache/datapackage_cache.json");
const client = new Client();
client.package.importPackage(JSON.parse(data));
await client.login("wss://archipelago.gg:38281", "Phar", "Clique");Example: Modern browser (using localStorage and ES-syntax)
<script src="archipelago.js" type="module">
import { Client } from "archipelago.js";
const data = localStorage.getItem("datapackage_cache");
const client = new Client();
client.package.importPackage(JSON.parse(data));
await client.login("wss://archipelago.gg:38281", "Phar", "Clique");
</script>- dataPackage: DataPackage
lookupItemName
- lookup
Item (game, id, fallback?): stringName Lookup an item name by its integer id.
Parameters
- game: string
The name of the game this item is associated with.
- id: number
The id of the item to name lookup.
Optional
fallback: trueIf
true
, returns"Unknown Item {id}"
instead ofundefined
, if id does not exist in package. Defaults totrue
, if omitted.
Returns string
- game: string
- lookup
Item (game, id, fallback): undefined | stringName Lookup an item name by its integer id.
Parameters
- game: string
The name of the game this item is associated with.
- id: number
The id of the item to name lookup.
- fallback: false
If
true
, returns"Unknown Item {id}"
instead ofundefined
, if id does not exist in package. Defaults totrue
, if omitted.
Returns undefined | string
- game: string
lookupLocationName
- lookup
Location (game, id, fallback?): stringName Lookup a location name by its integer id.
Parameters
- game: string
The name of the game this location is associated with.
- id: number
The id of the location to name lookup.
Optional
fallback: trueIf
true
, returns"Unknown Location {id}"
instead ofundefined
, if id does not exist in package. Defaults totrue
, if omitted.
Returns string
- game: string
- lookup
Location (game, id, fallback): undefined | stringName Lookup a location name by its integer id.
Parameters
- game: string
The name of the game this location is associated with.
- id: number
The id of the location to name lookup.
- fallback: false
If
true
, returns"Unknown Location {id}"
instead ofundefined
, if id does not exist in package. Defaults totrue
, if omitted.
Returns undefined | string
- game: string
Managers data packages metadata and exposes name lookup methods.