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

Creating mock spineData #557

Open
chky-nmnsoftware opened this issue Jun 13, 2024 · 0 comments
Open

Creating mock spineData #557

chky-nmnsoftware opened this issue Jun 13, 2024 · 0 comments

Comments

@chky-nmnsoftware
Copy link

Hello there. I'll make this as short as possible. My business is using jest to run tests on a pixi project of ours, and since these are tests, all resources are replaced with empty ones. This caused an issue because certain sprites that used pixi-spine would error due to the invalid data. I instead came up with the following function:

const mockData: ISkeletonData = {
        animations: [],
        name: "",
        bones: [],
        slots: [],
        skins: [],
        defaultSkin: undefined,
        events: [],
        version: "",
        hash: "",
        width: 0,
        height: 0,
        ikConstraints: [],
        transformConstraints: [],
        pathConstraints: [],

        findBone: function (): IBoneData { throw new Error("Function not implemented.") },
        findBoneIndex: function (): number { throw new Error("Function not implemented.") },
        findSlot: function (): ISlotData { throw new Error("Function not implemented.") },
        findSlotIndex: function (): number { throw new Error("Function not implemented.") },
        findSkin: function (): ISkin { throw new Error("Function not implemented.") },

        findEvent: function (): IEventData { throw new Error("Function not implemented.") },
        findAnimation: function (name) { return mockData.animations.filter(a => a.name === name)[0] },
        findIkConstraint: function (): IIkConstraintData { throw new Error("Function not implemented.") },
        findTransformConstraint: function (): ITransformConstraintData { throw new Error("Function not implemented.") },
        findPathConstraint: function (): IPathConstraintData { throw new Error("Function not implemented.") }
    }

    for (const animName of animationNames) {
        mockData.animations.push({
            name: animName,
            timelines: [],
            duration: 0
        })
    }

    return mockData

This is then used like this:

cache.set('titleAnimation', { spineData: createMockSpineData("intro", "loop", "outro") })

Although this works fine for creating the spineData and loading it up to a new Spine object, we came across an issue when running the setAnimation() function. What happens is that the animation will fire off the started event, but will not fire any other ones. From my observation, it is like it it isn't running at all.

My question is, how could I make a mock spineData to be used by other resources while retaining the "functionality" of a real Spine (mainly, the completed event)? Thank you for your time and help, it is truly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant