Skip to content

Commit

Permalink
fix: display what is real computed in tile
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Le Saux committed Apr 10, 2024
1 parent 5cd5453 commit aa1bb0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
20 changes: 12 additions & 8 deletions gfx/tilemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"image"
"image/color"
"image/draw"
"math"
"os"
"path/filepath"
Expand Down Expand Up @@ -547,16 +548,19 @@ func TilemapRaw(mode uint8, isCpcPlus bool, size constants.Size, in image.Image,

analyze := transformation.AnalyzeTilesBoard(m, cfg.Size)

// now thread all maps images
for y := 0; y < m.Bounds().Max.Y; y += analyze.TileSize.Height {
// now display all maps images
for y := 0; y < len(analyze.TileMap); y++ {
tilesmap := make([]image.Image, 0)
for x := 0; x < m.Bounds().Max.X; x += analyze.TileSize.Width {
sprt, err := transformation.ExtractTile(m, analyze.TileSize, x, y)
if err != nil {
log.GetLogger().Error("Error while extracting tile size(%d,%d) at position (%d,%d) error :%v\n", size.Width, size.Height, x, y, err)
break
for x := 0; x < len(analyze.TileMap[y]); x++ {
i := analyze.TileMap[y][x]
if i < len(analyze.BoardTiles) {
tl := analyze.BoardTiles[i]
tilesmap = append(tilesmap, tl.Tile.Image())
} else {
bl := image.NewNRGBA(image.Rect(0, 0, analyze.TileSize.Width, analyze.TileSize.Height))
draw.Draw(bl, bl.Bounds(), &image.Uniform{color.Alpha16{0xFFF}}, image.Pt(0, 0), draw.Src)
tilesmap = append(tilesmap, bl)
}
tilesmap = append(tilesmap, sprt.Image())
}
tilesImagesTilemap = append(tilesImagesTilemap, tilesmap)
}
Expand Down
17 changes: 13 additions & 4 deletions gfx/transformation/tile_analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ func AnalyzeTilesBoard(im image.Image, size constants.Size) *AnalyzeBoard {
board.TileMap[0][0] = 0

indexX := 1
for x := 0; x < im.Bounds().Max.X; x += size.Width {
for x := 0; x <= im.Bounds().Max.X; x += size.Width {
indexY := 0
for y := 0; y < im.Bounds().Max.Y; y += size.Height {
for y := 0; y <= im.Bounds().Max.Y; y += size.Height {
sprt, err := ExtractTile(im, size, x, y)
if err != nil {
// log.GetLogger().Error( "Error while extracting tile size(%d,%d) at position (%d,%d) error :%v\n", size.Width, size.Height, x, y, err)
Expand Down Expand Up @@ -535,13 +535,22 @@ func (a *AnalyzeBoard) SaveTilemap(filePath string) error {
return err
}
for _, v := range a.TileMap {
for _, val := range v {
_, err := f.WriteString("db ")
if err != nil {
return err
}
for x := 0; x < len(v)-1; x++ {
val := v[x]
_, err := f.WriteString(fmt.Sprintf("%.2d", val) + ",")
if err != nil {
return err
}
}
_, err := f.WriteString("\n")
_, err = f.WriteString(fmt.Sprintf("%.2d", v[len(v)-1]))
if err != nil {
return err
}
_, err = f.WriteString("\n")
if err != nil {
return err
}
Expand Down

0 comments on commit aa1bb0a

Please sign in to comment.