pref: translate to promise.

This commit is contained in:
Ansolve 2024-01-04 16:45:00 +08:00
parent a162629269
commit e3c47c91f8
No known key found for this signature in database
GPG Key ID: 2F2873AC9538CC2D
1 changed files with 137 additions and 131 deletions

View File

@ -24,144 +24,150 @@ export async function onload(resetGameTimeout) {
if (lib.config.touchscreen) createTouchDraggedFilter();
// 不拆分,太玄学了
if (lib.config.card_style == 'custom') {
game.getDB('image', 'card_style', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.card_stylesheet) {
ui.css.card_stylesheet.remove();
}
ui.css.card_stylesheet = lib.init.sheet('.card:not(*:empty){background-image:url(' + fileLoadedEvent.target.result + ')}');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (lib.config.card_style === 'custom') {
const fileToLoad = await game.getDB('image', 'card_style')
if (fileToLoad) {
const fileLoadedEvent = await new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad, "UTF-8");
})
if (ui.css.card_stylesheet) ui.css.card_stylesheet.remove();
ui.css.card_stylesheet = lib.init.sheet(`.card:not(*:empty){background-image:url(${fileLoadedEvent.target.result})}`);
}
}
if (lib.config.cardback_style == 'custom') {
game.getDB('image', 'cardback_style', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.cardback_stylesheet) {
ui.css.cardback_stylesheet.remove();
}
ui.css.cardback_stylesheet = lib.init.sheet('.card:empty,.card.infohidden{background-image:url(' + fileLoadedEvent.target.result + ')}');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
game.getDB('image', 'cardback_style2', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.cardback_stylesheet2) {
ui.css.cardback_stylesheet2.remove();
}
ui.css.cardback_stylesheet2 = lib.init.sheet('.card.infohidden:not(.infoflip){background-image:url(' + fileLoadedEvent.target.result + ')}');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (lib.config.cardback_style === 'custom') {
const fileToLoad1 = await game.getDB('image', 'cardback_style');
if (fileToLoad1) {
const fileLoadedEvent = await new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad1, "UTF-8");
})
if (ui.css.cardback_stylesheet) ui.css.cardback_stylesheet.remove();
ui.css.cardback_stylesheet = lib.init.sheet(`.card:empty,.card.infohidden{background-image:url(${fileLoadedEvent.target.result})}`);
}
const fileToLoad2 = await game.getDB('image', 'cardback_style2')
if (fileToLoad2) {
const fileLoadedEvent = await new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad2, "UTF-8");
})
if (ui.css.cardback_stylesheet2) ui.css.cardback_stylesheet2.remove();
ui.css.cardback_stylesheet2 = lib.init.sheet(`.card.infohidden:not(.infoflip){background-image:url(${fileLoadedEvent.target.result})}`);
}
}
if (lib.config.hp_style == 'custom') {
game.getDB('image', 'hp_style1', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.hp_stylesheet1) {
ui.css.hp_stylesheet1.remove();
}
ui.css.hp_stylesheet1 = lib.init.sheet('.hp:not(.text):not(.actcount)[data-condition="high"]>div:not(.lost){background-image:url(' + fileLoadedEvent.target.result + ')}');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
game.getDB('image', 'hp_style2', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.hp_stylesheet2) {
ui.css.hp_stylesheet2.remove();
}
ui.css.hp_stylesheet2 = lib.init.sheet('.hp:not(.text):not(.actcount)[data-condition="mid"]>div:not(.lost){background-image:url(' + fileLoadedEvent.target.result + ')}');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
game.getDB('image', 'hp_style3', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.hp_stylesheet3) {
ui.css.hp_stylesheet3.remove();
}
ui.css.hp_stylesheet3 = lib.init.sheet('.hp:not(.text):not(.actcount)[data-condition="low"]>div:not(.lost){background-image:url(' + fileLoadedEvent.target.result + ')}');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
game.getDB('image', 'hp_style4', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.hp_stylesheet4) {
ui.css.hp_stylesheet4.remove();
}
ui.css.hp_stylesheet4 = lib.init.sheet('.hp:not(.text):not(.actcount)>.lost{background-image:url(' + fileLoadedEvent.target.result + ')}');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (lib.config.hp_style === 'custom') {
const fileToLoad1 = await game.getDB('image', 'hp_style1')
if (fileToLoad1) {
const fileLoadedEvent = await new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad1, "UTF-8");
})
if (ui.css.hp_stylesheet1) ui.css.hp_stylesheet1.remove();
ui.css.hp_stylesheet1 = lib.init.sheet(`.hp:not(.text):not(.actcount)[data-condition="high"]>div:not(.lost){background-image:url(${fileLoadedEvent.target.result})}`);
}
const fileToLoad2 = await game.getDB('image', 'hp_style2');
if (fileToLoad2) {
const fileReader = new FileReader();
const fileLoadedEvent = await new Promise((resolve, reject) => {
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad2, "UTF-8");
});
if (ui.css.hp_stylesheet2) ui.css.hp_stylesheet2.remove();
ui.css.hp_stylesheet2 = lib.init.sheet(`.hp:not(.text):not(.actcount)[data-condition="mid"]>div:not(.lost){background-image:url(${fileLoadedEvent.target.result})}`);
}
const fileToLoad3 = await game.getDB('image', 'hp_style3');
if (fileToLoad3) {
const fileReader = new FileReader();
const fileLoadedEvent = await new Promise((resolve, reject) => {
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad3, "UTF-8");
});
if (ui.css.hp_stylesheet3) ui.css.hp_stylesheet3.remove();
ui.css.hp_stylesheet3 = lib.init.sheet(`.hp:not(.text):not(.actcount)[data-condition="low"]>div:not(.lost){background-image:url(${fileLoadedEvent.target.result})}`);
}
const fileToLoad4 = await game.getDB('image', 'hp_style4');
if (fileToLoad4) {
const fileReader = new FileReader();
const fileLoadedEvent = await new Promise((resolve, reject) => {
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad4, "UTF-8");
});
if (ui.css.hp_stylesheet4) ui.css.hp_stylesheet4.remove();
ui.css.hp_stylesheet4 = lib.init.sheet(`.hp:not(.text):not(.actcount)>.lost{background-image:url(${fileLoadedEvent.target.result})}`);
}
}
if (lib.config.player_style == 'custom') {
ui.css.player_stylesheet = lib.init.sheet('#window .player{background-image:none;background-size:100% 100%;}');
game.getDB('image', 'player_style', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.player_stylesheet) {
ui.css.player_stylesheet.remove();
}
ui.css.player_stylesheet = lib.init.sheet('#window .player{background-image:url("' + fileLoadedEvent.target.result + '");background-size:100% 100%;}');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (lib.config.player_style === 'custom') {
const fileToLoad = await game.getDB('image', 'player_style');
if (fileToLoad) {
const fileReader = new FileReader();
const fileLoadedEvent = await new Promise((resolve, reject) => {
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (ui.css.player_stylesheet) ui.css.player_stylesheet.remove();
ui.css.player_stylesheet = lib.init.sheet(`#window .player{background-image:url("${fileLoadedEvent.target.result}");background-size:100% 100%;}`);
} else {
ui.css.player_stylesheet = lib.init.sheet('#window .player{background-image:none;background-size:100% 100%;}');
}
}
if (lib.config.border_style == 'custom') {
game.getDB('image', 'border_style', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.border_stylesheet) {
ui.css.border_stylesheet.remove();
}
ui.css.border_stylesheet = lib.init.sheet();
ui.css.border_stylesheet.sheet.insertRule('#window .player>.framebg{display:block;background-image:url("' + fileLoadedEvent.target.result + '")}', 0);
ui.css.border_stylesheet.sheet.insertRule('.player>.count{z-index: 3 !important;border-radius: 2px !important;text-align: center !important;}', 0);
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (lib.config.border_style === 'custom') {
const fileToLoad = await game.getDB('image', 'border_style');
if (fileToLoad) {
const fileReader = new FileReader();
const fileLoadedEvent = await new Promise((resolve, reject) => {
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (ui.css.border_stylesheet) ui.css.border_stylesheet.remove();
ui.css.border_stylesheet = lib.init.sheet();
ui.css.border_stylesheet.sheet.insertRule(`#window .player>.framebg{display:block;background-image:url("${fileLoadedEvent.target.result}")}`, 0);
ui.css.border_stylesheet.sheet.insertRule('.player>.count{z-index: 3 !important;border-radius: 2px !important;text-align: center !important;}', 0);
}
}
if (lib.config.control_style == 'custom') {
game.getDB('image', 'control_style', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.control_stylesheet) {
ui.css.control_stylesheet.remove();
}
ui.css.control_stylesheet = lib.init.sheet('#window .control,.menubutton:not(.active):not(.highlight):not(.red):not(.blue),#window #system>div>div{background-image:url("' + fileLoadedEvent.target.result + '")}');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (lib.config.control_style === 'custom') {
const fileToLoad = await game.getDB('image', 'control_style');
if (fileToLoad) {
const fileReader = new FileReader();
const fileLoadedEvent = await new Promise((resolve, reject) => {
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (ui.css.control_stylesheet) ui.css.control_stylesheet.remove();
ui.css.control_stylesheet = lib.init.sheet(`#window .control,.menubutton:not(.active):not(.highlight):not(.red):not(.blue),#window #system>div>div{background-image:url("${fileLoadedEvent.target.result}")}`);
}
}
if (lib.config.menu_style == 'custom') {
game.getDB('image', 'menu_style', function (fileToLoad) {
if (!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
if (ui.css.menu_stylesheet) {
ui.css.menu_stylesheet.remove();
}
ui.css.menu_stylesheet = lib.init.sheet('html #window>.dialog.popped,html .menu,html .menubg{background-image:url("' + fileLoadedEvent.target.result + '");background-size:cover}');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (lib.config.menu_style === 'custom') {
const fileToLoad = await game.getDB('image', 'menu_style');
if (fileToLoad) {
const fileReader = new FileReader();
const fileLoadedEvent = await new Promise((resolve, reject) => {
fileReader.onload = resolve;
fileReader.onerror = reject;
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
if (ui.css.menu_stylesheet) ui.css.menu_stylesheet.remove();
ui.css.menu_stylesheet = lib.init.sheet(`html #window>.dialog.popped,html .menu,html .menubg{background-image:url("${fileLoadedEvent.target.result}");background-size:cover}`);
}
}
// 改不动,暂时不改了