Fix grid parsing

now compatiable with Yukki's resources!
This commit is contained in:
KingRainbow44 2023-04-11 02:05:38 -04:00
parent 990b36cbce
commit 76be70d4a8
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 29 additions and 7 deletions

View File

@ -3,12 +3,31 @@ package emu.grasscutter.data.server;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.utils.GridPosition;
import emu.grasscutter.utils.Position;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class Grid {
public Map<GridPosition, Set<Integer>> grid;
public Map<String, Set<Integer>> grid;
public Map<GridPosition, Set<Integer>> gridMap
= new LinkedHashMap<>();
/**
* Loads the correct grid map.
*/
public void load() {
this.grid.forEach((position, groups) ->
this.gridMap.put(new GridPosition(position), groups));
}
/**
* @return The correctly loaded grid map.
*/
public Map<GridPosition, Set<Integer>> getGrid() {
return this.gridMap;
}
public Set<Integer> getNearbyGroups(int vision_level, Position position) {
int width = Grasscutter.getConfig().server.game.visionOptions[vision_level].gridWidth;
@ -22,10 +41,10 @@ public class Grid {
// should not affect much the loading
for (int x = 0; x < vision_range_grid + 1; x++) {
for (int z = 0; z < vision_range_grid + 1; z++) {
nearbyGroups.addAll(grid.getOrDefault(pos.addClone(x, z), new HashSet<>()));
nearbyGroups.addAll(grid.getOrDefault(pos.addClone(-x, z), new HashSet<>()));
nearbyGroups.addAll(grid.getOrDefault(pos.addClone(x, -z), new HashSet<>()));
nearbyGroups.addAll(grid.getOrDefault(pos.addClone(-x, -z), new HashSet<>()));
nearbyGroups.addAll(gridMap.getOrDefault(pos.addClone(x, z), new HashSet<>()));
nearbyGroups.addAll(gridMap.getOrDefault(pos.addClone(-x, z), new HashSet<>()));
nearbyGroups.addAll(gridMap.getOrDefault(pos.addClone(x, -z), new HashSet<>()));
nearbyGroups.addAll(gridMap.getOrDefault(pos.addClone(-x, -z), new HashSet<>()));
}
}

View File

@ -427,6 +427,7 @@ public class SceneScriptManager {
try {
this.groupGrids = JsonUtils.loadToList(path, Grid.class);
this.groupGrids.forEach(Grid::load);
} catch (IOException ignored) {
Grasscutter.getLogger().error("Scene {} unable to load grid file.", getScene().getId());
} catch (Exception e) {
@ -552,7 +553,7 @@ public class SceneScriptManager {
this.groupGrids = new ArrayList<>();
for (int i = 0; i < 6; i++) {
this.groupGrids.add(new Grid());
this.groupGrids.get(i).grid = groupPositions.get(i);
this.groupGrids.get(i).gridMap = groupPositions.get(i);
}
try (FileWriter file = new FileWriter(path.toFile())) {

View File

@ -6,6 +6,7 @@ import java.io.Serializable;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
@Entity
public class GridPosition implements Serializable {
@ -37,7 +38,8 @@ public class GridPosition implements Serializable {
this.x = xzwidth.get(0);
}
public GridPosition(String str) throws IOException {
@SneakyThrows
public GridPosition(String str) {
String[] listOfParams = str.replace(" ", "").replace("(", "").replace(")", "").split(",");
if (listOfParams.length != 3)
throw new IOException("invalid size on GridPosition definition - ");