TileMap.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. class TileMap
  2. attr_accessor :tilemaplayer
  3. def initialize()
  4. end
  5. def new_from_size(width, height)
  6. @width = width
  7. @height = height
  8. @tilemaplayer = TilemapLayer.new($tileset, @width, @height)
  9. end
  10. def parse(data)
  11. @width = get_value_from_tree(["width", "_"], data, 10)
  12. @height = get_value_from_tree(["height", "_"], data, 10)
  13. @layer = get_value_from_tree(["layer", "_"], data, "interactive")
  14. @solid = get_value_from_tree(["solid", "_"], data, true)
  15. @speed = get_value_from_tree(["speed", "_"], data, 1.0)
  16. @tilemaplayer = TilemapLayer.new($tileset, @width, @height)
  17. @tilemaplayer.set_data(get_value_from_tree(["tiles"], data, []))
  18. end
  19. def save(writer)
  20. writer.start_list("tilemap")
  21. writer.write_int("width", @width)
  22. writer.write_int("height", @height)
  23. writer.write_string("layer", @layer)
  24. writer.write_bool("solid", @solid)
  25. writer.write_float("speed", @speed)
  26. writer.write_int_vector("tiles", @tilemaplayer.get_data())
  27. writer.end_list("tilemap")
  28. end
  29. end