sprite.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Some more OO wrappers for the low level sprite functionality
  2. class Sprite < Eruta::Sprite
  3. extend Registry
  4. attr_reader :id
  5. attr_reader :name
  6. def initialize(id, name)
  7. @id = id
  8. @name = name
  9. self.class.register(self)
  10. end
  11. BUILTIN_LAYOUTS = {
  12. :ulpcss => Eruta::Sprite::LOAD_ULPCSS_NORMAL,
  13. :ulpcss_slash => Eruta::Sprite::LOAD_ULPCSS_OVERSIZED_SLASH,
  14. :ulpcss_stab => Eruta::Sprite::LOAD_ULPCSS_OVERSIZED_STAB,
  15. }
  16. def self.load_builtin(sprite_id, layer, name, layout = :ulpcss)
  17. ilayout = BUILTIN_LAYOUTS[layout]
  18. full_name = "image/ulpcss/#{name}"
  19. p "load_builtin", sprite_id, layer, full_name, ilayout
  20. Eruta::Sprite.load_builtin sprite_id, layer, full_name, ilayout
  21. end
  22. # Loads a sprite sheet with built in layout as a layer.
  23. def load_builtin(layer, vpath, layout = :ulpcss)
  24. Sprite.load_builtin(@id, layer, vpath, layout)
  25. end
  26. # Loads a ULPCSS sprite sheet with built in layout as a layer.
  27. def load_ulpcss(layer, vpath)
  28. Sprite.load_builtin(@id, layer, vpath, :ulpcss)
  29. end
  30. # Loads a ULPCSS sprite sheet for an oversized slashing weapon
  31. # with built in layout as a layer.
  32. def load_ulpcss_slash(layer, vpath)
  33. Sprite.load_builtin(@id, layer, vpath, :ulpcss_slash)
  34. end
  35. # Loads a ULPCSS sprite sheet for an oversized stabbing weapon
  36. # with built in layout as a layer.
  37. def load_ulpcss_stab(layer, vpath)
  38. Sprite.load_builtin(@id, layer, vpath, :ulpcss_stab)
  39. end
  40. # Makes a new sprite posibly with the given ID, or otherwise tries to find a
  41. # free id.
  42. def self.make(name)
  43. id = Eruta::Sprite.sprite_new()
  44. p "Make sprite id #{id}"
  45. return nil if id < 0
  46. return self.new(id, name)
  47. end
  48. # Returns the action ID for the given pose and direction for this sprite.
  49. def action_index_for(pose, direction)
  50. return Erute::Sprite.action_index_for(@id, pose, direction)
  51. end
  52. # Deletes the underlying sprite. Don't use it anumore afterward!
  53. def delete
  54. Sprite.unregister(self)
  55. Eruta::Sprite.delete(@id)
  56. @id = nil
  57. return nil
  58. end
  59. end