"use strict";
/*!
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
/**
 * @hidden
 */
class ActorInternal {
    constructor(actor) {
        this.actor = actor;
        this.observing = true;
    }
    get collider() {
        return this.actor.collider ? this.actor.collider.internal : undefined;
    }
    performAction(actionEvent) {
        const behavior = (this.behavior && this.behavior.behaviorType === actionEvent.behaviorType)
            ? this.behavior : undefined;
        if (behavior && behavior._supportsAction(actionEvent.actionName)) {
            behavior._performAction(actionEvent.actionName, actionEvent.actionState, actionEvent.user, actionEvent.actionData);
        }
        else {
            const action = this.actor[`_${actionEvent.actionName.toLowerCase()}`];
            if (action) {
                action._performAction(actionEvent.user, actionEvent.actionState, actionEvent.actionData);
            }
        }
    }
    collisionEventRaised(collisionEventType, collisionData) {
        if (this.collider) {
            this.collider.eventReceived(collisionEventType, collisionData);
        }
    }
    triggerEventRaised(triggerEventType, otherActor) {
        if (this.collider) {
            this.collider.eventReceived(triggerEventType, otherActor);
        }
    }
    getPatchAndReset() {
        const patch = this.patch;
        if (patch) {
            patch.id = this.actor.id;
            delete this.patch;
            return __1.Actor.sanitize(patch);
        }
    }
    notifyCreated(success, reason) {
        this.created = { success, reason };
        if (this.createdPromises) {
            const createdPromises = this.createdPromises;
            delete this.createdPromises;
            for (const promise of createdPromises) {
                if (success) {
                    promise.resolve();
                }
                else {
                    promise.reject(reason);
                }
            }
        }
    }
    enqueueCreatedPromise(promise) {
        this.createdPromises = this.createdPromises || [];
        this.createdPromises.push(promise);
    }
}
exports.ActorInternal = ActorInternal;
//# sourceMappingURL=actorInternal.js.map