Public repository for MUR pre alpha
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

  1. extends Spatial
  2. class_name Route
  3. signal road_added(road)
  4. signal road_removed(road)
  5. func get_last_road():
  6. if get_child_count() > 0:
  7. return get_child(get_child_count() - 1)
  8. else:
  9. return null
  10. func get_road(road_index):
  11. if get_child_count() > road_index:
  12. return get_child(road_index)
  13. else:
  14. return null
  15. remotesync func add_road(type, creator):
  16. var transform = get_global_transform()
  17. var last_road = get_last_road()
  18. if last_road != null:
  19. transform = last_road.get_global_transform();
  20. var curve = last_road.get_curve()
  21. transform = transform.translated(curve.get_point_position(curve.get_point_count() - 1))
  22. if last_road.get_end_rotation().length() != 0:
  23. transform.basis = transform.basis.rotated(last_road.get_end_rotation().normalized(), last_road.get_end_rotation().length())
  24. var new_road = roads_factory.get_road_instance(type)
  25. new_road.set_global_transform(transform)
  26. new_road.set_preview(false)
  27. new_road.set_creator(creator)
  28. if creator > 0:
  29. var player = gamestate.game.get_node(str(creator))
  30. if player != null:
  31. new_road.set_color(player.get_player_color())
  32. add_child(new_road)
  33. emit_signal("road_added", new_road)
  34. remotesync func remove_road(road_index):
  35. var road = get_child(road_index)
  36. remove_child(road)
  37. emit_signal("road_removed", road)