2023-01-30 08:56:47 +00:00
|
|
|
extends Node
|
|
|
|
class_name PlayerRecorder
|
|
|
|
|
|
|
|
var replay: ReplayRecording
|
2023-01-30 19:49:06 +00:00
|
|
|
var this_frame: int = 0
|
2023-01-30 08:56:47 +00:00
|
|
|
var sprite: int = 0
|
2023-01-30 10:12:53 +00:00
|
|
|
var player: Node
|
|
|
|
var scene: Node
|
2023-01-30 08:56:47 +00:00
|
|
|
|
|
|
|
export var save_to: String
|
2023-01-30 10:12:53 +00:00
|
|
|
export var enabled: bool
|
2023-01-30 08:56:47 +00:00
|
|
|
|
|
|
|
func _ready():
|
2023-01-30 10:12:53 +00:00
|
|
|
if not enabled:
|
|
|
|
queue_free()
|
|
|
|
|
2023-01-30 08:56:47 +00:00
|
|
|
replay = ReplayRecording.new()
|
|
|
|
replay.time_per_frame = 1.0 / 30.0
|
|
|
|
player = get_parent()
|
|
|
|
player.recorder = self
|
2023-01-30 10:12:53 +00:00
|
|
|
scene = player.get_parent()
|
2023-01-30 08:56:47 +00:00
|
|
|
|
2023-01-30 19:10:26 +00:00
|
|
|
func _physics_process(_delta):
|
2023-01-30 19:49:06 +00:00
|
|
|
if this_frame == 0:
|
|
|
|
this_frame = 1
|
2023-01-30 08:56:47 +00:00
|
|
|
replay.positions.append(player.pos)
|
|
|
|
replay.sprites.append(sprite)
|
|
|
|
replay.frames += 1
|
|
|
|
|
|
|
|
else:
|
2023-01-30 19:49:06 +00:00
|
|
|
this_frame -= 1
|
2023-01-30 10:12:53 +00:00
|
|
|
|
|
|
|
func save():
|
|
|
|
replay.save_to_uri(save_to)
|
|
|
|
queue_free()
|