Mod Creation/Mod Context API Reference: Difference between revisions

m
fix double "the"
m (fix double "the")
 
(10 intermediate revisions by 2 users not shown)
Line 36: Line 36:


  <syntaxhighlight lang="js" line>const devCtx = mod.getDevContext();</syntaxhighlight>
  <syntaxhighlight lang="js" line>const devCtx = mod.getDevContext();</syntaxhighlight>
== Getter Properties ==
=== name: string ===
The name of the mod.
=== namespace: string | undefined ===
The defined namespace of the mod, if provided.
=== version: string ===
The currently loaded version of the mod.


== Loading Resources ==
== Loading Resources ==
Line 104: Line 118:
// my-independent-script.js has NOT run yet</syntaxhighlight>
// my-independent-script.js has NOT run yet</syntaxhighlight>


=== loadTemplates(path: string): void ===
=== loadTemplates(path: string): Promise<void> ===


Inject all <template> elements contained in a given HTML file into the document body.
Inject all <template> elements contained in a given HTML file into the document body.
Line 111: Line 125:


<code>path: string</code> The relative path to the HTML resource
<code>path: string</code> The relative path to the HTML resource
'''Returns'''
<code>Promise<void></code> A promise that is resolved once all templates have been injected into the document body.


'''Example'''
'''Example'''
Line 203: Line 221:
=== onCharacterSelectionLoaded(callback: (ctx: ModContext) => void | Promise<void>): void ===
=== onCharacterSelectionLoaded(callback: (ctx: ModContext) => void | Promise<void>): void ===


Execute code after the the character selection screen has fully loaded.
Execute code after the character selection screen has fully loaded.


'''Parameters'''
'''Parameters'''
Line 315: Line 333:


== Mod Settings ==
== Mod Settings ==
{{Disclaimer|When loading your mod as a Local Mod via the Creator Toolkit, the mod must be linked to mod.io and you must have subscribed to and installed the mod via mod.io in order for this data to persist.}}


The mod settings API can be accessed through the <code>settings</code> property on the root context object.
The mod settings API can be accessed through the <code>settings</code> property on the root context object.
Line 414: Line 434:
   // ...
   // ...
}</syntaxhighlight>
}</syntaxhighlight>
<small>''Comments in JSON are purely illustrative and not valid markup''</small>


  <syntaxhighlight lang="js" line>ctx.settings.type('customText', {
  <syntaxhighlight lang="js" line>ctx.settings.type('customText', {
Line 453: Line 475:
   input.type = 'text';
   input.type = 'text';
   input.name = name;
   input.name = name;
  input.addEventListener('change', () => onChange());


   const label = document.createElement('label');
   const label = document.createElement('label');
Line 623: Line 646:


== Character Data Storage ==
== Character Data Storage ==
{{Disclaimer|When loading your mod as a Local Mod via the Creator Toolkit, the mod must be linked to mod.io and you must have subscribed to and installed the mod via mod.io in order for this data to persist.}}


The character storage API can be accessed through the <code>characterStorage</code> property on the root context object.
The character storage API can be accessed through the <code>characterStorage</code> property on the root context object.
Line 684: Line 709:


== Account Data Storage ==
== Account Data Storage ==
{{Disclaimer|When loading your mod as a Local Mod via the Creator Toolkit, the mod must be linked to mod.io and you must have subscribed to and installed the mod via mod.io in order for this data to persist.}}


The account storage API can be accessed through the <code>accountStorage</code> property on the root context object.
The account storage API can be accessed through the <code>accountStorage</code> property on the root context object.
Line 924: Line 951:
   "setup": "setup.mjs"
   "setup": "setup.mjs"
}</syntaxhighlight>
}</syntaxhighlight>
<small>''Comments in JSON are purely illustrative and not valid markup''</small>


  <syntaxhighlight lang="js" line>// setup.mjs
  <syntaxhighlight lang="js" line>// setup.mjs
2

edits