A team game with an emphasis on movement (with no shooting), inspired by Overwatch and Zineth
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.

73 lines
1.7 KiB

  1. extends Node
  2. var recording
  3. var time
  4. func _ready():
  5. if is_network_master():
  6. print("readdyyyyy")
  7. read_recording()
  8. time = 0
  9. get_node("..").set_translation(str2var(recording.spawn))
  10. set_physics_process(true)
  11. func _physics_process(delta):
  12. if is_network_master():
  13. time += delta
  14. play_keys()
  15. func read_recording():
  16. # Gather all existing recordings
  17. var possible = []
  18. var begin = "%d-%d" % [get_node("..").player_info.level, get_node("..").player_info.hero]
  19. var path = "res://recordings/"
  20. var dir = Directory.new()
  21. dir.open(path)
  22. dir.list_dir_begin()
  23. while true:
  24. var fname = dir.get_next()
  25. print(fname)
  26. if fname == "":
  27. # Indicates end of directory
  28. break
  29. if fname.begins_with(begin):
  30. possible.append(fname)
  31. dir.list_dir_end()
  32. # Now pick a random one
  33. var fname = possible[randi() % possible.size()]
  34. # Read the file into recording.events for later use
  35. var frec = File.new()
  36. frec.open(path + fname, File.READ)
  37. recording = parse_json(frec.get_as_text())
  38. frec.close()
  39. func apply_dict(from, to):
  40. if typeof(from) != TYPE_DICTIONARY:
  41. return from
  42. else:
  43. for key in from:
  44. to[key] = apply_dict(from[key], to[key])
  45. return to
  46. func obj_to_event(d):
  47. var e
  48. if d.type == "motion": e = InputEventMouseMotion.new()
  49. if d.type == "key": e = InputEventKey.new()
  50. if d.type == "mb": e = InputEventMouseButton.new()
  51. d.erase("type") # Not in the event
  52. apply_dict(d, e)
  53. return e
  54. func play_keys():
  55. # events[0] is first event
  56. # events[0][0] is first event's TIME
  57. while float(recording.events[0][0]) <= time:
  58. # events[0][1] is first event's EVENT2
  59. var event_obj = recording.events.pop_front()[1]
  60. var event = obj_to_event(event_obj)
  61. Input.parse_input_event(event)
  62. #._input(event)
  63. #get_node("TPCamera")._input(event)