Documentation
¶
Overview ¶
Package arcade is the Concord Arcade standard for game plugins: a character-cell canvas with half-block pixels, the shaded pixel-font logo, seven-segment digits, colour roles taken from each viewer's Concord theme, the pass-and-draft reward system (Pit Passes, Gold Stars: each game names its own) and a generated chiptune sound kit.
Screens are drawn on a Canvas the size of the viewer's pane and returned from a pane model's View as Canvas.String(). Everything is plain text with SGR colours, so it works in any terminal Concord runs in.
Index ¶
- Constants
- Variables
- func DigitWidth(scale int) int
- func Flip(rows []string) []string
- func LogoHeight(scale int) int
- func LogoWidth(text string, scale int) int
- func SoundKit() map[string][]byte
- func SpriteWidth(rows []string, scale int) int
- func TextWidth(s string) int
- func WriteSoundKit(clientDir string) error
- type Canvas
- func (c *Canvas) Box(x, y, w, h int, role, title, titleRole string)
- func (c *Canvas) Center(y int, s, fg, bg string, bold bool) int
- func (c *Canvas) CenterIn(x, w, y int, s, fg, bg string, bold bool) int
- func (c *Canvas) Digit(d, x, py int, on string, scale int)
- func (c *Canvas) Fill(x, y, n int, ch, fg, bg string)
- func (c *Canvas) FinePx(fx, fy int, role string)
- func (c *Canvas) FineSprite(fx, fy int, rows []string, pal map[rune]string)
- func (c *Canvas) Keys(x, y int, keys ...Key) int
- func (c *Canvas) Logo(text string, x, py, scale int, shade []string)
- func (c *Canvas) Number(n, digits, x, py int, on string, scale int)
- func (c *Canvas) Px(x, py int, role string)
- func (c *Canvas) Shade(x, y, w, h int, bg string)
- func (c *Canvas) Sprite(x, py int, rows []string, pal map[rune]string, scale int)
- func (c *Canvas) String() string
- func (c *Canvas) Text(x, y int, s, fg, bg string, bold bool) int
- type Color
- type Key
- type Palette
- type Rewards
- func (r *Rewards) Count(items []Unlockable) int
- func (r *Rewards) Deal(items []Unlockable, rnd *rand.Rand) []string
- func (r *Rewards) Grant(n int, items []Unlockable) int
- func (r *Rewards) Locked(items []Unlockable) []Unlockable
- func (r *Rewards) Owns(id string, items []Unlockable) bool
- func (r *Rewards) Pick(id string) bool
- type Tier
- type Unlockable
Constants ¶
const ( SoundBlip = "sounds/blip.wav" // the menu cursor moves SoundSelect = "sounds/select.wav" // a choice is made SoundBack = "sounds/back.wav" // back one screen SoundCoin = "sounds/coin.wav" // PRESS ENTER SoundAmber = "sounds/amber.wav" // a countdown light SoundGo = "sounds/go.wav" // green: go SoundRed = "sounds/red.wav" // a foul or a false start SoundMistake = "sounds/mistake.wav" // a mistake SoundFinish = "sounds/finish.wav" // the finish fanfare SoundRecord = "sounds/record.wav" // a new record, an unlock )
The sound kit: short chiptune effects made from square, triangle and sawtooth waves, like an 8-bit sound chip. They're generated here, so every game has the same sounds and nothing is borrowed. Write them into a plugin's client/ folder with WriteSoundKit and play them with plugin.Conn.PlaySound(channel, viewer, arcade.SoundCoin, 0).
const OfferSize = 3
OfferSize is how many locked items a pass offers.
Variables ¶
var LogoShade = []string{"hi", "hi", "purple", "purple", "purple", "pink", "pink"}
LogoShade is the standard logo shading, one role per pixel row: light at the top, the brand purple, then pink at the foot.
var PaintNames = map[string]string{
"cyan": "ICE BLUE", "pink": "BUBBLEGUM", "green": "LIME LEAF", "orange": "ORANGE CRUSH",
"yellow": "LEMON DROP", "red": "CHERRY", "fg": "SILVER",
}
PaintNames are the paints' display names.
var Paints = []string{"cyan", "pink", "green", "orange", "yellow", "red", "fg"}
Paints are the colours a player can choose for their piece or car. They are theme roles, so they follow each viewer's theme. Purple is never a paint: it is the brand colour, kept for the grapes.
Functions ¶
func DigitWidth ¶
DigitWidth is a seven-segment digit's width in cells at scale, gap included.
func LogoHeight ¶
LogoHeight is how many rows Logo takes at scale, drop shadow included.
func SoundKit ¶
SoundKit returns every sound in the kit as WAV files (16-bit mono PCM), keyed by their path in client/.
func SpriteWidth ¶
SpriteWidth is the width in cells of rows at scale.
func WriteSoundKit ¶
WriteSoundKit writes the kit into a plugin's client folder (e.g. "client"), creating client/sounds/. Run it from a go:generate tool, and commit the files so releases include them.
Types ¶
type Canvas ¶
type Canvas struct {
W, H int
// contains filtered or unexported fields
}
Canvas is a grid of character cells the size of a pane. Coordinates are cells; pixel coordinates (py) count half-rows, two to a cell. Fine pixels (FinePx) also halve the columns: four to a cell.
func (*Canvas) Digit ¶
Digit draws one seven-segment digit (d < 0: all segments unlit) in role on, from column x and half-row py.
func (*Canvas) FinePx ¶ added in v0.15.0
FinePx sets one fine pixel: half-column fx, half-row fy. Fine pixels are drawn with quadrant characters (▘▝▖▗▚▞▙▛▜▟), twice the detail of Px across but half as wide, so art for them is drawn twice as wide. A cell shows at most two colours, so keep fine art to one colour on a background; a third colour in one cell is drawn in the second's place.
func (*Canvas) FineSprite ¶ added in v0.15.0
FineSprite draws pixel art in fine pixels from half-column fx and half-row fy: one string per row, one rune per fine pixel, looked up in pal (runes not in pal are see-through).
func (*Canvas) Keys ¶
Keys draws footer key chips the Concord way, the key in bold cyan on the current-line colour, from column x on row y.
func (*Canvas) Logo ¶
Logo draws text in the arcade pixel font from cell column x and half-row py, with a drop shadow one pixel down and right. shade gives each pixel row's role (one role for a single colour); nil uses LogoShade. Unknown characters draw as spaces.
func (*Canvas) Shade ¶ added in v0.12.0
Shade sets the background of the cells in a w x h box at (x, y), keeping what's drawn in them: a chalkboard, a highlighted square.
func (*Canvas) Sprite ¶
Sprite draws pixel art: one string per pixel row, one rune per pixel, looked up in pal (runes not in pal are see-through). Each pixel becomes a scale x scale block.
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color is one terminal colour: true colour, an ANSI palette index, or the terminal's own default.
func Mix ¶
Mix blends a toward b by t (0 = a, 1 = b). Only true colours can be mixed; otherwise it returns fallback.
func ParseColor ¶
ParseColor reads "#rrggbb", an ANSI index "0"-"15", or "" (default).
type Palette ¶
type Palette struct {
// contains filtered or unexported fields
}
Palette maps colour roles to the viewer's colours.
Base roles come straight from the Concord theme: bg, fg, comment, line, purple, pink, green, yellow, orange, red, cyan. Derived roles:
hi purple lightened: the top of the logo, grape shine
shadow purple darkened: the logo's drop shadow
ghost comment darkened: unlit segments, bulbs and locked silhouettes
dim quiet text
tire near black
hub wheel hubs
<paint>D a darker shade of each paint, e.g. "cyanD"
<colour>B a background tint of purple and each paint, e.g. "greenB" (a
chalkboard), falling back to "line" where colours can't mix
func NewPalette ¶
NewPalette builds the roles from a viewer's theme (nil: Dracula).
type Rewards ¶
type Rewards struct {
Passes int `json:"passes"`
Owned []string `json:"owned,omitempty"`
Offer []string `json:"offer,omitempty"`
}
Rewards is one player's passes and what they've unlocked. Each game names its passes to suit it -- Pit Passes in Grape Race, Gold Stars in tic-tac-toe -- and only the name on screen differs. Keep it in the player's saved record: the offer is saved with it, so leaving and coming back shows the same choices (no re-rolling).
func (*Rewards) Count ¶
func (r *Rewards) Count(items []Unlockable) int
Count is how many items are unlocked, starters included.
func (*Rewards) Deal ¶
func (r *Rewards) Deal(items []Unlockable, rnd *rand.Rand) []string
Deal returns the current offer, dealing a new one when there's a pass to spend and no offer yet: up to OfferSize locked items, weighted by tier (common 6, rare 3, legendary 1), no repeats.
func (*Rewards) Grant ¶
func (r *Rewards) Grant(n int, items []Unlockable) int
Grant adds n passes, never more than there is left to unlock. It reports how many were actually granted.
func (*Rewards) Locked ¶
func (r *Rewards) Locked(items []Unlockable) []Unlockable
Locked is everything still to unlock, in catalogue order.
type Unlockable ¶
type Unlockable struct {
ID string
Name string
Tier Tier
// Kind groups items a player picks one of ("pieces", "board"); a game
// with a single kind (Grape Race's cars) can leave it empty.
Kind string
// Blurb is a line about it, shown when it's offered.
Blurb string
}
Unlockable is something a player can earn: a car, a piece set, a board.