-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookdetails_view.go
55 lines (46 loc) · 1.27 KB
/
bookdetails_view.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
package main
import (
"game/engine/theme"
"strconv"
tea "github.com/charmbracelet/bubbletea"
)
type ObjectDetailsModel struct {
cursor int
object any
dm *DashboardModel
}
func InitialBookDetailsModel(object any, dm *DashboardModel) ObjectDetailsModel {
return ObjectDetailsModel{cursor: 0, object: object, dm: dm}
}
func (m ObjectDetailsModel) Init() tea.Cmd {
return nil
}
func (m ObjectDetailsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case tea.KeyCtrlC.String(), tea.KeyEsc.String():
return InitialRootModel().SwitchScreen(m.dm)
}
}
return m, nil
}
func (m ObjectDetailsModel) View() string {
s := ""
switch obj := m.object.(type) {
case Book:
s += theme.Heading1.Render(obj.Name)
s += "\n"
s += theme.Heading2.Render(obj.Author)
s += "\n\n"
s += "Knowledge Gain: " + strconv.Itoa(obj.KnowledgeIncrease) + "\n"
s += "This book increases your IQ by " + strconv.Itoa(obj.IntelligenceIncrease) + " on your first read.\n"
case Item:
s += theme.Heading1.Render(obj.Name)
s += "\n\n"
s += obj.Description
s += "\n"
s += obj.Effect
}
return s + "\n\n" + theme.HelpIcon.Render("esc") + theme.HelpText.Render(" back")
}