Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/framework/components/anim/data.js

This file was deleted.

16 changes: 2 additions & 14 deletions src/framework/components/anim/system.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { AnimTrack } from '../../anim/evaluator/anim-track.js';
import { Component } from '../component.js';
import { ComponentSystem } from '../system.js';
import { AnimComponent } from './component.js';
import { AnimComponentData } from './data.js';

/**
* @import { AppBase } from '../../app-base.js'
*/

const _schema = [
'enabled'
];

/**
* The AnimComponentSystem manages creating and deleting AnimComponents.
*
Expand All @@ -30,16 +24,13 @@ class AnimComponentSystem extends ComponentSystem {
this.id = 'anim';

this.ComponentType = AnimComponent;
this.DataType = AnimComponentData;

this.schema = _schema;

this.on('beforeremove', this.onBeforeRemove, this);
this.app.systems.on('animationUpdate', this.onAnimationUpdate, this);
}

initializeComponentData(component, data, properties) {
super.initializeComponentData(component, data, _schema);
super.initializeComponentData(component, data);
const complexProperties = ['animationAssets', 'stateGraph', 'layers', 'masks'];
Object.keys(data).forEach((key) => {
// these properties will be initialized manually below
Expand Down Expand Up @@ -93,9 +84,8 @@ class AnimComponentSystem extends ComponentSystem {
for (const id in components) {
if (components.hasOwnProperty(id)) {
const component = components[id].entity.anim;
const componentData = component.data;

if (componentData.enabled && component.entity.enabled && component.playing) {
if (component.enabled && component.entity.enabled && component.playing) {
component.update(dt);
}
}
Expand Down Expand Up @@ -151,6 +141,4 @@ class AnimComponentSystem extends ComponentSystem {
}
}

Component._buildAccessors(AnimComponent.prototype, _schema);

export { AnimComponentSystem };
5 changes: 0 additions & 5 deletions src/framework/components/animation/data.js

This file was deleted.

19 changes: 4 additions & 15 deletions src/framework/components/animation/system.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { Component } from '../component.js';
import { ComponentSystem } from '../system.js';
import { AnimationComponent } from './component.js';
import { AnimationComponentData } from './data.js';

/**
* @import { AppBase } from '../../app-base.js'
* @import { Entity } from '../../entity.js'
*/

const _schema = [
'enabled'
];

/**
* The AnimationComponentSystem manages creating and deleting AnimationComponents.
*
Expand All @@ -30,9 +24,6 @@ class AnimationComponentSystem extends ComponentSystem {
this.id = 'animation';

this.ComponentType = AnimationComponent;
this.DataType = AnimationComponentData;

this.schema = _schema;

this.on('beforeremove', this.onBeforeRemove, this);
this.app.systems.on('update', this.onUpdate, this);
Expand Down Expand Up @@ -60,7 +51,7 @@ class AnimationComponentSystem extends ComponentSystem {
}
}

super.initializeComponentData(component, data, _schema);
super.initializeComponentData(component, data);
}

/**
Expand Down Expand Up @@ -119,10 +110,10 @@ class AnimationComponentSystem extends ComponentSystem {

for (const id in components) {
if (components.hasOwnProperty(id)) {
const component = components[id];
const { entity } = components[id];

if (component.data.enabled && component.entity.enabled) {
component.entity.animation.update(dt);
if (entity.animation.enabled && entity.enabled) {
entity.animation.update(dt);
}
}
}
Expand All @@ -135,6 +126,4 @@ class AnimationComponentSystem extends ComponentSystem {
}
}

Component._buildAccessors(AnimationComponent.prototype, _schema);

export { AnimationComponentSystem };
5 changes: 0 additions & 5 deletions src/framework/components/audio-listener/data.js

This file was deleted.

17 changes: 4 additions & 13 deletions src/framework/components/audio-listener/system.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { Debug } from '../../../core/debug.js';
import { Component } from '../component.js';
import { ComponentSystem } from '../system.js';
import { AudioListenerComponent } from './component.js';
import { AudioListenerComponentData } from './data.js';

/**
* @import { AppBase } from '../../app-base.js'
*/

