game

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2025 License: GPL-3.0 Imports: 3 Imported by: 1

README

Game Package

The game package provides runtime infrastructure for loading and managing game entities. It bridges the gap between static data structures and active game objects that participate in the event system.

Purpose

This package handles:

  • Entity Loading: Converting persistent data into active game objects
  • Infrastructure Wiring: Connecting entities to event buses and other game systems
  • State Management: Common patterns for managing entity lifecycle
  • Runtime Context: Providing consistent context for game operations

What Belongs Here

YES:

  • GameContext[T] - Generic pattern for loading entities with infrastructure
  • Entity lifecycle management (loading, activating, deactivating)
  • Common runtime patterns shared across different game systems
  • Infrastructure integration (event bus, future systems)

NO:

  • Game rules (attack rolls, damage calculation, saving throws)
  • Combat mechanics (initiative, actions, reactions)
  • Character progression (leveling, experience)
  • Specific entity implementations (Character, Monster, Item)

Key Concepts

GameContext

The GameContext[T] pattern provides a consistent way to load any game entity:

// All entities load the same way
character := LoadCharacterFromData(ctx, GameContext[CharacterData]{...})
room := LoadRoomFromData(ctx, GameContext[RoomData]{...})
item := LoadItemFromData(ctx, GameContext[ItemData]{...})

This ensures:

  • Entities have access to required infrastructure (event bus)
  • Loading signatures are consistent across the toolkit
  • Future infrastructure can be added without changing every loader

Design Principles

  1. Rule-Agnostic: This package knows nothing about specific game rules
  2. Infrastructure-Focused: Provides plumbing, not game logic
  3. Generic Patterns: Solutions that work for any game system
  4. Minimal Dependencies: Only depends on core and events

Example Usage

// Create game context with infrastructure
gameCtx := game.NewContext(eventBus, characterData)

// Load character (in rulebook package)
character, err := character.LoadFromContext(ctx, gameCtx)

// Character is now wired to event bus and ready for gameplay

Future Considerations

As the toolkit grows, this package might also handle:

  • Session management
  • State persistence coordination
  • System registration (combat tracker, vision system, etc.)
  • Performance monitoring

However, these will only be added if they remain rule-agnostic infrastructure concerns.

Documentation

Overview

Package game provides runtime infrastructure for loading and managing game entities. It bridges static data structures with active game objects that participate in the event system.

This package is rule-agnostic and focuses solely on infrastructure concerns like entity lifecycle, event bus integration, and state management patterns.

Example:

// Create context with game infrastructure
ctx := context.Background()
gameCtx, err := game.NewContext(eventBus, characterData)
if err != nil {
    // Handle validation error
}

// Access data through getter methods
data := gameCtx.Data()
bus := gameCtx.EventBus()

// Load entity (implementation in rulebook/entity package)
character, err := LoadCharacterFromContext(ctx, gameCtx)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context[T any] struct {
	// contains filtered or unexported fields
}

Context provides a consistent pattern for loading game entities from data. It combines the entity's data with the game infrastructure needed for runtime operations.

The generic type T represents the data structure for the specific entity being loaded. For example: Context[RoomData], Context[CharacterData], etc.

This pattern ensures:

  • Consistent loading signatures across all entity types
  • Self-contained data (T has everything needed to reconstruct the entity)
  • Access to game infrastructure (event bus, future systems)
  • Clean separation between data and behavior

Context is immutable after creation to guarantee validity.

func NewContext

func NewContext[T any](eventBus events.EventBus, data T) (Context[T], error)

NewContext creates a new Context with the provided infrastructure and data. Both eventBus and data are required - returns error if either is nil/zero.

func (Context[T]) Data

func (c Context[T]) Data() T

Data returns the entity data for this context.

func (Context[T]) EventBus

func (c Context[T]) EventBus() events.EventBus

EventBus returns the event bus for this context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL