JSPM

@motioneffector/spatial

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q29081F
  • License MIT

Directional graph for room-based spatial navigation

Package Exports

  • @motioneffector/spatial

Readme

@motioneffector/spatial

A directional graph system for room-based spatial navigation in games and interactive fiction.

npm version license TypeScript

Features

  • Directional Connections - Link nodes via compass directions, vertical, and custom
  • Conditional Gates - Lock paths with keys, flags, or custom logic
  • Weighted Pathfinding - Find optimal routes with Dijkstra's algorithm
  • Multi-tile Nodes - Rooms spanning multiple grid positions with layers
  • Zone Management - Group and query nodes by zones
  • Graph Analysis - Detect orphans, dead ends, and disconnected subgraphs
  • Event System - React to graph changes in real-time
  • Serialization - Save and restore entire graph state

Read the full manual →

Quick Start

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')

Testing & Validation

  • Comprehensive test suite - 392 unit tests covering core functionality
  • Fuzz tested - Randomized input testing to catch edge cases
  • Strict TypeScript - Full type coverage with no any types
  • Zero dependencies - No supply chain risk

License

MIT © motioneffector