Skip to content

Commit 908174b

Browse files
committed
move tags under own package
1 parent 4e8c907 commit 908174b

22 files changed

Lines changed: 117 additions & 108 deletions

makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tinygo_flags += $(go_tags) --ldflags="-X github.com/oidoid/void/src/demo/engine.
2020
pack_demo = go run ./src/cmd/pack --out=dist/demo/ --tsconfig=src/demo/web/tsconfig.json $(1) src/demo/web/assets/index.html
2121
# $(1) flags
2222
tileset_manifest_demo := dist/demo/tileset-manifest.json
23-
packatlas_demo = go run ./src/cmd/packatlas --name=atlas --img-out=dist/demo/ --code-out=src/demo/assets/ --tileset-manifest-out=$(tileset_manifest_demo) $(1) src/demo/assets/atlas/
23+
packatlas_demo = go run ./src/cmd/packatlas --name=atlas --img-out=dist/demo/ --atlas-out=src/demo/assets/atlas_bin.go --tags-out=src/demo/tags/tags.go --tileset-manifest-out=$(tileset_manifest_demo) $(1) src/demo/assets/atlas/
2424
packlevels_demo = go run ./src/cmd/packlevels --tileset-manifest=$(tileset_manifest_demo) --out=src/demo/levels $(1) src/demo/assets/levels/
2525
favicon_demo = \
2626
mkdir -p dist/demo/favicon; \
@@ -51,7 +51,7 @@ build-levels: build-atlas; $(call packlevels_demo,)
5151
build-favicon:; $(favicon_demo)
5252
build-web: build-demo build-atlas; $(call pack_demo,--minify --one-file)
5353

54-
clean:; rm --force --recursive dist/ src/demo/assets/atlas_bin.go src/demo/assets/atlas_tags.go
54+
clean:; rm --force --recursive dist/ src/demo/assets/atlas_bin.go src/demo/tags/tags.go
5555

5656
# to-do:
5757
# go generate

src/cmd/internal/tilesetmanifest/tileset_manifest.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ type TilesetManifest struct {
2121
TileW uint8 `json:"tileW"`
2222
// native tileset cell height in pixels.
2323
TileH uint8 `json:"tileH"`
24-
// indexes final atlas tags by row-major preview canvas cell after
25-
// resolving the Aseprite native tile stored in each cell. adjacent cells
26-
// need not map to contiguous or increasing tags; eg, `[164, 163, 168]` maps
27-
// preview cells 0, 1, and 2 to atlas tags 164, 163, and 168. every tag
28-
// references one cel.
24+
// indexes final tags by row-major preview canvas cell after resolving the
25+
// Aseprite native tile stored in each cell. adjacent cells need not map to
26+
// contiguous or increasing tags; eg, `[164, 163, 168]` maps preview cells
27+
// 0, 1, and 2 to tags 164, 163, and 168. every tag references one cel.
2928
Tags []vatlas.Tag `json:"tags"`
3029
}

src/cmd/packatlas/argv.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import (
44
"errors"
55
"flag"
66
"fmt"
7-
"path/filepath"
87
)
98

