// Package slots defines the sixteen code slots each player has. Slots 1-3 hold // the built-in example programs and are read-only; slots 4-16 belong to the // player, who saves source code in them and picks one when launching a ship. package slots import ( "io/fs" "strings" "halcyon/examples" ) const Count = 16 // builtin lists the example programs, in slot order (slot 1 is the first). var builtin = []string{"echo", "telemetry", "pursue"} // FirstUser is the first slot a player can write to. var FirstUser = len(builtin) + 1 type Slot struct { Number int Name string Source string Builtin bool } // Valid reports whether n is one of the sixteen slots. func Valid(n int) bool { return n >= 1 && n <= Count } // Builtin returns the example that occupies slot n, if it is one of the first three. func Builtin(n int) (Slot, bool) { if n < 1 || n > len(builtin) { return Slot{}, false } src, err := fs.ReadFile(examples.FS, builtin[n-1]+".s") if err != nil { return Slot{}, false } return Slot{Number: n, Name: strings.ToUpper(builtin[n-1]), Source: string(src), Builtin: true}, true }