Skip to main content

Graphedge

Based on game build 714014 | Last updated: 2026-02-27

Overview

The Edge component defines a bidirectional connection between two graph nodes (node1 and node2) in the game's world map system. It maintains metadata such as visual colour, optional lock configuration, and content references. Edges are used internally to support procedural map generation, level traversal logic, and debug rendering — but are not attached to game entities as standard components (i.e., they exist as plain Lua objects, not ECS components). Each edge is automatically registered with both its connected nodes, and tracks whether it has been visited or is hidden.

Usage example

local node1 = GraphNode(1, x1, y1, data1)
local node2 = GraphNode(2, x2, y2, data2)
local edge = Edge("e_12", node1, node2, nil, { colour = { r=255, g=128, b=0, a=255 } })
edge.hidden = false
edge:RenderToMap(map_instance)

Dependencies & tags

Components used: None (the class is self-contained and does not reference or interact with any entity components via inst.components.X).
Tags: None identified.

Properties

PropertyTypeDefault ValueDescription
idstringUnique identifier for the edge.
node1GraphNodeFirst node this edge connects.
node2GraphNodeSecond node this edge connects.
visitedbooleanfalseFlag indicating whether this edge has been traversed.
hiddenbooleanfalseControls whether the edge is skipped during rendering.
datatable?nilOptional arbitrary data passed on construction (used for colour, etc.).
lockedtable?nilLock configuration in form {locktype, keytype, keynode}; if present, enforces traversal restrictions.
contentstable{}Mutable array-like table for edge-related content (e.g., loot, events).
colourtable{r=255,g=0,b=0,a=255}RGBA colour for debug rendering; defaults to red unless overridden via data.colour.

Main functions

RenderToMap(map, args)

  • Description: Renders a line segment between the two connected nodes on the specified map, using the second node's data value as the render value. Overridable via args.value_override.
  • Parameters:
    • map (Map): Target map object providing the DrawLine method and dimensions.
    • args (table?): Optional arguments; if present and contains value_override, its value replaces self.node2.data.value.
  • Returns: nil
  • Error states: No explicit error handling documented; silently returns if self.hidden == true.

DrawDebug(draw, map)

  • Description: Draws the edge as a debug line centered relative to the map, scaled by TILE_SCALE.
  • Parameters:
    • draw (Draw): Graphics context providing a Line method.
    • map (Map): Map instance used to compute center offsets.
  • Returns: nil

SaveEncode(map)

  • Description: Serializes essential edge state into a compact table, suitable for map saving/loading.
  • Parameters:
    • map (Map?): Unused in current implementation; included for API compatibility.
  • Returns: table with keys:
    • n1 (string): ID of node1.
    • n2 (string): ID of node2.
    • c (table): self.colour table (RGBA values).

Populate(map, spawnFn)

  • Description: Placeholder method intended for filling the edge with dynamic content (e.g., via a spawner function). Currently empty.
  • Parameters:
    • map (Map): Target map instance.
    • spawnFn (function): Expected callback for content generation.
  • Returns: nil

Events & listeners

None. This class does not register or dispatch any events via inst:ListenForEvent or inst:PushEvent.