let MemoryViewArr = []; 
let Nupu_Memory_Update = Game_Interpreter.prototype.NUpdate;
Game_Interpreter.prototype.NUpdate = function () {
    Nupu_Memory_Update.call(this);
    if ($gameVariables.value(VN_MemorySave) == 0) {
        let _SetSaveStr = "";
        for (let mi = 0; mi <= $Nupu_PSData.MemoryData.length - 1; mi++) {
            if (_SetSaveStr != "") _SetSaveStr += "■";
            _SetSaveStr += "0,0,0,0,0"
        }
        $gameVariables.setValue(VN_MemorySave, _SetSaveStr);
        GameVar_To_MemoryViewArr();
    }
    if (MemoryViewArr.length == 0) {
        GameVar_To_MemoryViewArr();
    }
}
let MemoryReset = function () {
    let _SetSaveStr = "";
    for (let mi = 0; mi <= $Nupu_PSData.MemoryData.length - 1; mi++) {
        if (_SetSaveStr != "") _SetSaveStr += "■";
        _SetSaveStr += "0,0,0,0,0"
    }
    $gameVariables.setValue(VN_MemorySave, _SetSaveStr);
    GameVar_To_MemoryViewArr();
}
let MemoryAllOpen = function () {
    let _SetSaveStr = "";
    for (let mi = 0; mi <= $Nupu_PSData.MemoryData.length - 1; mi++) {
        let memoryData = $Nupu_PSData.MemoryData[mi];
        if (_SetSaveStr != "") _SetSaveStr += "■";
        if (memoryData._Title != "") {
            _SetSaveStr += "1,1,1,1,1"
        } else {
            _SetSaveStr += "0,0,0,0,0"
        }
    }
    $gameVariables.setValue(VN_MemorySave, _SetSaveStr);
    GameVar_To_MemoryViewArr();
}
let GameVar_To_MemoryViewArr = function () {
    let _CkStr = $gameVariables.value(VN_MemorySave);
    let _CkArr = _CkStr.split('■');
    for (let i = _CkArr.length; i <= $Nupu_PSData.MemoryData.length - 1; i++) {
        _CkArr.push("0,0,0,0,0");
    }
    MemoryViewArr = [];
    for (let i = 0; i <= _CkArr.length - 1; i++) {
        let setValues = _CkArr[i].split(',');
        if (setValues.length == 5) {
            MemoryViewArr.push(_CkArr[i].split(','));
        } else {
            MemoryViewArr.push(["0","0","0","0","0"]);
        }
    }
}
let MemoryViewArr_To_GameVar = function () {
    let _SetSaveStr = "";
    for (let mi = 0; mi <= MemoryViewArr.length - 1; mi++) {
        if (_SetSaveStr != "") _SetSaveStr += "■";
        for (let mj = 0; mj <= MemoryViewArr[mi].length - 1; mj++) {
            if (mj > 0) _SetSaveStr += ",";
            _SetSaveStr += MemoryViewArr[mi][mj];
        }
    }
    $gameVariables.setValue(VN_MemorySave, _SetSaveStr);
}
let MemoryViewCk = function (_No) {
    for (let i = 0; i <= MemoryViewArr[_No].length - 1; i++) {
        if (MemoryViewArr[_No][i] == "1") return true;
    }
    return false;
}
Game_Interpreter.prototype.MemoryOn = function (_No, _PtnNo) {
    MemoryViewArr[_No - 1][_PtnNo - 1] = "1";
    MemoryViewArr_To_GameVar();
    this.UTA_Save(); 
};
//指定回想を閲覧しているかチェック（true or false)
Game_Interpreter.prototype.MemoryOpenCk = function (_No, _PtnNo) {
    return MemoryViewArr[_No - 1][_PtnNo - 1] == "1";
}
