pref: no gnc.

This commit is contained in:
Rintim 2023-12-21 01:14:23 +08:00
parent dd34cfddbb
commit 800c74eb10
No known key found for this signature in database
GPG Key ID: BE9E1EA615BACFCF
3 changed files with 67 additions and 67 deletions

View File

@ -1752,6 +1752,8 @@ export class Game extends Uninstantable {
else if (music.startsWith('ext:')) ui.backgroundMusic.src = `${lib.assetURL}extension/${music.slice(4)}`; else if (music.startsWith('ext:')) ui.backgroundMusic.src = `${lib.assetURL}extension/${music.slice(4)}`;
else ui.backgroundMusic.src = `${lib.assetURL}audio/background/${music}.mp3`; else ui.backgroundMusic.src = `${lib.assetURL}audio/background/${music}.mp3`;
} }
// 某种意义上,改不了,得重写
// 等正式用import导入再说
static import(type, content, url) { static import(type, content, url) {
if (type == 'extension') { if (type == 'extension') {
const promise = game.loadExtension(content).then((name) => { const promise = game.loadExtension(content).then((name) => {
@ -1778,10 +1780,10 @@ export class Game extends Uninstantable {
return promise; return promise;
} }
} }
static loadExtension = gnc.of(function* (object) { static async loadExtension(object) {
let noEval = false; let noEval = false;
if (typeof object == 'function') { if (typeof object == 'function') {
object = yield (gnc.is.generatorFunc(object) ? gnc.of(object) : object)(lib, game, ui, get, ai, _status); object = await (gnc.is.generatorFunc(object) ? gnc.of(object) : object)(lib, game, ui, get, ai, _status);
noEval = true; noEval = true;
} }
const name = object.name, extensionName = `extension_${name}`, extensionMenu = lib.extensionMenu[extensionName] = { const name = object.name, extensionName = `extension_${name}`, extensionMenu = lib.extensionMenu[extensionName] = {
@ -1882,7 +1884,7 @@ export class Game extends Uninstantable {
} }
if (precontent) { if (precontent) {
_status.extension = name; _status.extension = name;
yield (gnc.is.generatorFunc(precontent) ? gnc.of(precontent) : precontent).call(object, config); await (gnc.is.generatorFunc(precontent) ? gnc.of(precontent) : precontent).call(object, config);
delete _status.extension; delete _status.extension;
} }
if (content) lib.extensions.push([name, content, config, _status.evaluatingExtension, objectPackage || {}]); if (content) lib.extensions.push([name, content, config, _status.evaluatingExtension, objectPackage || {}]);
@ -1892,7 +1894,7 @@ export class Game extends Uninstantable {
} }
return name; return name;
}) }
static createDir(directory, successCallback, errorCallback) { static createDir(directory, successCallback, errorCallback) {
const paths = directory.split('/').reverse(); const paths = directory.split('/').reverse();
if (window.resolveLocalFileSystemURL) return new Promise((resolve, reject) => window.resolveLocalFileSystemURL(lib.assetURL, resolve, reject)).then(directoryEntry => { if (window.resolveLocalFileSystemURL) return new Promise((resolve, reject) => window.resolveLocalFileSystemURL(lib.assetURL, resolve, reject)).then(directoryEntry => {
@ -1921,10 +1923,10 @@ export class Game extends Uninstantable {
}; };
return redo(); return redo();
} }
static importExtension = gnc.of(function* (data, finishLoad, exportExtension, extensionPackage) { static async importExtension(data, finishLoad, exportExtension, extensionPackage) {
//by 来瓶可乐加冰、Rintim、Tipx-L //by 来瓶可乐加冰、Rintim、Tipx-L
if (!window.JSZip) if (!window.JSZip)
yield new Promise((resolve, reject) => lib.init.js(`${lib.assetURL}game`, "jszip", resolve, reject)); await new Promise((resolve, reject) => lib.init.js(`${lib.assetURL}game`, "jszip", resolve, reject));
const zip = new JSZip(); const zip = new JSZip();
if (get.objtype(data) == 'object') { if (get.objtype(data) == 'object') {
@ -1984,7 +1986,7 @@ export class Game extends Uninstantable {
if (str === "" || undefined) throw ('你导入的不是扩展!请选择正确的文件'); if (str === "" || undefined) throw ('你导入的不是扩展!请选择正确的文件');
_status.importingExtension = true; _status.importingExtension = true;
eval(str); eval(str);
yield Promise.allSettled(_status.extensionLoading); await Promise.allSettled(_status.extensionLoading);
delete _status.extensionLoading; delete _status.extensionLoading;
_status.importingExtension = false; _status.importingExtension = false;
if (!game.importedPack) throw ('err'); if (!game.importedPack) throw ('err');
@ -2072,7 +2074,7 @@ export class Game extends Uninstantable {
UHP(error); UHP(error);
return false; return false;
} }
}) }
static export(textToWrite, name) { static export(textToWrite, name) {
var textFileAsBlob = new Blob([textToWrite], { type: 'text/plain' }); var textFileAsBlob = new Blob([textToWrite], { type: 'text/plain' });
var fileNameToSaveAs = name || 'noname'; var fileNameToSaveAs = name || 'noname';
@ -4419,12 +4421,12 @@ export class Game extends Uninstantable {
splash: imgsrc, splash: imgsrc,
fromextension: true fromextension: true
} }
lib.init['setMode_' + name] = gnc.of(function* () { lib.init['setMode_' + name] = async () => {
yield game.import('mode', function (lib, game, ui, get, ai, _status) { await game.import('mode', (lib, game, ui, get, ai, _status) => {
info.name = name; info.name = name;
return info; return info;
}); });
}); };
if (!lib.config.extensionInfo[extname]) { if (!lib.config.extensionInfo[extname]) {
lib.config.extensionInfo[extname] = {}; lib.config.extensionInfo[extname] = {};
} }
@ -6255,8 +6257,8 @@ export class Game extends Uninstantable {
} }
static loadModeAsync(name, callback) { static loadModeAsync(name, callback) {
window.game = game; window.game = game;
var script = lib.init.js(lib.assetURL + 'mode', name, gnc.of(function* () { var script = lib.init.js(lib.assetURL + 'mode', name, async () => {
yield Promise.allSettled(_status.importing.mode); await Promise.allSettled(_status.importing.mode);
if (!lib.config.dev) delete window.game; if (!lib.config.dev) delete window.game;
script.remove(); script.remove();
var content = lib.imported.mode[name]; var content = lib.imported.mode[name];
@ -6265,7 +6267,7 @@ export class Game extends Uninstantable {
delete lib.imported.mode; delete lib.imported.mode;
} }
callback(content); callback(content);
})); });
} }
static switchMode(name, configx) { static switchMode(name, configx) {
if (!lib.layoutfixed.contains(name)) { if (!lib.layoutfixed.contains(name)) {
@ -6279,8 +6281,8 @@ export class Game extends Uninstantable {
} }
} }
window.game = game; window.game = game;
var script = lib.init.js(lib.assetURL + 'mode', name, gnc.of(function* () { var script = lib.init.js(lib.assetURL + 'mode', name, async () => {
yield Promise.allSettled(_status.importing.mode); await Promise.allSettled(_status.importing.mode);
if (!lib.config.dev) delete window.game; if (!lib.config.dev) delete window.game;
script.remove(); script.remove();
var mode = lib.imported.mode; var mode = lib.imported.mode;
@ -6451,7 +6453,7 @@ export class Game extends Uninstantable {
game.loop(); game.loop();
}); });
} }
})); });
} }
static loadMode(mode) { static loadMode(mode) {
var next = game.createEvent('loadMode', false); var next = game.createEvent('loadMode', false);

View File

@ -1458,7 +1458,7 @@ export class Library extends Uninstantable {
node.menu = ui.create.div(node, '', '<div></div><div></div><div></div><div></div>'); node.menu = ui.create.div(node, '', '<div></div><div></div><div></div><div></div>');
} }
}, },
onclick: gnc.of(function* (theme) { onclick: async (theme) => {
game.saveConfig('theme', theme); game.saveConfig('theme', theme);
ui.arena.hide(); ui.arena.hide();
lib.init.background(); lib.init.background();
@ -1471,17 +1471,17 @@ export class Library extends Uninstantable {
} }
} }
lib.announce.publish("Noname.Apperaence.Theme.onChanging", theme); lib.announce.publish("Noname.Apperaence.Theme.onChanging", theme);
yield new Promise(resolve => setTimeout(resolve, 500)); await new Promise(resolve => setTimeout(resolve, 500));
const deletingTheme = ui.css.theme; const deletingTheme = ui.css.theme;
ui.css.theme = lib.init.css(lib.assetURL + 'theme/' + lib.config.theme, 'style'); ui.css.theme = lib.init.css(lib.assetURL + 'theme/' + lib.config.theme, 'style');
deletingTheme.remove(); deletingTheme.remove();
lib.announce.publish("Noname.Apperaence.Theme.onChanged", theme); lib.announce.publish("Noname.Apperaence.Theme.onChanged", theme);
yield new Promise(resolve => setTimeout(resolve, 100)); await new Promise(resolve => setTimeout(resolve, 100));
ui.arena.show(); ui.arena.show();
lib.announce.publish("Noname.Apperaence.Theme.onChangeFinished", theme); lib.announce.publish("Noname.Apperaence.Theme.onChangeFinished", theme);
}) }
}, },
layout: { layout: {
name: '布局', name: '布局',
@ -9540,7 +9540,7 @@ export class Library extends Uninstantable {
if (!lengths.length) return constructingToLoad + 1; if (!lengths.length) return constructingToLoad + 1;
return constructingToLoad + Math.min(...lengths); return constructingToLoad + Math.min(...lengths);
}, 0); }, 0);
const packLoaded = gnc.of(function* () { const packLoaded = async () => {
toLoad--; toLoad--;
if (toLoad) return; if (toLoad) return;
if (_status.importing) { if (_status.importing) {
@ -9548,7 +9548,7 @@ export class Library extends Uninstantable {
for (const type in _status.importing) { for (const type in _status.importing) {
promises.addArray(_status.importing[type]) promises.addArray(_status.importing[type])
} }
yield Promise.allSettled(promises); await Promise.allSettled(promises);
delete _status.importing; delete _status.importing;
} }
@ -9557,7 +9557,7 @@ export class Library extends Uninstantable {
lib.init.onload(); lib.init.onload();
} }
else _status.packLoaded = true; else _status.packLoaded = true;
}); };
if (localStorage.getItem(`${lib.configprefix}playback`)) { if (localStorage.getItem(`${lib.configprefix}playback`)) {
toLoad++; toLoad++;
lib.init.js(`${lib.assetURL}mode`, lib.config.mode, packLoaded, packLoaded); lib.init.js(`${lib.assetURL}mode`, lib.config.mode, packLoaded, packLoaded);
@ -9645,16 +9645,16 @@ export class Library extends Uninstantable {
console.log(e); console.log(e);
}); });
var styleToLoad = 6; var styleToLoad = 6;
var styleLoaded = gnc.of(function* () { var styleLoaded = async () => {
--styleToLoad; --styleToLoad;
if (styleToLoad == 0) { if (styleToLoad == 0) {
if (extensionlist.length && (lib.config.mode != 'connect' || show_splash)) { if (extensionlist.length && (lib.config.mode != 'connect' || show_splash)) {
_status.extensionLoading = []; _status.extensionLoading = [];
let extToLoad = extensionlist.length; let extToLoad = extensionlist.length;
const extLoaded = gnc.of(function* () { const extLoaded = async () => {
--extToLoad; --extToLoad;
if (extToLoad == 0) { if (extToLoad == 0) {
yield Promise.allSettled(_status.extensionLoading); await Promise.allSettled(_status.extensionLoading);
_status.extensionLoaded.filter(Boolean).forEach(name => { _status.extensionLoaded.filter(Boolean).forEach(name => {
lib.announce.publish("Noname.Init.Extension.onLoad", name); lib.announce.publish("Noname.Init.Extension.onLoad", name);
lib.announce.publish(`Noname.Init.Extension.${name}.onLoad`, void 0); lib.announce.publish(`Noname.Init.Extension.${name}.onLoad`, void 0);
@ -9662,38 +9662,37 @@ export class Library extends Uninstantable {
delete _status.extensionLoading; delete _status.extensionLoading;
loadPack(); loadPack();
} }
}); };
//读取扩展 //读取扩展
var alerted = false; var alerted = false;
for (var i = 0; i < extensionlist.length; i++) { for (let i = 0; i < extensionlist.length; i++) {
if (window.bannedExtensions.contains(extensionlist[i])) { if (window.bannedExtensions.contains(extensionlist[i])) {
alerted = true; alerted = true;
--extToLoad; --extToLoad;
if (extToLoad == 0) { if (extToLoad == 0) {
yield Promise.allSettled(_status.extensionLoading); await Promise.allSettled(_status.extensionLoading);
delete _status.extensionLoading; delete _status.extensionLoading;
loadPack(); loadPack();
} }
continue; continue;
} }
lib.init.js(lib.assetURL + 'extension/' + extensionlist[i], 'extension', extLoaded, (function (i) { lib.init.js(lib.assetURL + 'extension/' + extensionlist[i], 'extension', extLoaded, async () => {
return gnc.of(function* () { game.removeExtension(extensionlist[i]);
game.removeExtension(i);
--extToLoad; --extToLoad;
if (extToLoad == 0) { if (extToLoad == 0) {
yield Promise.allSettled(_status.extensionLoading); await Promise.allSettled(_status.extensionLoading);
delete _status.extensionLoading; delete _status.extensionLoading;
loadPack(); loadPack();
} }
}); });
}(extensionlist[i])));
} }
} }
else { else {
loadPack(); loadPack();
} }
} }
}); };
if (lib.config.layout == 'default') { if (lib.config.layout == 'default') {
lib.config.layout = 'mobile'; lib.config.layout = 'mobile';
} }
@ -10304,13 +10303,13 @@ export class Library extends Uninstantable {
} }
}, },
//lib.onload支持传入GeneratorFunction以解决异步函数的问题 by诗笺 //lib.onload支持传入GeneratorFunction以解决异步函数的问题 by诗笺
onload: gnc.of(function* () { async onload() {
const libOnload = lib.onload; const libOnload = lib.onload;
delete lib.onload; delete lib.onload;
while (Array.isArray(libOnload) && libOnload.length) { while (Array.isArray(libOnload) && libOnload.length) {
const fun = libOnload.shift(); const fun = libOnload.shift();
if (typeof fun != "function") continue; if (typeof fun !== "function") continue;
yield (gnc.is.generatorFunc(fun) ? gnc.of(fun) : fun)(); await (gnc.is.generatorFunc(fun) ? gnc.of(fun) : fun)();
} }
ui.updated(); ui.updated();
game.documentZoom = game.deviceZoom; game.documentZoom = game.deviceZoom;
@ -10504,7 +10503,7 @@ export class Library extends Uninstantable {
}); });
} }
var proceed2 = gnc.of(function* () { var proceed2 = async () => {
var mode = lib.imported.mode; var mode = lib.imported.mode;
var card = lib.imported.card; var card = lib.imported.card;
var character = lib.imported.character; var character = lib.imported.character;
@ -10919,7 +10918,7 @@ export class Library extends Uninstantable {
_status.extension = lib.extensions[i][0]; _status.extension = lib.extensions[i][0];
_status.evaluatingExtension = lib.extensions[i][3]; _status.evaluatingExtension = lib.extensions[i][3];
if (typeof lib.extensions[i][1] == "function") if (typeof lib.extensions[i][1] == "function")
yield (gnc.is.coroutine(lib.extensions[i][1]) ? gnc.of(lib.extensions[i][1]) : lib.extensions[i][1]).call(lib.extensions[i], lib.extensions[i][2], lib.extensions[i][4]); await (gnc.is.coroutine(lib.extensions[i][1]) ? gnc.of(lib.extensions[i][1]) : lib.extensions[i][1]).call(lib.extensions[i], lib.extensions[i][2], lib.extensions[i][4]);
if (lib.extensions[i][4]) { if (lib.extensions[i][4]) {
if (lib.extensions[i][4].character) { if (lib.extensions[i][4].character) {
for (var j in lib.extensions[i][4].character.character) { for (var j in lib.extensions[i][4].character.character) {
@ -10967,31 +10966,30 @@ export class Library extends Uninstantable {
} }
delete lib.init.start; delete lib.init.start;
if (Array.isArray(_status.onprepare) && _status.onprepare.length) { if (Array.isArray(_status.onprepare) && _status.onprepare.length) {
yield Promise.allSettled(_status.onprepare); await Promise.allSettled(_status.onprepare);
delete _status.onprepare; delete _status.onprepare;
} }
game.loop(); game.loop();
}) };
var proceed = gnc.of(function* () { var proceed = async () => {
if (!lib.db) { if (!lib.db) {
try { try {
lib.storage = JSON.parse(localStorage.getItem(lib.configprefix + lib.config.mode)); lib.storage = JSON.parse(localStorage.getItem(lib.configprefix + lib.config.mode));
if (typeof lib.storage != 'object') throw ('err'); if (typeof lib.storage !== 'object') throw ('err');
if (lib.storage == null) throw ('err'); if (lib.storage === null) throw ('err');
} } catch (err) {
catch (err) {
lib.storage = {}; lib.storage = {};
localStorage.setItem(lib.configprefix + lib.config.mode, "{}"); localStorage.setItem(lib.configprefix + lib.config.mode, "{}");
} }
yield proceed2(); await proceed2();
} }
else { else {
game.getDB('data', lib.config.mode, function (obj) { await game.getDB('data', lib.config.mode, async (obj) => {
lib.storage = obj || {}; lib.storage = obj || {};
proceed2(); await proceed2();
}); });
} }
}); };
if (!lib.imported.mode || !lib.imported.mode[lib.config.mode]) { if (!lib.imported.mode || !lib.imported.mode[lib.config.mode]) {
window.inSplash = true; window.inSplash = true;
clearTimeout(window.resetGameTimeout); clearTimeout(window.resetGameTimeout);
@ -11087,7 +11085,7 @@ export class Library extends Uninstantable {
} }
} }
else { else {
yield proceed(); await proceed();
} }
localStorage.removeItem(lib.configprefix + 'directstart'); localStorage.removeItem(lib.configprefix + 'directstart');
delete lib.init.init; delete lib.init.init;
@ -11096,9 +11094,9 @@ export class Library extends Uninstantable {
while (Array.isArray(libOnload2) && libOnload2.length) { while (Array.isArray(libOnload2) && libOnload2.length) {
const fun = libOnload2.shift(); const fun = libOnload2.shift();
if (typeof fun != "function") continue; if (typeof fun != "function") continue;
yield (gnc.is.generatorFunc(fun) ? gnc.of(fun) : fun)(); await (gnc.is.generatorFunc(fun) ? gnc.of(fun) : fun)();
} }
}), },
startOnline: function () { startOnline: function () {
'step 0' 'step 0'
event._resultid = null; event._resultid = null;

View File

@ -4190,7 +4190,7 @@ class Create extends Uninstantable {
} }
editnode.classList.remove('disabled'); editnode.classList.remove('disabled');
}; };
var clickButton = lib.gnc.of(function* () { var clickButton = async () => {
if (currentButton == this) { if (currentButton == this) {
resetEditor(); resetEditor();
return; return;
@ -4229,7 +4229,7 @@ class Create extends Uninstantable {
dieaudionode.file = { dieaudionode.file = {
name: info[4][i].slice(info[4][i].lastIndexOf('/') + 1) name: info[4][i].slice(info[4][i].lastIndexOf('/') + 1)
}; };
yield new Promise(resolve => { await new Promise((resolve) => {
if (typeof game.readFile == 'function') { if (typeof game.readFile == 'function') {
game.readFile(info[4][i].slice(4).replace('ext:', 'extension/'), arraybuffer => { game.readFile(info[4][i].slice(4).replace('ext:', 'extension/'), arraybuffer => {
dieaudionode.arrayBuffer = arraybuffer; dieaudionode.arrayBuffer = arraybuffer;
@ -4266,7 +4266,7 @@ class Create extends Uninstantable {
editnode.classList.remove('disabled'); editnode.classList.remove('disabled');
delnode.innerHTML = '删除'; delnode.innerHTML = '删除';
delnode.button = this; delnode.button = this;
}); };
var createButton = function (name, image) { var createButton = function (name, image) {
var button = ui.create.div('.button.character'); var button = ui.create.div('.button.character');
button.link = name; button.link = name;