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.

47 lines
1.2 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. return get_child(road_index)
  12. remotesync func add_road(type, creator):
  13. var transform = get_global_transform()
  14. var last_road = get_last_road()
  15. if last_road != null:
  16. transform = last_road.get_global_transform();
  17. var curve = last_road.get_curve()
  18. transform = transform.translated(curve.get_point_position(curve.get_point_count() - 1))
  19. if last_road.get_end_rotation().length() != 0:
  20. transform.basis = transform.basis.rotated(last_road.get_end_rotation().normalized(), last_road.get_end_rotation().length())
  21. var new_road = roads_factory.get_road_instance(type)
  22. new_road.set_global_transform(transform)
  23. new_road.set_preview(false)
  24. new_road.set_creator(creator)
  25. if creator > 0:
  26. var player = gamestate.game.get_node(str(creator))
  27. if player != null:
  28. new_road.set_color(player.get_player_color())
  29. add_child(new_road)
  30. emit_signal("road_added", new_road)
  31. remotesync func remove_road(road_index):
  32. var road = get_child(road_index)
  33. remove_child(road)
  34. emit_signal("road_removed", road)