Creates a new ChangeRecord instance.
The path to the change record file.
The callback function to call when file handles are opened.
Options for the change record.
OptionaluseKeyframeRecord?: booleanWhether to use a keyframe record for snapshots. Default is true
The handle for the vhs.bin file.
StaticlagThe keyframe creation threshold in milliseconds. ChangeRecord.restoreBlockChangesToLevel uses this by checking how much time has passed when restoring from changes alone.
Appends a block change to the change record.
The position of the block change.
The block type.
Append an action to the change record.
Whether the action is a command.
The action bytes to append.
OptionalcommandString: stringThe command string (if applicable).
Trims the VHS file to the specified action count, discarding any actions beyond that count.
The action count to trim to.
Closes file handles of change record. Does not flush changes.
Flush changes to disk by compressing current buffer and append it to the VHS file.
The length of the flushed buffer.
Restore block changes to a level.
The level to restore changes to.
OptionalmaxActions: numberThe maximum number of actions to restore.
Optionalstaller: FunctionThe function to call to stall the restore process. Also prevents creating keyframes if defined.
The total number of actions restored.
I am a change record for a BaseLevel. I keep an append-only record of block changes and commands, allowing for restoring changes to levels.
I append actions representing block changes or commands to my record. My changes are buffered and periodically flushed to disk in compressed form. These actions can be restored to a level, replaying the recorded changes. I also support committing actions up to a specific action count, trimming the record.
Because of my append-only nature, long records can take a while to restore. In case that happens, my keyframeRecord can store periodic snapshots of the level state, allowing for faster restoration by starting from a recent keyframe instead of replaying all changes from the beginning.