entropy/main.go
2026-04-01 18:47:18 -06:00

227 lines
3.7 KiB
Go

package main
import (
"encoding/json"
"fmt"
"math/rand/v2"
"os"
)
var Cards = []struct {
lane Lane
typ Type
entropy int
recovery int
force int
name string
desc string
}{
{typ: Passive, recovery: 3,
name: `Rapid Response`, desc: `Your {{spell}}s cost {{1 hp}} less.`},
{typ: Passive, recovery: 2,
name: `Breaker`, desc: `The first {{unit}} you play per turn costs {{1 entropy}} less.`},
{typ: Passive, recovery: 0,
name: `Inverse Entropy`, desc: `Add {{1 hp}} to all {{lifesteal}} bonuses`},
}
type Lane int
const (
Any Lane = iota
Red
Green
Blue
)
type Type int
const (
Unit Type = iota
Spell
Passive
Token
)
func (l Lane) String() string {
switch l {
case Any:
return "⬜ Any"
case Red:
return "🟥 Red"
case Green:
return "🟩 Green"
case Blue:
return "🟦 Blue"
default:
panic("unknwon")
}
}
func (t Type) String() string {
switch t {
case Unit:
return "Unit"
case Passive:
return "Passive"
case Token:
return "Token"
default:
panic("unknown")
}
}
func main() {
type (
jsonfront struct {
Name string `json:"name"`
Type string `json:"type"`
Cost int `json:"cost"`
Image string `json:"image"`
Horizontal bool `json:"isHorizontal"`
}
jsoncard struct {
// required
Id string `json:"id"`
Face struct {
Front jsonfront `json:"front"`
} `json:"face"`
Name string `json:"name"`
Type string `json:"type"`
Cost int `json:"cost"`
Token bool `json:"isToken"`
// custom
Lane string `json:"Lane"`
Entropy int `json:"Entropy"`
Force int `json:"Force"`
Legal bool `json:"_legal"`
}
)
thejson := make(map[string]jsoncard)
for i := range len(Cards) {
card := &Cards[i]
if len(card.name) == 0 {
card.name = generateTemporaryName()
}
baseurl := "https://docs.brut.systems/judah/entropy/"
var imgurl string
switch card.lane {
case Red:
imgurl = baseurl + "red-base.png"
case Blue:
imgurl = baseurl + "blue-base.png"
case Green:
imgurl = baseurl + "green-base.png"
default:
imgurl = baseurl + "passive-base.png"
}
id := fmt.Sprintf("%03d", i)
thejson[id] = jsoncard{
Id: id,
Face: struct {
Front jsonfront `json:"front"`
}{
jsonfront{
Name: card.name,
Type: card.typ.String(),
Image: imgurl,
Cost: card.entropy,
Horizontal: false,
},
},
Token: card.typ == Token,
Name: card.name,
Type: card.typ.String(),
Cost: card.entropy,
Entropy: card.entropy,
Force: card.force,
Lane: card.lane.String(),
Legal: true,
}
}
enc, err := json.MarshalIndent(thejson, "", " ")
if err != nil {
panic(err)
}
if err := os.WriteFile("docs/CardList.json", enc, 0644); err != nil {
panic(err)
}
}
func generateTemporaryName() string {
var (
adjectives = []string{
"Absent",
"Ambient",
"Bare",
"Blunt",
"Civic",
"Composite",
"Concave",
"Dull",
"Errant",
"Excess",
"Flat",
"Former",
"Gross",
"Inland",
"Lateral",
"Live",
"Lucid",
"Moot",
"Nominal",
"Oblique",
"Partial",
"Passive",
"Petit",
"Polar",
"Residual",
"Rote",
"Soft",
"Spent",
"Terminal",
"Warm",
}
nouns = []string{
"Aperture",
"Axis",
"Bulk",
"Cartilage",
"Compact",
"Contour",
"Conviction",
"Cortex",
"Deficit",
"Dividend",
"Dosage",
"Envelope",
"Filament",
"Gesture",
"Gradient",
"Inlet",
"Lapse",
"Mandate",
"Membrane",
"Morale",
"Offset",
"Posture",
"Precinct",
"Prospect",
"Rapport",
"Reflex",
"Substrate",
"Surplus",
"Tendon",
"Volume",
}
)
return adjectives[rand.IntN(len(adjectives))] + nouns[rand.IntN(len(nouns))]
}