AttachmentLoader.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated January 1, 2020. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2020, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #include <spine/AttachmentLoader.h>
  30. #include <stdio.h>
  31. #include <spine/extension.h>
  32. typedef struct _spAttachmentLoaderVtable {
  33. spAttachment* (*createAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name, const char* path);
  34. void (*configureAttachment) (spAttachmentLoader* self, spAttachment*);
  35. void (*disposeAttachment) (spAttachmentLoader* self, spAttachment*);
  36. void (*dispose) (spAttachmentLoader* self);
  37. } _spAttachmentLoaderVtable;
  38. void _spAttachmentLoader_init (spAttachmentLoader* self,
  39. void (*dispose) (spAttachmentLoader* self),
  40. spAttachment* (*createAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name,
  41. const char* path),
  42. void (*configureAttachment) (spAttachmentLoader* self, spAttachment*),
  43. void (*disposeAttachment) (spAttachmentLoader* self, spAttachment*)
  44. ) {
  45. CONST_CAST(_spAttachmentLoaderVtable*, self->vtable) = NEW(_spAttachmentLoaderVtable);
  46. VTABLE(spAttachmentLoader, self)->dispose = dispose;
  47. VTABLE(spAttachmentLoader, self)->createAttachment = createAttachment;
  48. VTABLE(spAttachmentLoader, self)->configureAttachment = configureAttachment;
  49. VTABLE(spAttachmentLoader, self)->disposeAttachment = disposeAttachment;
  50. }
  51. void _spAttachmentLoader_deinit (spAttachmentLoader* self) {
  52. FREE(self->vtable);
  53. FREE(self->error1);
  54. FREE(self->error2);
  55. }
  56. void spAttachmentLoader_dispose (spAttachmentLoader* self) {
  57. VTABLE(spAttachmentLoader, self)->dispose(self);
  58. FREE(self);
  59. }
  60. spAttachment* spAttachmentLoader_createAttachment (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name,
  61. const char* path) {
  62. FREE(self->error1);
  63. FREE(self->error2);
  64. self->error1 = 0;
  65. self->error2 = 0;
  66. return VTABLE(spAttachmentLoader, self)->createAttachment(self, skin, type, name, path);
  67. }
  68. void spAttachmentLoader_configureAttachment (spAttachmentLoader* self, spAttachment* attachment) {
  69. if (!VTABLE(spAttachmentLoader, self)->configureAttachment) return;
  70. VTABLE(spAttachmentLoader, self)->configureAttachment(self, attachment);
  71. }
  72. void spAttachmentLoader_disposeAttachment (spAttachmentLoader* self, spAttachment* attachment) {
  73. if (!VTABLE(spAttachmentLoader, self)->disposeAttachment) return;
  74. VTABLE(spAttachmentLoader, self)->disposeAttachment(self, attachment);
  75. }
  76. void _spAttachmentLoader_setError (spAttachmentLoader* self, const char* error1, const char* error2) {
  77. FREE(self->error1);
  78. FREE(self->error2);
  79. MALLOC_STR(self->error1, error1);
  80. MALLOC_STR(self->error2, error2);
  81. }
  82. void _spAttachmentLoader_setUnknownTypeError (spAttachmentLoader* self, spAttachmentType type) {
  83. char buffer[16];
  84. sprintf(buffer, "%d", type);
  85. _spAttachmentLoader_setError(self, "Unknown attachment type: ", buffer);
  86. }