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