package moves import ( "strconv" "strings" rules "gno.land/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/brawl" ) func short(addr string) string { if len(addr) < 12 { return addr } return addr[:6] + "…" + addr[len(addr)-4:] } func secs(ticks int) string { s := strconv.Itoa(ticks / rules.TPS) if ticks%rules.TPS != 0 { s += "." + strconv.Itoa(ticks%rules.TPS) } return s + "s" } func row(b *strings.Builder, id int) { a, s := mustRecord(id) r := rules.MustRecipe(s) b.WriteString("| [#" + strconv.Itoa(id) + "](:move/" + strconv.Itoa(id) + ") | " + r.Name + " | " + secs(r.CD) + " | " + r.Describe() + " | [" + short(a) + "](:by/" + a + ") |\n") } const header = "| # | Move | Recharge | What it does | Author |\n|---|---|---|---|---|\n" // Render shows the newest moves, one move at "move/", or an author's // moves at "by/
". func Render(path string) string { var b strings.Builder switch { case strings.HasPrefix(path, "move/"): id, err := strconv.Atoi(path[5:]) if err != nil || record(id) == "" { return "No such move." } a, s := mustRecord(id) r := rules.MustRecipe(s) b.WriteString("# " + r.Name + "\n\n") b.WriteString("Move #" + strconv.Itoa(id) + " by [" + short(a) + "](:by/" + a + "). Recharges in " + secs(r.CD) + " (its effects need at least " + secs(r.Cost()) + ").\n\n") for _, e := range r.Fx { b.WriteString("- " + e.Describe() + "\n") } b.WriteString("\nRecipe: `" + s + "`\n") return b.String() case strings.HasPrefix(path, "by/"): addr := path[3:] ids := authorIDs(addr) b.WriteString("# Moves by " + short(addr) + "\n\n") if len(ids) == 0 { b.WriteString("None yet.\n") return b.String() } b.WriteString(header) for _, id := range ids { row(&b, id) } return b.String() } b.WriteString("# Move recipes\n\n") b.WriteString("Special moves anyone can design, written as data. Equip one in the brawler to use it in place of your class special; the chain runs it with the same rules as the browser.\n\n") b.WriteString("A recipe is `name/cooldown/effects`, for example `Blink Thief/84/D82S11`: dash 4 squares to the nearest gold, then steal 1 gold in melee. ") b.WriteString("Stronger effects need longer cooldowns. Check one with `Check(recipe)` and publish it with `Publish(recipe)`.\n\n") if count == 0 { b.WriteString("No moves published yet.\n") return b.String() } b.WriteString("## Newest\n\n" + header) for id := count; id >= 1 && id > count-20; id-- { row(&b, id) } b.WriteString("\n" + strconv.Itoa(count) + " moves published.\n") return b.String() }