Skip to content

Commit

Permalink
Format code [skip actions]
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 29, 2023
1 parent 98fbc4e commit 4320bc7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
8 changes: 5 additions & 3 deletions src/main/java/emu/grasscutter/data/ResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,16 @@ private static void loadScenePoints() {

private static void loadRoutes() {
try {
Files.newDirectoryStream(getResourcePath("BinOutput/LevelDesign/Routes/"),"*.json")
Files.newDirectoryStream(getResourcePath("BinOutput/LevelDesign/Routes/"), "*.json")
.forEach(
path -> {
try {
val data = JsonUtils.loadToClass(path, SceneRoutes.class);
val routesArray = data.getRoutes();
if (routesArray == null) return;
val routesMap = GameData.getSceneRouteData().getOrDefault(data.getSceneId(), new Int2ObjectOpenHashMap<>());
val routesMap =
GameData.getSceneRouteData()
.getOrDefault(data.getSceneId(), new Int2ObjectOpenHashMap<>());
for (Route route : routesArray) {
routesMap.put(route.getLocalId(), route);
}
Expand All @@ -284,7 +286,7 @@ private static void loadRoutes() {
}
});
Grasscutter.getLogger()
.debug("Loaded " + GameData.getSceneNpcBornData().size() + " SceneRouteDatas.");
.debug("Loaded " + GameData.getSceneNpcBornData().size() + " SceneRouteDatas.");
} catch (IOException e) {
Grasscutter.getLogger().error("Failed to load SceneRouteData folder.");
}
Expand Down
55 changes: 40 additions & 15 deletions src/main/java/emu/grasscutter/game/entity/EntityGadget.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,32 +248,57 @@ public boolean startPlatform() {
return true;
}

if(routeConfig instanceof ConfigRoute configRoute) {
if (routeConfig instanceof ConfigRoute configRoute) {
var route = this.getScene().getSceneRouteById(configRoute.getRouteId());
if(route != null) {
if (route != null) {
var points = route.getPoints();
val currIndex = configRoute.getStartIndex();

Position prevpos;
if(currIndex == 0) {
if (currIndex == 0) {
prevpos = getPosition();
this.getScene().getScriptManager().callEvent(new ScriptArgs(this.getGroupId(), EventType.EVENT_PLATFORM_REACH_POINT, this.getConfigId(), configRoute.getRouteId()).setParam3(0).setEventSource(this.getConfigId()));
}else {
this.getScene()
.getScriptManager()
.callEvent(
new ScriptArgs(
this.getGroupId(),
EventType.EVENT_PLATFORM_REACH_POINT,
this.getConfigId(),
configRoute.getRouteId())
.setParam3(0)
.setEventSource(this.getConfigId()));
} else {
prevpos = points[currIndex].getPos();
}

double time = 0;
for(var i = currIndex; i < points.length;++i) {
for (var i = currIndex; i < points.length; ++i) {
time += points[i].getPos().computeDistance(prevpos) / points[i].getTargetVelocity();
prevpos = points[i].getPos();
val I = i;
configRoute.getScheduledIndexes().add(this.getScene().getScheduler().scheduleDelayedTask(() -> {
if(points[I].isHasReachEvent() && I > currIndex) {
this.getScene().getScriptManager().callEvent(new ScriptArgs(this.getGroupId(), EventType.EVENT_PLATFORM_REACH_POINT, this.getConfigId(), configRoute.getRouteId()).setParam3(I).setEventSource(this.getConfigId()));
}
configRoute.setStartIndex(I);
this.position.set(points[I].getPos());
},(int)time));
configRoute
.getScheduledIndexes()
.add(
this.getScene()
.getScheduler()
.scheduleDelayedTask(
() -> {
if (points[I].isHasReachEvent() && I > currIndex) {
this.getScene()
.getScriptManager()
.callEvent(
new ScriptArgs(
this.getGroupId(),
EventType.EVENT_PLATFORM_REACH_POINT,
this.getConfigId(),
configRoute.getRouteId())
.setParam3(I)
.setEventSource(this.getConfigId()));
}
configRoute.setStartIndex(I);
this.position.set(points[I].getPos());
},
(int) time));
}
}
}
Expand All @@ -294,8 +319,8 @@ public boolean stopPlatform() {
return true;
}

if(routeConfig instanceof ConfigRoute configRoute) {
for(var task : configRoute.getScheduledIndexes()) {
if (routeConfig instanceof ConfigRoute configRoute) {
for (var task : configRoute.getScheduledIndexes()) {
this.getScene().getScheduler().cancelTask(task);
}
configRoute.getScheduledIndexes().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import emu.grasscutter.net.proto.MovingPlatformTypeOuterClass;
import emu.grasscutter.net.proto.PlatformInfoOuterClass;
import emu.grasscutter.scripts.data.SceneGadget;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;

public class ConfigRoute extends BaseRoute {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emu/grasscutter/game/world/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public void onTick() {
return;
}

if(!isPaused) {
if (!isPaused) {
this.getScheduler().runTasks();
}

Expand Down

0 comments on commit 4320bc7

Please sign in to comment.