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-turn-core

v0.3.0

Published

Engine-agnostic turn rules with explicit models for ordered actors, faction phases, seat-based players, and simultaneous submission barriers. No rendering or engine dependency.

Readme

miaoda-game-turn-core

Use this package when gameplay advances by explicit turns or rounds rather than frame time. It provides four engine-independent models for tactics, card games, board games, and simultaneous planning.

Install

pnpm add miaoda-game-turn-core

Pick a model

| Model | Use it when | | --- | --- | | TurnEngine | One actor acts at a time, optionally with initiative and action points | | PhaseTurnEngine | Faction phases contain a selectable set of ready actors | | PlayerTurnEngine | Turns move around stable player seats with skip, reverse, extra turn, or eligibility | | SimultaneousRoundEngine | Everyone submits privately, then the game resolves one joint round |

Only TurnEngine uses an actor order. Do not force a card-game seat loop or a simultaneous barrier into that model.

Actor turns and action points

import { TurnEngine } from 'miaoda-game-turn-core';

const turns = new TurnEngine({
  actors: [
    { id: 'hero', initiative: 12, actionPoints: 2 },
    { id: 'goblin', initiative: 8 },
  ],
  order: 'initiative',
  defaultActionPoints: 1,
  seed: 42,
});

turns.onChange((state, events) => renderTurnHud(state, events));
turns.start();

if (turns.spend(1)) commitMove(turns.activeId);
turns.endTurn();

Turns advance only when your game calls start, endTurn, or another explicit operation. spend never ends a turn automatically. Initiative ties preserve insertion order; random order uses the supplied deterministic seed.

Core operations

| Operation | Purpose | | --- | --- | | start / stop | Start or pause the engine while retaining its roster | | endTurn | Advance to the next actor or round | | canAfford / spend / grant | Inspect and change active action points | | add / updateActor / remove | Manage roster membership and future budgets | | state | Read the current actor, AP, round, cursor, and order | | onChange | Observe state plus ordered lifecycle facts | | snapshot / loadSnapshot | Save and restore exact turn state and RNG progress |

Invalid IDs, negative AP, non-finite initiatives, and malformed snapshots throw rather than silently corrupting the turn ledger. Listeners observe events; the engine does not run AI, animations, or game rules inside them.

Other models

import { PhaseTurnEngine, PlayerTurnEngine, SimultaneousRoundEngine } from 'miaoda-game-turn-core';

const phases = new PhaseTurnEngine({
  phases: [{ id: 'player' }, { id: 'enemy' }],
  actors: [{ id: 'hero', phaseId: 'player' }, { id: 'goblin', phaseId: 'enemy' }],
}).start();
phases.select('hero');
phases.finishActor();

const seats = new PlayerTurnEngine({ players: [{ id: 'north' }, { id: 'east' }] }).start();
seats.skipNext();
seats.reverse();
seats.repeatTurn();

const round = new SimultaneousRoundEngine({ participants: [{ id: 'a' }, { id: 'b' }] }).start();
round.markSubmitted('a');
round.markSubmitted('b');
// Your rules resolve the joint submissions, then call the next round operation.

PhaseTurnEngine skips empty phases and allows one ready actor selection at a time. PlayerTurnEngine keeps seat direction, dealer/button, eligibility, and explicit hand-off separate. SimultaneousRoundEngine is a submission barrier; it does not invent how submitted choices resolve.

Persistence and ownership

Snapshots are versioned, detached data and include enough cursor, roster, eligibility, and RNG state to reproduce future ordering. Restore with compatible static configuration and validate failures before changing live state.

The package owns turn sequencing and lifecycle facts. Your game owns legal actions, ability costs beyond AP, card/board rules, AI decisions, animation, networking, and persistence storage.