Skip to content

Commit

Permalink
ref: changed system for less calls of SignalStateLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Oct 20, 2024
1 parent 0796108 commit 66fd4f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ public interface SignalStateListener {
public void update(final SignalStateInfo info, final Map<SEProperty, String> changedProperties,
final ChangedState changedState);

default SignalStateListener andThen(final SignalStateListener otherTask) {
return (info, properties, state) -> {
this.update(info, properties, state);
otherTask.update(info, properties, state);
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public static void reset(final ResetInfo info) {
});
if (!propertiesToSet.isEmpty())
SignalStateHandler.setStates(info.current, propertiesToSet);
unloadSignal(stateInfo);
});
}

Expand All @@ -100,13 +99,10 @@ private void changeIfPresent(final List<ConfigProperty> values, final ConfigInfo
if (info.nextinfo != null) {
loadSignalAndRunTask(info.nextinfo, (nextInfo, nextProperties, _u2) -> {
changeSignals(values, info, oldProperties, nextProperties);
unloadSignal(nextInfo);
unloadSignal(stateInfo);
pathway.updatePrevious();
});
} else {
changeSignals(values, info, oldProperties, null);
unloadSignal(stateInfo);
pathway.updatePrevious();
}
});
Expand Down Expand Up @@ -145,19 +141,21 @@ private void loadWithoutPredicate(final List<ConfigProperty> values,
});
if (!propertiesToSet.isEmpty())
SignalStateHandler.setStates(current, propertiesToSet);
unloadSignal(info);
pathway.updatePrevious();
});
}
}

private static void loadSignalAndRunTask(final SignalStateInfo info,
final SignalStateListener task) {
if (!info.isValid() || info.worldNullOrClientSide())
return;
final boolean isSignalLoaded = SignalStateHandler.isSignalLoaded(info);
if (!isSignalLoaded) {
SignalStateHandler.loadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER));
task.andThen((_u1, _u2, _u3) -> SignalStateHandler
.unloadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER)));
}
SignalStateHandler.runTaskWhenSignalLoaded(info, task);
SignalStateHandler.loadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER));
}

private static void unloadSignal(final SignalStateInfo info) {
SignalStateHandler.unloadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER));
}
}

0 comments on commit 66fd4f4

Please sign in to comment.