"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.QuestStatus = void 0;
const Z64CORE = __importStar(require("../importsZ64"));
const FlagManager_1 = require("modloader64_api/FlagManager");
const JSONTemplate_1 = require("modloader64_api/JSONTemplate");
class QuestStatus extends JSONTemplate_1.JSONTemplate {
    emulator;
    instance = Z64CORE.Z64.Z64_SAVE; // Save Context
    questFlags;
    questFlagsAddr = this.instance + 0xBC;
    minimapFlags;
    minimapAddr = 0x801F0514;
    jsonFields = [
        'odolwaRemains',
        'gohtRemains',
        'gyorgRemains',
        'twinmoldRemains',
        'songOfTime',
        'songOfHealing',
        'eponaSong',
        'songOfSoaring',
        'songOfStorms',
        'sonataOfAwakening',
        'goronLullaby',
        'newWaveBossaNova',
        'elegyOfEmptiness',
        'oathToOrder',
        'bombersNotebook',
        'heartPieceCount'
    ];
    constructor(emu) {
        super();
        this.emulator = emu;
        this.questFlags = new FlagManager_1.FlagManager(emu, this.questFlagsAddr);
        this.minimapFlags = new FlagManager_1.FlagManager(emu, this.minimapAddr);
    }
    /*
      Quest Items (bitfield)	BC	1  bit 0: Lullaby Intro; bits 4-7: heart pieces
                                       bit 7: Lullaby Intro;
                                       bit 6: Nothing;
                                       bit 5: Nothing;
                                       bit 4: Nothing;
                                       bit 3, 2, 1, 0: HPieces
      Quest Items (bitfield)	BD	1  bits 0-1: songs; bit 2: Bomber's Notebook; bit 3: unknown
                                     bit 3: Song of Storms;
                                     bit 2: 2nd SoS icon
                                     bit 1: Bomeber's Notebook
                                     bit 0: Nothing
      Quest Items (bitfield)	BE	1  bits 0-7: songs
                                     bit 7: New Wave Bossa Nova
                                     bit 6: Elegy of Emptiness
                                     bit 5: Oath to Order
                                     bit 4: Prelude Icon
                                     bit 3: Song of Time
                                     bit 2: Song of Healing
                                     bit 1: Eponas Song
                                     bit 0: Song of Soaring
  
      Quest Items (bitfield)	BF	1  bits 0-3: Remains; bits 6-7: songs
                                     bit 7: Odolwa Remains
                                     bit 6: Goht Remains
                                     bit 5: Gyorg Remains
                                     bit 4: Twinmold Remains
                                     bit 3: Nothing
                                     bit 2: Nothing
                                     bit 1: Sonata of Awakening
                                     bit 0: Goron Lullaby
  */
    lullabyIntroFlag = new FlagManager_1.Flag(0x0, 0x7);
    get lullabyIntro() {
        return this.questFlags.isFlagSet(this.lullabyIntroFlag);
    }
    set lullabyIntro(bool) {
        this.questFlags.setFlag(this.lullabyIntroFlag, bool);
    }
    unknown1Flag = new FlagManager_1.Flag(0x0, 0x6);
    get unknown1() {
        return this.questFlags.isFlagSet(this.unknown1Flag);
    }
    set unknown1(bool) {
        this.questFlags.setFlag(this.unknown1Flag, bool);
    }
    unknown2Flag = new FlagManager_1.Flag(0x0, 0x5);
    get unknown2() {
        return this.questFlags.isFlagSet(this.unknown2Flag);
    }
    set unknown2(bool) {
        this.questFlags.setFlag(this.unknown2Flag, bool);
    }
    unknown3Flag = new FlagManager_1.Flag(0x0, 0x4);
    get unknown3() {
        return this.questFlags.isFlagSet(this.unknown3Flag);
    }
    set unknown3(bool) {
        this.questFlags.setFlag(this.unknown3Flag, bool);
    }
    get heartPieceCount() {
        let bits = this.emulator.rdramReadBits8(0x801EF72C); // your addr here
        let hp = bits.slice(0, 5);
        let count = (() => { let t = 0; if (hp[3] > 0 && hp[2] < 1) {
            t++;
        } if (hp[2] > 0 && hp[3] < 1) {
            t += 2;
        } if (hp[2] > 0 && hp[3] > 0) {
            t += 3;
        } return t; })();
        return count;
    }
    set heartPieceCount(count) {
        let bits = this.emulator.rdramReadBits8(0x801EF72C); // your addr here
        let hp = bits.slice(0, 5);
        (() => { if (count === 3) {
            hp[2] = 1;
            hp[3] = 1;
        }
        else if (count === 2) {
            hp[2] = 1;
            hp[3] = 0;
        }
        else if (count === 1) {
            hp[3] = 1;
            hp[2] = 0;
        }
        else if (count <= 0) {
            hp[3] = 0;
            hp[2] = 0;
        } })();
        this.emulator.rdramWriteBits8(0x801EF72C, bits);
    }
    heartPiecesFlag1 = new FlagManager_1.Flag(0x0, 0x3);
    get heartPieces1() {
        return this.questFlags.isFlagSet(this.heartPiecesFlag1);
    }
    set heartPieces1(bool) {
        this.questFlags.setFlag(this.heartPiecesFlag1, bool);
    }
    heartPiecesFlag2 = new FlagManager_1.Flag(0x0, 0x2);
    get heartPieces2() {
        return this.questFlags.isFlagSet(this.heartPiecesFlag2);
    }
    set heartPieces2(bool) {
        this.questFlags.setFlag(this.heartPiecesFlag2, bool);
    }
    heartPiecesFlag3 = new FlagManager_1.Flag(0x0, 0x1);
    get heartPieces3() {
        return this.questFlags.isFlagSet(this.heartPiecesFlag3);
    }
    set heartPieces3(bool) {
        this.questFlags.setFlag(this.heartPiecesFlag3, bool);
    }
    heartPiecesFlag4 = new FlagManager_1.Flag(0x0, 0x0);
    get heartPieces4() {
        return this.questFlags.isFlagSet(this.heartPiecesFlag4);
    }
    set heartPieces4(bool) {
        this.questFlags.setFlag(this.heartPiecesFlag4, bool);
    }
    songOfStormsFlag = new FlagManager_1.Flag(0x1, 0x7);
    get songOfStorms() {
        return this.questFlags.isFlagSet(this.songOfStormsFlag);
    }
    set songOfStorms(bool) {
        this.questFlags.setFlag(this.songOfStormsFlag, bool);
    }
    songOfStormsIconFlag = new FlagManager_1.Flag(0x1, 0x6);
    get songOfStormsIcon() {
        return this.questFlags.isFlagSet(this.songOfStormsIconFlag);
    }
    set songOfStormsIcon(bool) {
        this.questFlags.setFlag(this.songOfStormsIconFlag, bool);
    }
    bombersNotebookFlag = new FlagManager_1.Flag(0x1, 0x5);
    get bombersNotebook() {
        return this.questFlags.isFlagSet(this.bombersNotebookFlag);
    }
    set bombersNotebook(bool) {
        this.questFlags.setFlag(this.bombersNotebookFlag, bool);
    }
    unknown4Flag = new FlagManager_1.Flag(0x1, 0x4);
    get unknown4() {
        return this.questFlags.isFlagSet(this.unknown4Flag);
    }
    set unknown4(bool) {
        this.questFlags.setFlag(this.unknown4Flag, bool);
    }
    newWaveBossaNovaFlag = new FlagManager_1.Flag(0x2, 0x7);
    get newWaveBossaNova() {
        return this.questFlags.isFlagSet(this.newWaveBossaNovaFlag);
    }
    set newWaveBossaNova(bool) {
        this.questFlags.setFlag(this.newWaveBossaNovaFlag, bool);
    }
    elegyOfEmptinessFlag = new FlagManager_1.Flag(0x2, 0x6);
    get elegyOfEmptiness() {
        return this.questFlags.isFlagSet(this.elegyOfEmptinessFlag);
    }
    set elegyOfEmptiness(bool) {
        this.questFlags.setFlag(this.elegyOfEmptinessFlag, bool);
    }
    oathToOrderFlag = new FlagManager_1.Flag(0x2, 0x5);
    get oathToOrder() {
        return this.questFlags.isFlagSet(this.oathToOrderFlag);
    }
    set oathToOrder(bool) {
        this.questFlags.setFlag(this.oathToOrderFlag, bool);
    }
    preludeIconFlag = new FlagManager_1.Flag(0x2, 0x4);
    get preludeIcon() {
        return this.questFlags.isFlagSet(this.preludeIconFlag);
    }
    set preludeIcon(bool) {
        this.questFlags.setFlag(this.preludeIconFlag, bool);
    }
    songOfTimeFlag = new FlagManager_1.Flag(0x2, 0x3);
    get songOfTime() {
        return this.questFlags.isFlagSet(this.songOfTimeFlag);
    }
    set songOfTime(bool) {
        this.questFlags.setFlag(this.songOfTimeFlag, bool);
    }
    songOfHealingFlag = new FlagManager_1.Flag(0x2, 0x2);
    get songOfHealing() {
        return this.questFlags.isFlagSet(this.songOfHealingFlag);
    }
    set songOfHealing(bool) {
        this.questFlags.setFlag(this.songOfHealingFlag, bool);
    }
    eponaSongFlag = new FlagManager_1.Flag(0x2, 0x1);
    get eponaSong() {
        return this.questFlags.isFlagSet(this.eponaSongFlag);
    }
    set eponaSong(bool) {
        this.questFlags.setFlag(this.eponaSongFlag, bool);
    }
    songOfSoaringFlag = new FlagManager_1.Flag(0x2, 0x0);
    get songOfSoaring() {
        return this.questFlags.isFlagSet(this.songOfSoaringFlag);
    }
    set songOfSoaring(bool) {
        this.questFlags.setFlag(this.songOfSoaringFlag, bool);
    }
    odolwaRemainsFlag = new FlagManager_1.Flag(0x3, 0x7);
    get odolwaRemains() {
        return this.questFlags.isFlagSet(this.odolwaRemainsFlag);
    }
    set odolwaRemains(bool) {
        this.questFlags.setFlag(this.odolwaRemainsFlag, bool);
    }
    gohtRemainsFlag = new FlagManager_1.Flag(0x3, 0x6);
    get gohtRemains() {
        return this.questFlags.isFlagSet(this.gohtRemainsFlag);
    }
    set gohtRemains(bool) {
        this.questFlags.setFlag(this.gohtRemainsFlag, bool);
    }
    gyorgRemainsFlag = new FlagManager_1.Flag(0x3, 0x5);
    get gyorgRemains() {
        return this.questFlags.isFlagSet(this.gyorgRemainsFlag);
    }
    set gyorgRemains(bool) {
        this.questFlags.setFlag(this.gyorgRemainsFlag, bool);
    }
    twinmoldRemainsFlag = new FlagManager_1.Flag(0x3, 0x4);
    get twinmoldRemains() {
        return this.questFlags.isFlagSet(this.twinmoldRemainsFlag);
    }
    set twinmoldRemains(bool) {
        this.questFlags.setFlag(this.twinmoldRemainsFlag, bool);
    }
    unknown5Flag = new FlagManager_1.Flag(0x3, 0x3);
    get unknown5() {
        return this.questFlags.isFlagSet(this.unknown5Flag);
    }
    set unknown5(bool) {
        this.questFlags.setFlag(this.unknown5Flag, bool);
    }
    unknown6Flag = new FlagManager_1.Flag(0x3, 0x2);
    get unknown6() {
        return this.questFlags.isFlagSet(this.unknown6Flag);
    }
    set unknown6(bool) {
        this.questFlags.setFlag(this.unknown6Flag, bool);
    }
    sonataOfAwakeningFlag = new FlagManager_1.Flag(0x3, 0x1);
    get sonataOfAwakening() {
        return this.questFlags.isFlagSet(this.sonataOfAwakeningFlag);
    }
    set sonataOfAwakening(bool) {
        this.questFlags.setFlag(this.sonataOfAwakeningFlag, bool);
    }
    goronLullabyFlag = new FlagManager_1.Flag(0x3, 0x0);
    get goronLullaby() {
        return this.questFlags.isFlagSet(this.goronLullabyFlag);
    }
    set goronLullaby(bool) {
        this.questFlags.setFlag(this.goronLullabyFlag, bool);
    }
    get great_spin() {
        return this.emulator.rdramReadBit8(0x801F057F, 0x7);
    }
    set great_spin(flag) {
        this.emulator.rdramWriteBit8(0x801F057F, 0x7, flag);
    }
}
exports.QuestStatus = QuestStatus;
//# sourceMappingURL=QuestStatus.js.map