Skip to content

Commit

Permalink
fix scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
khjxiaogu committed Jan 24, 2025
1 parent 4f57ed3 commit c12fee3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,25 @@

public class FHIcons {
private static final TypedCodecRegistry<FHIcon> serializers = new TypedCodecRegistry<>();
public static final Codec<FHIcon> CODEC = new AlternativeCodecBuilder<FHIcon>(FHIcon.class)
public static final Codec<FHIcon> DEFAULT_CODEC = new AlternativeCodecBuilder<FHIcon>(FHIcon.class)
.fallback(() -> FHNopIcon.INSTANCE)
.addSaveOnly(FHNopIcon.class, FHNopIcon.CODEC.codec())
.add(FHItemIcon.class, FHItemIcon.ICON_CODEC)
.add(FHItemIcon.class, FHItemIcon.CODEC.codec())
.add(FHAnimatedIcon.class, FHAnimatedIcon.ICON_CODEC)
.add(serializers.codec())
.addSaveOnly(FHIcon.class, FHNopIcon.CODEC.codec())
.add(FHNopIcon.CODEC.codec())
.build();
public static final Codec<FHIcon> DEFAULT_CODEC = new AlternativeCodecBuilder<FHIcon>(FHIcon.class)
.fallback(() -> FHNopIcon.INSTANCE)
public static final Codec<FHIcon> CODEC = new AlternativeCodecBuilder<FHIcon>(FHIcon.class)
.addSaveOnly(FHNopIcon.class, FHNopIcon.CODEC.codec())
.add(FHItemIcon.class, FHItemIcon.ICON_CODEC)
.add(FHItemIcon.class, FHItemIcon.CODEC.codec())
.add(FHAnimatedIcon.class, FHAnimatedIcon.ICON_CODEC)
.add(serializers.codec())
.add(FHNopIcon.CODEC.codec())
.addSaveOnly(FHIcon.class, FHNopIcon.CODEC.codec())
.build();


static {
serializers.register(FHNopIcon.class, "nop", FHNopIcon.CODEC);
serializers.register(FHItemIcon.class, "item", FHItemIcon.CODEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,10 @@ public void setCallStack(LinkedList<ScenarioTarget> linkedList) {
this.callStack.clear();;
this.callStack.addAll(linkedList);
}
@Override
public void stop() {
super.stop();
currentLabel=null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public class BaseScenarioRunner implements ScenarioThread{

protected Scene scene;

@Override
public String toString() {
return "BaseScenarioRunner [sp=" + sp + ", nodeNum=" + nodeNum + ", scene=" + scene + ", toExecute=" + toExecute
+ ", triggers=" + triggers + ", status=" + status + ", waiting=" + waiting + ", callStack=" + callStack
+ ", isConducting=" + isConducting + ", currentLabel=" + currentLabel + "]";
}



/** Actions appended by trigger and awaiting execution. */
protected LinkedList<ScenarioTarget> toExecute=new LinkedList<>();

Expand Down Expand Up @@ -289,7 +298,8 @@ public void run(Scenario sp) {
* Stop.
*/
public void stop() {
nodeNum=getScenario().pieces().size();
this.sp=null;
nodeNum=0;
setStatus(RunStatus.STOPPED);
}
protected void runCodeExecutionLoop(ScenarioContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void enableActs() {
currentAct=acts.get(lastCurrent);
}
acts.values().forEach(t->{
if(!t.name.isAct())return;
if(t.getStatus()==RunStatus.WAITTRIGGER) {
t.scene().setSlient(true);
//t.getScene().setSlient(true);
Expand Down Expand Up @@ -129,25 +130,36 @@ public void tick(ServerPlayer player) {
//detect triggers
//System.out.println("start tick==============");

for(Act act:acts.values()) {
//System.out.println(act.name+": "+act);
act.tickTrigger(getContext());
}
//System.out.println("current act: "+getCurrentAct());
if(currentAct!=null) {
currentAct.tickMain(context);
if(currentAct.getStatus().shouldPause) {
currentAct=null;
}
}
if(currentAct==null)



//start act scheduling after system started
if(isActsEnabled) {
for(Act act:acts.values()) {

act.runScheduled(context);
if(!act.getStatus().shouldPause) {
currentAct=act;
}
//System.out.println(act.name+": "+act);
act.tickTrigger(context);
}
//System.out.println("current act: "+getCurrentAct());
if(currentAct!=null) {
currentAct.tickMain(context);
if(currentAct.getStatus().shouldPause) {
currentAct=null;
}
}
if(currentAct==null)
for(Act act:acts.values()) {

act.runScheduled(context);
if(!act.getStatus().shouldPause) {
currentAct=act;
}
}
}else {//during bootstrap steps
Act initact=acts.get(init);
initact.tickTrigger(context);
initact.tickMain(context);
initact.runScheduled(context);
}

}

Expand Down

0 comments on commit c12fee3

Please sign in to comment.