Skip to content

Commit

Permalink
Fix edge position offsets
Browse files Browse the repository at this point in the history
Edges now generate successfully, still missing webui edge visualization
  • Loading branch information
Danielv123 committed Jun 10, 2024
1 parent b548106 commit f4eb75a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 47 deletions.
31 changes: 10 additions & 21 deletions docs/worldgen/factionGrid/generate server.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ The server generation function takes care of the following:
2. Assign to a host with free capacity
3. Create a new save
4. Apply gridworld configuration options
5. Apply edge transports configuration
6. Apply edge transports configuration to neighboring servers
7. Start the server
8. Run world border creation scripts
5. Apply universal edges configuration
6. Start the server
7. Run world border creation scripts

## Gridworld configuration options

Expand All @@ -25,22 +24,12 @@ The following settings are set on the instance:
| `gridworld.grid_x_size` | The x size of the grid in the world |
| `gridworld.grid_y_size` | The y size of the grid in the world |

## Edge transports configuration
## Universal edges configuration

The following settings are set on the instance:
As of version 0.6 gridworld uses [universal_edges](https://github.com/Danielv123/universal_edges) instead of [edge_transports](https://github.com/clusterio/edge_transports). Universal edges is a typescript rewrite that uses a new configuration system and has support for more connector types (fluids, power, trains).

Edges allow for setting up connectors to transport items/fluids/power/trains between servers. They are automatically configured during server creation. Edges can be inspected/modified using the universal_edges web UI. There are a few peculiarities to how edges are set up with gridworld:

| Setting | Description |
| -------------------------- | ----------------------------- |
| `edge_transports.internal` | Edge transports configuration |

The edge transports configuration is an object like `{edges: []}`. Each edge has the following properties:

| Property | Description |
| ----------------- | ----------------------------------------------------------------------------------------------- |
| `id` | edge ID |
| `origin` | [x,y] |
| `surface` | Target surface index, always 1 for gridworld |
| `direction` | Factorio cardinal direction index. The border is drawn as a beam with the IO on the right side. |
| `length` | Length of border |
| `target_instance` | Instance ID of target server |
| `target_edge` | Corresponding edge ID on the target server |
1. Edge IDs are not random, but based on the grid square the edge connects. `edge_${from}_${to}` where `from` and `to` are x,y coordinates.
2. At least during initial develpment, edges are refreshed on each instance start. This reduces the need for migrations, but means manual changes to the edge config can be unstable.
3. Unlike the old edge transports integration, gridworld no longer overwrites edges it did not create. This allows for custom topologies.
1 change: 1 addition & 0 deletions instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class InstancePlugin extends BaseInstancePlugin {
await this.sendRcon(`/sc gridworld.create_spawn("${data.x_size}","${data.y_size}","${data.world_x}","${data.world_y}", false)`, true);
// Update neighboring nodes for edge_transports
await sleep(1000);
// TODO: The following command can be disabled once edge creation during instance creation is stable
await this.instance.sendTo("controller", new messages.UpdateEdgeTransportEdges({
instance_id: this.instance.config.get("instance.id"),
}));
Expand Down
18 changes: 0 additions & 18 deletions messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,6 @@ module.exports = {
items: { type: "number" },
},
},
edges: {
type: "array",
items: {
type: "object",
properties: {
id: { type: "integer" },
origin: {
type: "array",
items: { type: "integer" },
},
surface: { type: "integer" },
direction: { type: "integer" },
length: { type: "integer" },
target_instance: { type: "integer" },
target_edge: { type: "integer" },
},
},
},
},
},
},
Expand Down
1 change: 0 additions & 1 deletion src/request_handlers/getMapDataRequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ module.exports = async function getMapDataRequestHandler({ grid_id }) {
instance[1].config.get("gridworld.grid_y_size"),
],
],
edges: instance[1].config.get("edge_transports.internal").edges,
})),
};
};
2 changes: 1 addition & 1 deletion src/worldgen/factionGrid/createServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = async function createServer({
instanceId,
});
edges.forEach(edge => {
this.controller.plugins.get("universal_edges").handleSetEdgeConfigRequest({ edge });
plugin.controller.plugins.get("universal_edges").handleSetEdgeConfigRequest({ edge });
});

return {
Expand Down
8 changes: 4 additions & 4 deletions src/worldgen/getEdges.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ module.exports = function getEdges({
&& instance.config.get("gridworld.grid_x_position") === x + 1
&& instance.config.get("gridworld.grid_y_position") === y
)?.config.get("instance.id") || 0,
origin: [worldfactor_x, worldfactor_y + y_size], // Bottom left on source, top right on target
origin: [worldfactor_x + x_size, worldfactor_y + y_size], // Bottom right corner
surface: 1,
direction: string_to_direction("North"), // Points north, exit is from the right side
ready: false,
},
target: {
instanceId, // Local instance
origin: [worldfactor_x + x_size, worldfactor_y],
origin: [worldfactor_x + x_size, worldfactor_y], // Top right corner
surface: 1,
direction: string_to_direction("South"), // Points south, entrance is from the right side
ready: false,
Expand All @@ -117,9 +117,9 @@ module.exports = function getEdges({
&& instance.config.get("gridworld.grid_x_position") === x - 1
&& instance.config.get("gridworld.grid_y_position") === y
)?.config.get("instance.id") || 0,
origin: [worldfactor_x, worldfactor_y], // Top left corner of this instance, top right corner of target
origin: [worldfactor_x, worldfactor_y], // Top right corner
surface: 1,
direction: string_to_direction("South"), // Points south, entrane is from the right side
direction: string_to_direction("South"), // Points south, entrance is from the right side
ready: false,
},
});
Expand Down
4 changes: 2 additions & 2 deletions web/components/GridVisualizer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function GridVisualizer(props) {
minNativeZoom={10} // 7 min
/>
{mapData?.map_data?.map?.(instance => <div key={instance.instance_id}>
{instance.edges.map(edge => {
{/* {instance.edges.map(edge => { // TODO: Reimplement using universal_edges config subscription
// Coordinates are given as lat and long corresponding to Y and X in the grid
let origin = [-1 * edge.origin[1] / scaleFactor, edge.origin[0] / scaleFactor];
let destination = [...origin];
Expand All @@ -83,7 +83,7 @@ export default function GridVisualizer(props) {
positions={[origin, destination]}
opacity={0.3}
/>;
})}
})} */}
<InstanceRender
instance={instance}
activeInstance={activeInstance}
Expand Down

0 comments on commit f4eb75a

Please sign in to comment.