Skip to content

Commit 994a4d5

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

17 files changed

Lines changed: 469 additions & 74 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: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package cmd
2+
3+
import (
4+
"strings"
5+
6+
"github.com/charmbracelet/bubbles/table"
7+
tea "github.com/charmbracelet/bubbletea"
8+
"github.com/charmbracelet/lipgloss"
9+
"github.com/dark0dave/infinity_dialog/pkg/components"
10+
"github.com/dark0dave/infinity_dialog/pkg/util"
11+
)
12+
13+
type dialogueTree struct {
14+
table table.Model
15+
}
16+
17+
func NewDialogueTree() dialogueTree {
18+
columns := []table.Column{
19+
{Title: "FileName", Width: int(0.2 * float64(width))},
20+
{Title: "Character Name", Width: int(0.2 * float64(width))},
21+
{Title: "Value", Width: int(0.55 * float64(width))},
22+
}
23+
24+
t := table.New(
25+
table.WithColumns(columns),
26+
table.WithFocused(true),
27+
table.WithHeight(height-len(columns)+4),
28+
)
29+
30+
s := table.DefaultStyles()
31+
s.Header = s.Header.
32+
BorderStyle(lipgloss.NormalBorder()).
33+
BorderForeground(lipgloss.Color("240")).
34+
BorderTop(true).
35+
BorderBottom(true).
36+
Bold(false)
37+
s.Selected = s.Selected.
38+
Foreground(lipgloss.Color("229")).
39+
Background(lipgloss.Color("57")).
40+
Bold(false)
41+
t.SetStyles(s)
42+
43+
return dialogueTree{table: t}
44+
}
45+
46+
func (d dialogueTree) Init() tea.Cmd {
47+
return nil
48+
}
49+
50+
func (d dialogueTree) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
51+
switch msg := msg.(type) {
52+
case SelectedFilePath:
53+
// TODO: This only works on banter files
54+
rows := []table.Row{}
55+
files, err := util.ReadFiles(string(msg), "d")
56+
for fileName, fileContents := range files {
57+
for _, line := range *fileContents {
58+
if strings.Contains(line, "/*") && (strings.Contains(line, "@") || strings.Contains(line, "==")) {
59+
var characterName String
60+
if strings.Contains(line, "@") && strings.Contains(line, "==") {
61+
characterName = strings.Split(line, " ")[1]
62+
}
63+
64+
rows = append(rows, table.Row{
65+
fileName,
66+
})
67+
}
68+
}
69+
}
70+
if err != nil {
71+
return d, nil
72+
}
73+
d.table.SetRows(rows)
74+
case tea.WindowSizeMsg:
75+
h, w := docStyle.GetFrameSize()
76+
components.DynamicalSetTableSize(&d.table, &msg, h, w)
77+
case tea.KeyMsg:
78+
switch msg.String() {
79+
case "q", "esc":
80+
return state.PreviousCommand(), nil
81+
case "ctrl+c", "ctrl+d":
82+
return d, tea.Quit
83+
}
84+
}
85+
var cmd tea.Cmd
86+
d.table, cmd = d.table.Update(msg)
87+
return d, cmd
88+
}
89+
90+
func (d dialogueTree) View() string {
91+
return d.table.View()
92+
}

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/list-varriables.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/charmbracelet/bubbles/table"
99
tea "github.com/charmbracelet/bubbletea"
1010
"github.com/charmbracelet/lipgloss"
11+
"github.com/dark0dave/infinity_dialog/pkg/components"
1112
"github.com/dark0dave/infinity_dialog/pkg/translation"
1213
"github.com/dark0dave/infinity_dialog/pkg/util"
1314
)
@@ -97,19 +98,7 @@ func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9798
h1, w1 := baseStyle.GetFrameSize()
9899
h += h1
99100
w += w1
100-
if msg.Height > h {
101-
l.table.SetHeight(msg.Height - h)
102-
}
103-
if msg.Width > w {
104-
ratio := float64(msg.Width - w)
105-
l.table.SetColumns([]table.Column{
106-
{Title: "FileName", Width: int(0.2 * ratio)},
107-
{Title: "Lang", Width: int(0.1 * ratio)},
108-
{Title: "Id", Width: int(0.05 * ratio)},
109-
{Title: "Value", Width: int(0.55 * ratio)},
110-
})
111-
l.table.SetWidth(int(ratio))
112-
}
101+
components.DynamicalSetTableSize(&l.table, &msg, h, w)
113102
case tea.KeyMsg:
114103
switch msg.String() {
115104
case "q", "esc":

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,

0 commit comments

Comments
 (0)