Anonymous

Mod Creation/Mod Context API Reference: Difference between revisions

From Melvor Idle
Line 213: Line 213:
== Game Object Registration ==
== Game Object Registration ==


✔️ '''Not documented yet, but it is available''' ✔️
The game object registration API can be accessed through the <code>gameData</code> property on the root context object.
 
=== addPackage(data: string | GameDataPackage): Promise<void> ===
 
Registers a game data package.
 
'''Parameters'''
 
<code>data: string | GameDataPackage</code> The resource path to your game data package <code>.json</code> file or a valid JavaScript GameDataPackage object.
 
'''Example'''
 
<nowiki>// data.json
{
  "$schema": "https://melvoridle.com/assets/schema/gameData.json",
  "data": {
    // data objects here
  }
}</nowiki>
 
<nowiki>await ctx.gameData.addPackage('data.json');</nowiki>
 
=== buildPackage(builder: (packageBuilder: GameDataPackageBuilder) => void): BuiltGameDataPackage ===
 
Builds a GameDataPackage object using the <code>GameDataPackageBuilder</code> API.
 
'''Parameters'''
 
<code>builder: (packageBuilder: GameDataPackageBuilder) => void</code> The builder to be used to add individual game objects to the data package.
 
'''Returns'''
 
<code>BuiltGameDataPackage</code> A wrapper for the game data package. See information below.
 
'''Example'''
 
<nowiki>ctx.gameData.buildPackage((p) => {
  // data registration here
});</nowiki>
 
==== BuiltGameDataPackage.package: GameDataPackage ====
 
(Property) The actual built <code>GameDataPackage</code> object.
 
==== BuiltGameDataPackage.add(): void ====
 
Registers the built game data package.
 
'''Example'''
 
<nowiki>const pkg = ctx.gameData.buildPackage((p) => { /* ... */ });
pkg.add();</nowiki>


== Mod Settings ==
== Mod Settings ==
91

edits