maxgribov / Spine

Unofficial Spine runtime Swift library, allows you to play animations created in the Spine app (http://esotericsoftware.com).
MIT License
183 stars 36 forks source link

Fix empty time in animations #28

Closed kvaDrug closed 4 years ago

kvaDrug commented 4 years ago

Designer in our team uses Spine 3.8.72. The "time" parameter sometimes is missing in animations there, for example:

"bones": {
        "Body": {
          "rotate": [
            {
              "angle": -178.61
            },
            {
              "time": 0.5,
              "angle": 176.27
            },
            {
              "time": 1.1667,
              "angle": -174.45
            },
            {
              "time": 1.5,
              "angle": -178.61
            }
          ]
    }
}

Here you can see that the first "angle" items goes without "time". If you try to create a Skeleton from this json, it will fail.

In this pull requests I fix all the animations assuming that missing "time" simply means "time": 0. This is achieved by replacing

container.decode(TimeInterval.self, forKey: .time)

with

decodeIfPresent(TimeInterval.self, forKey: .time) ?? 0

Bonus: .gitignore file to remove .DS_Store etc. from commits.

maxgribov commented 4 years ago

Already fixed in v2.0