const _schema = ['enabled'];

/**
* Component System for adding and removing {@link AudioListenerComponent} objects to Entities.
*
Expand All @@ -28,9 +24,6 @@ class AudioListenerComponentSystem extends ComponentSystem {
this.id = 'audiolistener';

this.ComponentType = AudioListenerComponent;
this.DataType = AudioListenerComponentData;

this.schema = _schema;

this.manager = app.soundManager;
Debug.assert(this.manager, 'AudioListenerComponentSystem cannot be created without sound manager');
Expand All @@ -40,10 +33,10 @@ class AudioListenerComponentSystem extends ComponentSystem {
this.app.systems.on('update', this.onUpdate, this);
}

initializeComponentData(component, data, properties) {
properties = ['enabled'];

super.initializeComponentData(component, data, properties);
cloneComponent(entity, clone) {
return this.addComponent(clone, {
enabled: entity.audiolistener.enabled
});
}

onUpdate(dt) {
Expand All @@ -63,6 +56,4 @@ class AudioListenerComponentSystem extends ComponentSystem {
}
}

Component._buildAccessors(AudioListenerComponent.prototype, _schema);

export { AudioListenerComponentSystem };
5 changes: 0 additions & 5 deletions src/framework/components/button/data.js

This file was deleted.

11 changes: 1 addition & 10 deletions src/framework/components/button/system.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { Component } from '../component.js';
import { ComponentSystem } from '../system.js';
import { ButtonComponent } from './component.js';
import { ButtonComponentData } from './data.js';

/**
* @import { AppBase } from '../../app-base.js'
*/

const _schema = ['enabled'];

const _properties = [
'imageEntity',
'active',
Expand Down Expand Up @@ -44,9 +40,6 @@ class ButtonComponentSystem extends ComponentSystem {
this.id = 'button';

this.ComponentType = ButtonComponent;
this.DataType = ButtonComponentData;

this.schema = _schema;

this.on('beforeremove', this._onRemoveComponent, this);

Expand All @@ -64,7 +57,7 @@ class ButtonComponentSystem extends ComponentSystem {
}
}

super.initializeComponentData(component, data, _schema);
super.initializeComponentData(component, data);
}

cloneComponent(entity, clone) {
Expand Down Expand Up @@ -111,6 +104,4 @@ class ButtonComponentSystem extends ComponentSystem {
}
}

Component._buildAccessors(ButtonComponent.prototype, _schema);

export { ButtonComponentSystem };
5 changes: 0 additions & 5 deletions src/framework/components/camera/data.js

This file was deleted.

11 changes: 1 addition & 10 deletions src/framework/components/camera/system.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { sortPriority } from '../../../core/sort.js';
import { Color } from '../../../core/math/color.js';
import { Vec4 } from '../../../core/math/vec4.js';
import { Component } from '../component.js';
import { ComponentSystem } from '../system.js';
import { CameraComponent } from './component.js';
import { CameraComponentData } from './data.js';

/**
* @import { AppBase } from '../../app-base.js'
*/

const _schema = ['enabled'];

