import { DynamicLoadComponent } from '../components/DynamicLoadComponent';
import { Utils } from '../common/Utils';
import { Object3D } from './Object3D';
const registerComponentParam = { isResident: true };
const captureEvents = [
'wheel',
'mouseenter',
'mouseleave',
'mousemove',
'mousedown',
'mouseup',
'keydown',
'keyup',
'keypress',
'click',
'dblclick',
'beforeaddchild',
'afteraddchild',
'beforeremovechild',
'afterremovechild'
];
/**
* @class RootObject
* The root object.
* @memberof THING
* @extends THING.Object3D
*/
class RootObject extends Object3D {
/**
* The root object of all objects.
* @param {Object} param The initial parameters.
*/
constructor(param = {}) {
super(param);
}
onInitEventArgs(info) {
// Here we need to let root capture these events
if (captureEvents.indexOf(info.type) !== -1) {
info.useCapture = true;
info.includeSelf = true;
}
}
onSetupComponent(param) {
super.onSetupComponent(param);
this.addComponent(DynamicLoadComponent, 'dynamicLoad', registerComponentParam);
}
onSetupResource(param) {
// Root setup would complete in sync mode
this.onSetupURL(param);
this.onLoadComplete();
}
onLoadComplete() {
// The root object is an empty node that does not execute the methods of the parent class
if (this.destroyed) {
return;
}
// Update loaded flag
this._resourceState = Object3D.ResourceState.Loaded;
}
clone() {
return Promise.reject('The root node does not support clone!');
}
copy() {
return Promise.reject('The root node does not support copy!');
}
destroy(force = false) {
if (!force) {
Utils.error(`The root object can not be destroyed`);
return;
}
super.destroy();
}
// #region Accessor
// #endregion
/**
* Check whether it's RootObject type or inherit from it.
* @type {Boolean}
*/
get isRootObject() {
return true;
}
}
export { RootObject }