Skip to content

Commit

Permalink
fix: fix tilemap size and export
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelesaux committed Nov 10, 2024
1 parent 9b3ca66 commit cf9cc3e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
25 changes: 4 additions & 21 deletions gfx/tilemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ func AnalyzeTilemap(mode uint8, isCpcPlus bool, filename, picturePath string, in
nbTilePixelLarge = 40
}
scenes := make([]*image.NRGBA, 0)
err = os.Mkdir(filepath.Join(cfg.ScrCfg.OutputPath, "scenes"), os.ModePerm)
if err != nil {
return err
}

scenes, err = fillImage(m, scenes, nbTilePixelHigh, nbTilePixelLarge, choosenBoard.TileSize.Width, choosenBoard.TileSize.Height, cfg.ScrCfg.OutputPath)
if err != nil {
return err
Expand Down Expand Up @@ -238,10 +235,7 @@ func ExportTilemapClassical(m image.Image, filename string, palette color.Palett
nbTilePixelLarge = 40
}
scenes := make([]*image.NRGBA, 0)
err := os.Mkdir(filepath.Join(cfg.ScrCfg.OutputPath, "scenes"), os.ModePerm)
if err != nil {
return err
}
var err error
_, err = fillImage(m, scenes, nbTilePixelHigh, nbTilePixelLarge, board.TileSize.Width, board.TileSize.Height, cfg.ScrCfg.OutputPath)
if err != nil {
return err
Expand Down Expand Up @@ -440,10 +434,7 @@ func Tilemap(mode uint8, filename, picturePath string, size constants.Size, in i

// save the tilemap
scenes := make([]*image.NRGBA, 0)
err = os.Mkdir(filepath.Join(cfg.ScrCfg.OutputPath, "scenes"), os.ModePerm)
if err != nil {
return err
}

scenes, err = fillImage(m, scenes, nbTilePixelHigh, nbTilePixelLarge, analyze.TileSize.Width, analyze.TileSize.Height, cfg.ScrCfg.OutputPath)
if err != nil {
return err
Expand Down Expand Up @@ -488,7 +479,7 @@ func fillImage(m image.Image, scenes []*image.NRGBA, nbTilePixelHigh, nbTilePixe
}
// store the map in the slice
scenes = append(scenes, m1)
scenePath := filepath.Join(output, fmt.Sprintf("%sscenes%sscene-%.2d.png", string(filepath.Separator), string(filepath.Separator), index))
scenePath := filepath.Join(output, fmt.Sprintf("%sscene-%.2d.png", string(filepath.Separator), index))
if err := png.Png(scenePath, m1); err != nil {
log.GetLogger().Error("Cannot encode in png scene scene-%.2d error %v\n", index, err)
return scenes, err
Expand Down Expand Up @@ -608,10 +599,6 @@ func ExportTilemap(analyze *transformation.AnalyzeBoard, filename string, palett
}
}
// scenes := make([]*image.NRGBA, 0)
err = os.Mkdir(filepath.Join(cfg.ScrCfg.OutputPath, "scenes"), os.ModePerm)
if err != nil {
return err
}
index := 0
m := ci.Resize(in, mapSize, cfg.ScrCfg.Process.ResizingAlgo)
for y := 0; y < m.Bounds().Max.Y; y += (nbTilePixelHigh * analyze.TileSize.Height) {
Expand Down Expand Up @@ -736,10 +723,6 @@ func ExportImpdrawTilemap(analyze *transformation.AnalyzeBoard, filename string,
m := ci.Resize(in, mapSize, cfg.ScrCfg.Process.ResizingAlgo)
// save the tilemap
scenes := make([]*image.NRGBA, 0)
err = os.Mkdir(filepath.Join(cfg.ScrCfg.OutputPath, "scenes"), os.ModePerm)
if err != nil {
return err
}

_, err = fillImage(m, scenes, nbTilePixelHigh, nbTilePixelLarge, analyze.TileSize.Width, analyze.TileSize.Height, cfg.ScrCfg.OutputPath)
if err != nil {
Expand Down
18 changes: 11 additions & 7 deletions gfx/transformation/tile_analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,18 @@ func AnalyzeTilesBoard(im image.Image, size constants.Size, tilesHistoric *exspr
if (im.Bounds().Max.Y % size.Height) != 0 {
heightCorrection = 1
}
nbTileW := (im.Bounds().Max.X / size.Width) + 1
nbTileH := (im.Bounds().Max.Y / size.Height) - (heightCorrection) + 1
tileWLeft := 0
if (im.Bounds().Max.X % size.Width) != 0 {
tileWLeft = 1
}
tileHLeft := 0
if (im.Bounds().Max.Y % size.Height) != 0 {
tileHLeft = 1
}
nbTileW := (im.Bounds().Max.X / size.Width) + tileWLeft
nbTileH := (im.Bounds().Max.Y / size.Height) - (heightCorrection) + tileHLeft
board := NewAnalyzeBoard(size, im.Bounds(), nbTileH, nbTileW, tilesHistoric)

// sprt0, _ := ExtractTile(im, size, 0, 0)
/* if err != nil {
log.GetLogger().Error( "Error while extracting tile size(%d,%d) at position (%d,%d) error :%v\n", size.Width, size.Height, 0, 0, err)
}*/
// board.NewTile(sprt0, 0, 0, len(board.BoardTiles))
board.TileMap[0][0] = 0

indexX := 0
Expand Down Expand Up @@ -611,6 +614,7 @@ func (a *AnalyzeBoard) SaveAssemblyTiles(filePath string) error {
if err != nil {
return err
}
// To rework
for _, v := range a.TileMap {
_, err := f.WriteString("db ")
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions ui/martine-ui/tilemap_tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,12 @@ func (m *MartineUI) newTilemapTab(tm *menu.TilemapMenu) *fyne.Container {
),
container.New(
layout.NewHBoxLayout(),
isPlus,

container.New(
layout.NewVBoxLayout(),
container.New(
layout.NewVBoxLayout(),
isPlus,
modeLabel,
modes,
),
Expand All @@ -290,7 +291,7 @@ func (m *MartineUI) newTilemapTab(tm *menu.TilemapMenu) *fyne.Container {
layout.NewGridLayoutWithRows(6),

container.New(
layout.NewGridLayoutWithColumns(2),
layout.NewVBoxLayout(),
tm.PaletteImage(),
container.New(
layout.NewHBoxLayout(),
Expand Down

0 comments on commit cf9cc3e

Please sign in to comment.