Handle more weird naming cases

This commit is contained in:
Ian Gulliver
2023-05-14 16:35:29 -07:00
parent 1687366aec
commit 1e81c29fa1
3 changed files with 18 additions and 1 deletions

View File

@@ -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--

5
go.mod
View File

@@ -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
)

2
go.sum
View File

@@ -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=