From ad86b820e7c8ed827c2896dd07441ff3cb890125 Mon Sep 17 00:00:00 2001 From: Jerome Le Saux Date: Mon, 6 May 2024 20:29:51 +0200 Subject: [PATCH] fix: fix zigzag sprite export in sprite board --- export/impdraw/palette/kit.go | 16 +++++-- ui/martine-ui/export_sprite_board.go | 68 +++++++++++++++++++--------- 2 files changed, 58 insertions(+), 26 deletions(-) diff --git a/export/impdraw/palette/kit.go b/export/impdraw/palette/kit.go index f69b6f0..e3abb89 100644 --- a/export/impdraw/palette/kit.go +++ b/export/impdraw/palette/kit.go @@ -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]) @@ -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) diff --git a/ui/martine-ui/export_sprite_board.go b/ui/martine-ui/export_sprite_board.go index b7470f9..111546b 100644 --- a/ui/martine-ui/export_sprite_board.go +++ b/ui/martine-ui/export_sprite_board.go @@ -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" @@ -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...) } } @@ -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) @@ -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) }