Documentation
¶
Overview ¶
Package cast is where a character is authored: who it is, which work it was borrowed from, the preset it was tuned from, and the evolution line its stats grow along.
A character is a **definition** and a roster entry is a **placement**. The two are deliberately separate types in separate packages: the same character may stand in a dozen encounters at a dozen levels, and the engine only ever receives the flat stat line that falls out of resolving one at a level. That is why nothing below this package knows a character exists — battle.Roster gains no image, no biography and no origin, because the rules have no use for them.
Everything a character names is checked against the book that declares it, the same way skill.ParseBook checks the shapes and statuses a skill names: a character pointing at a skill, an origin or an archetype that does not exist fails at load rather than at the moment it would have mattered.
Like every other core package except battle, this one is a pure function of its arguments and never touches the filesystem. That has one visible consequence worth knowing about: ValidateImagePath checks the *shape* of an authored image path and nothing more. Whether the file is really there is cmd/hexforge's business, because only the caller knows what the path is relative to.
Index ¶
- Constants
- func ChooseFrom(subject, kind string, chosen, available []string, slots, level int, ...) ([]string, error)
- func ChooseLoadout(subject string, skills, passives []string, character Character, level int, ...) ([]string, []string, error)
- func HeldIDs(entries []Unlock, stage string) []string
- func LearnedIDs(entries []Unlock) []string
- func MediumNames() []string
- func UnlockedIDs(entries []Unlock, level int, stage string) []string
- func ValidateID(id string) error
- func ValidateImagePath(image string) error
- type Archetype
- type ArchetypeBook
- type ArchetypeDeps
- type ArtEntry
- type Book
- type Build
- type BuildBook
- type Character
- func (c Character) Art() []ArtEntry
- func (c Character) ElementAt(stage progression.Stage) element.Affinity
- func (c Character) FurthestAt(level int) ([]progression.Stage, error)
- func (c Character) PassivesAt(level int, stage string) []string
- func (c Character) Resolve(level int, stage string) (progression.Values, progression.Stage, error)
- func (c Character) SkillsAt(level int, stage string) []string
- func (c Character) StageArt(stage progression.Stage) string
- func (c Character) StagesAt(level int) ([]progression.Stage, error)
- type Deps
- type Medium
- type Origin
- type OriginBook
- type Species
- type SpeciesBook
- type Unlock
Constants ¶
const ( SkillSlots = 4 TraitSlots = 1 )
SkillSlots and TraitSlots are how much a placement may bring of what a character knows.
Four and one. They sit beside the learnset rather than beside the engine because they are a rule about learning: battle.Roster keeps taking a resolved kit exactly as it keeps taking a resolved stat line, and which four of the nine are brought is settled before a battle the way an evolution already is. They sit here rather than in internal/seed because two callers now read them — the roster that fields a placement and the spar that measures one — and a second copy of "four" is how a measurement quietly stops measuring what gets fielded.
Four is a per-turn nerf whose size is set by cooldowns: a skill on cooldown N contributes 1/(N+1) actions per turn, so a level-one unit holding a cooldown-1 and a cooldown-4 skill idles about a third of its turns. That is what being young should feel like, and it is also why a low-cooldown basic is close to mandatory in a four-slot world.
const ( Required = true Optional = false )
The two halves of a loadout differ in whether they may be left empty, and the reason is not symmetry but what the empty list means. A unit that brings no skills cannot act, so an empty kit is never something anybody chose; a unit that brings no trait is an ordinary unit, so an empty trait slot is a decision like any other. Insisting on one would make "I want the plain version" unwritable.
They are named rather than passed as a bare boolean so the call site says which rule it is asking for.
const MediumCount = int(Novel) + 1
MediumCount is the number of declared media.
Variables ¶
This section is empty.
Functions ¶
func ChooseFrom ¶
func ChooseFrom(subject, kind string, chosen, available []string, slots, level int, insist bool) ([]string, error)
ChooseFrom picks one half of a loadout out of what is available, or says why it cannot.
A character that has nothing of this sort at this level brings none of it, and that is not the same as leaving the choice out: naming one it does not have is still refused, because asking for something that does not exist is a typo whichever list it is in.
func ChooseLoadout ¶
func ChooseLoadout(subject string, skills, passives []string, character Character, level int, form string) ([]string, []string, error)
ChooseLoadout is the choice made about a character: which of the skills it knows it brings, and which trait.
It is **required**, not defaulted. A default would be a file quietly choosing four of nine on somebody's behalf and never saying which — and the whole point of a slot is that a person decided. The refusal names what was available, because whoever has just been told "no" wants the list rather than a second trip to the cast file.
Both halves obey one rule read from one place: what is available to this level *as this form*. Skills and traits are one mechanism, and the only thing that differs between them here is the number of slots and whether empty is legal.
⚠️ **This used to exist twice and was about to exist three times.** The seed roster had it as `chooseFrom` and `resolveBuild` had it as `chosenFor`, both unexported, both saying the same thing in slightly different words — and a squad builder needed it again. Three answers to "may this unit bring that skill" is two too many, and the one that disagreed would have been whichever the author was not looking at. The subject is a worded noun phrase rather than an id so each caller still says what it is talking about: a placement is a unit, a build is a build.
func HeldIDs ¶ added in v0.2.0
HeldIDs is LearnedIDs narrowed to one form: every id the named form may hold, at any level, in declaration order.
It is the question "what could this form ever carry", which is a third one beside LearnedIDs' "what does this character ever know" and UnlockedIDs' "what does it have now" — and it is the one a check about a *restriction* wants once a form can have an affinity of its own, because a restriction is a property of the skill and the affinity is a property of the form. Exported so that internal/forge can ask it rather than spelling the stage gate a second time.
func LearnedIDs ¶
LearnedIDs is every id in a learnset regardless of level, in declaration order.
It answers "what does this character ever know", which is a different question from SkillsAt's "what does it know now" — and the one every check about a *restriction* wants, because a restriction is a property of the skill rather than of when it is learned.
func MediumNames ¶
func MediumNames() []string
MediumNames returns every medium's name in declaration order, which is what a usage message wants.
func UnlockedIDs ¶
UnlockedIDs is the ids a unit of this level, fielded as this form, has — in declaration order.
One function rather than one per list, and it takes the list rather than reading a character, so the kit and the traits share it. Declaration order because the result reaches a roster entry and then an event log: an order a map decided would stop a battle replaying.
func ValidateID ¶
ValidateID checks the shape of a character id. One dot is allowed, which is how an id says which work it came from without two works being forced to invent unique names.
It is exported for the same reason ValidateImagePath is: an authoring tool has to be able to reject an answer as it is typed, rather than at the end of a wizard nobody wants to fill in twice. ParseBook applies exactly this check.
func ValidateImagePath ¶
ValidateImagePath checks the shape of an authored image path. Whether the file exists is the tool's business, not the parser's: internal/core may not read the filesystem, and only the caller knows which directory the path is relative to.
The checks use path rather than filepath on purpose. A data file is committed, so the same string has to mean the same thing on every platform, and filepath's behaviour depends on the one it is compiled for.
Types ¶
type Archetype ¶
type Archetype struct {
ID string `json:"id"`
// Role is one line saying what the preset is for. It is what an authoring
// tool shows next to the id.
Role string `json:"role"`
// Column is the formation column the role belongs in, counted from the
// front of its own side.
Column int `json:"column"`
// Stats is the suggested curve for every stat. A preset that does not
// itself fit the budget is a bug, not a stretch goal: it would hand every
// author a stat line that fails later.
Stats progression.Table `json:"stats"`
// Skills is the suggested kit.
Skills []string `json:"skills"`
// Passives is the suggested traits, and it is where an archetype finally
// gains a mechanical weight: until now a preset never reached the engine and
// nothing branched on one, so it was a curve and a kit under a name. A
// passive it suggests does reach the engine, through whatever character takes
// the suggestion — the preset itself still does not, which keeps
// battle.Roster free of an archetype exactly as before.
Passives []Unlock `json:"passives,omitempty"`
// Demands is the distinct non-neutral elements the kit requires, derived
// from Skills at parse time by skill.Demands.
//
// It is never read from the JSON, which is the whole point: an authored
// hint would be free to drift from the kit it claimed to describe, and the
// drift would only surface when a character built from the preset was
// refused by battle.New. A character must carry every element in this set,
// so a preset demanding two can be carried by exactly one affinity and a
// preset demanding three cannot be carried at all.
Demands []element.Element `json:"-"`
}
Archetype is the preset a character of a given role starts from: the shape of the stat curve and the kit that goes with it, before any tuning.
A preset is a starting point and not a constraint. A character records which archetype it came from and is then free to differ, which is what keeps two characters of the same role from being the same unit with two names.
func (Archetype) DemandNames ¶
DemandNames is the demanded elements written out, which is what a prompt and a listing want.
type ArchetypeBook ¶
type ArchetypeBook struct {
// contains filtered or unexported fields
}
ArchetypeBook is the declared presets.
func ParseArchetypes ¶
func ParseArchetypes(raw []byte, deps ArchetypeDeps) (*ArchetypeBook, error)
ParseArchetypes reads the presets and checks every name and number each one uses. It never touches the filesystem.
func (*ArchetypeBook) All ¶
func (b *ArchetypeBook) All() []Archetype
All returns every preset in declaration order.
func (*ArchetypeBook) Get ¶
func (b *ArchetypeBook) Get(id string) (Archetype, bool)
Get returns a preset by id.
func (*ArchetypeBook) IDs ¶
func (b *ArchetypeBook) IDs() []string
IDs returns every preset's id in declaration order, which is what a usage message and a prompt want.
type ArchetypeDeps ¶
type ArchetypeDeps struct {
Skills *skill.Book
// Passives is the book a suggested trait is checked against. It is optional
// only in the sense that a preset suggesting none never reaches it; a preset
// that names one without it is refused rather than accepted unchecked.
Passives *passive.Book
Limits progression.Limits
Rules combat.Rules
}
ArchetypeDeps are what a preset's declarations are checked against.
type ArtEntry ¶
type ArtEntry struct {
// Stage is the form's name, empty for the character's own picture.
Stage string
Image string
}
ArtEntry is one picture a character can show, and which form it belongs to.
type Book ¶
type Book struct {
// contains filtered or unexported fields
}
Book is the authored cast.
func ParseBook ¶
ParseBook reads a cast declaration and checks every name it uses. It never touches the filesystem.
An empty cast is allowed: a project that has not authored anyone yet is a starting point, not a data error. That is the one place this differs from skill.ParseBook, which rejects an empty book because a game with no skills cannot run.
func (*Book) Append ¶
Append returns a new book holding the existing characters plus the extra ones, validated exactly as a parse would validate them.
It works by marshalling and re-parsing rather than by re-implementing the checks, which is what guarantees the bytes an authoring tool is about to write are bytes that load.
func (*Book) Marshal ¶
Marshal writes the book as a data file: two-space indented JSON with the characters sorted by id.
This is the one place in the package that imposes an order instead of preserving the authored one, and it is deliberate. An authoring tool that adds a character rewrites the whole file, and a stable order is what makes that rewrite a one-line diff rather than a reshuffle nobody can review.
func (*Book) OfOrigin ¶
OfOrigin returns every character borrowed from one work, in declaration order.
func (*Book) OfSpecies ¶
OfSpecies returns every character that is one kind of creature, in declaration order.
A character may be several things at once, so the same character is returned by more than one call, which is the difference from OfOrigin: a work is a partition of the cast and a species is not.
type Build ¶
type Build struct {
// ID is the build's own identity, and is what a placement or a screen refers
// to. Prefixed by the character it belongs to by convention, so a listing
// sorted by id groups a character's directions together.
ID string
// Character names an entry in the cast book. A build without one would be a
// kit belonging to nobody.
Character string
// Name is what the build is called, in the language the data is authored in.
Name string
// Intent is one clause on why this direction exists. It is the only authored
// prose about a build, and it must stay intent: the skills describe
// themselves, and a number here would be a promise this type cannot keep.
Intent string
// Stage is the form this direction is built for, and it is only ever needed
// on a line that **forks**: absent means the furthest the cap reaches, which
// is what every build meant before any line had two arms.
//
// It is the same word a placement and a roster entry already use, and
// deliberately so — "which form" is one question and a second vocabulary for
// it is how two files come to disagree. On a forking line the absent answer
// is a refusal rather than a pick, because a kit carried by one arm and not
// the other is a different build.
Stage string
// Skills and Passives are the loadout, and they *choose* rather than list —
// each entry has to be something the character has learned by the cap, as
// the form the cap reaches.
Skills []string
Passives []string
}
Build is one named way to field a character at the level cap: which four of the skills its final form knows, and which of its traits fills the single trait slot.
It exists because the slots alone do not say what a character is *for*. A learnset of nine skills and five traits offers more combinations than anybody would field, and until a build was written down the only kit the repository could name was "the first four declared" — which is the order the file happens to list, not a decision. A build is that decision, authored.
It carries no numbers of its own and cannot: everything a build does is already described by the skills and the trait it names, and a second place saying how hard it hits would be a second place to drift. Name and Intent are the whole of what a build adds, and Intent says why an author would field it rather than what it computes.
type BuildBook ¶
type BuildBook struct {
// contains filtered or unexported fields
}
BuildBook is every authored build, indexed the two ways they are read: by the build's own id, and by the character whose directions they are.
func ParseBuilds ¶
ParseBuilds reads a build catalogue and checks every entry against the cast book, which is the only thing that can say whether a kit is fieldable.
It takes bytes rather than a path for the reason every other parser here does: the caller owns the file access, and a test hands it a fixture.
A build is validated at the level cap and at the form that cap reaches, because that is what a build *is* — the late-game shape of a character. A kit for an earlier form is a placement's business (see the roster), not a catalogue's: a half-grown unit fields what it has, and there is no decision to record.
func (*BuildBook) Of ¶
Of is one character's builds, in declaration order, and is empty for a character nobody has written a direction for yet.
Empty is a fact rather than a failure: a character whose learnset has one obvious kit has nothing to choose between, and a catalogue inventing a second direction for it would be saying something untrue.
type Character ¶
type Character struct {
// ID is the character's slug. It may carry one '.' separating the origin
// from the name, which is what keeps two works free to use the same name.
ID string `json:"id"`
Name string `json:"name"`
// Origin and Archetype are ids in their own books. The archetype is
// recorded rather than consumed: the numbers below are already tuned, and
// keeping the preset's name is what lets a tool say what a character was
// built from and what it drifted away from.
Origin string `json:"origin"`
Archetype string `json:"archetype"`
// Image is a relative path to the character's art. Its shape is validated
// here; its existence is not. See ValidateImagePath.
Image string `json:"image"`
Element element.Affinity `json:"element"`
Bio string `json:"bio,omitempty"`
// Hidden holds the character back from the lists an authoring tool offers to
// build a side out of. Absent means offered, which is the ordinary case, so
// the flag reaches the file only where it is set.
//
// It was an authoring convenience rather than a design statement: a hidden
// character still ships, still loads, still fights, and a squad or a roster
// naming one is as valid as any other. Nothing in this package or in the
// engine reads it — who an author is currently choosing between is not a
// fact a replay has any use for — and honouring it is a caller's job.
//
// ⚠️ It has a **second reader** now and that reader makes it a design
// statement: internal/draft.NewPool gates the ban-and-pick pool on it, so a
// held-back character cannot be banned, picked or fielded in a drafted match
// at all. The half above that still holds is the half about the engine.
// ⚠️ And it is still not "filter Hidden everywhere" — see
// internal/screen/picker.go's CharacterOptions, which offers a held-back
// character on purpose.
Hidden bool `json:"hidden,omitempty"`
// Species is what the character is, each by id in the species book. Absent
// is the ordinary case and it is a real answer rather than a gap: most
// characters need no lineage, and a skill that asks for one refuses a unit
// that is nothing in particular.
//
// A list because a unit may be several things at once, and because the
// alternative — one species per character — would force a choice between two
// true statements the moment a skill was written about either.
Species []string `json:"species,omitempty"`
// Stages is the evolution line the character's stats grow along. A
// character with one stage is the ordinary case, not a special one.
Stages progression.Line `json:"stages"`
// Skills is the character's learnset: every skill it will ever know, each
// from the level it learns it at.
//
// It is `Unlock`, the type the traits already use, because the two are one
// question — declare many, unlock by progression, bring some — and a second
// type beside it would be two vocabularies for one idea. What a unit
// actually brings into a battle is a *choice made at placement* from the
// entries unlocked at its level, which is a different list and lives on the
// roster rather than here.
Skills []Unlock `json:"skills"`
// Passives are the traits the character holds for the whole of every battle,
// each by id in the passive book and from the level it unlocks at. Absent is
// the ordinary case.
//
// Unlike an archetype, these do reach the engine: battle.Roster carries them
// because a passive is in force *during* a battle, where an archetype and an
// evolution stage are both settled before one starts. That is the line the
// roster's deliberate emptiness is drawn on — not "as little as possible",
// but "nothing a replay does not read".
Passives []Unlock `json:"passives,omitempty"`
}
Character is one authored combatant.
func (Character) Art ¶
Art is every distinct picture the character can show: its own first, then one per stage that names a different one.
A checker wants this rather than the single Image, because art that only a grown form uses is exactly the art nobody looks at until the character has grown — so a missing file there is the one that surfaces late. Distinct by path and in declaration order, so a stage sharing the character's picture adds no row and the result never depends on map order.
func (Character) ElementAt ¶ added in v0.2.0
func (c Character) ElementAt(stage progression.Stage) element.Affinity
ElementAt is the affinity one of the character's forms fights with: the stage's own when it declares one, and the character's when it does not.
This is the only place that fallback is decided, for StageArt's reason and with a sharper edge: a caller reading progression.Stage.Element directly gets a nil pointer for every ordinary stage, and a caller that dereferenced it without checking would panic on the common case rather than on the rare one. A second caller inventing the fallback again is how one character comes to have two elements depending on which screen is asking.
⚠️ **It is a fielding-time answer and nothing downstream keeps it.** What a battle receives is a resolved battle.Roster.Affinity, settled before the first turn exactly as the stat line is, so no unit's element can change during a fight and no replay reads a stage. The three producers that turn a character into a roster entry — placement.Placement.resolve, seed.resolveReference and forge.Library.duellist — are the whole of what has to call this.
func (Character) FurthestAt ¶
func (c Character) FurthestAt(level int) ([]progression.Stage, error)
FurthestAt is the grown end of each of the character's lines: one form on a line that does not fork, and one per arm on a line that does.
It exists for the callers that have to say something about "the character at the cap" and cannot pass progression.Furthest to do it, because a fork has no single furthest. A budget row is the example: the stat budget bites at the end of a line, and a forking character has two ends that are priced separately.
func (Character) PassivesAt ¶
PassivesAt is the traits the character holds at a level.
It is separate from Resolve rather than a fourth return value: a stat line and a stage answer "what is this unit", while this answers "what does it bring", and the second is the question a placement asks. Keeping them apart is also what lets the kit join it later without Resolve growing a fifth return.
func (Character) Resolve ¶
func (c Character) Resolve(level int, stage string) (progression.Values, progression.Stage, error)
Resolve flattens the character at a level, as a chosen stage, into the stat line the battle engine works with, and reports which stage it fielded.
progression.Furthest is what a caller passes when nobody is choosing — a screen showing this character at level 30 has no placement behind it — and it is the behaviour every caller had before a stage could be chosen at all.
func (Character) SkillsAt ¶
SkillsAt is the skills the character has learned by a level, in declaration order. It is the list a placement may choose its loadout from, and the same function the traits use — one "what is available at level N" for both lists, which is the whole of "skills and traits are one mechanism".
func (Character) StageArt ¶
func (c Character) StageArt(stage progression.Stage) string
StageArt is the picture of one of the character's forms: the stage's own art when it declares any, and the character's when it does not.
This is the only place the fallback is decided. A caller reading progression.Stage.Image directly would draw nothing for the ordinary stage that names none, and a second caller would invent the same fallback slightly differently — which is how a character ends up with two pictures depending on which screen is asking.
type Deps ¶
type Deps struct {
Origins *OriginBook
Archetypes *ArchetypeBook
Skills *skill.Book
// Passives is the book a character's traits are checked against, and it is
// wanted only by a character that names one — see resolvePassives.
Passives *passive.Book
// Species is the book a character's kinds are checked against, on the same
// terms as Passives: wanted only by a character that claims one, or by one
// carrying a skill that asks for one.
Species *SpeciesBook
Chart *element.Chart
Limits progression.Limits
Rules combat.Rules
}
Deps are the books a character's declarations are checked against, plus the budget its stats have to fit inside.
type Medium ¶
type Medium uint8
Medium is the kind of work a character was borrowed from.
func ParseMedium ¶
ParseMedium resolves a medium name as written in the data files.
func (Medium) MarshalJSON ¶
MarshalJSON writes the medium by name. Names are the wire format for every enum in this engine, for the same reason event kinds are: inserting a constant must not silently reinterpret a file that was already written.
func (*Medium) UnmarshalJSON ¶
UnmarshalJSON reads a medium by name.
type Origin ¶
type Origin struct {
ID string `json:"id"`
Title string `json:"title"`
Medium Medium `json:"medium"`
// Year is optional. Zero means it was not recorded.
Year int `json:"year"`
Note string `json:"note,omitempty"`
}
Origin is a work a character was borrowed from.
type OriginBook ¶
type OriginBook struct {
// contains filtered or unexported fields
}
OriginBook is the catalog of works the cast is drawn from.
func ParseOrigins ¶
func ParseOrigins(raw []byte) (*OriginBook, error)
ParseOrigins reads an origin catalog. It never touches the filesystem.
An empty catalog is allowed, because a project that has not borrowed from anything yet is a starting point rather than a data error.
func (*OriginBook) All ¶
func (b *OriginBook) All() []Origin
All returns every origin in declaration order. It never ranges over the lookup map, because Go randomises that and the order reaches an output.
func (*OriginBook) Append ¶
func (b *OriginBook) Append(extra ...Origin) (*OriginBook, error)
Append returns a new catalog holding the existing origins plus the extra ones, validated exactly as a parse would validate them.
func (*OriginBook) Get ¶
func (b *OriginBook) Get(id string) (Origin, bool)
Get returns an origin by id.
func (*OriginBook) IDs ¶
func (b *OriginBook) IDs() []string
IDs returns every origin id in declaration order, on SpeciesBook.IDs's terms: a picker and a refusal both want the alternatives, and both want them in the order the file was written rather than sorted a second way.
func (*OriginBook) Marshal ¶
func (b *OriginBook) Marshal() ([]byte, error)
Marshal writes the catalog as a data file: two-space indented JSON with the origins sorted by id, for the same reason Book.Marshal sorts.
type Species ¶
type Species struct {
ID string `json:"id"`
// Name is the word shown beside the id. It is required, which is the one
// place this differs from a passive's optional name: a species has no
// numbers beside it on a screen, so an id with no name is the whole of what
// a reader gets.
Name string `json:"name"`
// Note is optional prose about where the line is drawn — which is worth
// having, because "is a dragon" is a judgement about fiction rather than a
// fact about a stat line.
Note string `json:"note,omitempty"`
}
Species is what a unit *is*, as against what it is made of and how it fights.
An element answers the first of those and an archetype the second, and neither says whether a creature has a shell, roots or a lineage — so a skill named after a body was free to land on a body it did not fit. This is the missing axis, and it is deliberately the thinnest one: a species carries an id, a word for a screen and an optional note, and nothing else. No stats, no kit, no rule of its own.
Why it never reaches the engine ¶
Nothing in battle branches on a species, exactly as nothing branches on an archetype. A species is a **carry rule** — it decides who may hold a skill, which is settled while a character is authored — plus a word a browser prints. Pushing it into battle.Roster would put a fact into the replayable core that no replay reads. See CLAUDE.md, "What a restriction can enforce".
type SpeciesBook ¶
type SpeciesBook struct {
// contains filtered or unexported fields
}
SpeciesBook is the declared kinds of creature.
func ParseSpecies ¶
func ParseSpecies(raw []byte) (*SpeciesBook, error)
ParseSpecies reads a species catalog. It never touches the filesystem.
An empty catalog is allowed, for the same reason an empty origin catalog is: a project where nothing has needed the axis yet is a starting point rather than a data error, and every character's species list is optional.
func (*SpeciesBook) All ¶
func (b *SpeciesBook) All() []Species
All returns every species in declaration order. It never ranges over the lookup map, because Go randomises that and the order reaches an output.
func (*SpeciesBook) Append ¶
func (b *SpeciesBook) Append(extra ...Species) (*SpeciesBook, error)
Append returns a new catalog holding the existing species plus the extra ones, validated exactly as a parse would validate them.
func (*SpeciesBook) Get ¶
func (b *SpeciesBook) Get(id string) (Species, bool)
Get returns a species by id.
func (*SpeciesBook) IDs ¶
func (b *SpeciesBook) IDs() []string
IDs returns every species id in declaration order, which is what a refusal listing the alternatives wants.
func (*SpeciesBook) Marshal ¶
func (b *SpeciesBook) Marshal() ([]byte, error)
Marshal writes the catalog as a data file: two-space indented JSON sorted by id, for the same reason every other book sorts.
type Unlock ¶
type Unlock struct {
ID string `json:"id"`
// AtLevel is the first level the holder has it at. An unstated level is one:
// the common case is a trait a character has always had, and writing
// "at_level": 1 on every entry would be noise on the line that matters least.
AtLevel int `json:"at_level,omitempty"`
// Stages are the forms that may hold it, by stage name. Empty is every form,
// which is the ordinary case and the one that writes nothing.
Stages []string `json:"stages,omitempty"`
}
Unlock is something a character has from a level onwards.
It is the shape a *learnset* is written in, and it is deliberately about an id rather than about a trait: the kit is the same question — declare many, unlock by progression, bring some — so when skills gain their levels they gain this type rather than a second one beside it. Two vocabularies for one idea is the mistake this repository keeps a list of.
Two gates, and why the second one is a list ¶
A level gate says *when*; a stage gate says *which form*. They were one fact until a placement could choose its stage, because the stage was derived from the level — `at_stage: "Ivysaur"` was exactly `at_level: 16` and nothing else. A placement now names the form it fielded, so the two are different questions and both can be asked.
The stage gate is an **allowlist** rather than a threshold, and that is the whole reason evolving is a decision rather than a formality. A threshold could only ever say "from this form onwards", so everything an early form knew a grown one knew too, and choosing not to evolve would be choosing a weaker unit for nothing. A list can say "Bulbasaur only" — something the grown form never gets — which is what gives up an evolution in exchange for keeping a move.
It is the same shape `skill.Restriction` uses for elements and archetypes, for the same reason: an allowlist can name one member of a class, and a threshold cannot.
func Learn ¶
Learn turns a plain list of ids into learnset entries every one of which is known from level one.
It is what a preset's kit becomes when a character is built from it: an archetype has no level to gate against, so the suggestion it carries is "knows all of this", and somebody editing cast.json afterwards is who decides otherwise. Exported because the authoring tool is the caller and a second copy of this loop there would be the place the two spellings drift.
func (Unlock) Available ¶
Available reports whether a unit of this level, fielded as this form, has it. Both gates, asked together, because a caller that asked only one would be wrong in whichever direction it forgot.
func (Unlock) Held ¶
Held reports whether the named form may hold it.
An empty allowlist is every form. The form is matched by name because that is what a placement chooses by and what the data spells — a stage has no id of its own, and inventing one would be a second name for the thing already named.
func (Unlock) MarshalJSON ¶
MarshalJSON writes the entry as the declaration a parse would read back, and omits a gate of one.
The field cannot simply carry `omitempty`, because a parse *normalises* an unstated level to one: there is exactly one value in memory meaning "from the start", which is what lets every caller ask Unlocked without first asking which of two spellings it is holding. The cost of that is this method — the writer has to know that one is the value not worth writing.
func (Unlock) Unlocked ¶
Unlocked reports whether the entry's *level* gate is passed.
It answers half the question and is kept because half is what several callers want: an authoring screen printing "endurance@16" is describing the entry rather than a placement, and it has no form in front of it to ask about.