val dataModel = EntityContext.getDataModel()
// setup button event listener
button.entity.registerEventListener<EventArgs>("button") { _, _ ->
// handle event
}
dataModel?.sendEvent(entity, "button", EventArgs("click", dataModel))
class DataModel(dataModel_: Long)
DataModel
(
dataModel_
)
|
bumpComponentVersion
(
entityId
, componentId
)
|
Bumps the component version, marking it as "changed" without modifying data.
This forces a component to be considered changed for change detection purposes, even when the actual component data hasn't been modified. This will trigger component change listeners and queries that look for changed components.
Signature
fun bumpComponentVersion(entityId: Long, componentId: Int) Parameters
entityId:
Long
componentId:
Int
|
createEntity
()
|
Creates a new entity in the data model.
Signature
fun createEntity(): Entity |
createEntity
(
components
)
|
Creates a new entity in the data model with components.
Signature
fun createEntity(components: List<ComponentBase>): Entity Parameters
components:
List
|
createEntity
(
components
)
|
Creates a new entity in the data model with components.
Signature
fun createEntity(vararg components: ComponentBase): Entity Parameters
components:
ComponentBase |
deleteEntity
(
eid
)
|
Deletes an entity from the data model. The entity will be included in deleted queries next tick. We recommend using Entity.destroy() instead of this function.
Signature
fun deleteEntity(eid: Long) Parameters
eid:
Long
|
getEventListenerForEvent
(
eventType
)
|
Gets all listeners registered for a specific event type.
Signature
fun getEventListenerForEvent(eventType: String): Set<<Error class: unknown class><Entity, EventListener<EventArgs>>> Parameters
eventType:
String
Returns
Set
|
getKeyValueMap
(
id
, attribute
)
|
Signature
inline fun <T, V> getKeyValueMap(id: Long, attribute: Int): HashMap<T, V> Parameters
id:
Long
attribute:
Int
Returns
HashMap
|
getLastUpdateVersion
()
|
Experimental API. This gets a long that represents the last updated version of the data model.
This is important for making updates the same tick as other component changes. Example:
class MyComponentSystem() : SystemBase() {
private var lastUpdateVersion = 0UL
@OptIn(SpatialSDKExperimentalAPI::class)
override fun execute() {
for (entity in Query.where { changedSince(MyComponent.id, lastUpdateVersion) }.eval()) {
// handle changing entity
}
lastUpdateVersion = EntityContext.getDataModel()!!.getLastUpdateVersion()
}
}
Signature
fun getLastUpdateVersion(): ULong Returns
ULong
|
hasKey
(
id
, attribute
)
|
Checks if an entity has a specific attribute.
Signature
fun hasKey(id: Long, attribute: Int): Boolean Parameters
id:
Long
attribute:
Int
Returns
Boolean
|
nativeGetKeyValueMap
(
dataModel
, id
, attribute
)
|
Signature
external fun nativeGetKeyValueMap(dataModel: Long, id: Long, attribute: Int): Array<Any> Parameters
dataModel:
Long
id:
Long
attribute:
Int
Returns
Array
|
registerAttributeListener
(
attribute
, listener
)
|
Registers a listener for changes to a specific attribute.
Signature
fun registerAttributeListener(attribute: Int, listener: AttributeListener) Parameters
attribute:
Int
listener:
AttributeListener |
registerComponentListener
(
componentID
, componentClass
, listener
)
|
Registers a listener for changes to a specific component.
Signature
fun registerComponentListener(componentID: Int, componentClass: KClass<*>, listener: ComponentListener) Parameters
componentID:
Int
componentClass:
KClass
listener:
ComponentListener |
registerEventListener
(
entity
, eventType
, listener
)
|
Registers a listener for events on a specific entity.
Signature
fun registerEventListener(entity: Entity, eventType: String, listener: EventListener<EventArgs>) Parameters
entity:
Entity
eventType:
String
listener:
EventListener |
registerLinkedEntityAttribute
(
attributeID
)
|
This method is experimental and is subject to change in the future.
Registering a linked entity attribute makes it so that the DataModel will build a hierarchy based on the given entity attribute. This means that you can query for children of a given entity based on the registered linked entity attribute.
Example:
In Your Activity's OnCreate:
EntityContext.getDataModel()?.registerLinkedEntityAttribute(MyComponent.myEntityAttributeData)
Then you can query for children of a certain entity (Where their MyComponent.myEntityAttribute is myEntity) in a System Query:
val query = Query.where { childrenOf(myEntity, MyComponent.myEntityAttributeData) }
Signature
fun registerLinkedEntityAttribute(attributeID: Int) Parameters
attributeID:
Int
|
removeComponentListener
(
componentID
)
|
Removes a previously registered component listener.
Signature
fun removeComponentListener(componentID: Int) Parameters
componentID:
Int
|
getLocalDataModelTime
()
|
Gets the local time based on the data model.
Signature
fun getLocalDataModelTime(): Long Returns
Long
|
inner class KeyIterator(dm_: DataModel, it_: Long)
KeyIterator
(
dm_
, it_
)
|
Signature
constructor(dm_: DataModel, it_: Long) Parameters
dm_:
DataModel
it_:
Long
Returns
DataModel.KeyIterator
|
close
()
|
Signature
fun close() |
end
()
|
Signature
fun end(): Boolean Returns
Boolean
|
entity
()
|
Signature
fun entity(): Entity Returns |
finalize
()
|
Signature
fun finalize() |
next
()
|
Signature
operator fun next() |