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

miaoda-game-mode-core

v0.2.0

Published

Engine-agnostic concurrent timed gameplay modes with exclusivity, priority, pause, and cooldown.

Downloads

582

Readme

miaoda-game-mode-core

Use this engine-independent runner when several timed gameplay modes, buffs, challenges, or world events may run at once. Modes can be independent or mutually exclusive within a named priority group.

Install

pnpm add miaoda-game-mode-core

Define and run modes

import { ModeRunner } from 'miaoda-game-mode-core';

type Context = { scoreMultiplier: number };
const context: Context = { scoreMultiplier: 1 };
const modes = new ModeRunner<Context>([
  {
    id: 'double-score',
    duration: 20,
    onStart: (game) => { game.scoreMultiplier = 2; },
    onStop: (game) => { game.scoreMultiplier = 1; },
  },
  { id: 'boss', group: 'main', priority: 1, duration: 60 },
  { id: 'final-boss', group: 'main', priority: 10, duration: 90 },
]);

modes.start('double-score', context);
modes.tick(context, 1 / 60); // dt is seconds

canStart can reject a start based on context. onStart, onUpdate, and onStop receive the same caller-owned context. A mode without duration ends only when you call complete, fail, or cancel.

Lifecycle and groups

Statuses are idle, running, paused, completed, and failed. pause freezes elapsed time but still occupies its group; resume continues it. cancel returns to idle, while completion/failure leave the status visible and begin the configured cooldown.

Within one group, a running or paused mode blocks lower-priority starts. A new mode with equal or higher priority cancels the blockers before starting. Modes without a group can run in parallel.

All duration, cooldown, and tick(dt) values use seconds. Call tick from one authoritative game clock; this runner does not read wall-clock time.

Observing and Reacting

const off = modes.onChange((event) => {
  if (event.type === 'completed') showReward(event.mode.id);
});
const active = modes.active();
const all = modes.list();
off();

Snapshots are detached data containing status, elapsed seconds, remaining duration, and cooldown remaining. They are suitable for HUDs and persistence. The runner has no restore method; persist and rebuild any context-specific state with your own save protocol.

Public API

ModeRunner, ModeDefinition, ModeSnapshot, ModeEvent, ModeStatus, and ModeListener are exported. The core does not own rendering, input, a clock, or the effects applied by a mode.