From 1e81c29fa1393c6b442fb2f6d75871d313576905 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 14 May 2023 16:35:29 -0700 Subject: [PATCH] Handle more weird naming cases --- cmd/dndimport/main.go | 12 ++++++++++++ go.mod | 5 ++++- go.sum | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/dndimport/main.go b/cmd/dndimport/main.go index 1077eec..5f023e7 100644 --- a/cmd/dndimport/main.go +++ b/cmd/dndimport/main.go @@ -8,12 +8,14 @@ import ( "path/filepath" "strings" + "github.com/fatih/camelcase" "github.com/firestuff/dnd/internal" "github.com/samber/lo" "golang.org/x/exp/slog" ) var removeWords = map[string]bool{ + "+": true, "1": true, "2": true, "diamond": true, @@ -21,7 +23,9 @@ var removeWords = map[string]bool{ "high": true, "psd": true, "res": true, + "roll20": true, "roll20+tokens": true, + "tokens": true, } var actions = map[string]string{ @@ -37,10 +41,14 @@ var actions = map[string]string{ "*/high res/gridless/floor 1/*.png": "Maps/{MAPNAME}", "*/high res/gridless/floor 2/*.jpg": "Maps/{MAPNAME}", "*/high res/gridless/floor 2/*.png": "Maps/{MAPNAME}", + "*/high resolution/gridless/*.jpg": "Maps/{MAPNAME}", + "*/grid/*.jpg": "{SKIP}", "*/high res/grid/*.jpg": "{SKIP}", + "*/high resolution/grid/*.jpg": "{SKIP}", "*/creature tokens/*.png": "Creatures", "*/creature tokens/variants/*.png": "Creatures", "*/map tokens/*.png": "Maps/{MAPNAME}/Objects", + "*/tokens/*.png": "Maps/{MAPNAME}/Objects", "*/roll20/grid/*.jpg": "{SKIP}", "*/roll20/grid/*.png": "{SKIP}", "*/roll20/grid/attic/*.jpg": "{SKIP}", @@ -154,6 +162,10 @@ func mapName(path string) string { withoutZIP := strings.TrimSuffix(filepath.Base(path), ".zip") parts := strings.Split(withoutZIP, " ") + if len(parts) == 1 { + parts = camelcase.Split(parts[0]) + } + i := len(parts) - 1 for i >= 0 && removeWords[strings.ToLower(parts[i])] { i-- diff --git a/go.mod b/go.mod index 981a326..c286839 100644 --- a/go.mod +++ b/go.mod @@ -4,4 +4,7 @@ go 1.20 require github.com/samber/lo v1.38.1 -require golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea +require ( + github.com/fatih/camelcase v1.0.0 + golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea +) diff --git a/go.sum b/go.sum index b4e97a4..e8def20 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8= +github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc= github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM= github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4=