Skip to content

Commit

Permalink
fix: spine mipmap (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: Mat Groves <[email protected]>
  • Loading branch information
Zyie and GoodBoyDigital authored Jun 25, 2024
1 parent 0f210f5 commit 83d4add
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/spine/spineAtlasMipmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ function rescaleAtlas(raw: string, scale = 1, template = ''): string
// Regex for xy values, like 'size: 2019,463', 'orig: 134, 240'
const reXY = /(.*?:\s?)(\d+)(\s?,\s?)(\d+)$/;

// Regex for scale values, like 'scale: 0.75'
const regScale = /(scale:\s?)(\d+(\.\d+)?)$/;

// Regex for rect values, like 'bounds:2,270,804,737', 'offsets:0,0,110,113'
const regRect = /(.*?:\s?)(\d+)(\s?,\s?)(\d+)(\s?,\s?)(\d+)(\s?,\s?)(\d+)$/;

// Regex for image names, like 'image.png', 'img.jpg'
const reImg = /(.+)(.png|jpg|jpeg)$/;

Expand All @@ -82,6 +88,8 @@ function rescaleAtlas(raw: string, scale = 1, template = ''): string
{
let line = lines[i];
const matchXY = reXY.exec(line);
const matchScale = regScale.exec(line);
const matchRect = regRect.exec(line);

if (matchXY)
{
Expand All @@ -92,6 +100,21 @@ function rescaleAtlas(raw: string, scale = 1, template = ''): string
// Rewrite line with new values
line = line.replace(reXY, `$1${x}$3${y}`);
}
else if (matchScale)
{
const newScale = Number(matchScale[2]) * scale;

line = line.replace(regScale, `$1${newScale}`);
}
else if (matchRect)
{
const x1 = Math.floor(Number(matchRect[2]) * scale);
const y1 = Math.floor(Number(matchRect[4]) * scale);
const x2 = Math.floor(Number(matchRect[6]) * scale);
const y2 = Math.floor(Number(matchRect[8]) * scale);

line = line.replace(regRect, `$1${x1}$3${y1}$5${x2}$7${y2}`);
}

if (reImg.exec(line))
{
Expand Down

0 comments on commit 83d4add

Please sign in to comment.