Jam10/Scripts/PlayerRecorder.gd

37 lines
658 B
GDScript3
Raw Normal View History

2023-01-30 08:56:47 +00:00
extends Node
class_name PlayerRecorder
var replay: ReplayRecording
var this_frame: bool = true
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):
print(_delta)
2023-01-30 08:56:47 +00:00
if this_frame:
this_frame = false
replay.positions.append(player.pos)
replay.sprites.append(sprite)
replay.frames += 1
else:
this_frame = true
2023-01-30 10:12:53 +00:00
func save():
replay.save_to_uri(save_to)
queue_free()