82 lines
1.2 KiB
Go
82 lines
1.2 KiB
Go
package types
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
type CharStatus int
|
|
|
|
const (
|
|
CharStatusA CharStatus = iota
|
|
CharStatusB
|
|
CharStatusC
|
|
)
|
|
|
|
type Char struct {
|
|
Char rune `msgpack:"char"`
|
|
Status CharStatus `msgpack:"status"`
|
|
}
|
|
|
|
func NewChar() Char {
|
|
return Char{
|
|
Char: 0x0,
|
|
Status: CharStatusC,
|
|
}
|
|
}
|
|
|
|
func (self Char) View() string {
|
|
style := lipgloss.NewStyle()
|
|
|
|
switch self.Status {
|
|
case CharStatusA:
|
|
style = style.Background(lipgloss.Color("#00ff00"))
|
|
case CharStatusB:
|
|
style = style.Background(lipgloss.Color("#ffff00"))
|
|
case CharStatusC:
|
|
style = style.Background(lipgloss.Color("#808080"))
|
|
}
|
|
|
|
return style.Render(string(self.Char))
|
|
}
|
|
|
|
type Word struct {
|
|
Chars []Char `msgpack:"chars"`
|
|
}
|
|
|
|
func NewWord() Word {
|
|
return Word{
|
|
Chars: nil,
|
|
}
|
|
}
|
|
|
|
func (self Word) View() string {
|
|
var b strings.Builder
|
|
|
|
for _, char := range self.Chars {
|
|
b.WriteString(char.View())
|
|
b.WriteRune('\n')
|
|
}
|
|
|
|
return b.String()
|
|
}
|
|
|
|
const (
|
|
MaxLength = 5
|
|
)
|
|
|
|
type UserState struct {
|
|
History []Word `msgpack:"history"`
|
|
}
|
|
|
|
type WordleState struct {
|
|
Users []UserState `msgpack:"users"`
|
|
}
|
|
|
|
func NewWordleState() WordleState {
|
|
return WordleState{
|
|
Users: nil,
|
|
}
|
|
}
|