2023-01-30 08:56:47 +00:00
|
|
|
extends Object
|
|
|
|
class_name ReplayRecording
|
|
|
|
|
2023-01-30 10:12:53 +00:00
|
|
|
const TAPER: float = 7.0
|
|
|
|
|
2023-01-30 08:56:47 +00:00
|
|
|
var time_per_frame: float
|
|
|
|
var frames: int = 0
|
|
|
|
|
|
|
|
var positions: Array
|
|
|
|
var sprites: Array
|
|
|
|
|
|
|
|
func load_from(file: File):
|
|
|
|
time_per_frame = file.get_real()
|
|
|
|
frames = file.get_32()
|
|
|
|
positions = []
|
|
|
|
sprites = []
|
|
|
|
|
2023-01-30 10:12:53 +00:00
|
|
|
for _i in range(frames):
|
2023-01-30 08:56:47 +00:00
|
|
|
var x: float = file.get_real()
|
|
|
|
var y: float = file.get_real()
|
|
|
|
positions.append(Vector2(x, y))
|
|
|
|
sprites.append(file.get_8())
|
|
|
|
|
|
|
|
func load_from_uri(uri: String):
|
|
|
|
var file: File = File.new()
|
|
|
|
file.open(uri, File.READ)
|
|
|
|
load_from(file)
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
func save_to(file: File):
|
|
|
|
file.store_real(time_per_frame)
|
|
|
|
file.store_32(frames)
|
|
|
|
|
|
|
|
for i in range(frames):
|
|
|
|
file.store_real(positions[i].x)
|
|
|
|
file.store_real(positions[i].y)
|
|
|
|
file.store_8(sprites[i])
|
|
|
|
|
|
|
|
func save_to_uri(uri: String):
|
|
|
|
var file: File = File.new()
|
|
|
|
file.open(uri, File.WRITE)
|
|
|
|
save_to(file)
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
func position(frame: int) -> Vector2:
|
|
|
|
if frame < frames:
|
|
|
|
return positions[frame]
|
|
|
|
else:
|
2023-01-30 10:12:53 +00:00
|
|
|
return lerp(positions[-2], positions[-1], 2 + TAPER * atan((frame - frames) / TAPER))
|
2023-01-30 08:56:47 +00:00
|
|
|
|
|
|
|
func sprite(frame: int) -> int:
|
|
|
|
if frame < frames:
|
|
|
|
return sprites[frame]
|
|
|
|
else:
|
|
|
|
return sprites[-1]
|
2023-01-30 10:12:53 +00:00
|
|
|
|
|
|
|
func length() -> float:
|
|
|
|
return time_per_frame * frames
|