"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActorBase = exports.ActorDeathBehavior = exports.Rotation = exports.Position = void 0;
const JSONTemplate_1 = require("modloader64_api/JSONTemplate");
const Z64CORE = __importStar(require("../importsZ64"));
const Vector3_1 = __importDefault(require("modloader64_api/math/Vector3"));
class Position extends JSONTemplate_1.JSONTemplate {
    offset;
    parent;
    jsonFields = ['x', 'y', 'z'];
    constructor(parent, offset = Z64CORE.Z64.Z64_ACTOR_POSITION_OFFSET) {
        super();
        this.parent = parent;
        this.offset = offset;
    }
    get x() {
        return this.parent.rdramReadF32(this.offset + 0);
    }
    set x(x) {
        this.parent.rdramWriteF32(this.offset + 0, x);
    }
    get y() {
        return this.parent.rdramReadF32(this.offset + 4);
    }
    set y(y) {
        this.parent.rdramWriteF32(this.offset + 4, y);
    }
    get z() {
        return this.parent.rdramReadF32(this.offset + 8);
    }
    set z(z) {
        this.parent.rdramWriteF32(this.offset + 8, z);
    }
    getRawPos() {
        return this.parent.rdramReadBuffer(this.offset, Z64CORE.Z64.Z64_ACTOR_POSITION_SIZE);
    }
    setRawPos(pos) {
        this.parent.rdramWriteBuffer(this.offset, pos);
    }
    getVec3() {
        return new Vector3_1.default(this.x, this.y, this.z);
    }
}
exports.Position = Position;
class Rotation extends JSONTemplate_1.JSONTemplate {
    parent;
    offset;
    jsonFields = ['x', 'y', 'z'];
    constructor(parent, offset = Z64CORE.Z64.Z64_ACTOR_ROTATION_OFFSET) {
        super();
        this.parent = parent;
        this.offset = offset;
    }
    get x() {
        return this.parent.rdramReadS16(this.offset + 0);
    }
    set x(x) {
        this.parent.rdramWrite16(this.offset + 0, x);
    }
    get y() {
        return this.parent.rdramReadS16(this.offset + 2);
    }
    set y(y) {
        this.parent.rdramWrite16(this.offset + 2, y);
    }
    get z() {
        return this.parent.rdramReadS16(this.offset + 4);
    }
    set z(z) {
        this.parent.rdramWrite16(this.offset + 4, z);
    }
    getRawRot() {
        return this.parent.rdramReadBuffer(this.offset, Z64CORE.Z64.Z64_ACTOR_ROTATION_SIZE);
    }
    setRawRot(rot) {
        this.parent.rdramWriteBuffer(this.offset, rot);
    }
    getVec3() {
        return new Vector3_1.default(this.x, this.y, this.z);
    }
}
exports.Rotation = Rotation;
class ActorDeathBehavior {
    offset;
    behavior_calc;
    constructor(offset, behavior_calc) {
        this.offset = offset;
        this.behavior_calc = behavior_calc;
    }
}
exports.ActorDeathBehavior = ActorDeathBehavior;
class ActorBase extends JSONTemplate_1.JSONTemplate {
    actorUUID = '';
    emulator;
    pointer;
    exists = true;
    rotation;
    position;
    homePos;
    homeRot;
    jsonFields = [
        'actorID',
        'actorUUID',
        'rotation',
        'position',
        'variable'
    ];
    constructor(ModLoader, scene, pointer) {
        super();
        this.emulator = ModLoader.emulator;
        this.pointer = pointer;
        this.rotation = new Rotation(this);
        this.position = new Position(this);
        this.homePos = new Position(this, 0x8);
        this.homeRot = new Rotation(this, 0xC);
        this.actorUUID = `${this.actorID}|${this.actorType}|${scene}|${this.room}|${this.homePos.getRawPos().toString('hex')}|${this.homeRot.getRawRot().toString('hex')}`;
        this.actorUUID = ModLoader.utils.hashBuffer(Buffer.from(this.actorUUID));
    }
    isTransitionActor = false;
    getRdramBuffer() {
        return this.emulator.getRdramBuffer();
    }
    bitCount8(value) {
        return this.emulator.bitCount8(value);
    }
    bitCount16(value) {
        return this.emulator.bitCount16(value);
    }
    bitCount32(value) {
        return this.emulator.bitCount32(value);
    }
    bitCountBuffer(buf, off, len) {
        return this.emulator.bitCountBuffer(buf, off, len);
    }
    invalidateCachedCode() {
    }
    get actorID() {
        return this.rdramRead16(0x0);
    }
    get actorType() {
        return this.rdramRead8(0x2);
    }
    get room() {
        return this.rdramRead8(0x3);
    }
    set room(r) {
        this.rdramWrite8(0x3, r);
    }
    get renderingFlags() {
        return this.rdramRead32(0x4);
    }
    set renderingFlags(flags) {
        this.rdramWrite32(0x4, flags);
    }
    get variable() {
        return this.rdramRead16(0x1c);
    }
    get objectTableIndex() {
        return this.rdramRead8(0x1e);
    }
    get soundEffect() {
        return this.rdramRead16(0x20);
    }
    set soundEffect(s) {
        this.rdramWrite16(0x20, s);
    }
    get health() {
        return this.rdramRead8(0xaf);
    }
    set health(h) {
        this.rdramWrite8(0xaf, h);
    }
    get redeadFreeze() {
        return this.rdramReadS16(0x110);
    }
    set redeadFreeze(f) {
        this.rdramWrite16(0x110, f);
    }
    destroy() {
        this.rdramWrite32(0x130, 0x0);
        this.rdramWrite32(0x134, 0x0);
    }
    rdramRead8(addr) {
        return this.emulator.rdramRead8(this.pointer + addr);
    }
    rdramWrite8(addr, value) {
        this.emulator.rdramWrite8(this.pointer + addr, value);
    }
    rdramRead16(addr) {
        return this.emulator.rdramRead16(this.pointer + addr);
    }
    rdramWrite16(addr, value) {
        this.emulator.rdramWrite16(this.pointer + addr, value);
    }
    rdramWrite32(addr, value) {
        this.emulator.rdramWrite32(this.pointer + addr, value);
    }
    rdramRead32(addr) {
        return this.emulator.rdramRead32(this.pointer + addr);
    }
    rdramReadBuffer(addr, size) {
        return this.emulator.rdramReadBuffer(this.pointer + addr, size);
    }
    rdramWriteBuffer(addr, buf) {
        this.emulator.rdramWriteBuffer(this.pointer + addr, buf);
    }
    dereferencePointer(addr) {
        return this.emulator.dereferencePointer(this.pointer + addr);
    }
    rdramReadS8(addr) {
        return this.emulator.rdramReadS8(this.pointer + addr);
    }
    rdramReadS16(addr) {
        return this.emulator.rdramReadS16(this.pointer + addr);
    }
    rdramReadS32(addr) {
        return this.emulator.rdramReadS32(this.pointer + addr);
    }
    rdramReadBitsBuffer(addr, bytes) {
        return this.emulator.rdramReadBitsBuffer(this.pointer + addr, bytes);
    }
    rdramReadBits8(addr) {
        return this.emulator.rdramReadBits8(this.pointer + addr);
    }
    rdramReadBit8(addr, bitoffset) {
        return this.emulator.rdramReadBit8(this.pointer + addr, bitoffset);
    }
    rdramWriteBitsBuffer(addr, buf) {
        this.emulator.rdramWriteBitsBuffer(this.pointer + addr, buf);
    }
    rdramWriteBits8(addr, buf) {
        this.emulator.rdramWriteBits8(this.pointer + addr, buf);
    }
    rdramWriteBit8(addr, bitoffset, bit) {
        this.emulator.rdramWriteBit8(this.pointer + addr, bitoffset, bit);
    }
    rdramReadPtr8(addr, offset) {
        return this.emulator.rdramReadPtr8(this.pointer + addr, offset);
    }
    rdramWritePtr8(addr, offset, value) {
        this.emulator.rdramWritePtr8(this.pointer + addr, offset, value);
    }
    rdramReadPtr16(addr, offset) {
        return this.emulator.rdramReadPtr16(this.pointer + addr, offset);
    }
    rdramWritePtr16(addr, offset, value) {
        this.emulator.rdramWritePtr16(this.pointer + addr, offset, value);
    }
    rdramWritePtr32(addr, offset, value) {
        this.emulator.rdramWritePtr32(this.pointer + addr, offset, value);
    }
    rdramReadPtr32(addr, offset) {
        return this.emulator.rdramReadPtr32(this.pointer + addr, offset);
    }
    rdramReadPtrBuffer(addr, offset, size) {
        return this.emulator.rdramReadPtrBuffer(this.pointer + addr, offset, size);
    }
    rdramWritePtrBuffer(addr, offset, buf) {
        this.emulator.rdramWritePtrBuffer(this.pointer + addr, offset, buf);
    }
    rdramReadPtrS8(addr, offset) {
        return this.emulator.rdramReadPtrS8(this.pointer + addr, offset);
    }
    rdramReadPtrS16(addr, offset) {
        return this.emulator.rdramReadPtrS16(this.pointer + addr, offset);
    }
    rdramReadPtrS32(addr, offset) {
        return this.emulator.rdramReadPtrS32(this.pointer + addr, offset);
    }
    rdramReadPtrBitsBuffer(addr, offset, bytes) {
        return this.emulator.rdramReadPtrBitsBuffer(this.pointer + addr, offset, bytes);
    }
    rdramReadPtrBits8(addr, offset) {
        return this.emulator.rdramReadPtrBits8(this.pointer + addr, offset);
    }
    rdramReadPtrBit8(addr, offset, bitoffset) {
        return this.emulator.rdramReadPtrBit8(this.pointer + addr, offset, bitoffset);
    }
    rdramWritePtrBitsBuffer(addr, offset, buf) {
        this.emulator.rdramWritePtrBitsBuffer(this.pointer + addr, offset, buf);
    }
    rdramWritePtrBits8(addr, offset, buf) {
        this.emulator.rdramWritePtrBits8(this.pointer + addr, offset, buf);
    }
    rdramWritePtrBit8(addr, offset, bitoffset, bit) {
        this.emulator.rdramWritePtrBit8(this.pointer + addr, offset, bitoffset, bit);
    }
    rdramReadF32(addr) {
        return this.emulator.rdramReadF32(this.pointer + addr);
    }
    rdramReadPtrF32(addr, offset) {
        return this.emulator.rdramReadPtrF32(this.pointer + addr, offset);
    }
    rdramWriteF32(addr, value) {
        this.emulator.rdramWriteF32(this.pointer + addr, value);
    }
    rdramWritePtrF32(addr, offset, value) {
        this.emulator.rdramWritePtrF32(this.pointer + addr, offset, value);
    }
    rdramRead64(addr) {
        return this.emulator.rdramRead64(this.pointer + addr);
    }
    rdramReadS64(addr) {
        return this.emulator.rdramReadS64(this.pointer + addr);
    }
    rdramReadF64(addr) {
        return this.emulator.rdramReadF64(this.pointer + addr);
    }
    rdramWrite64(addr, val) {
        this.emulator.rdramWrite64(this.pointer + addr, val);
    }
    rdramWriteF64(addr, val) {
        this.emulator.rdramWriteF64(this.pointer + addr, val);
    }
    rdramReadBigInt64(addr) {
        return this.emulator.rdramReadBigInt64(this.pointer + addr);
    }
    rdramReadBigIntS64(addr) {
        return this.emulator.rdramReadBigIntS64(this.pointer + addr);
    }
    rdramWriteBigInt64(addr, val) {
        this.emulator.rdramWriteBigInt64(this.pointer + addr, val);
    }
    memoryDebugLogger(bool) { }
    u8;
    u16;
    u32;
    u64;
    s8;
    s16;
    s32;
    s64;
    f32;
    f64;
}
exports.ActorBase = ActorBase;
//# sourceMappingURL=Actor.js.map