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.

60 lines
1.6 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 road_index >= 0 && get_child_count() > road_index:
  12. return get_child(road_index)
  13. else:
  14. return null
  15. master func add_road(type):
  16. if is_network_master():
  17. var sender_id = get_tree().get_rpc_sender_id()
  18. if sender_id == 0:
  19. sender_id = 1
  20. var creator = gamestate.game.get_player_by_network_id(sender_id)
  21. if creator != null && creator.is_in_group("first"):
  22. set_road(type,creator.get_name())
  23. rpc("set_road", type, creator.get_name())
  24. puppet func set_road(type, creator):
  25. var transform = get_global_transform()
  26. var last_road = get_last_road()
  27. if last_road != null:
  28. transform = last_road.get_global_transform();
  29. var curve = last_road.get_curve()
  30. transform = transform.translated(curve.get_point_position(curve.get_point_count() - 1))
  31. if last_road.get_end_rotation().length() != 0:
  32. transform.basis = transform.basis.rotated(last_road.get_end_rotation().normalized(), last_road.get_end_rotation().length())
  33. var new_road = roads_factory.get_road_instance(type)
  34. new_road.set_global_transform(transform)
  35. new_road.set_preview(false)
  36. new_road.set_creator(creator)
  37. var player = gamestate.game.get_player(str(creator))
  38. if player != null:
  39. new_road.set_color(player.get_player_color())
  40. add_child(new_road)
  41. emit_signal("road_added", new_road)
  42. remotesync func remove_road(road_index):
  43. var road = get_child(road_index)
  44. remove_child(road)
  45. emit_signal("road_removed", road)