Skip to content

Commit

Permalink
fix: mouse support and card casting error
Browse files Browse the repository at this point in the history
  • Loading branch information
BigJk committed May 15, 2024
1 parent 2cbf45a commit 509567f
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ui/menus/about/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m.parent, nil
}
case tea.MouseMsg:
if (msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft) && m.zones.Get("back").InBounds(msg) {
if (msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft) && m.zones.Get("back").InBounds(msg) {
audio.Play("btn_menu")

return m.parent, nil
Expand Down
4 changes: 2 additions & 2 deletions ui/menus/eventview/eventview.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.MouseMsg:
m.LastMouse = msg

if (msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft) || msg.Type == tea.MouseMotion {
if (msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft) || msg.Action == tea.MouseActionMotion {
if m.session.GetEvent() != nil {
for i := 0; i < len(m.session.GetEvent().Choices); i++ {
if choiceZone := m.zones.Get(fmt.Sprintf("%s%d", ZoneChoice, i)); choiceZone.InBounds(msg) {
if (msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft) && m.selectedChoice == i {
if (msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft) && m.selectedChoice == i {
audio.Play("btn_menu")
m = m.tryFinishEvent()
break
Expand Down
2 changes: 1 addition & 1 deletion ui/menus/gameover/gameover.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.MouseMsg:
m.lastMouse = msg

if (msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft) && m.zones.Get(ZoneToMenu).InBounds(msg) {
if (msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft) && m.zones.Get(ZoneToMenu).InBounds(msg) {
m.session.Close()
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion ui/menus/gameview/damage_anim.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (m DamageAnimationModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return nil, nil
}
case tea.MouseMsg:
if m.elapsed > 0.2 && (msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft) {
if m.elapsed > 0.2 && (msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft) {
return nil, nil
}
case DamageAnimationFrame:
Expand Down
2 changes: 1 addition & 1 deletion ui/menus/gameview/death_anim.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (m DeathAnimationModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return nil, nil
}
case tea.MouseMsg:
if m.progress > 0.1 && (msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft) {
if m.progress > 0.1 && (msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft) {
return nil, nil
}
case DeathAnimationFrame:
Expand Down
2 changes: 1 addition & 1 deletion ui/menus/gameview/end_turn_anim.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (m EndTurnAnimationModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return nil, nil
}
case tea.MouseMsg:
if m.elapsed > 0.1 && (msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft) {
if m.elapsed > 0.1 && (msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft) {
return nil, nil
}
case EndTurnAnimationFrame:
Expand Down
14 changes: 7 additions & 7 deletions ui/menus/gameview/gameview.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.LastMouse = msg

if len(m.animations) == 0 {
if msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft {
if msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft {
cmds = append(cmds, root.TooltipClear())

switch m.Session.GetGameState() {
Expand All @@ -172,13 +172,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}

if (msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft) || msg.Type == tea.MouseMotion {
if (msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft) || msg.Action == tea.MouseActionMotion {
switch m.Session.GetGameState() {
case game.GameStateFight:
if m.inOpponentSelection {
for i := 0; i < m.Session.GetOpponentCount(game.PlayerActorID); i++ {
if m.zones.Get(fmt.Sprintf("%s%d", ZoneEnemy, i)).InBounds(msg) {
if msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft {
if msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft {
m.selectedOpponent = i
m = m.tryCast()
}
Expand All @@ -189,19 +189,19 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
for i := 0; i < len(m.Session.GetFight().Hand); i++ {
if m.zones.Get(fmt.Sprintf("%s%d", ZoneCard, i)).InBounds(msg) {
onCard = true
if (msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft) && m.selectedCard == i {
if (msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft) && m.selectedCard == i {
m = m.tryCast()
} else {
m.selectedCard = i
}
}
}

if !onCard && msg.Type == tea.MouseMotion {
if !onCard && msg.Action == tea.MouseActionMotion {
m.selectedCard = -1
}

if !m.inOpponentSelection && msg.Type == tea.MouseLeft {
if !m.inOpponentSelection && msg.Button == tea.MouseButtonLeft {
for i := 0; i < m.Session.GetOpponentCount(game.PlayerActorID); i++ {
if m.zones.Get(fmt.Sprintf("%s%d", ZoneEnemy, i)).InBounds(msg) {
m.selectedOpponent = i
Expand Down Expand Up @@ -428,7 +428,7 @@ func (m Model) tryCast() Model {
before := m.Session.MarkState()

hand := m.Session.GetFight().Hand
if len(hand) > 0 && m.selectedCard < len(hand) {
if len(hand) > 0 && m.selectedCard < len(hand) && m.selectedCard >= 0 {
card, _ := m.Session.GetCard(hand[m.selectedCard])
if card.NeedTarget {
if m.inOpponentSelection {
Expand Down
2 changes: 1 addition & 1 deletion ui/menus/lua_error/lua_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return nil, nil
}
case tea.MouseMsg:
if msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft {
if msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft {
if m.zones.Get(ZoneCopy).InBounds(msg) {
if os.Getenv("NO_CLIPBOARD") == "1" {
return m, nil
Expand Down
4 changes: 2 additions & 2 deletions ui/menus/mainmenu/choices.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ func (m ChoicesModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
audio.Play("interface_move", -1.5)
}
case tea.MouseMsg:
if (msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft) || msg.Type == tea.MouseMotion {
if (msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft) || msg.Action == tea.MouseActionMotion {
for i := range m.choices {
if m.zones.Get("choice_"+string(m.choices[i].(choiceItem).key)).InBounds(msg) || m.zones.Get("choice_desc_"+string(m.choices[i].(choiceItem).key)).InBounds(msg) {
if m.list.Index() != i {
audio.Play("interface_move", -1.5)
}

m.list.Select(i)
if msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft {
if msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft {
m.selected = m.choices[i].(choiceItem).key
}
break
Expand Down
4 changes: 2 additions & 2 deletions ui/menus/merchant/merchant.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

switch m.state {
case StateMain:
if msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft {
if msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft {
if m.zones.Get(ZoneBuyItem).InBounds(msg) {
audio.Play("btn_menu")
m = m.merchantBuy()
Expand All @@ -91,7 +91,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case StateUpgrade:
fallthrough
case StateRemove:
if msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft {
if msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft {
if m.zones.Get(ZoneBuyItem).InBounds(msg) {
audio.Play("btn_menu")
if m.state == StateUpgrade {
Expand Down
2 changes: 1 addition & 1 deletion ui/menus/overview/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (m MenuModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
audio.Play("interface_move", -1.5)
}
case tea.MouseMsg:
if msg.Action == tea.MouseActionRelease && msg.Type == tea.MouseLeft {
if msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft {
for i := range m.choices {
if m.zones.Get(ZoneChoices + string(m.choices[i].(choiceItem).key)).InBounds(msg) {
m.list.Select(i)
Expand Down

0 comments on commit 509567f

Please sign in to comment.