Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multipack textures #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions glue/glueatlas.monkey
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Class SpineDefaultAtlasLoader Implements SpineAtlasLoader
Local imagesDir:String = SpineExtractDir(path)

Local page:SpineDefaultAtlasPage
Local pageIndex:= 0
Local pageIndex:= -1
Local pageNew:= True
Local pageHasStart:= False
Local pageHasHeader:= False
Expand Down Expand Up @@ -98,13 +98,13 @@ Class SpineDefaultAtlasLoader Implements SpineAtlasLoader
'ignore blank lines
If line.Length > 0
If pageHasStart = False
pageIndex += 1
'first line has no ':' it states the image file
'get image path
pageFilePath = SpineCombinePaths(imagesDir, line)

'create new page
page = SpineDefaultAtlasPage(atlas.AddPage(pageFilePath))

'check that page was loaded
If page = Null Throw New SpineException("Invalid Image '" + pageFilePath + "' For Page '" + pageIndex + "' In Atlas '" + path + "'")

Expand Down Expand Up @@ -143,6 +143,7 @@ Class SpineDefaultAtlasLoader Implements SpineAtlasLoader
'new region
regionNew = True
regionNextName = line
regionSave = True
EndIf
EndIf
EndIf
Expand All @@ -152,11 +153,13 @@ Class SpineDefaultAtlasLoader Implements SpineAtlasLoader
'page is finished
pageNew = True
pageHasHeader = False
pageHasStart = False
regionSave = True
Else
'do reset of values
If regionNew
regionNew = False

regionName = regionNextName
regionIndex = -1
regionRotate = False
Expand Down Expand Up @@ -246,7 +249,6 @@ Class SpineDefaultAtlasLoader Implements SpineAtlasLoader

'add the region
region = SpineDefaultAtlasRegion(atlas.AddRegion(page, regionName, regionX, regionY, regionWidth, regionHeight, regionFrameX, regionFrameY, regionFrameWidth, regionFrameHeight))

'check to see if we failed to create this region?
If region = Null
Throw New SpineException("Invalid Region '" + regionName + "' For Page '" + pageIndex + "' In Atlas '" + path + "'")
Expand All @@ -273,7 +275,7 @@ Class SpineMakeAtlasLoader Implements SpineAtlasLoader
Local jsonPages:JSONArray
Local fileStream:= fileLoader.LoadFile(path)
If fileStream jsonPages = JSONArray(JSONData.ReadJSON(fileStream.ReadAll()))
If jsonPages = Null Throw New SpineException("Invalid Atlas '" + path + "'")
If jsonPages = Null Error SpineException("Invalid Atlas '" + path + "'")

'get images directory
Local imagesDir:String = SpineExtractDir(path)
Expand Down Expand Up @@ -507,7 +509,7 @@ Class SpineDefaultAtlas Implements SpineAtlas

'load the page image
page.image = LoadImage(path)
If page.image = Null Throw New SpineException("Invalid atlas page image '" + path + "'")
If page.image = Null Error("Invalid atlas page image '" + path + "'")

'add to pages
If pagesCount >= pages.Length pages = pages.Resize(pages.Length * 2 + 10)
Expand Down Expand Up @@ -539,13 +541,13 @@ Class SpineDefaultAtlas Implements SpineAtlas
region.image = region.page.image.GrabImage(x, y, width, height)

'figure out correct mid handle
region.image.SetHandle(0, 0)'offsetX + (originalWidth / 2.0), offsetY + (originalHeight / 2.0))
region.image.SetHandle(0, 0)

'add to regions
If regionsCount >= regions.Length regions = regions.Resize(regions.Length * 2 + 10)
regions[regionsCount] = region
regionsCount += 1

'return it
Return region
End
Expand Down
30 changes: 14 additions & 16 deletions glue/gluefiles.monkey
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,22 @@ Class SpineDefaultFileLoader Implements SpineFileLoader
End

Class SpineDefaultFileStream Implements SpineFileStream
Field originalString:String
Field path:String
Field buffer:DataBuffer
Field index:Int
Field total:Int
Field start:Int

Method Load:Bool(path:String)
'convert string into buffer
Self.path = path
index = 0
start = 0
index = 1
start = 1

'create buffer
Local data:String = LoadString(path)
total = data.Length
buffer = New DataBuffer(total)
buffer.PokeString(0, data)
originalString = LoadString(path)

total = originalString.Length

'return success
Return True
Expand All @@ -57,29 +56,28 @@ Class SpineDefaultFileStream Implements SpineFileStream
End

Method ReadLine:String()
If buffer = Null or index >= total Return ""
If originalString = "" or index >= total Return ""

For index = index Until total
For index = index Until total
'check for end of line
If buffer.PeekByte(index) = 10
Local result:String = buffer.PeekString(start, (index - start))
index = index + 1
If originalString[index] = 10
Local result:String = originalString[start..index]
index += 1
start = index
Return result
EndIf
End
Next

Return ""
End

Method ReadAll:String()
'just return the entire contents in a string
Local result:= buffer.PeekString(start)
start = total
Return result
Return originalString
End

Method Eof:Bool()
Return index >= total
End
End
End
3 changes: 3 additions & 0 deletions glue/gluespineentity.monkey
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ Class SpineEntity
End

Method Load:Bool(skeletonPath:String, atlas:SpineAtlas, fileLoader:SpineFileLoader)
Self.atlas = atlas

' --- load a new spine entity ---
'load skeleton data
'we lock the atlas again

atlas.Lock()
Local skeletonJson:= New SpineSkeletonJson(atlas)
data = skeletonJson.ReadSkeletonData(skeletonPath)
Expand Down
2 changes: 2 additions & 0 deletions spineskeletonjson.monkey
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ Class SpineSkeletonJson

'get the offset array
jsonOffsetArray = JSONArray(jsonOrder.GetItem("offsets"))
If (jsonOffsetArray = Null) Then Continue

jsonOffsetTotal = jsonOffsetArray.values.Count()

'create draw order array and reset it
Expand Down
1 change: 0 additions & 1 deletion spineskin.monkey
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ Class SpineSkin
End

' Attach all attachments from this if:skin the corresponding attachment from the old is:skin currently attached.
Private
Method AttachAll:Void(skeleton:SpineSkeleton, oldSkin:SpineSkin)
If oldSkin.attachments = Null Return

Expand Down