package advent import ( "strconv" "strings" "time" "chain/runtime" "gno.land/p/moul/kit/ui/v0" "gno.land/p/moul/realmpath/v0" ) const app = "https://moul.github.io/gno-contracts/advent/" func webLinks() (string, string) { if runtime.ChainID() == "moulstaging-1" { return app + "?net=moul-dev", "https://gno-staging.moul.p2p.team/faucet" } return app, "https://onyx.testnets.gno.land/faucet" } func Render(path string) string { req := realmpath.Parse(path) switch req.PathPart(0) { case "": return renderCalendar() case "scores": return calendarLink() + "\n\n" + renderScores() case "door": day, _ := strconv.Atoi(req.PathPart(1)) return renderDoor(day) case "seal": day, _ := strconv.Atoi(req.PathPart(1)) id, _ := strconv.Atoi(req.PathPart(2)) return renderSeal(day, id) default: return "## Lost in the snow\n\n" + calendarLink() } } func renderCalendar() string { play, faucet := webLinks() var out strings.Builder out.WriteString("# ✷ Gnoël\n\n") out.WriteString("**The North Pole, one realm over.**\n\n") out.WriteString("![A snowbound Gnome outpost](" + app + "outpost.webp)\n\n") out.WriteString("The Gno-mes hid 24 riddles in the VM. Open a door, follow the clues, and send a sealed guess. Every opened door stays playable.\n\n") out.WriteString("[Play Gnoël](" + play + ") · [Get test GNOT](" + faucet + ") · [🏆 Leaderboard](" + route("scores") + ")\n\n") out.WriteString("## Advent calendar\n\n") table := ui.NewTable("First door", "Second door", "Third door", "Fourth door", "Fifth door", "Sixth door") open, solves := 0, 0 for week := 0; week < 4; week++ { row := make([]string, 0, 6) for j := 1; j <= 6; j++ { day := week*6 + j n := dayNumber(day) d := doors(day) if d == nil { row = append(row, "🔒 **"+n+"**") continue } open++ solves += d.solves row = append(row, "**["+n+"]("+doorURL(day)+")** · "+solveCount(d.solves)) } table.Row(row...) } out.WriteString("**" + strconv.Itoa(open) + " / 24 doors open** · **" + solveCount(solves) + "**\n\n") out.WriteString(table.String() + "\n") out.WriteString("A right guess earns one point after the oracle checks the seals. The public ledger shows each commitment and verdict.\n\n") out.WriteString(renderScores()) return out.String() } func renderDoor(day int) string { play, faucet := webLinks() d := doors(day) if d == nil { return "## 🔒 Still snowed in\n\nThis door opens when the organizer posts its riddle.\n\n" + calendarLink() } var out strings.Builder out.WriteString(calendarLink() + "\n\n") out.WriteString("# Door " + dayNumber(day) + " · " + ui.Inline(d.title) + "\n\n") for _, line := range strings.Split(d.clue, "\n") { out.WriteString("> " + ui.Inline(line) + "\n") } out.WriteString("\n**" + solveCount(d.solves) + "** · " + strconv.Itoa(d.submitted) + " sealed guesses · " + strconv.Itoa(d.submitted-d.reviewed) + " awaiting review\n\n") out.WriteString("First review from **" + time.Unix(d.reviewFrom, 0).UTC().Format("2 Jan 2006, 15:04 UTC") + "**. This door stays open for late arrivals.\n\n") out.WriteString("[Seal a guess](" + play + "#door-" + strconv.Itoa(day) + ") · [Get test GNOT](" + faucet + ")\n\n") out.WriteString("## Public seals\n\n") if d.submitted == 0 { return out.String() + "_The snow is still fresh here. Send the first guess._\n" } table := ui.NewTable("Seal", "Gnome", "Commitment", "Verdict") for id := d.submitted; id > 0 && id > d.submitted-8; id-- { a := d.attempt(id) n := strconv.Itoa(id) table.Row("[#"+n+"]("+route("seal/"+strconv.Itoa(day)+"/"+n)+")", ui.AddrOf(a.player), "`"+ui.ShortN(a.commitment, 10, 4)+"`", verdict(a.status)) } out.WriteString(table.String()) return out.String() } func renderSeal(day, id int) string { d := doors(day) if d == nil || id < 1 || id > d.submitted { return "## Seal not found\n\n" + calendarLink() } a := d.attempt(id) return "# Seal #" + strconv.Itoa(id) + "\n\n[Back to door " + dayNumber(day) + "](" + doorURL(day) + ")\n\n" + "**Gnome** " + a.player + "\n\n**Verdict** " + verdict(a.status) + "\n\n**Public SHA-256 commitment**\n\n`" + a.commitment + "`\n" } func renderScores() string { const heading = "## 🏆 The Nice List\n\n" rows := leaders() if len(rows) == 0 { return heading + "_Nobody has thawed the scoreboard yet._\n" } table := ui.NewTable("Rank", "Gnome", "Solves") for i, e := range rows { table.Row(strings.TrimSpace(strconv.Itoa(i+1)+" "+ui.Podium(i)), "`"+e.Key+"`", strconv.FormatInt(e.Score, 10)) } return heading + table.String() } func verdict(status int) string { switch status { case solved: return "✅ Solved" case missed: return "↩ Try again" default: return "✉️ Sealed" } } func dayNumber(day int) string { n := strconv.Itoa(day) if day < 10 { return "0" + n } return n } func solveCount(n int) string { if n == 1 { return "1 solve" } return strconv.Itoa(n) + " solves" } func route(path string) string { return strings.TrimPrefix(self, "gno.land") + ":" + path } func doorURL(day int) string { return route("door/" + strconv.Itoa(day)) } func calendarLink() string { return "[Gnoël calendar](" + strings.TrimPrefix(self, "gno.land") + ")" }