@@ -36,6 +36,8 @@ object Replay : Module(
3636 private val record by setting(" Record" , KeyCode .R )
3737 private val play by setting(" Play / Pause" , KeyCode .C )
3838 private val stop by setting(" Stop" , KeyCode .X )
39+ private val check by setting(" Checkpoint" , KeyCode .V , description = " Create a checkpoint in the recording." )
40+ private val playCheck by setting(" Play checkpoints" , KeyCode .B , description = " Replays until the last set checkpoint." )
3941 private val loop by setting(" Loop" , false )
4042 private val loops by setting(" Loops" , - 1 , - 1 .. 10 , 1 , description = " Number of times to loop the replay. -1 for infinite." , unit = " repeats" ) { loop }
4143 private val cancelOnDerivation by setting(" Cancel on derivation" , true )
@@ -50,6 +52,7 @@ object Replay : Module(
5052 RECORDING ,
5153 PAUSED_RECORDING ,
5254 PLAYING ,
55+ PLAYING_CHECKPOINTS ,
5356 PAUSED_REPLAY
5457 }
5558
@@ -83,6 +86,7 @@ object Replay : Module(
8386 }
8487 }
8588
89+ private var checkpoint: Recording ? = null
8690 private var recording: Recording ? = null
8791 private var replay: Recording ? = null
8892 private var repeats = 0
@@ -95,6 +99,8 @@ object Replay : Module(
9599 record.key -> handleRecord()
96100 play.key -> handlePlay()
97101 stop.key -> handleStop()
102+ check.key -> handleCheckpoint()
103+ playCheck.key -> handlePlayCheckpoints()
98104 else -> {}
99105 }
100106 }
@@ -107,18 +113,17 @@ object Replay : Module(
107113 it.position.add(player.pos)
108114 }
109115 }
110- State .PLAYING -> {
116+ State .PLAYING , State . PLAYING_CHECKPOINTS -> {
111117 replay?.let {
112- it.position.removeFirstOrNull()?.let { pos ->
118+ it.position.removeFirstOrNull()?.let a@ { pos ->
113119 val diff = pos.subtract(player.pos).length()
114- if (diff > 0.001 ) {
115- this @Replay.info(" Current derivation: ${" %.2f" .format(diff)} blocks." )
120+ if (diff < 0.001 ) return @a
116121
117- if (cancelOnDerivation && diff > derivationThreshold) {
118- state = State . INACTIVE
119- this @Replay.info( " Replay cancelled due to exceeding derivation threshold. " )
120- return @listener
121- }
122+ this @Replay.info( " Current derivation: ${ " %.3f " .format( diff)} blocks. " )
123+ if (cancelOnDerivation && diff > derivationThreshold) {
124+ state = State . INACTIVE
125+ this @Replay.info( " Replay cancelled due to exceeding derivation threshold. " )
126+ return @listener
122127 }
123128 }
124129 it.movement.removeFirstOrNull()?.update(event) ? : run {
@@ -127,8 +132,15 @@ object Replay : Module(
127132 replay = recording?.duplicate()
128133 this @Replay.info(" Replay looped. $repeats / $loops " )
129134 } else {
130- state = State .INACTIVE
131- this @Replay.info(" Recording finished after ${recording?.duration} ." )
135+ if (state != State .PLAYING_CHECKPOINTS ) {
136+ state = State .INACTIVE
137+ this @Replay.info(" Replay finished after ${recording?.duration} ." )
138+ return @listener
139+ }
140+
141+ state = State .RECORDING
142+ recording = checkpoint?.duplicate()
143+ this @Replay.info(" Checkpoint replayed. Continued recording..." )
132144 }
133145 }
134146 }
@@ -142,7 +154,7 @@ object Replay : Module(
142154 State .RECORDING -> {
143155 recording?.rotation?.add(player.rotation)
144156 }
145- State .PLAYING -> {
157+ State .PLAYING , State . PLAYING_CHECKPOINTS -> {
146158 replay?.let {
147159 it.rotation.removeFirstOrNull()?.let { rot ->
148160 event.context = RotationContext (rot, rotationConfig)
@@ -158,7 +170,7 @@ object Replay : Module(
158170 State .RECORDING -> {
159171 recording?.sprint?.add(player.isSprinting)
160172 }
161- State .PLAYING -> {
173+ State .PLAYING , State . PLAYING_CHECKPOINTS -> {
162174 replay?.let {
163175 it.sprint.removeFirstOrNull()?.let { sprint ->
164176 event.sprint = sprint
@@ -190,7 +202,7 @@ object Replay : Module(
190202 state = State .RECORDING
191203 this @Replay.info(" Recording resumed." )
192204 }
193- State .PLAYING -> {
205+ State .PLAYING , State . PLAYING_CHECKPOINTS -> { // ToDo: More general pausing for all states
194206 state = State .PAUSED_REPLAY
195207 this @Replay.info(" Replay paused." )
196208 }
@@ -222,14 +234,34 @@ object Replay : Module(
222234 state = State .INACTIVE
223235 this @Replay.info(" Recording stopped. Recorded for ${recording?.duration} ." )
224236 }
225- State .PLAYING , State .PAUSED_REPLAY -> {
237+ State .PLAYING , State .PAUSED_REPLAY , State . PLAYING_CHECKPOINTS -> {
226238 state = State .INACTIVE
227239 this @Replay.info(" Replay stopped." )
228240 }
229241 else -> {}
230242 }
231243 }
232244
245+ private fun handleCheckpoint () {
246+ when (state) {
247+ State .RECORDING -> {
248+ checkpoint = recording?.duplicate()
249+ this @Replay.info(" Checkpoint created." )
250+ }
251+ else -> {}
252+ }
253+ }
254+
255+ private fun handlePlayCheckpoints () {
256+ when (state) {
257+ State .INACTIVE -> {
258+ state = State .PLAYING_CHECKPOINTS
259+ replay = checkpoint?.duplicate()
260+ }
261+ else -> {}
262+ }
263+ }
264+
233265 data class MoveInputAction (
234266 @SerializedName(" i" )
235267 val input : InputAction ,
0 commit comments