npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

narrative-event-scheduler

v1.0.0

Published

A flexible TypeScript library for creating dynamic, condition-based narrative events in games and interactive storytelling applications

Readme

Narrative Event Scheduler

A sophisticated narrative event scheduling system built with TypeScript. This system manages story events using reactive state management, conditional availability (with Quis-style conditions), and story grammar for narrative structure.

🏗️ Architecture

The system consists of several key components:

Core Components

  • ReactiveStateManager: Manages application state with reactive updates and change notifications
  • NarrativeEvent: Represents individual story events with conditions, priorities, and execution logic
  • ConditionEvaluator: Evaluates event conditions against current state (with simplified Quis-style logic)
  • NarrativeEventScheduler: Main scheduler that manages event selection and execution
  • StoryGrammarIntegration: Integrates story grammar rules for narrative structure

Key Features

  • Reactive State Management: State changes automatically trigger updates
  • Conditional Event Availability: Events only execute when their conditions are met
  • Multiple Selection Strategies: Priority-based, random, weighted random, least executed
  • Grammar-based Narrative Structure: Uses story grammar for structured storytelling
  • Tick-based Execution: Discrete time steps for event scheduling
  • Extensible Event System: Custom execution logic and state changes

🚀 Setup

Install dependencies:

npm install

📖 Usage

Build Commands

  • Build for production: npm run build
  • Build for development with watch mode: npm run dev

Code Quality

  • Lint TypeScript files: npm run lint
  • Auto-fix linting issues: npm run lint:fix

Running the Example

The project includes a complete example adventure story that demonstrates all features:

npm run build && node dist/index.js

This runs an interactive adventure where:

  • Hero starts in a village
  • Can explore forest, meet villagers, rest at inn
  • Encounters wolves, finds treasure
  • State affects event availability
  • Story concludes when victory conditions are met

🎯 Example Usage

import { 
  NarrativeEventScheduler, 
  NarrativeEvent, 
  SelectionStrategies 
} from './dist/index.js';

// Create events
const events = [
  new NarrativeEvent({
    id: 'start',
    name: 'Begin Adventure',
    conditions: ['!hasStarted'],
    priority: 10,
    stateChanges: { hasStarted: true, location: 'forest' }
  })
];

// Create scheduler
const scheduler = new NarrativeEventScheduler({
  events,
  initialState: { hasStarted: false },
  selectionStrategy: SelectionStrategies.highestPriority
});

// Run narrative
const result = await scheduler.tick();
console.log(`Executed ${result.eventsExecuted} events`);

🎮 Condition System

Events use a simplified condition syntax:

// Boolean checks
'hasStarted'           // Check if variable is truthy
'!hasStarted'          // Negation

// Comparisons  
'health > 50'          // Greater than
'gold >= 100'          // Greater than or equal
'level < 5'            // Less than
'name == "hero"'       // Equality

📊 Event Selection Strategies

  • Priority-based: Select highest priority event
  • Random: Random selection from available events
  • Weighted Random: Random selection weighted by priority
  • Least Executed: Balanced storytelling by execution count
  • Grammar-based: Uses story grammar rules for structured narrative

🎭 Story Grammar

Define narrative structure with grammar rules:

const grammarRules = [
  GrammarRuleBuilder.create('exploration')
    .withEvents(['explore_forest', 'find_treasure'])
    .withCondition('location == "forest"')
    .withWeight(8)
    .build()
];

🔧 Development Workflow

  1. Write TypeScript code in the src/ directory
  2. Use npm run dev for development with automatic rebuilding
  3. Use npm run lint to check code quality
  4. Use npm run build to create a production build
  5. Test with node dist/index.js

📋 Dependencies

  • Runtime: quis, story-grammar
  • Development: TypeScript, ESLint, Webpack, ts-loader

✨ Features Implemented

  • ✅ Reactive state management with change notifications
  • ✅ Event system with conditions and custom execution logic
  • ✅ Multiple event selection strategies
  • ✅ Simplified Quis-style condition evaluation
  • ✅ Story grammar integration for narrative structure
  • ✅ Complete working example with adventure story
  • ✅ TypeScript with strict type checking
  • ✅ ESLint configuration
  • ✅ Webpack bundling
  • ✅ Comprehensive documentation

The system provides a solid foundation for narrative-driven applications, interactive storytelling, and procedural content generation.