59 lines
1.2 KiB
GDScript
59 lines
1.2 KiB
GDScript
extends Object
|
|
class_name ReplayRecording
|
|
|
|
const TAPER: float = 7.0
|
|
|
|
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 = []
|
|
|
|
for _i in range(frames):
|
|
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:
|
|
return lerp(positions[-2], positions[-1], 2 + TAPER * atan((frame - frames) / TAPER))
|
|
|
|
func sprite(frame: int) -> int:
|
|
if frame < frames:
|
|
return sprites[frame]
|
|
else:
|
|
return sprites[-1]
|
|
|
|
func length() -> float:
|
|
return time_per_frame * frames
|