Skip to content

Commit

Permalink
fix: fix zigzag sprite export in sprite board
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Le Saux committed May 6, 2024
1 parent d974ece commit ad86b82
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 26 deletions.
16 changes: 11 additions & 5 deletions export/impdraw/palette/kit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ type KitPalette struct {
Colors [16]constants.CpcPlusColor
}

func (i *KitPalette) ToString() string {
func (i KitPalette) ToCode() string {
var out string
for _, v := range i.Colors {
out += v.ToString() + "\n"
}

out += "db "
for index, v := range i.Colors {
out += fmt.Sprintf("#%0.2X, #%0.2X", v.Bytes()[0], v.Bytes()[1])
Expand All @@ -42,6 +38,16 @@ func (i *KitPalette) ToString() string {
return out
}

func (i *KitPalette) ToString() string {
var out string
for _, v := range i.Colors {
out += v.ToString() + "\n"
}

out += i.ToCode()
return out
}

func OpenKit(filePath string) (color.Palette, *KitPalette, error) {
log.GetLogger().Info("Opening (%s) file\n", filePath)
fr, err := os.Open(filePath)
Expand Down
68 changes: 47 additions & 21 deletions ui/martine-ui/export_sprite_board.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,32 @@ func (m *MartineUI) ExportSpriteBoard(s *menu.SpriteMenu) {
pi.Hide()
case export.SpriteFlatExport:
buf := make([]byte, 0)
for _, v := range s.SpritesData {
if s.ExportZigzag {
im := sprite.ToImg(v, s.Palette())
z := transformation.Zigzag(im)
for y := 0; y < z.Bounds().Max.Y; y++ {
for x := 0; x < z.Bounds().Max.X; x++ {
c := s.Palette().Index(z.At(x, y))
v[y][x] = byte(c)
if s.ExportZigzag {
for x := 0; x < len(s.SpritesCollection); x++ {
for y := 0; y < len(s.SpritesCollection[x]); y++ {
z := transformation.Zigzag(s.SpritesCollection[x][y])
sp, _, _, err := sprite.ToSprite(z,
s.Palette(),
constants.Size{
Width: s.SpriteWidth,
Height: s.SpriteHeight,
},
uint8(s.Mode),
config.NewMartineConfig("", ""),
)
if err != nil {
pi.Hide()
dialog.NewError(err, m.window).Show()
return
}
buf = append(buf, sp...)
}
}
for _, v0 := range v {
buf = append(buf, v0...)
} else {
for _, v := range s.SpritesData {
for _, v0 := range v {
buf = append(buf, v0...)
}
}
}
filename := s.ExportFolderPath + string(filepath.Separator) + "SPRITES.BIN"
Expand Down Expand Up @@ -286,17 +299,29 @@ func (m *MartineUI) ExportSpriteBoard(s *menu.SpriteMenu) {
}
if s.ExportText {
data := make([][]byte, 0)
for _, v := range s.SpritesData {
if s.ExportZigzag {
im := sprite.ToImg(v, s.Palette())
z := transformation.Zigzag(im)
for y := 0; y < z.Bounds().Max.Y; y++ {
for x := 0; x < z.Bounds().Max.X; x++ {
c := s.Palette().Index(z.At(x, y))
v[y][x] = byte(c)
if s.ExportZigzag {
for x := 0; x < len(s.SpritesCollection); x++ {
for y := 0; y < len(s.SpritesCollection[x]); y++ {
z := transformation.Zigzag(s.SpritesCollection[x][y])
sp, _, _, err := sprite.ToSprite(z,
s.Palette(),
constants.Size{
Width: s.SpriteWidth,
Height: s.SpriteHeight,
},
uint8(s.Mode),
config.NewMartineConfig("", ""),
)
if err != nil {
pi.Hide()
dialog.NewError(err, m.window).Show()
return
}
data = append(data, sp)
}
} else {
}
} else {
for _, v := range s.SpritesData {
data = append(data, v...)
}
}
Expand All @@ -306,8 +331,8 @@ func (m *MartineUI) ExportSpriteBoard(s *menu.SpriteMenu) {
}
header := fmt.Sprintf("' from file %s\n", s.FilePath)
code := header + ascii.SpritesHardText(data, s.ExportCompression)
code += "palette:\n"
code += kitPalette.ToString()
code += "Palette\n"
code += kitPalette.ToCode()

filename := s.ExportFolderPath + string(filepath.Separator) + "SPRITES.ASM"
err := amsdos.SaveStringOSFile(filename, code)
Expand All @@ -316,6 +341,7 @@ func (m *MartineUI) ExportSpriteBoard(s *menu.SpriteMenu) {
dialog.NewError(err, m.window).Show()
return
}
pi.Hide()
}
dialog.ShowInformation("Saved", "Your export ended in the folder : "+s.ExportFolderPath, m.window)
}

0 comments on commit ad86b82

Please sign in to comment.