-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gameview.go
620 lines (522 loc) · 20.2 KB
/
gameview.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
package gameview
import (
"fmt"
"github.com/BigJk/end_of_eden/game"
"github.com/BigJk/end_of_eden/system/audio"
"github.com/BigJk/end_of_eden/ui"
"github.com/BigJk/end_of_eden/ui/components"
"github.com/BigJk/end_of_eden/ui/menus/carousel"
"github.com/BigJk/end_of_eden/ui/menus/eventview"
"github.com/BigJk/end_of_eden/ui/menus/gameover"
"github.com/BigJk/end_of_eden/ui/menus/merchant"
"github.com/BigJk/end_of_eden/ui/menus/overview"
"github.com/BigJk/end_of_eden/ui/root"
"github.com/BigJk/end_of_eden/ui/style"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
zone "github.com/lrstanley/bubblezone"
"github.com/samber/lo"
"strings"
)
const (
ZoneCard = "card_"
ZoneEnemy = "enemy_"
ZoneEndTurn = "end_turn"
ZonePlayerInspect = "player_inspect"
)
type Model struct {
ui.MenuBase
zones *zone.Manager
parent tea.Model
selectedCard int
selectedOpponent int
inOpponentSelection bool
inEnemyView bool
inPlayerView bool
animations []tea.Model
ctrlDown bool
lastGameState game.GameState
lastEvent string
event tea.Model
merchant tea.Model
Session *game.Session
Start game.StateCheckpointMarker
BeforeStateSwitch game.StateCheckpointMarker
}
func New(parent tea.Model, zones *zone.Manager, session *game.Session) Model {
session.Log(game.LogTypeSuccess, "Game started! Good luck...")
return Model{
zones: zones,
parent: parent,
event: eventview.New(zones, session),
merchant: merchant.New(zones, session),
lastGameState: session.GetGameState(),
lastEvent: session.GetEventID(),
Session: session,
Start: session.MarkState(),
BeforeStateSwitch: session.MarkState(),
}
}
func (m Model) Init() tea.Cmd {
return nil
}
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if cmd := root.CheckLuaErrors(m.zones, m.Session); cmd != nil {
return m, cmd
}
var (
cmd tea.Cmd
cmds []tea.Cmd
)
switch msg := msg.(type) {
//
// Keyboard
//
case tea.KeyMsg:
if len(m.animations) == 0 {
switch msg.Type {
case tea.KeyEnter:
switch m.Session.GetGameState() {
// Cast a card
case game.GameStateFight:
if m.selectedCard >= len(m.Session.GetFight().Hand) {
m.selectedCard = 0
}
m = m.tryCast()
}
case tea.KeyEscape:
cmds = append(cmds, root.TooltipClear())
// Switch to menu
if m.inOpponentSelection || m.inEnemyView || m.inPlayerView {
m.inOpponentSelection = false
m.inEnemyView = false
m.inPlayerView = false
} else {
return overview.New(m, m.zones, m.Session), tea.Batch(cmds...)
}
case tea.KeyTab:
switch m.Session.GetGameState() {
// Select a card or opponent
case game.GameStateFight:
if len(m.Session.GetFight().Hand) > 0 {
if m.inOpponentSelection {
m.selectedOpponent = (m.selectedOpponent + 1) % m.Session.GetOpponentCount(game.PlayerActorID)
} else {
m.selectedCard = (m.selectedCard + 1) % len(m.Session.GetFight().Hand)
}
}
}
case tea.KeySpace:
switch m.Session.GetGameState() {
// End turn
case game.GameStateFight:
m = m.finishTurn()
}
case tea.KeyLeft:
m.selectedCard = lo.Clamp(m.selectedCard-1, 0, len(m.Session.GetFight().Hand)-1)
case tea.KeyRight:
m.selectedCard = lo.Clamp(m.selectedCard+1, 0, len(m.Session.GetFight().Hand)-1)
case tea.KeyCtrlDown:
m.ctrlDown = true
case tea.KeyCtrlU:
m.ctrlDown = false
}
// Show tooltip
if msg.String() == "x" {
for i := 0; i < m.Session.GetOpponentCount(game.PlayerActorID); i++ {
if m.zones.Get(fmt.Sprintf("%s%d", ZoneEnemy, i)).InBounds(m.LastMouse) {
cmds = append(cmds, root.TooltipCreate(root.Tooltip{
ID: "ENEMY",
Content: m.fightEnemyInspectTooltipView(),
X: m.LastMouse.X,
Y: m.LastMouse.Y,
}))
}
}
}
}
//
// Mouse
//
case tea.MouseMsg:
m.LastMouse = msg
if len(m.animations) == 0 {
if msg.Action == tea.MouseActionRelease && msg.Button == tea.MouseButtonLeft {
cmds = append(cmds, root.TooltipClear())
switch m.Session.GetGameState() {
case game.GameStateFight:
if m.zones.Get(ZoneEndTurn).InBounds(msg) {
m = m.finishTurn()
} else if m.zones.Get(ZonePlayerInspect).InBounds(msg) {
m.inPlayerView = true
}
}
}
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.Button == tea.MouseButtonLeft {
m.selectedOpponent = i
m = m.tryCast()
}
}
}
} else {
onCard := false
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.Button == tea.MouseButtonLeft) && m.selectedCard == i {
m = m.tryCast()
} else {
m.selectedCard = i
}
}
}
if !onCard && msg.Action == tea.MouseActionMotion {
m.selectedCard = -1
}
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
m.inEnemyView = true
}
}
}
}
}
}
}
//
// Window Size
//
case tea.WindowSizeMsg:
m.Size = msg
// Always pass size events
m.event, _ = m.event.Update(msg)
m.merchant, _ = m.merchant.Update(msg)
for i := range m.animations {
m.animations[i], _ = m.animations[i].Update(tea.WindowSizeMsg{Width: m.Size.Width, Height: m.fightEnemyViewHeight() + m.fightCardViewHeight() + 1})
}
}
//
// Updating
//
if len(m.animations) > 0 {
d, cmd := m.animations[0].Update(msg)
if d == nil {
m.animations = lo.Drop(m.animations, 1)
} else {
m.animations[0] = d
}
return m, cmd
}
switch m.Session.GetGameState() {
case game.GameStateFight:
case game.GameStateMerchant:
m.merchant, cmd = m.merchant.Update(msg)
cmds = append(cmds, cmd)
case game.GameStateEvent:
m.event, cmd = m.event.Update(msg)
cmds = append(cmds, cmd)
case game.GameStateGameOver:
return gameover.New(m.zones, m.Session, m.Start), nil
}
//
// Show "New Artifacts" / "New Cards" if there are any.
//
var stateCmds []tea.Cmd
m, stateCmds = m.checkStateChange()
cmds = append(cmds, stateCmds...)
return m, tea.Batch(cmds...)
}
func (m Model) View() string {
if !m.HasSize() {
return "..."
}
// Always finish death animations.
if len(m.animations) > 0 {
return lipgloss.JoinVertical(
lipgloss.Top,
m.fightStatusTop(),
m.animations[0].View(),
m.fightStatusBottom(),
)
}
switch m.Session.GetGameState() {
case game.GameStateFight:
if m.inEnemyView {
return lipgloss.JoinVertical(
lipgloss.Top,
m.fightStatusTop(),
m.fightEnemyInspectView(),
m.fightStatusBottom(),
)
}
if m.inPlayerView {
return lipgloss.JoinVertical(
lipgloss.Top,
m.fightStatusTop(),
m.playerInspectView(),
m.fightStatusBottom(),
)
}
return lipgloss.JoinVertical(
lipgloss.Top,
m.fightStatusTop(),
lipgloss.NewStyle().Width(m.Size.Width).Height(m.fightEnemyViewHeight()).Render(m.fightEnemyView()),
m.fightDivider(),
lipgloss.NewStyle().Width(m.Size.Width).Height(m.fightCardViewHeight()).Render(m.fightCardView()),
m.fightStatusBottom(),
)
case game.GameStateMerchant:
return lipgloss.JoinVertical(lipgloss.Top, m.fightStatusTop(), m.merchant.View())
case game.GameStateEvent:
return lipgloss.Place(m.Size.Width, m.Size.Height, lipgloss.Center, lipgloss.Center, m.event.View(), lipgloss.WithWhitespaceChars(" "))
}
return fmt.Sprintf("Unknown State: %s", m.Session.GetGameState())
}
func (m Model) checkStateChange() (Model, []tea.Cmd) {
var cmds []tea.Cmd
currentState := m.Session.GetGameState()
currentEvent := m.Session.GetEventID()
if currentState != m.lastGameState || currentEvent != m.lastEvent {
diff := m.BeforeStateSwitch.Diff(m.Session)
m.BeforeStateSwitch = m.Session.MarkState()
m.lastGameState = currentState
m.lastEvent = currentEvent
if len(diff) > 0 {
artifacts := lo.Map(lo.Filter(diff, func(item game.StateCheckpoint, index int) bool {
added, ok := item.Events[game.StateEventArtifactAdded].(game.StateEventArtifactAddedData)
return ok && !lo.SomeBy(diff, func(item game.StateCheckpoint) bool {
removed, ok := item.Events[game.StateEventArtifactRemoved].(game.StateEventArtifactRemovedData)
return ok && added.GUID == removed.GUID
})
}), func(item game.StateCheckpoint, index int) string {
return components.ArtifactCard(m.Session, item.Events[game.StateEventArtifactAdded].(game.StateEventArtifactAddedData).GUID, 20, 45)
})
cards := lo.Map(lo.Filter(diff, func(item game.StateCheckpoint, index int) bool {
added, ok := item.Events[game.StateEventCardAdded].(game.StateEventCardAddedData)
return ok && !lo.SomeBy(diff, func(item game.StateCheckpoint) bool {
removed, ok := item.Events[game.StateEventCardRemoved].(game.StateEventCardRemovedData)
return ok && added.GUID == removed.GUID
})
}), func(item game.StateCheckpoint, index int) string {
return components.HalfCard(m.Session, item.Events[game.StateEventCardAdded].(game.StateEventCardAddedData).GUID, false, 20, 20, false, 45, false)
})
var pushModels []tea.Model
if len(cards) > 0 {
c := carousel.New(nil, m.zones, fmt.Sprintf("%d New Cards", len(cards)), cards)
c.Size = m.Size
pushModels = append(pushModels, root.NewOnVisibleModel(c, func(model tea.Model) {
audio.Play("new_cards")
}))
}
if len(artifacts) > 0 {
c := carousel.New(nil, m.zones, fmt.Sprintf("%d New Artifacts", len(artifacts)), artifacts)
c.Size = m.Size
pushModels = append(pushModels, root.NewOnVisibleModel(c, func(model tea.Model) {
audio.Play("new_artifacts")
}))
}
if len(pushModels) > 0 {
cmds = append(cmds, root.PushAll(pushModels...))
}
}
cmds = append(cmds, tea.ClearScreen)
}
return m, cmds
}
//
// Actions
//
func (m Model) finishTurn() Model {
audio.Play("btn_complete")
before := m.Session.MarkState()
m.Session.FinishPlayerTurn()
damages := before.DiffEvent(m.Session, game.StateEventDamage)
if len(damages) > 0 {
hp := m.Session.GetPlayer().HP
var damageActors []game.Actor
var damageEnemies []*game.Enemy
var damageData []game.StateEventDamageData
for i := range damages {
dmg := damages[i].Events[game.StateEventDamage].(game.StateEventDamageData)
if dmg.Source == game.PlayerActorID {
continue
}
src := damages[i].Session.GetActor(dmg.Source)
damageData = append(damageData, dmg)
damageEnemies = append(damageEnemies, damages[i].Session.GetEnemy(src.TypeID))
damageActors = append(damageActors, src)
hp += dmg.Damage
}
m.animations = append(m.animations, NewDamageAnimationModel(m.Size.Width, m.fightEnemyViewHeight()+m.fightCardViewHeight()+1, hp, damageActors, damageEnemies, damageData))
}
m.animations = append(m.animations, NewEndTurnAnimationModel(m.Size.Width, m.fightEnemyViewHeight()+m.fightCardViewHeight()+1, m.Session.GetFightRound()+1))
return m
}
func (m Model) tryCast() Model {
before := m.Session.MarkState()
hand := m.Session.GetFight().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 {
m.inOpponentSelection = false
if err := m.Session.PlayerCastHand(m.selectedCard, m.Session.GetOpponentByIndex(game.PlayerActorID, m.selectedOpponent).GUID); err == nil {
audio.Play("damage_1")
} else {
audio.Play("btn_deny")
}
} else {
audio.Play("btn_menu")
m.inOpponentSelection = true
}
} else {
if err := m.Session.PlayerCastHand(m.selectedCard, ""); err == nil {
audio.Play("btn_menu")
} else {
audio.Play("btn_deny")
}
}
}
// Check if any death occurred in this operation, so we can trigger animations.
diff := before.DiffEvent(m.Session, game.StateEventDeath)
m.animations = append(m.animations, lo.Map(diff, func(item game.StateCheckpoint, index int) tea.Model {
death := item.Events[game.StateEventDeath].(game.StateEventDeathData)
actor := item.Session.GetActor(death.Target)
enemy := m.Session.GetEnemy(actor.TypeID)
return NewDeathAnimationModel(m.Size.Width, m.fightEnemyViewHeight()+m.fightCardViewHeight()+1, actor, enemy, death)
})...)
return m
}
//
// Fight View
//
func (m Model) fightStatusTop() string {
fight := m.Session.GetFight()
player := m.Session.GetPlayer()
return components.Header(m.Size.Width, []components.HeaderValue{
components.NewHeaderValue(fmt.Sprintf("Gold: %d", player.Gold), lipgloss.Color("#FFFF00")),
components.NewHeaderValue(fmt.Sprintf("HP: %d / %d", player.HP, player.MaxHP), style.BaseRed),
components.NewHeaderValue(fmt.Sprintf("%d. Stage", m.Session.GetStagesCleared()+1), style.BaseWhite),
components.NewHeaderValue(fmt.Sprintf("%d. Round", fight.Round+1), style.BaseWhite),
}, fight.Description)
}
func (m Model) fightDivider() string {
if m.inOpponentSelection {
const message = " Select a target for your card... "
return lipgloss.Place(m.Size.Width, 1, lipgloss.Center, lipgloss.Center, style.RedText.Bold(true).Render(message), lipgloss.WithWhitespaceForeground(style.BaseGrayDarker), lipgloss.WithWhitespaceChars("─"))
}
return lipgloss.NewStyle().Foreground(style.BaseGrayDarker).Render(strings.Repeat("─", m.Size.Width))
}
func (m Model) fightStatusBottom() string {
outerStyle := lipgloss.NewStyle().
Width(m.Size.Width).
Foreground(style.BaseWhite).
Border(lipgloss.BlockBorder(), true, false, false, false).
BorderForeground(style.BaseRedDarker)
fight := m.Session.GetFight()
return outerStyle.Render(lipgloss.JoinHorizontal(
lipgloss.Center,
lipgloss.Place(m.Size.Width-40, 3, lipgloss.Left, lipgloss.Center, lipgloss.JoinHorizontal(
lipgloss.Center,
lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(style.BaseWhite)).Padding(0, 4, 0, 4).Render(fmt.Sprintf("Deck: %d", len(fight.Deck))),
lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#FFFF00")).Padding(0, 4, 0, 0).Render(fmt.Sprintf("Used: %d", len(fight.Used))),
lipgloss.NewStyle().Bold(true).Foreground(style.BaseRed).Padding(0, 4, 0, 0).Render(fmt.Sprintf("Exhausted: %d", len(fight.Exhausted))),
lipgloss.NewStyle().Bold(true).Foreground(style.BaseGreen).Padding(0, 4, 0, 0).Render(fmt.Sprintf("Action Points: (%d) %s", fight.CurrentPoints, strings.Repeat("• ", fight.CurrentPoints))),
m.zones.Mark(ZonePlayerInspect, components.StatusEffects(m.Session, m.Session.GetPlayer())),
),
),
lipgloss.Place(40, 3, lipgloss.Right, lipgloss.Center, lipgloss.JoinHorizontal(
lipgloss.Center,
m.zones.Mark(ZoneEndTurn, style.HeaderStyle.Copy().Background(lo.Ternary(m.zones.Get(ZoneEndTurn).InBounds(m.LastMouse), style.BaseRed, style.BaseRedDarker)).Margin(0, 4, 0, 0).Render("End Turn")),
style.RedDarkerText.Render(`▀ █▌█▌▪
·██·
▪▐█·█▌`))),
))
}
func (m Model) fightEnemyViewHeight() int {
return m.Size.Height / 3
}
func (m Model) fightCardViewHeight() int {
return m.Size.Height - m.fightEnemyViewHeight() - 1 - 4 - 4
}
func (m Model) fightEnemyInspectTooltipView() string {
enemy := m.Session.GetOpponents(game.PlayerActorID)[m.selectedOpponent]
intend := lipgloss.NewStyle().Bold(true).Underline(true).Foreground(style.BaseWhite).Render("Intend:") + "\n\n" + m.Session.GetActorIntend(enemy.GUID) + "\n\n"
status := lipgloss.NewStyle().Bold(true).Underline(true).Foreground(style.BaseWhite).Render("Status Effects:") + "\n\n" + strings.Join(lo.Map(enemy.StatusEffects.ToSlice(), func(guid string, index int) string {
return components.StatusEffect(m.Session, guid) + ": " + m.Session.GetStatusEffectState(guid)
}), "\n\n")
return lipgloss.NewStyle().Border(lipgloss.ThickBorder(), true).Padding(1, 2).BorderForeground(style.BaseRedDarker).Render(
lipgloss.NewStyle().Width(30).Render(intend + status),
)
}
func (m Model) fightEnemyInspectView() string {
enemy := m.Session.GetOpponents(game.PlayerActorID)[m.selectedOpponent]
intend := lipgloss.NewStyle().Bold(true).Underline(true).Foreground(style.BaseWhite).Render("Intend:") + "\n\n" + m.Session.GetActorIntend(enemy.GUID) + "\n\n"
status := lipgloss.NewStyle().Bold(true).Underline(true).Foreground(style.BaseWhite).Render("Status Effects:") + "\n\n" + strings.Join(lo.Map(enemy.StatusEffects.ToSlice(), func(guid string, index int) string {
return components.StatusEffect(m.Session, guid) + ": " + m.Session.GetStatusEffectState(guid)
}), "\n\n")
return lipgloss.Place(m.Size.Width, m.fightEnemyViewHeight()+m.fightCardViewHeight()+1, lipgloss.Center, lipgloss.Center,
lipgloss.NewStyle().Border(lipgloss.ThickBorder(), true).Padding(1, 2).BorderForeground(style.BaseRedDarker).Render(
lipgloss.JoinHorizontal(lipgloss.Top,
lipgloss.NewStyle().Border(lipgloss.NormalBorder(), false, true, false, false).BorderForeground(style.BaseGrayDarker).Padding(0, 2, 2, 0).Render(components.Actor(m.Session, enemy, m.Session.GetEnemy(enemy.TypeID), true, true, false)),
lipgloss.NewStyle().Margin(0, 0, 0, 3).Width(30).Render(intend+status+"\n\n"+style.GrayText.Render("press 'esc' to close")),
),
),
lipgloss.WithWhitespaceChars("?"), lipgloss.WithWhitespaceForeground(style.BaseGrayDarker),
)
}
func (m Model) playerInspectView() string {
player := m.Session.GetPlayer()
status := lipgloss.NewStyle().Bold(true).Underline(true).Foreground(style.BaseWhite).Render("Status Effects:") + "\n\n" + strings.Join(lo.Map(player.StatusEffects.ToSlice(), func(guid string, index int) string {
return components.StatusEffect(m.Session, guid) + ": " + m.Session.GetStatusEffectState(guid)
}), "\n\n")
return lipgloss.Place(m.Size.Width, m.fightEnemyViewHeight()+m.fightCardViewHeight()+1, lipgloss.Center, lipgloss.Center,
lipgloss.NewStyle().Border(lipgloss.ThickBorder(), true).Padding(1, 2).BorderForeground(style.BaseRedDarker).Render(
lipgloss.JoinHorizontal(lipgloss.Top,
lipgloss.NewStyle().Margin(0, 0, 0, 3).Width(30).Render(
lipgloss.NewStyle().Foreground(style.BaseWhite).Bold(true).Underline(true).Render("Player Status")+"\n\n"+status+"\n\n"+style.GrayText.Render("press 'esc' to close"),
),
),
),
lipgloss.WithWhitespaceChars("?"), lipgloss.WithWhitespaceForeground(style.BaseGrayDarker),
)
}
func (m Model) fightEnemyView() string {
enemyBoxes := lo.Map(m.Session.GetOpponents(game.PlayerActorID), func(actor game.Actor, i int) string {
intend := m.Session.GetActorIntend(actor.GUID)
if len(intend) > 0 {
intend = "\n" + lipgloss.NewStyle().Italic(true).Foreground(style.BaseGray).Render(intend)
}
return components.Actor(
m.Session,
actor,
m.Session.GetEnemy(actor.TypeID),
true,
true,
m.inOpponentSelection && i == m.selectedOpponent || m.zones.Get(fmt.Sprintf("%s%d", ZoneEnemy, i)).InBounds(m.LastMouse),
intend,
)
})
enemyBoxes = lo.Map(enemyBoxes, func(item string, i int) string {
return m.zones.Mark(fmt.Sprintf("%s%d", ZoneEnemy, i), item)
})
return lipgloss.Place(m.Size.Width, m.fightEnemyViewHeight(), lipgloss.Center, lipgloss.Center, lipgloss.JoinHorizontal(lipgloss.Center, enemyBoxes...), lipgloss.WithWhitespaceChars(" "))
}
func (m Model) fightCardView() string {
fight := m.Session.GetFight()
var cardBoxes = lo.Map(fight.Hand, func(guid string, index int) string {
return components.HalfCard(m.Session, guid, index == m.selectedCard, m.fightCardViewHeight()/2, m.fightCardViewHeight()-1, len(fight.Hand)*35 >= m.Size.Width, 0, true)
})
cardBoxes = lo.Map(cardBoxes, func(item string, i int) string {
return m.zones.Mark(fmt.Sprintf("%s%d", ZoneCard, i), item)
})
return lipgloss.Place(m.Size.Width, m.fightCardViewHeight(), lipgloss.Center, lipgloss.Bottom, lipgloss.JoinHorizontal(lipgloss.Bottom, cardBoxes...), lipgloss.WithWhitespaceChars(" "))
}