109
type Argv struct {
1110
ColorMode string
1211
Entries []string
1312
Name string
1413
ImgOut string
15-
Pkg string
16-
CodeOut string
14+
AtlasOut string
15+
TagsOut string
1716
TilesetManifestOut string
1817
Watch bool
1918
}
@@ -23,7 +22,8 @@ func NewArgv() (Argv, error) {
2322
flag.StringVar(&this.ColorMode, "color-mode", "indexed", "Aseprite color mode")
2423
flag.StringVar(&this.Name, "name", "", "atlas name")
2524
flag.StringVar(&this.ImgOut, "img-out", "", "image output directory")
26-
flag.StringVar(&this.CodeOut, "code-out", "", "gencode output directory")
25+
flag.StringVar(&this.AtlasOut, "atlas-out", "", "atlas Go output file")
26+
flag.StringVar(&this.TagsOut, "tags-out", "", "tags Go output file")
2727
flag.StringVar(
2828
&this.TilesetManifestOut,
2929
"tileset-manifest-out",
@@ -35,6 +35,7 @@ func NewArgv() (Argv, error) {
3535
fmt.Fprintf(
3636
flag.CommandLine.Output(),
3737
"packatlas --name=<name> --img-out=<dir> "+
38+
"--atlas-out=<file> --tags-out=<file> "+
3839
"[--tileset-manifest-out=<file>] "+
3940
"[--color-mode=<mode>] [--watch] <entries…>\n",
4041
)
@@ -51,7 +52,12 @@ func NewArgv() (Argv, error) {
5152
if this.ImgOut == "" {
5253
return Argv{}, errors.New("--img-out required")
5354
}
54-
this.Pkg = filepath.Base(this.CodeOut)
55+
if this.AtlasOut == "" {
56+
return Argv{}, errors.New("--atlas-out required")
57+
}
58+
if this.TagsOut == "" {
59+
return Argv{}, errors.New("--tags-out required")
60+
}
5561

5662
return this, nil
5763
}

src/cmd/packatlas/atlas_parser.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func filterAnims(assets []*asset) (anims []anim, err error) {
126126
for _, tag := range asset.TagSpans {
127127
k := stemTag{stem: stem, tag: tag.Name}
128128
if seen[k] {
129-
return nil, fmt.Errorf("atlas tag %q duplicate", k.qualifiedTag())
129+
return nil, fmt.Errorf("tag %q duplicate", k.qualifiedTag())
130130
}
131131
seen[k] = true
132132
anims = append(anims, anim{stemTag: k, asset: asset, tagSpan: tag})
@@ -516,7 +516,7 @@ func parseAtlas(
516516
packed = append(packed, tiles...)
517517
if len(packed) > vatlas.MaxTags {
518518
return nil, nil, nil, fmt.Errorf(
519-
"atlas tag count %d exceeds %d",
519+
"tag count %d exceeds %d",
520520
len(packed), vatlas.MaxTags,
521521
)
522522
}
@@ -609,7 +609,7 @@ func parseBoxes(
609609
for _, k := range assetSlice.Keys {
610610
if k.Header.Bounds != first {
611611
return hit, hurt, fmt.Errorf(
612-
"atlas tag %q hitbox bounds varies across frames", tag,
612+
"tag %q hitbox bounds varies across frames", tag,
613613
)
614614
}
615615
}
@@ -625,7 +625,7 @@ func parseBoxes(
625625
case vatlas.AseRGBA{B: 255, A: 255}:
626626
hit, hurt = box, box
627627
default:
628-
return hit, hurt, fmt.Errorf("atlas tag %q hitbox color unsupported", tag)
628+
return hit, hurt, fmt.Errorf("tag %q hitbox color unsupported", tag)
629629
}
630630
}
631631
return

src/cmd/packatlas/main.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,28 @@ func packAtlas(argv *Argv) error {
114114
return fmt.Errorf("converting to WebP: %w", err)
115115
}
116116
atlasBin := vatlas.EncodeAtlas(atlas)
117-
dataSrc, err := genData(argv.Pkg, atlasBin)
117+
dataSrc, err := genData(
118+
filepath.Base(filepath.Dir(argv.AtlasOut)), atlasBin,
119+
)
118120
if err != nil {
119121
return err
120122
}
121-
if err := os.WriteFile(
122-
filepath.Join(argv.CodeOut, argv.Name+"_bin.go"),
123-
dataSrc,
124-
0o644,
125-
); err != nil {
123+
if err := os.MkdirAll(filepath.Dir(argv.AtlasOut), 0o755); err != nil {
124+
return err
125+
}
126+
if err := os.WriteFile(argv.AtlasOut, dataSrc, 0o644); err != nil {
126127
return err
127128
}
128-
tagsSrc, err := genTags(argv.Pkg, stemTags)
129+
tagsSrc, err := genTags(
130+
filepath.Base(filepath.Dir(argv.TagsOut)), stemTags,
131+
)
129132
if err != nil {
130133
return err
131134
}
132-
if err := os.WriteFile(
133-
filepath.Join(argv.CodeOut, argv.Name+"_tags.go"),
134-
tagsSrc,
135-
0o644,
136-
); err != nil {
135+
if err := os.MkdirAll(filepath.Dir(argv.TagsOut), 0o755); err != nil {
136+
return err
137+
}
138+
if err := os.WriteFile(argv.TagsOut, tagsSrc, 0o644); err != nil {
137139
return err
138140
}
139141
if argv.TilesetManifestOut == "" {

src/cmd/packlevels/tiled.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func readLevel(path string, tilesets tilesetIndex) (vlevels.Level, error) {
178178
}, nil
179179
}
180180

181-
// resolves a Tiled global tile ID to its final atlas tag.
181+
// resolves a Tiled global tile ID to its final tag.
182182
func tagForGID(gid uint32, tilesets []tmxTileset) (vatlas.Tag, error) {
183183
if gid == 0 {
184184
return 0, nil
@@ -193,7 +193,7 @@ func tagForGID(gid uint32, tilesets []tmxTileset) (vatlas.Tag, error) {
193193
if gid < tileset.FirstGID {
194194
return 0, fmt.Errorf("GID %d has no tileset", gid)
195195
}
196-
// Tiled GID -> preview canvas cell -> Aseprite native tile -> final atlas tag.
196+
// Tiled GID -> preview canvas cell -> Aseprite native tile -> final tag.
197197
// adjacent preview cells may resolve to non-contiguous tags.
198198
localID := gid - tileset.FirstGID
199199
if localID >= uint32(len(tileset.manifest.Tags)) {

src/demo/assets/atlas_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package assets
33
import (
44
"testing"
55

6+
"github.com/oidoid/void/src/demo/tags"
67
"github.com/oidoid/void/src/void/vatlas"
78
"github.com/oidoid/void/src/void/vgeo"
89
)
910

1011
func TestSuperballHitbox(t *testing.T) {
1112
atlas := vatlas.DecodeAtlas(AtlasBin)
12-
if got, want := atlas.Anims[int(SuperballDefault)].Hitbox,
13+
if got, want := atlas.Anims[int(tags.SuperballDefault)].Hitbox,
1314
vgeo.XYWH[uint16](1, 1, 6, 6); got != want {
1415
t.Fatalf("Superball hitbox = %v, want %v", got, want)
1516
}

src/demo/engine/engine.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/oidoid/void/src/demo/game"
99
"github.com/oidoid/void/src/demo/gfx"
1010
"github.com/oidoid/void/src/demo/levels"
11+
"github.com/oidoid/void/src/demo/tags"
1112
"github.com/oidoid/void/src/void/vatlas"
1213
"github.com/oidoid/void/src/void/vengine"
1314
"github.com/oidoid/void/src/void/ventities"
@@ -52,7 +53,7 @@ const (
5253

5354
func New() *Engine {
5455
font := vtext.MemProp5x6
55-
font.FirstTag = assets.MemProp5x600
56+
font.FirstTag = tags.MemProp5x600
5657
this := &Engine{
5758
Engine: vengine.New[*Engine](&vengine.EngineOpts{
5859
Font: font,
@@ -80,10 +81,10 @@ func New() *Engine {
8081
this.Layer(gfx.LayerGrid).CamMode = vgfx.LayerCamModeFixed
8182
this.Layer(gfx.LayerGrid).BlendMode = vgfx.LayerBlendModeMultiply
8283
this.Atlas = vatlas.DecodeAtlas(assets.AtlasBin)
83-
anim := this.Atlas.Anims[int(assets.SuperballDefault)]
84+
anim := this.Atlas.Anims[int(tags.SuperballDefault)]
8485
diameter := float32(anim.Hitbox.Max.X - anim.Hitbox.Min.X)
8586
// omit level edge.
86-
lvl := vgeo.NewBox[float32](
87+
lvl := vgeo.NewBox(
8788
float32(this.Level.Tile.W),
8889
float32(this.Level.Tile.H),
8990
float32(this.Level.W-int32(this.Level.Tile.W)),

src/demo/entities/button_ents.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package entities
22

33
import (
4-
"github.com/oidoid/void/src/demo/assets"
54
"github.com/oidoid/void/src/demo/gfx"
5+
"github.com/oidoid/void/src/demo/tags"
66
"github.com/oidoid/void/src/void/ventities"
77
game "github.com/oidoid/void/src/void/vgame"
88
"github.com/oidoid/void/src/void/vgeo"
@@ -86,16 +86,16 @@ func newButtonEnt(
8686
this := ventities.ButtonEnt{
8787
NinePatchEnt: newWidgetNinePatch(),
8888
Pals: ventities.ButtonPals{
89-
Base: assets.PalWidget,
90-
Focused: assets.PalWidgetFocused,
91-
On: assets.PalWidgetOn,
92-
FocusedOn: assets.PalWidgetFocusedOn,
89+
Base: tags.PalWidget,
90+
Focused: tags.PalWidgetFocused,
91+
On: tags.PalWidgetOn,
92+
FocusedOn: tags.PalWidgetFocusedOn,
9393
},
9494
TextPals: ventities.ButtonPals{
95-
Base: assets.PalText,
96-
Focused: assets.PalText,
97-
On: assets.PalTextLight,
98-
FocusedOn: assets.PalTextLight,
95+
Base: tags.PalText,
96+
Focused: tags.PalText,
97+
On: tags.PalTextLight,
98+
FocusedOn: tags.PalTextLight,
9999
},
100100
Anchor: ventities.AnchorEnt{
101101
Dir: vgeo.DirW,
@@ -112,8 +112,8 @@ func newButtonEnt(
112112
}
113113

114114
func newWidgetNinePatch() ventities.NinePatchEnt {
115-
edge := vgfx.Spr{TagCel: assets.WidgetEdgeLight.Cel(0)}
116-
fill := vgfx.Spr{TagCel: assets.WidgetFill.Cel(0)}
115+
edge := vgfx.Spr{TagCel: tags.WidgetEdgeLight.Cel(0)}
116+
fill := vgfx.Spr{TagCel: tags.WidgetFill.Cel(0)}
117117
return ventities.NinePatchEnt{
118118
PatchByDir: [9]vgfx.Spr{
119119
vgeo.DirE: edge,

src/demo/entities/ent_status_ent.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package entities
33
import (
44
"strings"
55

6-
"github.com/oidoid/void/src/demo/assets"
76
"github.com/oidoid/void/src/demo/game"
87
"github.com/oidoid/void/src/demo/gfx"
8+
"github.com/oidoid/void/src/demo/tags"
99
"github.com/oidoid/void/src/void/ventities"
1010
"github.com/oidoid/void/src/void/vgame"
1111
"github.com/oidoid/void/src/void/vgeo"
@@ -25,11 +25,11 @@ func NewEntStatusEnt() EntStatusEnt {
2525
this := EntStatusEnt{}
2626
this.Fill = ventities.NinePatchEnt{
2727
PatchByDir: [9]vgfx.Spr{
28-
vgeo.DirE: {TagCel: assets.ColorBlue.Cel(0)},
29-
vgeo.DirN: {TagCel: assets.ColorBlue.Cel(0)},
30-
vgeo.DirW: {TagCel: assets.ColorBlue.Cel(0)},
31-
vgeo.DirS: {TagCel: assets.ColorBlue.Cel(0)},
32-
vgeo.DirCenter: {TagCel: assets.ColorBlue.Cel(0)},
28+
vgeo.DirE: {TagCel: tags.ColorBlue.Cel(0)},
29+
vgeo.DirN: {TagCel: tags.ColorBlue.Cel(0)},
30+
vgeo.DirW: {TagCel: tags.ColorBlue.Cel(0)},
31+
vgeo.DirS: {TagCel: tags.ColorBlue.Cel(0)},
32+
vgeo.DirCenter: {TagCel: tags.ColorBlue.Cel(0)},
3333
},
3434
CornerWH: vgeo.NewWH[uint16](1, 1),
3535
}

0 commit comments

Comments
 (0)