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

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

View File

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