Merge pull request #1002 from nofficalfs/Dev-fix-resthonf
修复生成器content的状态共享
This commit is contained in:
commit
5402e8de25
|
@ -3,7 +3,7 @@ root = true
|
|||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = crlf
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.js]
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
> W.I.P
|
||||
|
||||
自由开源是无名杀社区的灵魂,希望所有人都能够遵循这一精神。
|
|
@ -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规范。
|
|
@ -409,7 +409,18 @@ export class GameEvent {
|
|||
catch {
|
||||
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;
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
import { nonameInitialized, assetURL, userAgent, Uninstantable, GeneratorFunction, AsyncFunction } from "../../util/index.js";
|
||||
import { AI as ai } from '../../ai/index.js';
|
||||
import { Get as get } from '../../get/index.js';
|
||||
import { Game as game } from '../../game/index.js';
|
||||
import { Library as lib } from "../index.js";
|
||||
import { status as _status } from '../../status/index.js';
|
||||
import { UI as ui } from '../../ui/index.js';
|
||||
import { GNC as gnc } from '../../gnc/index.js';
|
||||
import { AI as ai } from '../../ai/index.js'
|
||||
import { Get as get } from '../../get/index.js'
|
||||
import { Game, Game as game } from '../../game/index.js'
|
||||
import { Library as lib } from "../index.js"
|
||||
import { status as _status } from '../../status/index.js'
|
||||
import { UI as ui } from '../../ui/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 {
|
||||
/**
|
||||
|
@ -693,30 +695,37 @@ export class LibInit extends Uninstantable {
|
|||
}
|
||||
case "function":
|
||||
if (gnc.is.generatorFunc(item)) {
|
||||
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 gen, lastEvent;
|
||||
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;
|
||||
if (!gen) gen = item(event, {
|
||||
event: event,
|
||||
step: step,
|
||||
source: source,
|
||||
player: player,
|
||||
target: target,
|
||||
targets: targets,
|
||||
card: card,
|
||||
cards: cards,
|
||||
skill: skill,
|
||||
forced: forced,
|
||||
num: num,
|
||||
trigger: trigger,
|
||||
result: result
|
||||
if (!this.gen) this.gen = item(event, {
|
||||
event,
|
||||
step,
|
||||
source,
|
||||
player,
|
||||
target,
|
||||
targets,
|
||||
card,
|
||||
cards,
|
||||
skill,
|
||||
forced,
|
||||
num,
|
||||
trigger,
|
||||
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){
|
||||
gen = null;
|
||||
this.gen = null;
|
||||
return event.finish();
|
||||
}
|
||||
var currentResult = res.value;
|
||||
let currentResult = res.value;
|
||||
// TODO: use `event.debugger` to replace source
|
||||
if (typeof currentResult == "function") yield currentResult;
|
||||
else {
|
||||
|
@ -724,9 +733,14 @@ export class LibInit extends Uninstantable {
|
|||
event.step = currentResult[1];
|
||||
currentResult = currentResult[0];
|
||||
}
|
||||
lastEvent = currentResult;
|
||||
this.last = currentResult;
|
||||
}
|
||||
}
|
||||
}.bind({
|
||||
gen: null,
|
||||
last: undefined
|
||||
})
|
||||
content._gen = true
|
||||
return content
|
||||
} else if (item._parsed) return item;
|
||||
// falls through
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue