Skip to content
Max Ziebell edited this page Feb 2, 2024 · 1 revision
/*!
 * Hype Extension Template
 * Copyright (Year) Your Name, (https://yourwebsite.com). MIT-license
 */

/*
 * Version-History
 * 1.0.0 Template created
 */

// Ensure the extension isn't redefined
if ("HypeExtensionName" in window === false) {
  window['HypeExtensionName'] = (function () {

	// Define default settings for the extension
	var _default = {
	  // Default properties
	  // Example: propertyName: 'defaultValue',
	  // These are key values or settings used in the extensions
	  // That might get globally overridden
	};

	/**
	 * Set or update a default value for the extension.
	 * 
	 * @param {String|Object} key - The default's key or an object with multiple defaults.
	 * @param {*} [value] - The new value for the default, if key is a string.
	 */
	function setDefault(key, value) {
	  if (typeof key === 'object') {
		_default = Object.assign(_default, key);
	  } else {
		_default[key] = value;
	  }
	}

	/**
	 * Get the current value of a default.
	 * 
	 * @param {String} [key] - The key of the default to get. If omitted, all defaults are returned.
	 * @returns {*} The default value(s).
	 */
	function getDefault(key) {
	  return key ? _default[key] : _default;
	}

	// Add custom utility functions here
	// Example: function utilityFunction() {}

	// Hype Document Load handler
	function HypeDocumentLoad(hypeDocument, element, event) {
	  // use this place to extend the Hype API on hypeDocument.someFunction = function (){}
  	}

	// Hype Scene Prepare For Display handler
	function HypeScenePrepareForDisplay(hypeDocument, element, event) {
	  // As Hype switches scene prepare things here on scene changes
	  // use HypeSceneLoad for the moment the scene is playing
	  // and HypeSceneUnload for garbage collection on a scene basis
	}

	// Register event listeners
	if ("HYPE_eventListeners" in window === false) {
	  window.HYPE_eventListeners = Array();
	}
	window.HYPE_eventListeners.push({"type": "HypeDocumentLoad", "callback": HypeDocumentLoad});
	window.HYPE_eventListeners.push({"type": "HypeScenePrepareForDisplay", "callback": HypeScenePrepareForDisplay});

	// Public API for the extension
	return {
	  version: '1.0.0',
	  setDefault: setDefault,
	  getDefault: getDefault,

	  // Add any other public methods or properties here
	  // Example: utilityFunction: utilityFunction
	};

  })();
}


Clone this wiki locally