Skip to content

Commit 8d6096e

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

7 files changed

Lines changed: 103 additions & 7 deletions

File tree

.vscode/launch.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"mode": "remote",
1212
"port": 2345,
1313
"host": "127.0.0.1",
14-
"showLog": true,
15-
"preLaunchTask": "dlv debug --headless --api-version=2 --listen=0.0.0.0:2345 || reset"
14+
"showLog": true
1615
}
1716
]
1817
}

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: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
"strconv"
8+
9+
"github.com/The-Mod-Elephant/infinity_file_formats/bg"
10+
"github.com/charmbracelet/bubbles/key"
11+
"github.com/charmbracelet/bubbles/table"
12+
tea "github.com/charmbracelet/bubbletea"
13+
)
14+
15+
type ModList struct {
16+
*table.Model
17+
}
18+
19+
func NewModList() ModList {
20+
columns := []table.Column{
21+
{Title: "Index", Width: int(0.1 * float64(width))},
22+
{Title: "Tp2 file", Width: int(0.35 * float64(width))},
23+
{Title: "Language", Width: int(0.1 * float64(width))},
24+
{Title: "Component", Width: int(0.1 * float64(width))},
25+
{Title: "Component name", Width: int(0.35 * float64(width))},
26+
}
27+
t := table.New(
28+
table.WithColumns(columns),
29+
table.WithFocused(true),
30+
table.WithHeight(height-7),
31+
)
32+
return ModList{&t}
33+
}
34+
35+
func (m ModList) Init() tea.Cmd {
36+
return nil
37+
}
38+
39+
func (m ModList) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
40+
if !m.Focused() {
41+
return m, nil
42+
}
43+
44+
switch msg := msg.(type) {
45+
case SelectedFilePath:
46+
path := filepath.Join(filepath.Clean(string(msg)), "weidu.log")
47+
file, err := os.Open(filepath.Clean(path))
48+
if err != nil {
49+
return m, tea.Quit
50+
}
51+
defer file.Close()
52+
log, err := bg.OpenLog(file)
53+
if err != nil {
54+
return m, tea.Quit
55+
}
56+
rows := []table.Row{}
57+
for i, c := range log.Components {
58+
items := []string{strconv.Itoa(i), fmt.Sprintf("%s%s%s", c.Name, string(os.PathSeparator), c.TpFile), c.Lang, c.Component, c.ComponentName}
59+
rows = append(rows, table.Row(items))
60+
}
61+
m.SetRows(rows)
62+
case tea.KeyMsg:
63+
switch {
64+
case key.Matches(msg, m.KeyMap.LineUp):
65+
m.MoveUp(1)
66+
case key.Matches(msg, m.KeyMap.LineDown):
67+
m.MoveDown(1)
68+
case key.Matches(msg, m.KeyMap.PageUp):
69+
m.MoveUp(m.Height())
70+
case key.Matches(msg, m.KeyMap.PageDown):
71+
m.MoveDown(m.Height())
72+
case key.Matches(msg, m.KeyMap.HalfPageUp):
73+
m.MoveUp(m.Height() / 2)
74+
case key.Matches(msg, m.KeyMap.HalfPageDown):
75+
m.MoveDown(m.Height() / 2)
76+
case key.Matches(msg, m.KeyMap.GotoTop):
77+
m.GotoTop()
78+
case key.Matches(msg, m.KeyMap.GotoBottom):
79+
m.GotoBottom()
80+
}
81+
switch msg.String() {
82+
case "q", "esc":
83+
return state.PreviousCommand(), nil
84+
case "ctrl+c", "ctrl+d":
85+
return m, tea.Quit
86+
}
87+
}
88+
89+
return m, nil
90+
}

cmd/tree.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func parseArea(nodes *[]tree.Node, path string, fileMap map[string]string) {
146146
return
147147
}
148148

149-
childName := fmt.Sprintf("%s.%s", strings.Split(strings.ToLower(string(area.Offsets.Script.Name[:])), "\x00")[0], "baf")
149+
childName := fmt.Sprintf("%s.%s", strings.Split(strings.ToLower(string(area.Script[:])), "\x00")[0], "baf")
150150
filePath := fileMap[childName]
151151

152152
parent := tree.Node{
@@ -165,7 +165,7 @@ func parseArea(nodes *[]tree.Node, path string, fileMap map[string]string) {
165165
}
166166

167167
for _, entrance := range area.Entrances {
168-
areaName := fmt.Sprintf("%s.%s", strings.ToLower(string(entrance.Name.Value[:])), "are")
168+
areaName := fmt.Sprintf("%s.%s", strings.ToLower(string(entrance.Name[:])), "are")
169169
areaPath := fileMap[childName]
170170
if !presentInTopOfTree(*nodes, areaName) {
171171
parseArea(nodes, areaPath, fileMap)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/The-Mod-Elephant/infinity_dialog
33
go 1.24
44

55
require (
6-
github.com/The-Mod-Elephant/infinity_file_formats v0.6.1
6+
github.com/The-Mod-Elephant/infinity_file_formats v0.6.2
77
github.com/charmbracelet/bubbles v0.20.0
88
github.com/charmbracelet/bubbletea v1.2.4
99
github.com/charmbracelet/lipgloss v1.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2-
github.com/The-Mod-Elephant/infinity_file_formats v0.6.1 h1:ZqEGSWoRgx6vULeI93axNtDXzhKWmLZABtsVwHkz8vg=
3-
github.com/The-Mod-Elephant/infinity_file_formats v0.6.1/go.mod h1:tbwTKZowSqG5PgMrSV6QzXsGVEc05i9prpKWaruoXhM=
2+
github.com/The-Mod-Elephant/infinity_file_formats v0.6.2 h1:9nkf6KH5IRvKk+Kymb8F9HTa9vuTqAACGyexOKlKj40=
3+
github.com/The-Mod-Elephant/infinity_file_formats v0.6.2/go.mod h1:tbwTKZowSqG5PgMrSV6QzXsGVEc05i9prpKWaruoXhM=
44
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
55
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
66
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b h1:slYM766cy2nI3BwyRiyQj/Ud48djTMtMebDqepE95rw=

shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{ pkgs ? import <nixpkgs> {} }:
22
pkgs.mkShell {
33
buildInputs = with pkgs; [
4+
delve
45
git
56
go
67
golangci-lint

0 commit comments

Comments
 (0)