mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-02-13 17:53:23 +08:00
Fix grid parsing
now compatiable with Yukki's resources!
This commit is contained in:
parent
990b36cbce
commit
76be70d4a8
@ -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<>()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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())) {
|
||||
|
@ -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 - ");
|
||||
|
Loading…
Reference in New Issue
Block a user