Skip to content

Commit d51f87d

Browse files
committed
feat(mods): Add mod list command
Signed-off-by: dark0dave <dark0dave@mykolab.com>
1 parent 82cffba commit d51f87d

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

cmd/initial.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func InitialModel() Initial {
3838
Item{title: "Discover", desc: "Find all strings in a mod/directory"},
3939
Item{title: "Traverse", desc: "Show tree of locations through a mod"},
4040
Item{title: "View", desc: "View any Infinity Engine file or text file"},
41+
Item{title: "Mods", desc: "View what mods are installed, in a game directory"},
4142
// TODO: Implement these
4243
// item{title: "Add", desc: "Add strings to tra"},
4344
// item{title: "Range", desc: "What range of numbers are free"},
@@ -96,6 +97,11 @@ func (i Initial) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9697
v := NewFileView()
9798
state.SetNextCommand(d).SetNextCommand(v)
9899
return state.SetAndGetNextCommand(i), SendSelectedFile(currentPath)
100+
case "Mods":
101+
d := NewDirectoryPicker(true, "Select a game directory folder (BGEE, BG2EE, or EET)")
102+
m := NewModList()
103+
state.SetNextCommand(d).SetNextCommand(m)
104+
return state.SetAndGetNextCommand(i), SendSelectedFile(currentPath)
99105
}
100106
}
101107
}

cmd/mods.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package cmd
2+
3+
import (
4+
"path/filepath"
5+
6+
"github.com/The-Mod-Elephant/infinity_dialog/pkg/readers"
7+
"github.com/charmbracelet/bubbles/key"
8+
"github.com/charmbracelet/bubbles/table"
9+
tea "github.com/charmbracelet/bubbletea"
10+
)
11+
12+
type ModList struct {
13+
*table.Model
14+
}
15+
16+
func NewModList() ModList {
17+
columns := []table.Column{
18+
{Title: "Index", Width: int(0.1 * float64(width))},
19+
{Title: "Tp2 file", Width: int(0.35 * float64(width))},
20+
{Title: "Language", Width: int(0.1 * float64(width))},
21+
{Title: "Component", Width: int(0.1 * float64(width))},
22+
{Title: "Component name", Width: int(0.35 * float64(width))},
23+
}
24+
t := table.New(
25+
table.WithColumns(columns),
26+
table.WithFocused(true),
27+
table.WithHeight(height-7),
28+
)
29+
return ModList{&t}
30+
}
31+
32+
func (m ModList) Init() tea.Cmd {
33+
return nil
34+
}
35+
36+
func (m ModList) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
37+
if !m.Focused() {
38+
return m, nil
39+
}
40+
41+
switch msg := msg.(type) {
42+
case PathMsg:
43+
path := filepath.Join("weidu.log", filepath.Clean(string(msg)))
44+
_, err := readers.ReadFileToSlice(path)
45+
if err != nil {
46+
return m, tea.Quit
47+
}
48+
49+
case tea.KeyMsg:
50+
switch {
51+
case key.Matches(msg, m.KeyMap.LineUp):
52+
m.MoveUp(1)
53+
case key.Matches(msg, m.KeyMap.LineDown):
54+
m.MoveDown(1)
55+
case key.Matches(msg, m.KeyMap.PageUp):
56+
m.MoveUp(m.Height())
57+
case key.Matches(msg, m.KeyMap.PageDown):
58+
m.MoveDown(m.Height())
59+
case key.Matches(msg, m.KeyMap.HalfPageUp):
60+
m.MoveUp(m.Height() / 2)
61+
case key.Matches(msg, m.KeyMap.HalfPageDown):
62+
m.MoveDown(m.Height() / 2)
63+
case key.Matches(msg, m.KeyMap.GotoTop):
64+
m.GotoTop()
65+
case key.Matches(msg, m.KeyMap.GotoBottom):
66+
m.GotoBottom()
67+
}
68+
}
69+
70+
return m, nil
71+
}

0 commit comments

Comments
 (0)