Skip to content

Commit

Permalink
Merge pull request #468 from Tousen/master
Browse files Browse the repository at this point in the history
fix version detection of binary spine file #415
  • Loading branch information
ivanpopelyshev authored Jan 8, 2023
2 parents bf8b3db + e78df42 commit 1e7ca4c
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions packages/loader-uni/src/SpineLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ class UniBinaryParser implements ISkeletonParser {
scale = 1;

readSkeletonData(atlas: TextureAtlas, dataToParse: Uint8Array): ISkeletonData {
let input = new BinaryInput(dataToParse);
input.readString();
let version = input.readString();
let ver = detectSpineVersion(version);
let parser: any = null;

let version = this.readVersionOldFormat(dataToParse);
let ver = detectSpineVersion(version);
if (ver === SPINE_VERSION.VER38) {
parser = new spine38.SkeletonBinary(new spine38.AtlasAttachmentLoader(atlas));
}

input = new BinaryInput(dataToParse);
input.readInt32();
input.readInt32();
version = input.readString();
version = this.readVersionNewFormat(dataToParse);
ver = detectSpineVersion(version);
if (ver === SPINE_VERSION.VER40 || ver === SPINE_VERSION.VER41) {
parser = new spine41.SkeletonBinary(new spine41.AtlasAttachmentLoader(atlas));
Expand All @@ -36,6 +29,32 @@ class UniBinaryParser implements ISkeletonParser {
parser.scale = this.scale;
return parser.readSkeletonData(dataToParse);
}

readVersionOldFormat(dataToParse: Uint8Array){
let input = new BinaryInput(dataToParse);
let version;
try {
input.readString();
version = input.readString();
}catch (e){
version = "";
}
return version || ""
}

readVersionNewFormat(dataToParse: Uint8Array){
let input = new BinaryInput(dataToParse);
input.readInt32();
input.readInt32();
let version;
try {
version = input.readString();
}catch (e){
version = ""
}

return version || ""
}
}

class UniJsonParser implements ISkeletonParser {
Expand Down

0 comments on commit 1e7ca4c

Please sign in to comment.