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

@patterkit/play-helpers

v0.1.2

Published

Thin game-integration helpers around @patterkit/runtime: save/load serialisation, runtime property setters, a state logger, the Patterpad Live Link client + hot reload, a property inspector, and audio resolution. The Patterplay JS companion.

Downloads

85

Readme

@patterkit/play-helpers

Thin game-integration helpers around @patterkit/runtime's Engine - the Patterplay JS companion. None are required to play a bundle; they smooth the host wiring most games end up writing anyway.

npm install @patterkit/play-helpers

Save / load

Wrap the engine's whole-game snapshot in a tagged, versioned envelope - drop it into localStorage or a file, and a foreign blob throws instead of corrupting a run.

import { serializeState, deserializeState } from "@patterkit/play-helpers";

localStorage.setItem("slot1", serializeState(engine));
deserializeState(engine, localStorage.getItem("slot1")!);   // throws on a non-patter blob

saveState / loadState are the object-level variants (no JSON string).

Runtime properties

Read / write @patter globals, @scene props, or a wired foreign scope at runtime - e.g. the game pushing inventory into the dialogue.

import { setProperty, setProperties, getProperty } from "@patterkit/play-helpers";

setProperties(engine, { "@hp": 10, "@scene.locked": false });
getProperty(engine, "@hp");   // 10

(Localisation needs no helper: an Embedded bundle carries its strings - construct with { locale } or switch live via engine.setLocale(); an IDs-only bundle emits beat IDs your game localises itself, re-interpolated with flow.interpolate(). See the Localisation guide.)

State logger

A debug companion that watches the mutable runtime state (@patter / @scene / visit counts, shared + per-flow) and reports what changed between captures. logStep traces each played step, including its gameData (the host-event channel).

import { createStateLogger } from "@patterkit/play-helpers";

const log = createStateLogger(engine, { label: "main" });
const step = flow.advance();
log.logStep(step);   // [main] line WATCHMAN: "..." gameData={...}
log.capture();       // [main] @patter.bell_tolls: 0 -> 1

snapshotState(engine) / diffState(a, b) are the underlying pure functions.

Live Link (Patterpad debug + hot reload)

createDebugLink streams the running story's cursor to Patterpad over a localhost WebSocket, so the editor follows the game like a debugger - and receives live bundle pushes back when the author edits, for hot reload without restarting:

import { createDebugLink, applyLiveBundle } from "@patterkit/play-helpers";

let engine = new Engine(bundle);
const link = createDebugLink({
  build: bundle.content.hash,
  onBundle: (msg) => {
    ({ engine, bundle } = applyLiveBundle(engine, bundle, msg.data));
    link.setBuild(msg.build);   // re-hello under the new build id
    rerender();
  },
});
link.flowOpened("main");
// after each step: link.observe(flowId, sceneId, beatId, step.type)

applyLiveBundle picks the cheapest tier itself: same structureHash -> in-place replaceStrings (kind: "text", nothing lost); structural change -> hotSwap to a fresh engine restored from the old one (kind: "structure"). Wire it behind a dev flag - it is a development tool, not a shipping feature.

Property inspector

createPropertyInspector(engine) builds a small DOM panel of the engine's @patter properties with type-aware editors (toggle / number / text / enum / flags) and reset-to-default - the JS equivalent of the Unity / Unreal / Godot runtime-state panels. refresh() re-reads values; destroy() unhooks; pollMs auto-refreshes.

Audio resolution

createAudioResolver(manifestJson, basePath) reads a patteraudio.json manifest (the sidecar Patterpad's Build writes next to the audio root) and resolves a beat to its winning take:

import { createAudioResolver } from "@patterkit/play-helpers";

const audio = createAudioResolver(await (await fetch("audio/patteraudio.json")).text(), "audio");
const src = audio.resolve(step.id);   // "audio/scratch/beat42.wav" | null

It resolves; you play (an <audio> element, your engine's mixer, anything).