From a1d4db0b5d105579fb1b0121b0c17339b5990e39 Mon Sep 17 00:00:00 2001 From: Jochen Heizmann Date: Fri, 12 Sep 2014 16:04:07 +0200 Subject: [PATCH 1/6] Fixed: Support for multipack textures --- glue/glueatlas.monkey | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/glue/glueatlas.monkey b/glue/glueatlas.monkey index 1d493e7..34a2418 100644 --- a/glue/glueatlas.monkey +++ b/glue/glueatlas.monkey @@ -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 @@ -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 + "'") @@ -143,6 +143,7 @@ Class SpineDefaultAtlasLoader Implements SpineAtlasLoader 'new region regionNew = True regionNextName = line + regionSave = True EndIf EndIf EndIf @@ -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 @@ -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 + "'") @@ -272,8 +274,10 @@ Class SpineMakeAtlasLoader Implements SpineAtlasLoader 'attempt to load atlas json 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 + "'") + Local fileString := fileStream.ReadAll() + Print fileString + If fileStream jsonPages = JSONArray(JSONData.ReadJSON(fileString)) + If jsonPages = Null Error SpineException("Invalid Atlas '" + path + "'") 'get images directory Local imagesDir:String = SpineExtractDir(path) @@ -507,7 +511,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) @@ -539,13 +543,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 From 291a3a007f8586681bdef7d9f3f421911deaf3e1 Mon Sep 17 00:00:00 2001 From: Jochen Heizmann Date: Fri, 12 Sep 2014 16:04:54 +0200 Subject: [PATCH 2/6] Fix for MonkeyV79: Method was private but it's required to be public --- spineskin.monkey | 1 - 1 file changed, 1 deletion(-) diff --git a/spineskin.monkey b/spineskin.monkey index f07ef60..de9cc5f 100644 --- a/spineskin.monkey +++ b/spineskin.monkey @@ -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 From 5657e08815cfacefe715fc4b747d34d43adf3c5a Mon Sep 17 00:00:00 2001 From: Jochen Heizmann Date: Fri, 12 Sep 2014 16:06:11 +0200 Subject: [PATCH 3/6] Fix: When offsets-item is not available the loader will crash --- spineskeletonjson.monkey | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spineskeletonjson.monkey b/spineskeletonjson.monkey index 059af5f..17fd364 100644 --- a/spineskeletonjson.monkey +++ b/spineskeletonjson.monkey @@ -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 From f3646a550f9da0c45338e50555420c785c700866 Mon Sep 17 00:00:00 2001 From: Jochen Heizmann Date: Fri, 12 Sep 2014 16:07:03 +0200 Subject: [PATCH 4/6] Replaced SpineDefaultFileStream with own implementation so it works directly on a string. The problem was that the "total" (length) wasn't calculated correctly when UTF-8 encoded files were used. --- glue/gluefiles.monkey | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/glue/gluefiles.monkey b/glue/gluefiles.monkey index 9c4ae9f..1e1e56c 100644 --- a/glue/gluefiles.monkey +++ b/glue/gluefiles.monkey @@ -30,8 +30,8 @@ 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 @@ -39,14 +39,13 @@ Class SpineDefaultFileStream Implements SpineFileStream 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 @@ -57,16 +56,16 @@ 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 "" @@ -74,12 +73,11 @@ Class SpineDefaultFileStream Implements SpineFileStream 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 \ No newline at end of file +End From 3890fef57b4610806cddd5271004b93bc4ca3e86 Mon Sep 17 00:00:00 2001 From: Jochen Heizmann Date: Fri, 12 Sep 2014 16:11:15 +0200 Subject: [PATCH 5/6] cleaned up code --- glue/glueatlas.monkey | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/glue/glueatlas.monkey b/glue/glueatlas.monkey index 34a2418..b2339a8 100644 --- a/glue/glueatlas.monkey +++ b/glue/glueatlas.monkey @@ -274,9 +274,7 @@ Class SpineMakeAtlasLoader Implements SpineAtlasLoader 'attempt to load atlas json Local jsonPages:JSONArray Local fileStream:= fileLoader.LoadFile(path) - Local fileString := fileStream.ReadAll() - Print fileString - If fileStream jsonPages = JSONArray(JSONData.ReadJSON(fileString)) + If fileStream jsonPages = JSONArray(JSONData.ReadJSON(fileStream.ReadAll())) If jsonPages = Null Error SpineException("Invalid Atlas '" + path + "'") 'get images directory From 7ba637242f10c91099216dbfab2e07078dcda23f Mon Sep 17 00:00:00 2001 From: Jochen Heizmann Date: Thu, 18 Sep 2014 14:06:31 +0200 Subject: [PATCH 6/6] Setting attlas member or GetAtlas won't work when loaded with final atlas... --- glue/gluespineentity.monkey | 3 +++ 1 file changed, 3 insertions(+) diff --git a/glue/gluespineentity.monkey b/glue/gluespineentity.monkey index 2eb9c17..0ff9e77 100644 --- a/glue/gluespineentity.monkey +++ b/glue/gluespineentity.monkey @@ -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)