"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GlobalContext = void 0;
const JSONTemplate_1 = require("modloader64_api/JSONTemplate");
const Z64CORE = __importStar(require("../importsZ64"));
class GlobalContext extends JSONTemplate_1.JSONTemplate {
    emulator;
    current_scene_addr = 0x0000a4;
    switch_flags_addr = 0x001d28;
    temp_switch_flags_addr = 0x001d2c;
    chest_flags_addr = 0x001d38;
    room_clear_flags_addr = 0x001d3c;
    current_room_addr = 0x011cbc;
    frame_count_addr = 0x011de4;
    scene_frame_count_addr = 0x9c;
    collectable_flag_addr = 0x01d44;
    continue_state_addr = 0x98;
    viewStruct;
    jsonFields = ['scene', 'room', 'framecount'];
    constructor(ModLoader) {
        super();
        this.emulator = ModLoader.emulator;
        this.viewStruct = new Z64CORE.Z64.viewStruct(ModLoader);
    }
    get fogDistance() {
        return this.emulator.rdramReadPtr16(Z64CORE.Z64.Z64_GLOBAL_PTR, 0xD4);
    }
    set fogDistance(fog) {
        this.emulator.rdramWritePtr16(Z64CORE.Z64.Z64_GLOBAL_PTR, 0xD4, fog);
    }
    get fogColor() {
        return 0;
    }
    set fogColor(color) {
    }
    get scene() {
        return this.emulator.rdramReadPtr16(Z64CORE.Z64.Z64_GLOBAL_PTR, this.current_scene_addr);
    }
    get room() {
        return this.emulator.rdramReadPtr8(Z64CORE.Z64.Z64_GLOBAL_PTR, this.current_room_addr);
    }
    get framecount() {
        return this.emulator.rdramReadPtr32(Z64CORE.Z64.Z64_GLOBAL_PTR, this.frame_count_addr);
    }
    get scene_framecount() {
        return this.emulator.rdramReadPtr32(Z64CORE.Z64.Z64_GLOBAL_PTR, this.scene_frame_count_addr);
    }
    get liveSceneData_chests() {
        return this.emulator.rdramReadPtrBuffer(Z64CORE.Z64.Z64_GLOBAL_PTR, this.chest_flags_addr, 0x4);
    }
    set liveSceneData_chests(buf) {
        this.emulator.rdramWritePtrBuffer(Z64CORE.Z64.Z64_GLOBAL_PTR, this.chest_flags_addr, buf);
    }
    get liveSceneData_clear() {
        return this.emulator.rdramReadPtrBuffer(Z64CORE.Z64.Z64_GLOBAL_PTR, this.room_clear_flags_addr, 0x4);
    }
    set liveSceneData_clear(buf) {
        this.emulator.rdramWritePtrBuffer(Z64CORE.Z64.Z64_GLOBAL_PTR, this.room_clear_flags_addr, buf);
    }
    get liveSceneData_switch() {
        return this.emulator.rdramReadPtrBuffer(Z64CORE.Z64.Z64_GLOBAL_PTR, this.switch_flags_addr, 0x4);
    }
    set liveSceneData_switch(buf) {
        this.emulator.rdramWritePtrBuffer(Z64CORE.Z64.Z64_GLOBAL_PTR, this.switch_flags_addr, buf);
    }
    get liveSceneData_temp() {
        return this.emulator.rdramReadPtrBuffer(Z64CORE.Z64.Z64_GLOBAL_PTR, this.temp_switch_flags_addr, 0x4);
    }
    set liveSceneData_temp(buf) {
        this.emulator.rdramWritePtrBuffer(Z64CORE.Z64.Z64_GLOBAL_PTR, this.temp_switch_flags_addr, buf);
    }
    get liveSceneData_collectable() {
        return this.emulator.rdramReadPtrBuffer(Z64CORE.Z64.Z64_GLOBAL_PTR, this.collectable_flag_addr, 0x8);
    }
    set liveSceneData_collectable(buf) {
        this.emulator.rdramWritePtrBuffer(Z64CORE.Z64.Z64_GLOBAL_PTR, this.collectable_flag_addr, buf);
    }
    get continue_state() {
        return (this.emulator.rdramReadPtr32(Z64CORE.Z64.Z64_GLOBAL_PTR, this.continue_state_addr) === 1);
    }
    get lastOrCurrentEntrance() {
        return this.emulator.rdramReadPtr16(Z64CORE.Z64.Z64_GLOBAL_PTR, 0x11E1A);
    }
    getSaveDataForCurrentScene() {
        return this.emulator.rdramReadBuffer(Z64CORE.Z64.Z64_SAVE + 0x00d4 + this.scene * 0x1c, 0x1c);
    }
    writeSaveDataForCurrentScene(buf) {
        if (buf.byteLength === 0x1c) {
            this.emulator.rdramWriteBuffer(Z64CORE.Z64.Z64_SAVE + 0x00d4 + this.scene * 0x1c, buf);
        }
    }
}
exports.GlobalContext = GlobalContext;
//# sourceMappingURL=GlobalContext.js.map