Merge pull request #1002 from nofficalfs/Dev-fix-resthonf

修复生成器content的状态共享
This commit is contained in:
Spmario233 2024-03-02 14:45:37 +08:00 committed by GitHub
commit 5402e8de25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 62 additions and 31 deletions

View File

@ -3,7 +3,7 @@ root = true
[*] [*]
charset = utf-8 charset = utf-8
end_of_line = crlf end_of_line = lf
insert_final_newline = true insert_final_newline = true
[*.js] [*.js]

3
CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,3 @@
> W.I.P
自由开源是无名杀社区的灵魂,希望所有人都能够遵循这一精神。

3
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,3 @@
> W.I.P
请参考[此处](https://github.com/libccy/noname/wiki/%E3%80%8A%E6%97%A0%E5%90%8D%E6%9D%80%E3%80%8B%E9%A1%B9%E7%9B%AE-Pull-Request-%E6%8F%90%E4%BA%A4%E8%A7%84%E8%8C%83)了解无名杀的PR规范。

View File

@ -409,7 +409,18 @@ export class GameEvent {
catch { catch {
throw new Error(`Content ${item} may not exist.\nlib.element.content[${item}] = ${lib.element.content[item]}`); throw new Error(`Content ${item} may not exist.\nlib.element.content[${item}] = ${lib.element.content[item]}`);
} }
this.content = lib.element.content[item];
if (typeof lib.element.content[item] === "undefined")
throw new Error(`Cannot find lib.element.content[${item}]`)
// Generator的状态重置
else if (lib.element.content[item]._gen) {
this.content = lib.element.content[item].bind({
gen: null,
last: undefined
})
} else {
this.content = lib.element.content[item];
}
break; break;
} }
return this; return this;

View File

@ -1,13 +1,15 @@
import { nonameInitialized, assetURL, userAgent, Uninstantable, GeneratorFunction, AsyncFunction } from "../../util/index.js"; import { nonameInitialized, assetURL, userAgent, Uninstantable, GeneratorFunction, AsyncFunction } from "../../util/index.js";
import { AI as ai } from '../../ai/index.js'; import { AI as ai } from '../../ai/index.js'
import { Get as get } from '../../get/index.js'; import { Get as get } from '../../get/index.js'
import { Game as game } from '../../game/index.js'; import { Game, Game as game } from '../../game/index.js'
import { Library as lib } from "../index.js"; import { Library as lib } from "../index.js"
import { status as _status } from '../../status/index.js'; import { status as _status } from '../../status/index.js'
import { UI as ui } from '../../ui/index.js'; import { UI as ui } from '../../ui/index.js'
import { GNC as gnc } from '../../gnc/index.js'; import { GNC as gnc } from '../../gnc/index.js'
import { LibInitPromises } from "./promises.js"; import { LibInitPromises } from "./promises.js"
import { GameEvent } from "../element/gameEvent.js"
import { GameEventPromise } from "../element/gameEventPromise.js"
export class LibInit extends Uninstantable { export class LibInit extends Uninstantable {
/** /**
@ -693,30 +695,37 @@ export class LibInit extends Uninstantable {
} }
case "function": case "function":
if (gnc.is.generatorFunc(item)) { if (gnc.is.generatorFunc(item)) {
let gen, lastEvent; // let gen, lastEvent;
return function* (event, step, source, player, target, targets, card, cards, skill, forced, num, trigger, result, _status, lib, game, ui, get, ai) { let content = function* (event, step, source, player, target, targets, card, cards, skill, forced, num, trigger, result, _status, lib, game, ui, get, ai) {
event.step = NaN; event.step = NaN;
if (!gen) gen = item(event, { if (!this.gen) this.gen = item(event, {
event: event, event,
step: step, step,
source: source, source,
player: player, player,
target: target, target,
targets: targets, targets,
card: card, card,
cards: cards, cards,
skill: skill, skill,
forced: forced, forced,
num: num, num,
trigger: trigger, trigger,
result: result result
}); });
var res = gen.next((lastEvent && (typeof lastEvent == 'object') && ("result" in lastEvent)) ? lastEvent.result : lastEvent);
let res
if (!this.last) res = this.gen.next()
else if (typeof this.last !== "object") res = this.gen.next(this.last)
else if (this.last instanceof GameEvent || this.last instanceof GameEventPromise)
res = this.gen.next(this.last.result)
else res = this.gen.next(this.last)
if (res.done){ if (res.done){
gen = null; this.gen = null;
return event.finish(); return event.finish();
} }
var currentResult = res.value; let currentResult = res.value;
// TODO: use `event.debugger` to replace source // TODO: use `event.debugger` to replace source
if (typeof currentResult == "function") yield currentResult; if (typeof currentResult == "function") yield currentResult;
else { else {
@ -724,9 +733,14 @@ export class LibInit extends Uninstantable {
event.step = currentResult[1]; event.step = currentResult[1];
currentResult = currentResult[0]; currentResult = currentResult[0];
} }
lastEvent = currentResult; this.last = currentResult;
} }
} }.bind({
gen: null,
last: undefined
})
content._gen = true
return content
} else if (item._parsed) return item; } else if (item._parsed) return item;
// falls through // falls through
default: default: