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

fix version detection of binary spine file #415 #468

Merged
merged 1 commit into from
Jan 8, 2023
Merged
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
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