CodeAssetManager

CodeAssetManager

Manages adding and removing code assets from the scene.
Exported as a singleton instance.

Constructor

new CodeAssetManager()

Constructs a new CodeAssetManager.

Methods

addScriptToPage(codeAsset)

Adds a script tag to the page with contents based on the provided code asset.

Parameters:
Name Type Description
codeAsset Object

The code asset containing script contents.

addToScene(scene, codeAssets)

Adds/updates a code asset to the scene list and its associated script element.
If a code asset was updated: it removes the current script element and creates a new one with updated content.
If a code asset was added: it adds the new code asset to the scene list and adds a new script element to the page.

Parameters:
Name Type Description
scene Object

The current scene.

codeAssets Array.<CodeAsset>

An array of code assets to add.

createScriptBody(codeAsset) → {string}

Takes a code asset that is being added to the page in a script tag and inserts it inside the body template
The webpack configuration we have provided to the user will output a global var sumerianCodeAsset.
We set a new variable equal to codeAsset.name that references this outputed variable and allows for access
to its functions from the script editor without polluting the global name space.

Parameters:
Name Type Description
codeAsset CodeAsset

The code asset for which the script body will be generated.

removeFromScene(scene, codeAssets)

Removes a code asset from scene list and its associated script element from the page.

Parameters:
Name Type Description
scene Object

The current scene.

codeAssets Array.<CodeAsset>

An array of removed code assets.

removeScriptFromPage(codeRef)

Removes a previously added script element from the page.

Parameters:
Name Type Description
codeRef String

The codeRef for the previously added CodeAsset.