From 994a4d57a20448733760fdf42eef35d4d2dba7ea Mon Sep 17 00:00:00 2001 From: dark0dave Date: Fri, 7 Mar 2025 11:08:16 +0000 Subject: [PATCH] feat(human): Add human readable tree Signed-off-by: dark0dave --- .envrc-sample | 3 ++ .gitignore | 5 +- .vscode/launch.json | 5 +- CONTRIBUTING.md | 78 +++++++++++++++++++++++++++++ cmd/check-varriables.go | 2 +- cmd/dialogue-tree.go | 92 ++++++++++++++++++++++++++++++++++ cmd/file-view.go | 14 +++--- cmd/initial.go | 14 ++++-- cmd/list-varriables.go | 15 +----- cmd/tree.go | 3 +- go.mod | 16 +++--- go.sum | 28 +++++------ pkg/characters/bg1_names.go | 96 ++++++++++++++++++++++++++++++++++++ pkg/characters/bg2_names.go | 98 +++++++++++++++++++++++++++++++++++++ pkg/components/table.go | 19 +++++++ pkg/util/read.go | 41 +++++++++------- shell.nix | 14 ++++++ 17 files changed, 469 insertions(+), 74 deletions(-) create mode 100644 .envrc-sample create mode 100644 CONTRIBUTING.md create mode 100644 cmd/dialogue-tree.go create mode 100644 pkg/characters/bg1_names.go create mode 100644 pkg/characters/bg2_names.go create mode 100644 pkg/components/table.go create mode 100644 shell.nix diff --git a/.envrc-sample b/.envrc-sample new file mode 100644 index 0000000..223f788 --- /dev/null +++ b/.envrc-sample @@ -0,0 +1,3 @@ +set -a +use nix +mkdir -p $TMPDIR diff --git a/.gitignore b/.gitignore index ba727cb..74f2dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,7 @@ go.work go.work.sum # env file -.env +.envrc # Our files weidu* @@ -40,3 +40,6 @@ infinity_dialog* # Log files debug.log __debug* + +# bins +infinity_dialog diff --git a/.vscode/launch.json b/.vscode/launch.json index 5fb50f6..05cf551 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,7 +1,4 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { @@ -10,7 +7,7 @@ "request": "attach", "mode": "remote", "port": 2345, - "host": "127.0.0.1", + "host": "0.0.0.0", "showLog": true } ] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0edf8aa --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,78 @@ +# Contributing to Mod Installer + +First off, thank you for considering contributing to Mod Installer. It's people like you that make Mod Installer such a great tool. + +## Code of Conduct + +By participating in this project, you are expected to uphold our Code of Conduct. Please report unacceptable behavior to [PROJECT MAINTAINER EMAIL]. + +## How Can I Contribute? + +### Reporting Bugs + +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. + +- Use a clear and descriptive title for the issue to identify the problem. +- Describe the exact steps which reproduce the problem in as many details as possible. +- Provide specific examples to demonstrate the steps. + +### Suggesting Enhancements + +This section guides you through submitting an enhancement suggestion for Mod Installer, including completely new features and minor improvements to existing functionality. + +- Use a clear and descriptive title for the issue to identify the suggestion. +- Provide a step-by-step description of the suggested enhancement in as many details as possible. +- Provide specific examples to demonstrate the steps. + +### Pull Requests + +- Fill in the required template +- Do not include issue numbers in the PR title +- Include screenshots and animated GIFs in your pull request whenever possible. +- Follow the Rust styleguides. +- Include thoughtfully-worded, well-structured tests. +- Document new code based on the Documentation Styleguide +- End all files with a newline + +## Styleguides + +### Git Commit Messages + +- Use the present tense ("Add feature" not "Added feature") +- Use the imperative mood ("Move cursor to..." not "Moves cursor to...") +- Limit the first line to 72 characters or less +- Reference issues and pull requests liberally after the first line +- Consider starting the commit message with an applicable emoji: + - 🎨 `:art:` when improving the format/structure of the code + - 🐎 `:racehorse:` when improving performance + - 🚱 `:non-potable_water:` when plugging memory leaks + - 📝 `:memo:` when writing docs + - 🐧 `:penguin:` when fixing something on Linux + - 🍎 `:apple:` when fixing something on macOS + - 🏁 `:checkered_flag:` when fixing something on Windows + - 🐛 `:bug:` when fixing a bug + - 🔥 `:fire:` when removing code or files + - 💚 `:green_heart:` when fixing the CI build + - ✅ `:white_check_mark:` when adding tests + - 🔒 `:lock:` when dealing with security + - ⬆️ `:arrow_up:` when upgrading dependencies + - ⬇️ `:arrow_down:` when downgrading dependencies + +### Rust Styleguide + +All Rust code should adhere to [Rust Style](https://doc.rust-lang.org/beta/style-guide/index.html) and be formatted using `cargo fmt`. + +## Additional Notes + +### Issue and Pull Request Labels + +This section lists the labels we use to help us track and manage issues and pull requests. + +* `bug` - Issues that are bugs. +* `enhancement` - Issues that are feature requests. +* `documentation` - Issues or pull requests related to documentation. +* `good first issue` - Good for newcomers. + +### Thank you! + +Your contributions to open source, large or small, make great projects like this possible. Thank you for taking the time to contribute. diff --git a/cmd/check-varriables.go b/cmd/check-varriables.go index 0ead983..f7f40a6 100644 --- a/cmd/check-varriables.go +++ b/cmd/check-varriables.go @@ -100,7 +100,7 @@ func (c *checkVariables) genRows() *[]table.Row { } } out := []table.Row{} - for lang, _ := range rows { + for lang := range rows { for filename, stringVariables := range largest { size_for_lang := rows[lang][filename] sliceDiff := util.SortedDifference(&stringVariables, &size_for_lang) diff --git a/cmd/dialogue-tree.go b/cmd/dialogue-tree.go new file mode 100644 index 0000000..1008834 --- /dev/null +++ b/cmd/dialogue-tree.go @@ -0,0 +1,92 @@ +package cmd + +import ( + "strings" + + "github.com/charmbracelet/bubbles/table" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" + "github.com/dark0dave/infinity_dialog/pkg/components" + "github.com/dark0dave/infinity_dialog/pkg/util" +) + +type dialogueTree struct { + table table.Model +} + +func NewDialogueTree() dialogueTree { + columns := []table.Column{ + {Title: "FileName", Width: int(0.2 * float64(width))}, + {Title: "Character Name", Width: int(0.2 * float64(width))}, + {Title: "Value", Width: int(0.55 * float64(width))}, + } + + t := table.New( + table.WithColumns(columns), + table.WithFocused(true), + table.WithHeight(height-len(columns)+4), + ) + + s := table.DefaultStyles() + s.Header = s.Header. + BorderStyle(lipgloss.NormalBorder()). + BorderForeground(lipgloss.Color("240")). + BorderTop(true). + BorderBottom(true). + Bold(false) + s.Selected = s.Selected. + Foreground(lipgloss.Color("229")). + Background(lipgloss.Color("57")). + Bold(false) + t.SetStyles(s) + + return dialogueTree{table: t} +} + +func (d dialogueTree) Init() tea.Cmd { + return nil +} + +func (d dialogueTree) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case SelectedFilePath: + // TODO: This only works on banter files + rows := []table.Row{} + files, err := util.ReadFiles(string(msg), "d") + for fileName, fileContents := range files { + for _, line := range *fileContents { + if strings.Contains(line, "/*") && (strings.Contains(line, "@") || strings.Contains(line, "==")) { + var characterName String + if strings.Contains(line, "@") && strings.Contains(line, "==") { + characterName = strings.Split(line, " ")[1] + } + + rows = append(rows, table.Row{ + fileName, + }) + } + } + } + if err != nil { + return d, nil + } + d.table.SetRows(rows) + case tea.WindowSizeMsg: + h, w := docStyle.GetFrameSize() + components.DynamicalSetTableSize(&d.table, &msg, h, w) + case tea.KeyMsg: + switch msg.String() { + case "q", "esc": + return state.PreviousCommand(), nil + case "ctrl+c", "ctrl+d": + return d, tea.Quit + } + } + var cmd tea.Cmd + d.table, cmd = d.table.Update(msg) + return d, cmd +} + +func (d dialogueTree) View() string { + return d.table.View() +} diff --git a/cmd/file-view.go b/cmd/file-view.go index d8c9246..bf10211 100644 --- a/cmd/file-view.go +++ b/cmd/file-view.go @@ -44,12 +44,10 @@ func NewFileView() fileview { return f } -func GetFileContents(path string) (string, string) { +func GetFileContents(path string) (*string, string) { dir := filepath.Base(path) content := "" - f, err := os.Open(path) - if err != nil { - } + f, _ := os.Open(path) defer f.Close() switch strings.ToLower(filepath.Ext(path)) { case ".are": @@ -120,12 +118,12 @@ func GetFileContents(path string) (string, string) { } content = buf.String() default: - content, err = util.ReadFileToString(path) + content, err := util.ReadFileToString(path) if err != nil { return content, dir } } - return content, dir + return &content, dir } func (f fileview) Init() tea.Cmd { @@ -143,13 +141,13 @@ func (f fileview) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return f, f.Init() case SelectedFilePath: content, title := GetFileContents(string(msg)) - f.content = content + f.content = *content f.viewport.SetContent(f.content) f.title = title return f, f.Init() case PathMsg: content, title := GetFileContents(string(msg)) - f.content = content + f.content = *content f.viewport.SetContent(f.content) f.title = title return f, f.Init() diff --git a/cmd/initial.go b/cmd/initial.go index 0a4491a..c658576 100644 --- a/cmd/initial.go +++ b/cmd/initial.go @@ -34,6 +34,7 @@ func InitialModel() initial { 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"}, @@ -69,29 +70,34 @@ func (i initial) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } switch i.list.SelectedItem().FilterValue() { case "Check": - d := NewDirectoryPicker(true, "Select a Mod Directory") + 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") + 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") + 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 file to start") + 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) } } } diff --git a/cmd/list-varriables.go b/cmd/list-varriables.go index bd33d76..69e10cd 100644 --- a/cmd/list-varriables.go +++ b/cmd/list-varriables.go @@ -8,6 +8,7 @@ import ( "github.com/charmbracelet/bubbles/table" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/dark0dave/infinity_dialog/pkg/components" "github.com/dark0dave/infinity_dialog/pkg/translation" "github.com/dark0dave/infinity_dialog/pkg/util" ) @@ -97,19 +98,7 @@ func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) { h1, w1 := baseStyle.GetFrameSize() h += h1 w += w1 - if msg.Height > h { - l.table.SetHeight(msg.Height - h) - } - if msg.Width > w { - ratio := float64(msg.Width - w) - l.table.SetColumns([]table.Column{ - {Title: "FileName", Width: int(0.2 * ratio)}, - {Title: "Lang", Width: int(0.1 * ratio)}, - {Title: "Id", Width: int(0.05 * ratio)}, - {Title: "Value", Width: int(0.55 * ratio)}, - }) - l.table.SetWidth(int(ratio)) - } + components.DynamicalSetTableSize(&l.table, &msg, h, w) case tea.KeyMsg: switch msg.String() { case "q", "esc": diff --git a/cmd/tree.go b/cmd/tree.go index 089814d..9141334 100644 --- a/cmd/tree.go +++ b/cmd/tree.go @@ -175,13 +175,12 @@ func findChildren(path string, file_map *map[string]string, nodes *[]tree.Node, return nil } contents, err := util.ReadFileToString(path) - contents = strings.ToLower(contents) if err != nil { return err } filename := filepath.Base(path) for k, v := range *file_map { - if k != filename && strings.Contains(contents, "\""+k[:len(k)-4]+"\")") { + if k != filename && strings.Contains(strings.ToLower(*contents), "\""+k[:len(k)-4]+"\")") { child.Children = append(child.Children, tree.Node{ Value: k, Desc: v, diff --git a/go.mod b/go.mod index db3c9cd..558048a 100644 --- a/go.mod +++ b/go.mod @@ -1,21 +1,21 @@ module github.com/dark0dave/infinity_dialog -go 1.23 +go 1.23.0 require ( github.com/charmbracelet/bubbles v0.20.0 - github.com/charmbracelet/bubbletea v1.2.4 + github.com/charmbracelet/bubbletea v1.3.4 github.com/charmbracelet/lipgloss v1.0.0 - github.com/dark0dave/infinity_file_formats v0.0.0-20241205000111-f0cefbb38b7d + github.com/dark0dave/infinity_file_formats v0.0.0-20250208171459-bfc2e8c1d507 github.com/savannahostrowski/tree-bubble v0.0.0-20230724043728-d7bb06a8a67e - golang.org/x/text v0.21.0 + golang.org/x/text v0.23.0 ) require ( github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect - github.com/charmbracelet/x/ansi v0.5.2 // indirect + github.com/charmbracelet/x/ansi v0.8.0 // indirect github.com/charmbracelet/x/term v0.2.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect @@ -25,10 +25,10 @@ require ( github.com/mattn/go-runewidth v0.0.16 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect - github.com/muesli/termenv v0.15.2 // indirect + github.com/muesli/termenv v0.16.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/sahilm/fuzzy v0.1.1 // indirect github.com/ulikunitz/xz v0.5.12 // indirect - golang.org/x/sync v0.10.0 // indirect - golang.org/x/sys v0.28.0 // indirect + golang.org/x/sync v0.12.0 // indirect + golang.org/x/sys v0.31.0 // indirect ) diff --git a/go.sum b/go.sum index d93b77d..3dfe6e2 100644 --- a/go.sum +++ b/go.sum @@ -11,18 +11,18 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA= github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE= github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU= -github.com/charmbracelet/bubbletea v1.2.4 h1:KN8aCViA0eps9SCOThb2/XPIlea3ANJLUkv3KnQRNCE= -github.com/charmbracelet/bubbletea v1.2.4/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM= +github.com/charmbracelet/bubbletea v1.3.4 h1:kCg7B+jSCFPLYRA52SDZjr51kG/fMUEoPoZrkaDHyoI= +github.com/charmbracelet/bubbletea v1.3.4/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo= github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg= github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo= -github.com/charmbracelet/x/ansi v0.5.2 h1:dEa1x2qdOZXD/6439s+wF7xjV+kZLu/iN00GuXXrU9E= -github.com/charmbracelet/x/ansi v0.5.2/go.mod h1:KBUFw1la39nl0dLl10l5ORDAqGXaeurTQmwyyVKse/Q= +github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= +github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAMdlwSltxJyULnrYbkZpp4k58Co7Tah3ciKhSNo0Q= github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/dark0dave/infinity_file_formats v0.0.0-20241205000111-f0cefbb38b7d h1:MQ8pfkxWfGJ6pGbNIxjyXe2Cc3bOr6WEkiPfGmytV3E= -github.com/dark0dave/infinity_file_formats v0.0.0-20241205000111-f0cefbb38b7d/go.mod h1:UMjDDPYYSRO+nW/ptNX6IZyXi/N3CRpZmZuiIgAKnEo= +github.com/dark0dave/infinity_file_formats v0.0.0-20250208171459-bfc2e8c1d507 h1:vd1Fq7oT4SKJWHKtJxgRiNpMuulCkGKdzjGTH62vxjg= +github.com/dark0dave/infinity_file_formats v0.0.0-20250208171459-bfc2e8c1d507/go.mod h1:UMjDDPYYSRO+nW/ptNX6IZyXi/N3CRpZmZuiIgAKnEo= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= @@ -42,8 +42,8 @@ github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= -github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= -github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= +github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= +github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= @@ -63,20 +63,20 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= -golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= +golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= diff --git a/pkg/characters/bg1_names.go b/pkg/characters/bg1_names.go new file mode 100644 index 0000000..68ea0f8 --- /dev/null +++ b/pkg/characters/bg1_names.go @@ -0,0 +1,96 @@ +package characters + +const ( + BAJANT BG1_Characters = iota + BALORA + BBRANW + BCORAN + BDORN + BDYNAH + BEDWIN + BELDOT + BFALDO + BGARRI + BIMOEN + BJAHEI + BKAGAI + BKHALI + BKIVAN + BMINSC + BMONTA + BNEERA + BQUAYL + BRASAAD + BSAFAN + BSHART + BSKIE + BTIAX + BVICON + BXANNN + BXZAR + BYESLI +) + +type BG1_Characters int64 + +func (s BG1_Characters) String() string { + switch s { + case BKIVAN: + return "KIVAN" + case BALORA: + return "ALORA" + case BMINSC: + return "MINSC" + case BDYNAH: + return "DYNAHEIR" + case BYESLI: + return "YESLICK" + case BCORAN: + return "CORAN" + case BAJANT: + return "AJANTIS" + case BKHALI: + return "KHALID" + case BJAHEI: + return "JAHEIRA" + case BGARRI: + return "GARRICK" + case BSAFAN: + return "SAFANA" + case BFALDO: + return "FALDORN" + case BBRANW: + return "BRANWEN" + case BQUAYL: + return "QUAYLE" + case BXANNN: + return "XAN" + case BSKIE: + return "SKIE" + case BELDOT: + return "ELDOTH" + case BXZAR: + return "XZAR" + case BMONTA: + return "MONTARON" + case BTIAX: + return "TIAX" + case BKAGAI: + return "KAGAIN" + case BSHART: + return "SHARTEEL" + case BEDWIN: + return "EDWIN" + case BVICON: + return "VICONIA" + case BIMOEN: + return "IMOEN" + case BNEERA: + return "NEERA" + case BDORN: + return "DORN" + case BRASAAD: + return "RASAAD" + } + return "" +} diff --git a/pkg/characters/bg2_names.go b/pkg/characters/bg2_names.go new file mode 100644 index 0000000..004b415 --- /dev/null +++ b/pkg/characters/bg2_names.go @@ -0,0 +1,98 @@ +package characters + +const ( + BAERIE BG2_Characters = iota + BAERIE25 + BANOME25 + BANOMEN + BCERND + BCERND25 + BDORN25 + BEDWIN25 + BHAERD25 + BHAERDA + BHEXXA25 + BHEXXAT + BIMOEN2 + BIMOEN25 + BJAHEI25 + BJAHEIR + BJAN + BJAN25 + BKELDO25 + BKELDOR + BKORGA25 + BKORGAN + BMAZZY + BMAZZY25 + BMINSC25 + BNALIA + BNALIA25 + BNEERA25 + BRASAA25 + BSAREV25 + BVALYG25 + BVALYGA + BVICON25 + BVICONI + BYOSHIM + CERNDJ + DORNJ + WILSON + ZDBAE25B + ZDBAEB +) + +type BG2_Characters int64 + +func (s BG2_Characters) String() string { + switch s { + case BAERIE, BAERIE25: + return "Aerie" + case BANOMEN, BANOME25: + return "Anomen" + case BCERND, BCERND25: + return "Cernd" + case BEDWIN25: + return "Edwin" + case BJAHEIR, BJAHEI25: + return "Jaheria" + case BJAN, BJAN25: + return "Jan" + case BKELDOR, BKELDO25: + return "Keldorn" + case BKORGAN, BKORGA25: + return "Korgan" + case BHAERDA, BHAERD25: + return "Haedalis" + case BMAZZY, BMAZZY25: + return "Mazzy" + case BMINSC25: + return "Minsc" + case BNALIA, BNALIA25: + return "Nalia" + case BHEXXAT, BHEXXA25: + return "Hexxat" + case BIMOEN2, BIMOEN25: + return "Imeon" + case BNEERA25: + return "Neera" + case BDORN25: + return "Dorn" + case BRASAA25: + return "Rasaad" + case BSAREV25: + return "Sarevok" + case BVALYGA, BVALYG25: + return "Valygar" + case BVICONI, BVICON25: + return "Viconia" + case BYOSHIM: + return "Yoshimo" + case WILSON: + return "Wilson" + case ZDBAEB, ZDBAE25B: + return "Baeloth" + } + return "" +} diff --git a/pkg/components/table.go b/pkg/components/table.go new file mode 100644 index 0000000..ed129c0 --- /dev/null +++ b/pkg/components/table.go @@ -0,0 +1,19 @@ +package components + +import ( + "github.com/charmbracelet/bubbles/table" + tea "github.com/charmbracelet/bubbletea" +) + +func DynamicalSetTableSize(t *table.Model, msg *tea.WindowSizeMsg, h int, w int) { + if msg.Height > h { + t.SetHeight(msg.Height - h) + } + if msg.Width > w { + ratio := float64(msg.Width - w) + for _, c := range t.Columns() { + c.Width = int((float64(t.Width()) / float64(c.Width)) * ratio) + } + t.SetWidth(int(ratio)) + } +} diff --git a/pkg/util/read.go b/pkg/util/read.go index 7734fe9..e5c4fc4 100644 --- a/pkg/util/read.go +++ b/pkg/util/read.go @@ -5,25 +5,27 @@ import ( "io/fs" "os" "path/filepath" + "strings" ) -func GetFiles(path string, ext string) []fs.FileInfo { - out := []fs.FileInfo{} - f, err := os.Open(path) - if err != nil { - return out - } - defer f.Close() - files, err := f.Readdir(0) - if err != nil { - return out - } - for _, f := range files { - if !f.IsDir() && filepath.Ext(f.Name()) == ext { - out = append(out, f) +func ReadFiles(root string, ext string) (map[string]*[]string, error) { + files := map[string]*[]string{} + err := filepath.WalkDir(root, func(path string, file fs.DirEntry, err error) error { + if err != nil { + return err } - } - return out + file_ext := strings.ToLower(filepath.Ext(file.Name())) + target_ext := "." + strings.ToLower(ext) + if !file.IsDir() && file_ext == target_ext { + fileContent, err := ReadFileToSlice(path) + if err != nil { + return err + } + files[file.Name()] = fileContent + } + return nil + }) + return files, err } func ReadFile(path string) (*[]byte, error) { @@ -34,12 +36,13 @@ func ReadFile(path string) (*[]byte, error) { return &data, nil } -func ReadFileToString(path string) (string, error) { +func ReadFileToString(path string) (*string, error) { data, err := ReadFile(path) if err != nil { - return "", err + return nil, err } - return string(*data), nil + out := string(*data) + return &out, nil } func ReadFileToSlice(path string) (*[]string, error) { diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..943d585 --- /dev/null +++ b/shell.nix @@ -0,0 +1,14 @@ +with import {}; + +stdenv.mkDerivation { + name = "go-env"; + buildInputs = [ + delve + git + gnupg + pre-commit + go + ]; + + # Set Environment Variables +}