|
|
@ -22,7 +22,7 @@ var movement_charge = 0.15 # In percent per meter (except when heroes change tha |
|
|
|
const fall_height = -50 |
|
|
|
|
|
|
|
var debug_node |
|
|
|
var recording = { "time": 0, "events": [], "spawn": Vector3() } |
|
|
|
var recording = { "time": 0, "states": [], "spawn": Vector3() } |
|
|
|
|
|
|
|
slave var slave_transform = Basis() |
|
|
|
slave var slave_lin_v = Vector3() |
|
|
@ -58,40 +58,6 @@ func spawn(): |
|
|
|
set_translation(placement) |
|
|
|
set_linear_velocity(Vector3()) |
|
|
|
|
|
|
|
func event_to_obj(event): |
|
|
|
var d = {} |
|
|
|
if event is InputEventMouseMotion: |
|
|
|
d.relative = {} |
|
|
|
d.relative.x = event.relative.x |
|
|
|
d.relative.y = event.relative.y |
|
|
|
d.type = "motion" |
|
|
|
if event is InputEventKey: |
|
|
|
d.scancode = event.scancode |
|
|
|
d.pressed = event.pressed |
|
|
|
d.type = "key" |
|
|
|
if event is InputEventMouseButton: |
|
|
|
d.button_index = event.button_index |
|
|
|
d.pressed = event.pressed |
|
|
|
d.type = "mb" |
|
|
|
return d |
|
|
|
|
|
|
|
func apply_dict(from, to): |
|
|
|
if typeof(from) != TYPE_DICTIONARY: |
|
|
|
return from |
|
|
|
else: |
|
|
|
for key in from: |
|
|
|
to[key] = apply_dict(from[key], to[key]) |
|
|
|
return to |
|
|
|
|
|
|
|
func obj_to_event(d): |
|
|
|
var e |
|
|
|
if d.type == "motion": e = InputEventMouseMotion.new() |
|
|
|
if d.type == "key": e = InputEventKey.new() |
|
|
|
if d.type == "mb": e = InputEventMouseButton.new() |
|
|
|
d.erase("type") # Not in the event |
|
|
|
apply_dict(d, e) |
|
|
|
return e |
|
|
|
|
|
|
|
func _input(event): |
|
|
|
if is_network_master(): |
|
|
|
if Input.is_action_just_pressed("switch_hero"): |
|
|
@ -99,8 +65,6 @@ func _input(event): |
|
|
|
# Quit the game: |
|
|
|
if Input.is_action_pressed("quit"): |
|
|
|
quit() |
|
|
|
if "record" in player_info: |
|
|
|
recording.events.append([recording.time, event_to_obj(event)]) |
|
|
|
|
|
|
|
func toggle_mouse_capture(): |
|
|
|
if (Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED): |
|
|
@ -115,10 +79,18 @@ func set_rotation(): |
|
|
|
get_node("Yaw").set_rotation(Vector3(0, deg2rad(get_node(tp_camera).cam_yaw), 0)) |
|
|
|
get_node("Yaw/Pitch").set_rotation(Vector3(deg2rad(-get_node(tp_camera).cam_pitch), 0, 0)) |
|
|
|
|
|
|
|
func record_status(status): |
|
|
|
if "record" in player_info: |
|
|
|
for i in range(status.size()): |
|
|
|
status[i] = var2str(status[i]) |
|
|
|
recording.states.append([recording.time, status]) |
|
|
|
|
|
|
|
func _integrate_forces(state): |
|
|
|
if is_network_master(): |
|
|
|
control_player(state) |
|
|
|
rpc_unreliable("set_status", get_status()) |
|
|
|
var status = get_status() |
|
|
|
rpc_unreliable("set_status", status) |
|
|
|
record_status(status) |
|
|
|
set_rotation() |
|
|
|
|
|
|
|
slave func set_status(s): |
|
|
@ -198,6 +170,9 @@ func _process(delta): |
|
|
|
if get_translation().y < fall_height: |
|
|
|
spawn() |
|
|
|
switch_hero_interface() |
|
|
|
|
|
|
|
if "record" in player_info: |
|
|
|
recording.time += delta |
|
|
|
|
|
|
|
func switch_hero_interface(): |
|
|
|
# Interface needs the mouse! |
|
|
@ -228,6 +203,8 @@ sync func switch_hero(hero): |
|
|
|
|
|
|
|
func _exit_scene(): |
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) |
|
|
|
if "record" in player_info: |
|
|
|
write_recording() |
|
|
|
|
|
|
|
# Functions |
|
|
|
# ========= |
|
|
@ -236,7 +213,7 @@ func write_recording(): |
|
|
|
var save = File.new() |
|
|
|
var fname = "res://recordings/%d-%d-%d.rec" % [player_info.level, player_info.hero, randi() % 10000] |
|
|
|
save.open(fname, File.WRITE) |
|
|
|
save.store_line(to_json(recording)) |
|
|
|
save.store_line(to_json(recording.states)) |
|
|
|
save.close() |
|
|
|
|
|
|
|
# Quits the game: |
|
|
|