50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "entityinteractable.h"
|
|
#include "entity/entitymanager.h"
|
|
|
|
void entityInteractableInit(
|
|
const entityid_t entityId,
|
|
const componentid_t componentId
|
|
) {
|
|
entityinteractable_t *inter = entityInteractableGet(entityId, componentId);
|
|
inter->onInteract = NULL;
|
|
inter->user = NULL;
|
|
}
|
|
|
|
entityinteractable_t * entityInteractableGet(
|
|
const entityid_t entityId,
|
|
const componentid_t componentId
|
|
) {
|
|
return componentGetData(entityId, componentId, COMPONENT_TYPE_INTERACTABLE);
|
|
}
|
|
|
|
void entityInteractableSetCallback(
|
|
const entityid_t entityId,
|
|
const componentid_t componentId,
|
|
void (*onInteract)(
|
|
const entityid_t entityId,
|
|
const componentid_t componentId,
|
|
void *user
|
|
),
|
|
void *user
|
|
) {
|
|
entityinteractable_t *inter = entityInteractableGet(entityId, componentId);
|
|
inter->onInteract = onInteract;
|
|
inter->user = user;
|
|
}
|
|
|
|
void entityInteractableTrigger(
|
|
const entityid_t entityId,
|
|
const componentid_t componentId
|
|
) {
|
|
entityinteractable_t *inter = entityInteractableGet(entityId, componentId);
|
|
if(inter->onInteract == NULL) return;
|
|
inter->onInteract(entityId, componentId, inter->user);
|
|
}
|