-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitial.go
More file actions
111 lines (101 loc) · 3.38 KB
/
initial.go
File metadata and controls
111 lines (101 loc) · 3.38 KB
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
package cmd
import (
"os"
list "github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/dark0dave/infinity_dialog/pkg/nav"
)
var (
state = nav.NewState()
docStyle = lipgloss.NewStyle().Margin(1, 2)
width = 0
height = 0
)
type item struct {
title, desc string
}
func (i item) Title() string { return i.title }
func (i item) Description() string { return i.desc }
func (i item) FilterValue() string { return i.title }
type initial struct {
list list.Model
}
func InitialModel() initial {
items := []list.Item{
item{title: "Check", desc: "Check all strings in a mod/directory"},
item{title: "Discover", desc: "Find all strings in a mod/directory"},
item{title: "Traverse", desc: "Show tree of locations through a mod"},
item{title: "View", desc: "View any Infinity Engine file or text file"},
item{title: "Dialogue Tree", desc: "View the Dialogue tree of a mod"},
// TODO: Implement these
// item{title: "Add", desc: "Add strings to tra"},
// item{title: "Range", desc: "What range of numbers are free"},
// item{title: "Convert", desc: "Convert files to be traified"},
// item{title: "Decompiler", desc: "Dialogue decompiler"},
}
i := initial{
list: list.New(items, list.NewDefaultDelegate(), 0, 0),
}
i.list.Title = "Infinity Dialogue"
return i
}
func (i initial) Init() tea.Cmd {
return nil
}
func (i initial) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
h, v := docStyle.GetFrameSize()
i.list.SetSize(msg.Width-h, msg.Height-v)
height, width = max(msg.Height, height), max(msg.Width, width)
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "ctrl+d", "q":
return i, tea.Quit
case "enter", " ":
state = nav.NewState()
current_path, err := os.Getwd()
if err != nil {
return i, tea.Quit
}
switch i.list.SelectedItem().FilterValue() {
case "Check":
d := NewDirectoryPicker(true, "Select a Mod Directory to start")
c := NewCheck()
f := NewFileView()
state.SetNextCommand(d).SetNextCommand(c).SetNextCommand(f)
return state.SetAndGetNextCommand(i), SendSelectedFile(current_path)
case "Discover":
d := NewDirectoryPicker(true, "Select a Mod Directory to start")
l := NewList()
f := NewFileView()
state.SetNextCommand(d).SetNextCommand(l).SetNextCommand(f)
return state.SetAndGetNextCommand(i), SendSelectedFile(current_path)
case "Traverse":
d := NewDirectoryPicker(true, "Select a Mod Directory to start")
f := NewDirectoryPicker(false, "Select an area to start")
t := NewTree()
v := NewFileView()
state.SetNextCommand(d).SetNextCommand(f).SetNextCommand(t).SetNextCommand(v)
return state.SetAndGetNextCommand(i), SendSelectedFile(current_path)
case "View":
d := NewDirectoryPicker(false, "Select a Mod Directory to start")
v := NewFileView()
state.SetNextCommand(d).SetNextCommand(v)
return state.SetAndGetNextCommand(i), SendSelectedFile(current_path)
case "Dialogue Tree":
d := NewDirectoryPicker(true, "Select a Mod Directory to start")
t := NewDialogueTree()
state.SetNextCommand(d).SetNextCommand(t)
return state.SetAndGetNextCommand(i), SendSelectedFile(current_path)
}
}
}
var cmd tea.Cmd
i.list, cmd = i.list.Update(msg)
return i, cmd
}
func (i initial) View() string {
return docStyle.Render(i.list.View())
}