local docker dev + starting on gameplay

This commit is contained in:
2026-09-16 09:30:29 -05:00
parent ab9573b875
commit d4b4de17aa
5 changed files with 348 additions and 25 deletions
+106 -23
View File
@@ -217,18 +217,21 @@ const (
)
type model struct {
DB *db.Database
page page
tabs []string
tab tab
term string
profile string
term string
width int
height int
bg string
DB *db.Database
page page
angler models.Angler
tabs []string
tab tab
error string
ti textinput.Model
spinner spinner.Model
angler models.Angler
active tea.Model
cast models.Cast
}
func (m model) Init() tea.Cmd {
@@ -249,7 +252,13 @@ func (m model) Init() tea.Cmd {
}
func (m model) ChooseNameView() tea.View {
input := lipgloss.JoinVertical(lipgloss.Top, "Got a name?", m.ti.View())
var error string
if len(m.error) > 0 {
error = lipgloss.NewStyle().Foreground(lipgloss.Red).Render(m.error)
}
input := lipgloss.JoinVertical(lipgloss.Top, "aye fresh meat, got a name laddie?", m.ti.View(), error)
center := lipgloss.Place(
m.width,
@@ -279,7 +288,7 @@ func (m model) ChooseNameView() tea.View {
c = m.ti.Cursor()
c.Y += lipgloss.Height("aye, fresh meat – got a name laddie?") + (m.height-3-lipgloss.Height(input))/2
c.Y += lipgloss.Height("aye fresh meat, got a name laddie?") + (m.height-3-lipgloss.Height(input))/2
c.X += (m.width - lipgloss.Width(input)) / 2
v := tea.NewView(str)
@@ -294,20 +303,33 @@ func (m model) ChooseNameUpdate(msg tea.Msg) (model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyPressMsg:
m.error = ""
switch msg.String() {
case "enter":
err := m.DB.Conn.Get(
&m.angler,
"UPDATE anglers SET angler_username = $1 WHERE angler_id = $2 RETURNING angler_id, angler_username, angler_email",
m.ti.Value(), m.angler.ID,
)
existing := 0
desired_username := m.ti.Value()
err := m.DB.Conn.Get(&existing, "SELECT 1 FROM anglers WHERE angler_username = $1", desired_username)
if err != nil {
// TODO: handle error
}
m, cmd = m.gotoGameplayView()
cmds = append(cmds, cmd)
if existing > 0 {
m.error = "that one is taken"
} else {
err = m.DB.Conn.Get(
&m.angler,
"UPDATE anglers SET angler_username = $1 WHERE angler_id = $2 RETURNING angler_id, angler_username, angler_email",
desired_username, m.angler.ID,
)
if err != nil {
// TODO: handle error
}
m, cmd = m.gotoGameplayView()
cmds = append(cmds, cmd)
}
}
}
@@ -318,7 +340,8 @@ func (m model) ChooseNameUpdate(msg tea.Msg) (model, tea.Cmd) {
return m, tea.Batch(cmds...)
}
var buttonStyle = lipgloss.NewStyle().Background(lipgloss.Color("30")).Padding(0, 3).Align(lipgloss.Center)
var buttonStyle = lipgloss.NewStyle().Padding(0, 2).Align(lipgloss.Center).Background(lipgloss.Color("8"))
var buttonActiveStyle = buttonStyle.Background(lipgloss.Color("30"))
var sidebarBtnStyle = lipgloss.NewStyle().Padding(0, 2).Align(lipgloss.Center).Foreground(lipgloss.Color("30"))
var sidebarBtnActiveStyle = sidebarBtnStyle.UnsetForeground().Background(lipgloss.Color("30"))
@@ -348,7 +371,11 @@ func (m model) GameplayView() tea.View {
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(lipgloss.Color("30")).
Padding(paddingY, paddingX).
Render(fmt.Sprintf("Ay matie %s", m.angler.Username))
Render(lipgloss.JoinVertical(
lipgloss.Left,
lipgloss.NewStyle().MarginBottom(1).Render(fmt.Sprintf("Aye matie %s...time to get fishin'", m.angler.Username)),
buttonActiveStyle.Render("Cast"),
))
footer := lipgloss.NewStyle().Foreground(lipgloss.Color("8")).Render("(esc to quit)")
@@ -387,17 +414,54 @@ func (m model) GameplayView() tea.View {
type GameplayKeyMap struct {
CycleTab key.Binding
AltCycleTab key.Binding
Interact key.Binding
}
var DefaultGameplayKeyMap = GameplayKeyMap{
CycleTab: key.NewBinding(
key.WithKeys("tab"),
key.WithHelp("shift+tab", "Cycle Tab Right"),
key.WithHelp("tab", "Cycle Tab Right"),
),
AltCycleTab: key.NewBinding(
key.WithKeys("shift+tab"),
key.WithHelp("shift+tab", "Cycle Tab Left"),
),
Interact: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "Interact with selected option"),
),
}
var sayings = []string{
// Near Misses
"Close but no cigar",
"Almost only counts in horseshoes and hand grenades",
"A day late and a dollar short",
"A miss is as good as a mile",
"Always a bridesmaid, never a bride",
"Snatched defeat from the jaws of victory",
"Fell at the last hurdle",
"Missed the boat",
"Missed it by a whisker",
"So near, and yet so far",
"A swing and a miss",
// Futile Efforts
"Beating a dead horse",
"Tilting at windmills",
"Squeezing blood from a stone",
"Nailing jelly to a wall",
"Herding cats",
"Rearranging deck chairs on the Titanic",
"Pushing a rope",
"Spitting in the wind",
"Putting toothpaste back in the tube",
"Shoveling snow in a blizzard",
"Spinning your wheels",
"Emptying the ocean with a teaspoon",
"Barking up the wrong tree",
"A wild goose chase",
"Catching the wind in a net",
}
func (m model) GameplayUpdate(msg tea.Msg) (model, tea.Cmd) {
@@ -422,6 +486,25 @@ func (m model) GameplayUpdate(msg tea.Msg) (model, tea.Cmd) {
} else {
m.tab -= 1
}
case key.Matches(msg, DefaultGameplayKeyMap.Interact):
// if m.active = {
is_casting, err := m.DB.IsCasting(m.angler.ID)
if is_casting {
m.error = "looks like you are already casting somewhere"
// TODO: clear after a timeout
}
m.cast, err = m.DB.CreateNewCast(m.angler.ID)
if err != nil {
m.error = "unable to start your cast"
// TODO: handle error
}
// TODO: implement rest of casting logic
// }
}
}
@@ -498,17 +581,17 @@ func teaHandler(DB *db.Database) func(ssh.Session) (tea.Model, []tea.ProgramOpti
angler, _ := s.Context().Value("angler").(models.Angler)
m := model{
DB: DB,
tabs: []string{"fishin'", "wares", "dock", "settings"},
tab: TabFishin,
page: PageChooseName,
term: pty.Term,
width: pty.Window.Width,
height: pty.Window.Height,
bg: "light",
DB: DB,
page: PageChooseName,
angler: angler,
tabs: []string{"fishin'", "wares", "dock", "settings"},
tab: TabFishin,
ti: textinput.New(),
spinner: spinner.New(),
angler: angler,
}
if angler.Username == gossh.FingerprintSHA256(s.PublicKey()) {