Skip to main content

CoreObject

@physion/app / Exports / CoreObject

Class: CoreObject

Serves as the base class for most classes in Physion.

CoreObject itself extends EventEmitter to allow notifying the outside world on important events.

Hierarchy

  • EventEmitter

    CoreObject

    ↳↳ Asset

    ↳↳ Node

Constructors

constructor

new CoreObject(): CoreObject

Constructs a new instance.

A unique CoreObject.id will be assigned to the newly created instance.

Returns

CoreObject

Overrides

EventEmitter.constructor

Properties

EVT_NAME_CHANGED

Static Readonly EVT_NAME_CHANGED: "nameChanged"

The name of the event that is emitted whenever the name of this object changes.

The argument suplied is the new CoreObject.name of the object.


EVT_PROPERTY_CHANGED

Static Readonly EVT_PROPERTY_CHANGED: "propertyChanged"

The name of the event that is emitted whenever a property of this object changes.

The arguments supplied are: (1) The name of the property that has changed and (2) the new value of that property.

Accessors

flags

get flags(): CoreObjectFlags

Returns

CoreObjectFlags


id

get id(): string

Object's (unique) id

Note that the id of the object cannot be set (it is automatically assigned upon construction)

Returns

string


metaObject

get metaObject(): undefined | MetaObject

Returns the MetaObject that describes this class

Returns

undefined | MetaObject


name

get name(): string

The object's name

The object's name is a free text value which defaults to an empty string.

Note that when the name of the object changes, the CoreObject.EVT_NAME_CHANGED signal will be emitted.

Returns

string

set name(v): void

Parameters

NameType
vstring

Returns

void

Methods

getExtras

getExtras(): any

Returns any extra data that this object needs to save during serialization.

In some cases an object might need to save some extra data without necessarily this extra data being part of its state (e.g. the AssetsLibrary of a Scene). In these cases subclasses can re-implement this method and return the data required.

The default implementation returns undefined meaning that no extra data needs to be saved during serialization.

Returns

any


getState

getState(minified?): any

Returns this object's state

The object's state is an object containing key/value pairs corresponding to this object's properties. For example:

{
id: "Ssba4ch5ruok",
name: "Circle",
radius: 2,
// ...
}

To avoid including properties that are currently in their default value you can set minified = true when calling getState.

Note that read-only properties are not part of the object's state (with the exception of the id)

Parameters

NameTypeDefault valueDescription
minifiedbooleanfalseWhether to return a minified state or not

Returns

any


setExtras

setExtras(_x): boolean

Sets any extra data that this object needs during de-serialization.

Returns true on success, otherwise returns false.

The default implementation does nothing and returns true.

Parameters

NameType
_xany

Returns

boolean


setFlag

setFlag(flag, on?): void

Parameters

NameTypeDefault value
flagCoreObjectFlagsundefined
onbooleantrue

Returns

void


setState

setState(state, updateId?): boolean

Sets the object's state

Parameters

NameTypeDefault valueDescription
stateanyundefinedThe state to be set
updateIdbooleantrueWhether to also update the id property

Returns

boolean

True on success otherwise false


testFlag

testFlag(flag): boolean

Parameters

NameType
flagCoreObjectFlags

Returns

boolean