Skip to content

Commit 5c3a621

Browse files
committed
feat(human): Add human readable tree
Signed-off-by: dark0dave <dark0dave@mykolab.com>
1 parent d3a33e8 commit 5c3a621

15 files changed

Lines changed: 424 additions & 61 deletions

.envrc-sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set -a
2+
use nix
3+
mkdir -p $TMPDIR

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ go.work
2323
go.work.sum
2424

2525
# env file
26-
.env
26+
.envrc
2727

2828
# Our files
2929
weidu*
@@ -40,3 +40,6 @@ infinity_dialog*
4040
# Log files
4141
debug.log
4242
__debug*
43+
44+
# bins
45+
infinity_dialog

.vscode/launch.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
52
"version": "0.2.0",
63
"configurations": [
74
{
@@ -10,7 +7,7 @@
107
"request": "attach",
118
"mode": "remote",
129
"port": 2345,
13-
"host": "127.0.0.1",
10+
"host": "0.0.0.0",
1411
"showLog": true
1512
}
1613
]

CONTRIBUTING.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Contributing to Mod Installer
2+
3+
First off, thank you for considering contributing to Mod Installer. It's people like you that make Mod Installer such a great tool.
4+
5+
## Code of Conduct
6+
7+
By participating in this project, you are expected to uphold our Code of Conduct. Please report unacceptable behavior to [PROJECT MAINTAINER EMAIL].
8+
9+
## How Can I Contribute?
10+
11+
### Reporting Bugs
12+
13+
This section guides you through submitting a bug report for Mod Installer. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports.
14+
15+
- Use a clear and descriptive title for the issue to identify the problem.
16+
- Describe the exact steps which reproduce the problem in as many details as possible.
17+
- Provide specific examples to demonstrate the steps.
18+
19+
### Suggesting Enhancements
20+
21+
This section guides you through submitting an enhancement suggestion for Mod Installer, including completely new features and minor improvements to existing functionality.
22+
23+
- Use a clear and descriptive title for the issue to identify the suggestion.
24+
- Provide a step-by-step description of the suggested enhancement in as many details as possible.
25+
- Provide specific examples to demonstrate the steps.
26+
27+
### Pull Requests
28+
29+
- Fill in the required template
30+
- Do not include issue numbers in the PR title
31+
- Include screenshots and animated GIFs in your pull request whenever possible.
32+
- Follow the Rust styleguides.
33+
- Include thoughtfully-worded, well-structured tests.
34+
- Document new code based on the Documentation Styleguide
35+
- End all files with a newline
36+
37+
## Styleguides
38+
39+
### Git Commit Messages
40+
41+
- Use the present tense ("Add feature" not "Added feature")
42+
- Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
43+
- Limit the first line to 72 characters or less
44+
- Reference issues and pull requests liberally after the first line
45+
- Consider starting the commit message with an applicable emoji:
46+
- 🎨 `:art:` when improving the format/structure of the code
47+
- 🐎 `:racehorse:` when improving performance
48+
- 🚱 `:non-potable_water:` when plugging memory leaks
49+
- 📝 `:memo:` when writing docs
50+
- 🐧 `:penguin:` when fixing something on Linux
51+
- 🍎 `:apple:` when fixing something on macOS
52+
- 🏁 `:checkered_flag:` when fixing something on Windows
53+
- 🐛 `:bug:` when fixing a bug
54+
- 🔥 `:fire:` when removing code or files
55+
- 💚 `:green_heart:` when fixing the CI build
56+
-`:white_check_mark:` when adding tests
57+
- 🔒 `:lock:` when dealing with security
58+
- ⬆️ `:arrow_up:` when upgrading dependencies
59+
- ⬇️ `:arrow_down:` when downgrading dependencies
60+
61+
### Rust Styleguide
62+
63+
All Rust code should adhere to [Rust Style](https://doc.rust-lang.org/beta/style-guide/index.html) and be formatted using `cargo fmt`.
64+
65+
## Additional Notes
66+
67+
### Issue and Pull Request Labels
68+
69+
This section lists the labels we use to help us track and manage issues and pull requests.
70+
71+
* `bug` - Issues that are bugs.
72+
* `enhancement` - Issues that are feature requests.
73+
* `documentation` - Issues or pull requests related to documentation.
74+
* `good first issue` - Good for newcomers.
75+
76+
### Thank you!
77+
78+
Your contributions to open source, large or small, make great projects like this possible. Thank you for taking the time to contribute.

cmd/check-varriables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (c *checkVariables) genRows() *[]table.Row {
100100
}
101101
}
102102
out := []table.Row{}
103-
for lang, _ := range rows {
103+
for lang := range rows {
104104
for filename, stringVariables := range largest {
105105
size_for_lang := rows[lang][filename]
106106
sliceDiff := util.SortedDifference(&stringVariables, &size_for_lang)

cmd/dialogue-tree.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package cmd
2+
3+
import (
4+
"strings"
5+
6+
"github.com/charmbracelet/bubbles/viewport"
7+
tea "github.com/charmbracelet/bubbletea"
8+
"github.com/dark0dave/infinity_dialog/pkg/util"
9+
)
10+
11+
type dialogueTree struct {
12+
CurrentDirectory string
13+
content []string
14+
viewport viewport.Model
15+
}
16+
17+
func NewDialogueTree() dialogueTree {
18+
return dialogueTree{}
19+
}
20+
21+
func (d *dialogueTree) setViewport(msg tea.WindowSizeMsg) {
22+
d.viewport.YPosition = msg.Height
23+
d.viewport.Width = msg.Width
24+
d.viewport.Height = msg.Height
25+
}
26+
27+
func (d dialogueTree) Init() tea.Cmd {
28+
return nil
29+
}
30+
31+
func (d dialogueTree) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
32+
switch msg := msg.(type) {
33+
case SelectedFilePath:
34+
d.CurrentDirectory = string(msg)
35+
// TODO: This only works on banter files
36+
files, err := util.ReadFiles(d.CurrentDirectory, "d")
37+
for _, fileContents := range files {
38+
for _, line := range *fileContents {
39+
if strings.Contains(line, "/*") && (strings.Contains(line, "@") || strings.Contains(line, "==")) {
40+
d.content = append(d.content, line)
41+
}
42+
}
43+
}
44+
if err != nil {
45+
return d, nil
46+
}
47+
d.viewport.SetContent(strings.Join(d.content, "\n"))
48+
d.viewport.Height = height
49+
d.viewport.Width = width
50+
case tea.WindowSizeMsg:
51+
d.setViewport(msg)
52+
case tea.KeyMsg:
53+
switch msg.String() {
54+
case "q", "esc":
55+
return state.PreviousCommand(), nil
56+
case "ctrl+c", "ctrl+d":
57+
return d, tea.Quit
58+
}
59+
}
60+
var cmd tea.Cmd
61+
d.viewport, cmd = d.viewport.Update(msg)
62+
return d, cmd
63+
}
64+
65+
func (d dialogueTree) View() string {
66+
out := d.viewport.View()
67+
return out
68+
}

cmd/file-view.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ func NewFileView() fileview {
4444
return f
4545
}
4646

47-
func GetFileContents(path string) (string, string) {
47+
func GetFileContents(path string) (*string, string) {
4848
dir := filepath.Base(path)
4949
content := ""
50-
f, err := os.Open(path)
51-
if err != nil {
52-
}
50+
f, _ := os.Open(path)
5351
defer f.Close()
5452
switch strings.ToLower(filepath.Ext(path)) {
5553
case ".are":
@@ -120,12 +118,12 @@ func GetFileContents(path string) (string, string) {
120118
}
121119
content = buf.String()
122120
default:
123-
content, err = util.ReadFileToString(path)
121+
content, err := util.ReadFileToString(path)
124122
if err != nil {
125123
return content, dir
126124
}
127125
}
128-
return content, dir
126+
return &content, dir
129127
}
130128

131129
func (f fileview) Init() tea.Cmd {
@@ -143,13 +141,13 @@ func (f fileview) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
143141
return f, f.Init()
144142
case SelectedFilePath:
145143
content, title := GetFileContents(string(msg))
146-
f.content = content
144+
f.content = *content
147145
f.viewport.SetContent(f.content)
148146
f.title = title
149147
return f, f.Init()
150148
case PathMsg:
151149
content, title := GetFileContents(string(msg))
152-
f.content = content
150+
f.content = *content
153151
f.viewport.SetContent(f.content)
154152
f.title = title
155153
return f, f.Init()

cmd/initial.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func InitialModel() initial {
3434
item{title: "Discover", desc: "Find all strings in a mod/directory"},
3535
item{title: "Traverse", desc: "Show tree of locations through a mod"},
3636
item{title: "View", desc: "View any Infinity Engine file or text file"},
37+
item{title: "Dialogue Tree", desc: "View the Dialogue tree of a mod"},
3738
// TODO: Implement these
3839
// item{title: "Add", desc: "Add strings to tra"},
3940
// item{title: "Range", desc: "What range of numbers are free"},
@@ -69,29 +70,34 @@ func (i initial) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6970
}
7071
switch i.list.SelectedItem().FilterValue() {
7172
case "Check":
72-
d := NewDirectoryPicker(true, "Select a Mod Directory")
73+
d := NewDirectoryPicker(true, "Select a Mod Directory to start")
7374
c := NewCheck()
7475
f := NewFileView()
7576
state.SetNextCommand(d).SetNextCommand(c).SetNextCommand(f)
7677
return state.SetAndGetNextCommand(i), SendSelectedFile(current_path)
7778
case "Discover":
78-
d := NewDirectoryPicker(true, "Select a Mod Directory")
79+
d := NewDirectoryPicker(true, "Select a Mod Directory to start")
7980
l := NewList()
8081
f := NewFileView()
8182
state.SetNextCommand(d).SetNextCommand(l).SetNextCommand(f)
8283
return state.SetAndGetNextCommand(i), SendSelectedFile(current_path)
8384
case "Traverse":
84-
d := NewDirectoryPicker(true, "Select a Mod Directory")
85+
d := NewDirectoryPicker(true, "Select a Mod Directory to start")
8586
f := NewDirectoryPicker(false, "Select an area to start")
8687
t := NewTree()
8788
v := NewFileView()
8889
state.SetNextCommand(d).SetNextCommand(f).SetNextCommand(t).SetNextCommand(v)
8990
return state.SetAndGetNextCommand(i), SendSelectedFile(current_path)
9091
case "View":
91-
d := NewDirectoryPicker(false, "Select a file to start")
92+
d := NewDirectoryPicker(false, "Select a Mod Directory to start")
9293
v := NewFileView()
9394
state.SetNextCommand(d).SetNextCommand(v)
9495
return state.SetAndGetNextCommand(i), SendSelectedFile(current_path)
96+
case "Dialogue Tree":
97+
d := NewDirectoryPicker(true, "Select a Mod Directory to start")
98+
t := NewDialogueTree()
99+
state.SetNextCommand(d).SetNextCommand(t)
100+
return state.SetAndGetNextCommand(i), SendSelectedFile(current_path)
95101
}
96102
}
97103
}

cmd/tree.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,12 @@ func findChildren(path string, file_map *map[string]string, nodes *[]tree.Node,
175175
return nil
176176
}
177177
contents, err := util.ReadFileToString(path)
178-
contents = strings.ToLower(contents)
179178
if err != nil {
180179
return err
181180
}
182181
filename := filepath.Base(path)
183182
for k, v := range *file_map {
184-
if k != filename && strings.Contains(contents, "\""+k[:len(k)-4]+"\")") {
183+
if k != filename && strings.Contains(strings.ToLower(*contents), "\""+k[:len(k)-4]+"\")") {
185184
child.Children = append(child.Children, tree.Node{
186185
Value: k,
187186
Desc: v,

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
module github.com/dark0dave/infinity_dialog
22

3-
go 1.23
3+
go 1.23.0
44

55
require (
66
github.com/charmbracelet/bubbles v0.20.0
7-
github.com/charmbracelet/bubbletea v1.2.4
7+
github.com/charmbracelet/bubbletea v1.3.4
88
github.com/charmbracelet/lipgloss v1.0.0
9-
github.com/dark0dave/infinity_file_formats v0.0.0-20241205000111-f0cefbb38b7d
9+
github.com/dark0dave/infinity_file_formats v0.0.0-20250208171459-bfc2e8c1d507
1010
github.com/savannahostrowski/tree-bubble v0.0.0-20230724043728-d7bb06a8a67e
11-
golang.org/x/text v0.21.0
11+
golang.org/x/text v0.23.0
1212
)
1313

1414
require (
1515
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect
1616
github.com/atotto/clipboard v0.1.4 // indirect
1717
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
18-
github.com/charmbracelet/x/ansi v0.5.2 // indirect
18+
github.com/charmbracelet/x/ansi v0.8.0 // indirect
1919
github.com/charmbracelet/x/term v0.2.1 // indirect
2020
github.com/dustin/go-humanize v1.0.1 // indirect
2121
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
@@ -25,10 +25,10 @@ require (
2525
github.com/mattn/go-runewidth v0.0.16 // indirect
2626
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
2727
github.com/muesli/cancelreader v0.2.2 // indirect
28-
github.com/muesli/termenv v0.15.2 // indirect
28+
github.com/muesli/termenv v0.16.0 // indirect
2929
github.com/rivo/uniseg v0.4.7 // indirect
3030
github.com/sahilm/fuzzy v0.1.1 // indirect
3131
github.com/ulikunitz/xz v0.5.12 // indirect
32-
golang.org/x/sync v0.10.0 // indirect
33-
golang.org/x/sys v0.28.0 // indirect
32+
golang.org/x/sync v0.12.0 // indirect
33+
golang.org/x/sys v0.31.0 // indirect
3434
)

0 commit comments

Comments
 (0)