/**
* Used to add and remove {@link CameraComponent}s from Entities. It also holds an array of all
* active cameras.
Expand All @@ -38,9 +34,6 @@ class CameraComponentSystem extends ComponentSystem {
this.id = 'camera';

this.ComponentType = CameraComponent;
this.DataType = CameraComponentData;

this.schema = _schema;

this.on('beforeremove', this.onBeforeRemove, this);
this.app.on('prerender', this.onAppPrerender, this);
Expand Down Expand Up @@ -108,7 +101,7 @@ class CameraComponentSystem extends ComponentSystem {
}
}

super.initializeComponentData(component, data, ['enabled']);
super.initializeComponentData(component, data);
}

cloneComponent(entity, clone) {
Expand Down Expand Up @@ -179,6 +172,4 @@ class CameraComponentSystem extends ComponentSystem {
}
}

Component._buildAccessors(CameraComponent.prototype, _schema);

export { CameraComponentSystem };
5 changes: 0 additions & 5 deletions src/framework/components/collision/data.js

This file was deleted.

11 changes: 1 addition & 10 deletions src/framework/components/collision/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { Vec3 } from '../../../core/math/vec3.js';
import { SEMANTIC_POSITION } from '../../../platform/graphics/constants.js';
import { GraphNode } from '../../../scene/graph-node.js';
import { Model } from '../../../scene/model.js';
import { Component } from '../component.js';
import { ComponentSystem } from '../system.js';
import { CollisionComponent } from './component.js';
import { CollisionComponentData } from './data.js';
import { Trigger } from './trigger.js';

/**
Expand All @@ -21,8 +19,6 @@ const p2 = new Vec3();
const quat = new Quat();
const tempGraphNode = new GraphNode();

const _schema = ['enabled'];

const _properties = [
'halfExtents',
'radius',
Expand Down Expand Up @@ -633,9 +629,6 @@ class CollisionComponentSystem extends ComponentSystem {
this.id = 'collision';

this.ComponentType = CollisionComponent;
this.DataType = CollisionComponentData;

this.schema = _schema;

this.implementations = { };

Expand Down Expand Up @@ -680,7 +673,7 @@ class CollisionComponentSystem extends ComponentSystem {
const impl = this._createImplementation(component._type);
impl.beforeInitialize(component);

super.initializeComponentData(component, data, _schema);
super.initializeComponentData(component, data);

impl.afterInitialize(component);
}
Expand Down Expand Up @@ -875,6 +868,4 @@ class CollisionComponentSystem extends ComponentSystem {
}
}

Component._buildAccessors(CollisionComponent.prototype, _schema);

export { CollisionComponentSystem };
30 changes: 25 additions & 5 deletions src/framework/components/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class Component extends EventHandler {
*/
entity;

/**
* The enabled state of the component.
*
* @type {boolean}
* @private
*/
_enabled = true;

/**
* Base constructor for a Component.
*
Expand All @@ -47,7 +55,9 @@ class Component extends EventHandler {
this.system = system;
this.entity = entity;

if (this.system.schema && !this._accessorsBuilt) {
// Legacy path for external components (e.g. playcanvas-spine) that define a schema on
// their system: build data-backed instance accessors for each schema property
if (this.system.schema?.length && !this._accessorsBuilt) {
this.buildAccessors(this.system.schema);
}

Expand All @@ -58,7 +68,12 @@ class Component extends EventHandler {
this.on('set_enabled', this.onSetEnabled, this);
}

/** @ignore */
/**
* Legacy path for external components (e.g. playcanvas-spine) that store their properties in
* a ComponentData object: creates data-backed accessors for each schema property.
*
* @ignore
*/
static _buildAccessors(obj, schema) {
// Create getter/setter pairs for each property defined in the schema
schema.forEach((descriptor) => {
Expand Down Expand Up @@ -115,7 +130,9 @@ class Component extends EventHandler {

/**
* Access the component data directly. Usually you should access the data properties via the
* individual properties as modifying this data directly will not fire 'set' events.
* individual properties as modifying this data directly will not fire 'set' events. This is a
* legacy path for external components that still store their properties in a ComponentData
* object - engine components no longer store any data here.
*
* @type {*}
* @ignore
Expand All @@ -130,7 +147,10 @@ class Component extends EventHandler {
*
* @type {boolean}
*/
set enabled(arg) {
set enabled(value) {
const oldValue = this._enabled;
this._enabled = value;
this.fire('set', 'enabled', oldValue, value);
}

/**
Expand All @@ -139,7 +159,7 @@ class Component extends EventHandler {
* @type {boolean}
*/
get enabled() {
return true;
return this._enabled;
}
}

Expand Down
Loading