import register from "../util/register.js";
import m_data_fact from "../intern/data.js";
import m_loader_fact from "../intern/loader.js";
/**
* Data API. Used to load/unload exported JSON data files.
* @module data
* @local StageloadCallback
* @local LoadedCallback
*/
function Data(ns, exports) {
/**
* Data loaded callback.
* Executed when the data loading process has been completed.
* @callback LoadedCallback
* @param {number} data_id Data ID
* @param {boolean} success Load success
*/
/**
* Loading stage callback.
* Used to implement loading progress indicators (preloaders).
* @callback StageloadCallback
* @param {number} percentage Loading progress (0-100).
* @param {number} load_time Loading time in ms.
* @param {number} data_id Data ID
*/
var m_data = m_data_fact(ns);
var m_loader = m_loader_fact(ns);
/**
* Load data from the json file exported from Blender.
* @method module:data.load
* @param {string} path Path to JSON file
* @param {LoadedCallback} [loaded_cb=null] Callback to be executed right after load
* @param {StageloadCallback} [stageload_cb=null] Callback to report about the loading progress
* @param {boolean} [wait_complete_loading=false] Wait until all resources are loaded
* @param {boolean} [load_hidden=false] Hide loaded and disable physics objects
* @returns {number} ID of loaded data.
*/
exports.load = m_data.load;
/**
* Unload the previously loaded data.
* @method module:data.unload
* @param {number} [data_id=0] ID of unloaded data. Unload all data if data_id is zero.
*/
exports.unload = function(data_id) {
data_id = data_id | 0;
m_data.unload(data_id);
}
/**
* Set the root which contains the resources, for debug purposes.
* Enables the checking of loading paths, so if the resources are not loaded from
* the app root, there will be a warning in m_print.
* @method module:data.set_debug_resources_root
* @param {string} debug_resources_root App root directory.
*/
exports.set_debug_resources_root = m_data.set_debug_resources_root;
/**
* Check if the engine primary data (main scene) is loaded (detect the last loading stage).
* @method module:data.is_primary_loaded
* @returns {boolean} Check result
*/
exports.is_primary_loaded = m_data.is_primary_loaded;
/**
* Check if the engine has finished all of the scheduled loading actions.
* @method module:data.is_idle
* @returns {boolean} Check result
*/
exports.is_idle = m_loader.is_finished;
exports.load_and_add_new = m_data.load;
exports.cleanup = exports.unload;
/**
* Activate media data context.
* Activation of audio/video contexts is required for mobile platforms which
* disable media playback without explicit user interaction. This method
* should be executed inside some input event listener.
* @method module:data.activate_media
*/
exports.activate_media = m_data.activate_media;
/**
* Preload scene's resources and put them into cache.
* @param {string} path Path to JSON file
* @param {LoadedCallback} [loaded_cb=null] Callback to be executed right after load
* @param {StageloadCallback} [stageload_cb=null] Callback to report about the loading progress
* @method module:data.prefetch
*/
exports.prefetch = m_data.prefetch;
/**
* Clear loading cache.
* @method module:data.unfetch
*/
exports.unfetch = m_data.unfetch;
}
var data_factory = register("data", Data);
export default data_factory;