AttachmentLoader.c 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. #include <spine/AttachmentLoader.h>
  31. #include <stdio.h>
  32. #include <spine/extension.h>
  33. typedef struct _spAttachmentLoaderVtable {
  34. spAttachment* (*createAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name,
  35. const char* path);
  36. void (*configureAttachment) (spAttachmentLoader* self, spAttachment*);
  37. void (*disposeAttachment) (spAttachmentLoader* self, spAttachment*);
  38. void (*dispose) (spAttachmentLoader* self);
  39. } _spAttachmentLoaderVtable;
  40. void _spAttachmentLoader_init (spAttachmentLoader* self,
  41. void (*dispose) (spAttachmentLoader* self),
  42. spAttachment* (*createAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name,
  43. const char* path),
  44. void (*configureAttachment) (spAttachmentLoader* self, spAttachment*),
  45. void (*disposeAttachment) (spAttachmentLoader* self, spAttachment*)
  46. ) {
  47. CONST_CAST(_spAttachmentLoaderVtable*, self->vtable) = NEW(_spAttachmentLoaderVtable);
  48. VTABLE(spAttachmentLoader, self)->dispose = dispose;
  49. VTABLE(spAttachmentLoader, self)->createAttachment = createAttachment;
  50. VTABLE(spAttachmentLoader, self)->configureAttachment = configureAttachment;
  51. VTABLE(spAttachmentLoader, self)->disposeAttachment = disposeAttachment;
  52. }
  53. void _spAttachmentLoader_deinit (spAttachmentLoader* self) {
  54. FREE(self->vtable);
  55. FREE(self->error1);
  56. FREE(self->error2);
  57. }
  58. void spAttachmentLoader_dispose (spAttachmentLoader* self) {
  59. VTABLE(spAttachmentLoader, self)->dispose(self);
  60. FREE(self);
  61. }
  62. spAttachment* spAttachmentLoader_createAttachment (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name,
  63. const char* path) {
  64. FREE(self->error1);
  65. FREE(self->error2);
  66. self->error1 = 0;
  67. self->error2 = 0;
  68. return VTABLE(spAttachmentLoader, self)->createAttachment(self, skin, type, name, path);
  69. }
  70. void spAttachmentLoader_configureAttachment (spAttachmentLoader* self, spAttachment* attachment) {
  71. if (!VTABLE(spAttachmentLoader, self)->configureAttachment) return;
  72. VTABLE(spAttachmentLoader, self)->configureAttachment(self, attachment);
  73. }
  74. void spAttachmentLoader_disposeAttachment (spAttachmentLoader* self, spAttachment* attachment) {
  75. if (!VTABLE(spAttachmentLoader, self)->disposeAttachment) return;
  76. VTABLE(spAttachmentLoader, self)->disposeAttachment(self, attachment);
  77. }
  78. void _spAttachmentLoader_setError (spAttachmentLoader* self, const char* error1, const char* error2) {
  79. FREE(self->error1);
  80. FREE(self->error2);
  81. MALLOC_STR(self->error1, error1);
  82. MALLOC_STR(self->error2, error2);
  83. }
  84. void _spAttachmentLoader_setUnknownTypeError (spAttachmentLoader* self, spAttachmentType type) {
  85. char buffer[16];
  86. sprintf(buffer, "%d", type);
  87. _spAttachmentLoader_setError(self, "Unknown attachment type: ", buffer);
  88. }