tilemap.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Models a low level tile map and helps manage loaded tile maps.
  2. class Tilemap < Store
  3. extend Store::Forward
  4. # Loads the tile map sample. Supports .tmx files.
  5. def self.load(name, vpath)
  6. load_something(forward_name(name), vpath, self) do | nid |
  7. Eruta::Store.load_tilemap(nid, vpath)
  8. end
  9. end
  10. # Sets a tile map as the active tile map.
  11. # Does not drop the previous tile map.
  12. def self.activate!(tilemap)
  13. active_map_ tilemap.id
  14. @active = tilemap
  15. end
  16. # returns the current active tilemap
  17. def self.active
  18. return @active || nil
  19. end
  20. # Equivalent to Tilemap.actvate(self)
  21. def activate!
  22. Tilemap.activate!(self)
  23. end
  24. # Reloads the current active tile map. Doesn othing if there is no active map
  25. # Returns the reloaded map. The map ID might have changed.
  26. def self.reload
  27. return nil unless self.active
  28. path = self.active.vpath
  29. name = self.active.name
  30. # Disable map
  31. active_map_(-1)
  32. # Drop the current map
  33. self.active_map.drop!
  34. # Load the map again and set it as active
  35. map = self.load(name, vpath)
  36. self.activate!(map) if map
  37. return map
  38. end
  39. end