Skip to content

Commit

Permalink
fix(layout): generate an image for each layout
Browse files Browse the repository at this point in the history
The layout name was not appended to the name of the image, so each layout overrode the prior.

Closes #7
  • Loading branch information
MrMarble committed May 8, 2022
1 parent 1a05be7 commit dcfa0e7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions internal/lib/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lib

import (
"fmt"
"image"
"image/png"
"os"
Expand Down Expand Up @@ -29,15 +28,15 @@ func (g *GenerateCmd) Run() error {
}
g.KeyboardName = strings.ReplaceAll(g.KeyboardName, "/", "_")

for _, layout := range keyboardInfo {
for layoutName, layout := range keyboardInfo {
ctx := createContext(&layout)
err := drawLayout(ctx, g.Transparent, layout)
if err != nil {
return err
}

base := ctx.Image()
images[path.Join(g.Output, fmt.Sprintf("%s.png", g.KeyboardName))] = base
images[generateName(g.Output, g.KeyboardName, layoutName, "")] = base

if keymap, ok := parseKeymap(g.File); ok {
for _, layer := range keymap.Device.Keymap.Layers {
Expand All @@ -47,7 +46,7 @@ func (g *GenerateCmd) Run() error {
if err != nil {
return err
}
images[path.Join(g.Output, fmt.Sprintf("%s_%s.png", g.KeyboardName, layer.Name))] = ctx.Image()
images[generateName(g.Output, g.KeyboardName, layoutName, layer.Name)] = ctx.Image()
}
}
}
Expand All @@ -66,3 +65,14 @@ func (g *GenerateCmd) Run() error {

return nil
}

func generateName(output, name, layout, layer string) string {
file := name
if layout != "LAYOUT" {
file += "_" + strings.ReplaceAll(layout, "LAYOUT_", "")
}
if layer != "" {
file += "_" + layer
}
return path.Join(output, file+".png")
}

0 comments on commit dcfa0e7

Please sign in to comment.