GitHubGet started
More

Level progression

pkg/progression defines a versioned level pack with unique IDs, one-to-three star targets, and star thresholds for unlocking levels. Its parser refuses unknown fields and invalid thresholds, and Encode produces deterministic YAML. The rules are pure data operations, so a game can persist earned stars separately and use the same checks in a level-select UI and a headless test.

The level-pack file

version: 1
levels:
  - id: meadow-1
    stars: 3
  - id: meadow-2
    stars: 3
    unlockAt: 2

stars is how many stars a level can award, from 1 to 3, and unlockAt the total stars a player needs before the level opens, 0 when it is missing. progression.Parse refuses unknown fields, a second YAML document, a version other than 1, an empty pack, an empty, padded or repeated id, and out-of-range numbers, with a *loaderr.Error naming the field, such as levels[1].id. Pack.Unlocked(id, stars) reports whether a player with stars stars in total may play the level.

Edit this page