Files
Catacombs/ui/title.go
tolelom 1563091de1 fix: 13 bugs found via systematic code review and testing
Multiplayer:
- Add WaitingScreen between class select and game start; previously
  selecting a class immediately started the game and locked the room,
  preventing other players from joining
- Add periodic lobby room list refresh (2s interval)
- Add LeaveRoom method for backing out of waiting room

Combat & mechanics:
- Mark invalid attack targets with TargetIdx=-1 to suppress misleading
  "0 dmg" combat log entries
- Make Freeze effect actually skip frozen player's action (was purely
  cosmetic before - expired during tick before action processing)
- Implement Life Siphon relic heal-on-damage effect (was defined but
  never applied in combat)
- Fix combo matching to track used actions and prevent reuse

Game modes:
- Wire up weekly mutations to GameSession via ApplyWeeklyMutation()
- Implement 3 mutation runtime effects: no_shop, glass_cannon, elite_flood
- Pass HardMode toggle from lobby UI through Context to GameSession
- Apply HardMode difficulty multipliers (1.5x monsters, 2x shop, 0.5x heal)

Polish:
- Set starting room (index 0) to always be Empty (safe start)
- Distinguish shop purchase errors: "Not enough gold" vs "Inventory full"
- Record random events in codex for discovery tracking

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 20:45:56 +09:00

127 lines
4.1 KiB
Go

package ui
import (
"fmt"
"strings"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
// TitleScreen is the main menu screen.
type TitleScreen struct{}
func NewTitleScreen() *TitleScreen {
return &TitleScreen{}
}
func (s *TitleScreen) Update(msg tea.Msg, ctx *Context) (Screen, tea.Cmd) {
if key, ok := msg.(tea.KeyMsg); ok {
if isEnter(key) {
if ctx.Fingerprint == "" {
ctx.Fingerprint = fmt.Sprintf("anon-%d", time.Now().UnixNano())
}
if ctx.Store != nil {
name, err := ctx.Store.GetProfile(ctx.Fingerprint)
if err != nil {
// First time player — show nickname input
return NewNicknameScreen(), nil
}
ctx.PlayerName = name
} else {
ctx.PlayerName = "Adventurer"
}
if ctx.Lobby != nil {
ctx.Lobby.PlayerOnline(ctx.Fingerprint, ctx.PlayerName)
}
// Check for active session to reconnect
if ctx.Lobby != nil {
code, session := ctx.Lobby.GetActiveSession(ctx.Fingerprint)
if session != nil {
ctx.RoomCode = code
ctx.Session = session
gs := NewGameScreen()
gs.gameState = ctx.Session.GetState()
ctx.Session.TouchActivity(ctx.Fingerprint)
ctx.Session.SendChat("System", ctx.PlayerName+" reconnected!")
return gs, gs.pollState()
}
}
ls := NewLobbyScreen()
ls.refreshLobby(ctx)
return ls, ls.pollLobby()
} else if isKey(key, "h") {
return NewHelpScreen(), nil
} else if isKey(key, "s") {
return NewStatsScreen(), nil
} else if isKey(key, "a") {
return NewAchievementsScreen(), nil
} else if isKey(key, "l") {
return NewLeaderboardScreen(), nil
} else if isKey(key, "c") {
return NewCodexScreen(ctx), nil
} else if isQuit(key) {
return s, tea.Quit
}
}
return s, nil
}
func (s *TitleScreen) View(ctx *Context) string {
return renderTitle(ctx.Width, ctx.Height)
}
var titleLines = []string{
` ██████╗ █████╗ ████████╗ █████╗ ██████╗ ██████╗ ███╗ ███╗██████╗ ███████╗`,
`██╔════╝██╔══██╗╚══██╔══╝██╔══██╗██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔════╝`,
`██║ ███████║ ██║ ███████║██║ ██║ ██║██╔████╔██║██████╔╝███████╗`,
`██║ ██╔══██║ ██║ ██╔══██║██║ ██║ ██║██║╚██╔╝██║██╔══██╗╚════██║`,
`╚██████╗██║ ██║ ██║ ██║ ██║╚██████╗╚██████╔╝██║ ╚═╝ ██║██████╔╝███████║`,
` ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝`,
}
var titleColors = []lipgloss.Color{
lipgloss.Color("196"),
lipgloss.Color("202"),
lipgloss.Color("208"),
lipgloss.Color("214"),
lipgloss.Color("220"),
lipgloss.Color("226"),
}
func renderTitle(width, height int) string {
var logoLines []string
for i, line := range titleLines {
color := titleColors[i%len(titleColors)]
style := lipgloss.NewStyle().Foreground(color).Bold(true)
logoLines = append(logoLines, style.Render(line))
}
logo := strings.Join(logoLines, "\n")
subtitle := lipgloss.NewStyle().
Foreground(colorGray).
Render("⚔ A Cooperative Dungeon Crawler ⚔")
server := lipgloss.NewStyle().
Foreground(colorCyan).
Render("ssh catacombs.tolelom.xyz")
menu := lipgloss.NewStyle().
Foreground(colorWhite).
Bold(true).
Render("[Enter] Start [H] Help [S] Stats [A] Achievements [L] Leaderboard [C] Codex [Q] Quit")
content := lipgloss.JoinVertical(lipgloss.Center,
logo,
"",
subtitle,
server,
"",
"",
menu,
)
return lipgloss.Place(width, height, lipgloss.Center, lipgloss.Center, content)
}