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
4 changes: 2 additions & 2 deletions src/framework/components/anim/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ class AnimComponent extends Component {
}

resolveDuplicatedEntityReferenceProperties(oldAnim, duplicatedIdsMap) {
if (oldAnim.rootBone && duplicatedIdsMap[oldAnim.rootBone.getGuid()]) {
this.rootBone = duplicatedIdsMap[oldAnim.rootBone.getGuid()];
if (oldAnim.rootBone && duplicatedIdsMap[oldAnim.rootBone.guid]) {
this.rootBone = duplicatedIdsMap[oldAnim.rootBone.guid];
} else {
this.rebind();
}
Expand Down
6 changes: 3 additions & 3 deletions src/framework/components/button/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class ButtonComponent extends Component {
set imageEntity(arg) {
if (this._imageEntity !== arg) {
const isString = typeof arg === 'string';
if (this._imageEntity && isString && this._imageEntity.getGuid() === arg) {
if (this._imageEntity && isString && this._imageEntity.guid === arg) {
return;
}

Expand All @@ -422,7 +422,7 @@ class ButtonComponent extends Component {
}

if (this._imageEntity) {
this.data.imageEntity = this._imageEntity.getGuid();
this.data.imageEntity = this._imageEntity.guid;
} else if (isString && arg) {
this.data.imageEntity = arg;
}
Expand Down Expand Up @@ -1185,7 +1185,7 @@ class ButtonComponent extends Component {

resolveDuplicatedEntityReferenceProperties(oldButton, duplicatedIdsMap) {
if (oldButton.imageEntity) {
this.imageEntity = duplicatedIdsMap[oldButton.imageEntity.getGuid()];
this.imageEntity = duplicatedIdsMap[oldButton.imageEntity.guid];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/framework/components/collision/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class CollisionSystemImpl {

// Called when the collision is cloned to another entity
clone(entity, clone) {
const src = this.system.store[entity.getGuid()];
const src = this.system.store[entity.guid];

const data = {
enabled: src.data.enabled,
Expand Down
2 changes: 1 addition & 1 deletion src/framework/components/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Component extends EventHandler {
* @ignore
*/
get data() {
const record = this.system.store[this.entity.getGuid()];
const record = this.system.store[this.entity.guid];
return record ? record.data : null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/framework/components/render/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ class RenderComponent extends Component {
set rootBone(value) {
if (this._rootBone !== value) {
const isString = typeof value === 'string';
if (this._rootBone && isString && this._rootBone.getGuid() === value) {
if (this._rootBone && isString && this._rootBone.guid === value) {
return;
}

Expand Down Expand Up @@ -1067,7 +1067,7 @@ class RenderComponent extends Component {

resolveDuplicatedEntityReferenceProperties(oldRender, duplicatedIdsMap) {
if (oldRender.rootBone) {
this.rootBone = duplicatedIdsMap[oldRender.rootBone.getGuid()];
this.rootBone = duplicatedIdsMap[oldRender.rootBone.guid];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/framework/components/rigid-body/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ class RigidBodyComponentSystem extends ComponentSystem {
*/
_storeCollision(entity, other) {
let isNewCollision = false;
const guid = entity.getGuid();
const guid = entity.guid;

this.collisions[guid] = this.collisions[guid] || { others: [], entity: entity };

Expand Down
2 changes: 1 addition & 1 deletion src/framework/components/screen/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ScreenComponent extends Component {
* the next update loop.
*/
syncDrawOrder() {
this.system.queueDrawOrderSync(this.entity.getGuid(), this._processDrawOrderSync, this);
this.system.queueDrawOrderSync(this.entity.guid, this._processDrawOrderSync, this);
}

_recurseDrawOrderSync(e, i) {
Expand Down
6 changes: 3 additions & 3 deletions src/framework/components/script/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,17 +610,17 @@ class ScriptComponent extends Component {

const newGuidArray = oldValue.slice();
for (let i = 0; i < len; i++) {
const guid = newGuidArray[i] instanceof Entity ? newGuidArray[i].getGuid() : newGuidArray[i];
const guid = newGuidArray[i] instanceof Entity ? newGuidArray[i].guid : newGuidArray[i];
if (duplicatedIdsMap[guid]) {
newGuidArray[i] = useGuid ? duplicatedIdsMap[guid].getGuid() : duplicatedIdsMap[guid];
newGuidArray[i] = useGuid ? duplicatedIdsMap[guid].guid : duplicatedIdsMap[guid];
}
}

newAttributes[attributeName] = newGuidArray;
} else {
// handle regular entity attribute
if (oldValue instanceof Entity) {
oldValue = oldValue.getGuid();
oldValue = oldValue.guid;
} else if (typeof oldValue !== 'string') {
return;
}
Expand Down
16 changes: 8 additions & 8 deletions src/framework/components/scroll-view/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class ScrollViewComponent extends Component {
}

const isString = typeof arg === 'string';
if (this._viewportEntity && isString && this._viewportEntity.getGuid() === arg) {
if (this._viewportEntity && isString && this._viewportEntity.guid === arg) {
return;
}

Expand Down Expand Up @@ -512,7 +512,7 @@ class ScrollViewComponent extends Component {
}

const isString = typeof arg === 'string';
if (this._contentEntity && isString && this._contentEntity.getGuid() === arg) {
if (this._contentEntity && isString && this._contentEntity.guid === arg) {
return;
}

Expand Down Expand Up @@ -554,7 +554,7 @@ class ScrollViewComponent extends Component {
}

const isString = typeof arg === 'string';
if (this._horizontalScrollbarEntity && isString && this._horizontalScrollbarEntity.getGuid() === arg) {
if (this._horizontalScrollbarEntity && isString && this._horizontalScrollbarEntity.guid === arg) {
return;
}

Expand Down Expand Up @@ -598,7 +598,7 @@ class ScrollViewComponent extends Component {
}

const isString = typeof arg === 'string';
if (this._verticalScrollbarEntity && isString && this._verticalScrollbarEntity.getGuid() === arg) {
if (this._verticalScrollbarEntity && isString && this._verticalScrollbarEntity.guid === arg) {
return;
}

Expand Down Expand Up @@ -1350,16 +1350,16 @@ class ScrollViewComponent extends Component {

resolveDuplicatedEntityReferenceProperties(oldScrollView, duplicatedIdsMap) {
if (oldScrollView.viewportEntity) {
this.viewportEntity = duplicatedIdsMap[oldScrollView.viewportEntity.getGuid()];
this.viewportEntity = duplicatedIdsMap[oldScrollView.viewportEntity.guid];
}
if (oldScrollView.contentEntity) {
this.contentEntity = duplicatedIdsMap[oldScrollView.contentEntity.getGuid()];
this.contentEntity = duplicatedIdsMap[oldScrollView.contentEntity.guid];
}
if (oldScrollView.horizontalScrollbarEntity) {
this.horizontalScrollbarEntity = duplicatedIdsMap[oldScrollView.horizontalScrollbarEntity.getGuid()];
this.horizontalScrollbarEntity = duplicatedIdsMap[oldScrollView.horizontalScrollbarEntity.guid];
}
if (oldScrollView.verticalScrollbarEntity) {
this.verticalScrollbarEntity = duplicatedIdsMap[oldScrollView.verticalScrollbarEntity.getGuid()];
this.verticalScrollbarEntity = duplicatedIdsMap[oldScrollView.verticalScrollbarEntity.guid];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/framework/components/scrollbar/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class ScrollbarComponent extends Component {

resolveDuplicatedEntityReferenceProperties(oldScrollbar, duplicatedIdsMap) {
if (oldScrollbar.handleEntity) {
this.handleEntity = duplicatedIdsMap[oldScrollbar.handleEntity.getGuid()];
this.handleEntity = duplicatedIdsMap[oldScrollbar.handleEntity.guid];
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/framework/components/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ComponentSystem extends EventHandler {
const component = new this.ComponentType(this, entity);
const componentData = new this.DataType();

this.store[entity.getGuid()] = {
this.store[entity.guid] = {
entity: entity,
data: componentData
};
Expand All @@ -80,13 +80,13 @@ class ComponentSystem extends EventHandler {
*/
removeComponent(entity) {
const id = this.id;
const record = this.store[entity.getGuid()];
const record = this.store[entity.guid];
const component = entity.c[id];

component.fire('beforeremove');
this.fire('beforeremove', entity, component);

delete this.store[entity.getGuid()];
delete this.store[entity.guid];

entity[id] = undefined;
delete entity.c[id];
Expand All @@ -104,7 +104,7 @@ class ComponentSystem extends EventHandler {
*/
cloneComponent(entity, clone) {
// default clone is just to add a new component with existing data
const src = this.store[entity.getGuid()];
const src = this.store[entity.guid];
return this.addComponent(clone, src.data);
}

Expand Down
58 changes: 41 additions & 17 deletions src/framework/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,37 +473,61 @@ class Entity extends GraphNode {
}

/**
* Get the GUID value for this Entity. The GUID is generated lazily on first access if one has
* not been assigned.
* Sets the GUID for this Entity. Note that it is unlikely that you should need to change the
* GUID value of an Entity at run-time. Doing so will corrupt the graph this Entity is in.
*
* @returns {string} The GUID of the Entity.
* @type {string}
* @ignore
*/
getGuid() {
set guid(value) {
// remove current guid from entityIndex
const index = this._app._entityIndex;
if (this._guid) {
delete index[this._guid];
}

// add new guid to entityIndex
this._guid = value;
index[this._guid] = this;
}

/**
* Gets the GUID for this Entity.
*
* @type {string}
*/
get guid() {
// if the guid hasn't been set yet then set it now before returning it
if (!this._guid) {
this.setGuid(guid.create());
this.guid = guid.create();
}

return this._guid;
}

/**
* Get the GUID value for this Entity.
*
* @returns {string} The GUID of the Entity.
* @ignore
* @deprecated Use {@link Entity#guid} instead.
*/
getGuid() {
Debug.deprecated('Entity#getGuid is deprecated. Use Entity#guid instead.');
return this.guid;
}

/**
* Set the GUID value for this Entity. Note that it is unlikely that you should need to change
* the GUID value of an Entity at run-time. Doing so will corrupt the graph this Entity is in.
*
* @param {string} guid - The GUID to assign to the Entity.
* @ignore
* @deprecated Use {@link Entity#guid} instead.
*/
setGuid(guid) {
// remove current guid from entityIndex
const index = this._app._entityIndex;
if (this._guid) {
delete index[this._guid];
}

// add new guid to entityIndex
this._guid = guid;
index[this._guid] = this;
Debug.deprecated('Entity#setGuid is deprecated. Use Entity#guid instead.');
this.guid = guid;
}

/**
Expand Down Expand Up @@ -642,7 +666,7 @@ class Entity extends GraphNode {
clone() {
const duplicatedIdsMap = {};
const clone = this._cloneRecursively(duplicatedIdsMap);
duplicatedIdsMap[this.getGuid()] = clone;
duplicatedIdsMap[this.guid] = clone;

resolveDuplicatedEntityReferenceProperties(this, this, clone, duplicatedIdsMap);

Expand Down Expand Up @@ -689,7 +713,7 @@ class Entity extends GraphNode {
if (oldChild instanceof Entity) {
const newChild = oldChild._cloneRecursively(duplicatedIdsMap);
clone.addChild(newChild);
duplicatedIdsMap[oldChild.getGuid()] = newChild;
duplicatedIdsMap[oldChild.guid] = newChild;
}
}

Expand Down Expand Up @@ -730,7 +754,7 @@ function resolveDuplicatedEntityReferenceProperties(oldSubtreeRoot, oldEntity, n
const entityIsWithinOldSubtree = !!oldSubtreeRoot.findByGuid(oldEntityReferenceId);

if (entityIsWithinOldSubtree) {
const newEntityReferenceId = duplicatedIdsMap[oldEntityReferenceId].getGuid();
const newEntityReferenceId = duplicatedIdsMap[oldEntityReferenceId].guid;

if (newEntityReferenceId) {
newEntity.c[componentName][propertyName] = newEntityReferenceId;
Expand Down
6 changes: 3 additions & 3 deletions src/framework/input/element-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,9 @@ class ElementInput {
const hovered = this._getTargetElementByCoords(cameras[c], coords.x, coords.y);
if (hovered === element) {

if (!this._clickedEntities[element.entity.getGuid()]) {
if (!this._clickedEntities[element.entity.guid]) {
this._fireEvent('click', new ElementTouchEvent(event, element, camera, x, y, touch));
this._clickedEntities[element.entity.getGuid()] = Date.now();
this._clickedEntities[element.entity.guid] = Date.now();
}

}
Expand Down Expand Up @@ -759,7 +759,7 @@ class ElementInput {
// click event
if (this._pressedElement === this._hoveredElement) {
// fire click event if it hasn't been fired already by the touchend handler
const guid = this._hoveredElement.entity.getGuid();
const guid = this._hoveredElement.entity.guid;
// Always fire, if there are no clicked entities
let fireClick = !this._clickedEntities;
// But if there are, we need to check how long ago touchend added a "click brake"
Expand Down
4 changes: 2 additions & 2 deletions src/framework/parsers/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SceneParser {
_createEntity(data, compressed) {
const entity = new Entity(data.name, this._app);

entity.setGuid(data.resource_id);
entity.guid = data.resource_id;
this._setPosRotScale(entity, data, compressed);
entity._enabled = data.enabled ?? true;

Expand Down Expand Up @@ -93,7 +93,7 @@ class SceneParser {
const systemsList = this._app.systems.list;

let len = systemsList.length;
const entityData = entities[entity.getGuid()];
const entityData = entities[entity.guid];
for (let i = 0; i < len; i++) {
const system = systemsList[i];
const componentData = entityData.components[system.id];
Expand Down
4 changes: 2 additions & 2 deletions test/assets/scripts/cloner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ const Cloner = pc.createScript('cloner');
Cloner.attributes.add('entityToClone', { type: 'entity' });

Cloner.prototype.initialize = function () {
window.initializeCalls.push(`${this.entity.getGuid()} initialize cloner`);
window.initializeCalls.push(`${this.entity.guid} initialize cloner`);
const clone = this.entityToClone.clone();
clone.name += ' - clone';
this.app.root.addChild(clone);
};

Cloner.prototype.postInitialize = function () {
window.initializeCalls.push(`${this.entity.getGuid()} postInitialize cloner`);
window.initializeCalls.push(`${this.entity.guid} postInitialize cloner`);
};
Loading