Skip to content

Delegate spatial mechanics to Viron server #234

@dmccoystephenson

Description

@dmccoystephenson

Summary

Replace Roam's JSON file-based spatial data management (environments, grids, locations, entities) with a Viron server as the authoritative backend. Changes must be persisted immediately via the Viron REST API rather than buffered and flushed on shutdown.

Background

Roam currently manages room/grid/location/entity relationships in-memory and serializes them to JSON files on shutdown or room transition via RoomJsonReaderWriter (src/world/roomJsonReaderWriter.py) and related classes. Viron is a Spring Boot REST service (Java 21, PostgreSQL) that manages exactly this hierarchy — environments → grids → locations → entities — through a clean REST API. The Python client services (EnvironmentService, GridService, LocationService, EntityService) already exist in the Viron repo under src/main/python/preponderous/viron/services/.

Requirements

Infrastructure

  • Add Viron connection config to config.yml (e.g. vironHost, vironPort) and load it in Config (src/config/config.py)
  • Register a VironClient wrapper (or reuse the existing Viron Python service classes directly) in the DI container via src/bootstrap.py
  • The Viron server must be running before Roam launches; if the connection fails at startup, Roam should log an error via gameLogging (PR Add structured logging with structlog across codebase #344) and fall back gracefully or exit with a clear message

Data Mapping

Map Roam's domain concepts to Viron's:

Roam Viron
Room Environment
Room grid Grid
Location Location
DrawableEntity / LivingEntity Entity

Immediate Persistence

  • All state-mutating operations (entity placement, movement, removal, room generation) must call the Viron REST API immediately rather than accumulating in-memory state for later file writes
  • Remove or bypass the existing JSON file write paths in RoomJsonReaderWriter.saveRoom(), Stats.save(), and TickCounter.save() for data covered by Viron — stats and tick count may continue using JSON files if they have no Viron equivalent
  • Background thread save calls in WorldScreen (src/screen/worldScreen.py) that defer room writes should be replaced with synchronous or async Viron API calls using the existing ThreadPoolExecutor pattern

Read Path

  • On room load/transition, fetch environment + grid + location + entity data from Viron via the appropriate service (GET /api/v1/environments/{id}, GET /api/v1/locations/environment/{environmentId}, etc.) instead of reading from room JSON files
  • Map.getRoom() and RoomPreloader._loadOrGenerate() (src/world/roomPreloader.py) should query Viron first, then fall back to generating a new room if Viron returns 404

Entity Lifecycle

  • When WorldScreen places, gathers, or removes an entity, call PUT /api/v1/locations/{locationId}/entity/{entityId} or DELETE /api/v1/locations/entity/{entityId} immediately
  • When a living entity moves between locations (in room.py moveLivingEntities()), update its location in Viron atomically: remove from current location then add to new location
  • When a living entity dies (checkForLivingEntityDeaths() in worldScreen.py), call DELETE /api/v1/entities/{id} to remove it from Viron

Save Directory Compatibility

  • The pathToSaveDirectory config and associated JSON schemas may be retained for stats, tick count, inventory, and player attributes that have no Viron equivalent
  • Room JSON files under saves/*/rooms/ should no longer be written or read for data now owned by Viron

Acceptance Criteria

  • Roam reads initial room/entity state from a running Viron server on launch
  • All entity placement and movement operations are reflected in Viron immediately (no deferred writes)
  • Room transitions query Viron for existing room data before generating new rooms
  • Removing or killing entities calls the Viron delete endpoint immediately
  • Roam logs a clear error via gameLogging and exits gracefully if Viron is unreachable at startup
  • Inventory, stats, tick count, and player attributes continue to persist via existing JSON file mechanism
  • All existing tests that do not depend on the JSON room persistence path continue to pass
  • New tests cover the Viron client integration (mocked HTTP) for room load, entity placement, movement, and deletion

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions