- function loadPackageData(targetobj, filepath, options) {
- if (RPGMakerMV.xhrSucceeded) {
- if (!isObject(options)) {
- options = {};
- };
- var xhr = new XMLHttpRequest();
- xhr.responseType = 'blob';
- xhr.open('GET', filepath);
- xhr.overrideMimeType('application/zip');
- xhr.onload = () => {
- if (xhr.status < 400) {
- var zipReader = new zip.ZipReader(new zip.BlobReader(xhr.response));
- zipReader.getEntries().then(entries => {
- if (entries && entries.length) {
- for (var i = 0; i < entries.length; i++) {
- if (!entries[i].directory) {
- targetobj[entries[i].filename] = entries[i];
- targetobj[entries[i].filename][RPGMakerMV.pKey] = RPGMakerMV.compileKey(options[RPGMakerMV.pKey]);
- };
- };
- };
- }).finally(() => {
- zipReader.close();
- if (typeof options.onLoad === 'function') {
- options.onLoad();
- };
- });
- } else {
- if (typeof options.onError === 'function') {
- options.onError();
- };
- }
- };
- xhr.onerror = () => {
- if (typeof options.onError === 'function') {
- options.onError();
- };
- };
- xhr.send();
- } else {
- var message = 'Your browser does not allow to read local files.';
- RPGMakerMV.printError('Error', message);
- };
- };
复制代码 |