A directional graph system for room-based spatial navigation in games and interactive fiction.
import { createSpatialGraph, Direction } from '@motioneffector/spatial'
// Create a graph and add rooms
const graph = createSpatialGraph()
graph.createNode('entrance', { name: 'Entrance Hall' })
graph.createNode('library', { name: 'Library' })
// Connect rooms with directions
graph.connect('entrance', Direction.NORTH, 'library')
// Add a locked gate
graph.setGate('entrance', Direction.NORTH, {
id: 'door-1',
locked: true,
keyId: 'brass-key'
})
// Check if player can traverse
const result = graph.canTraverse('entrance', Direction.NORTH, {
inventory: ['brass-key']
})
console.log(result.allowed) // true
// Find shortest path
const path = graph.findPath('entrance', 'library')
any typesMIT © motioneffector