Skip to content

Commit 78ff477

Browse files
committed
Path Manager: continue recording (from path's start or end)
1 parent 9d456b9 commit 78ff477

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

data/raw/keybindings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,6 +3427,12 @@
34273427
"category": "PATH_MANAGER",
34283428
"name": "Start recording"
34293429
},
3430+
{
3431+
"type": "keybinding",
3432+
"id": "CONTINUE_RECORDING",
3433+
"category": "PATH_MANAGER",
3434+
"name": "Continue recording"
3435+
},
34303436
{
34313437
"type": "keybinding",
34323438
"id": "STOP_RECORDING",

src/path_manager.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ class path_manager_impl
102102
* Start recording a new path.
103103
*/
104104
void start_recording();
105+
/**
106+
* Continue recording the first path the player is standing at start or end of.
107+
*/
108+
void continue_recording();
105109
/**
106110
* Stop recording path.
107111
*/
@@ -132,6 +136,8 @@ class path_manager_impl
132136
void set_recording_path( int p_index );
133137
void swap_selected( int index_a, int index_b );
134138
int recording_path_index = -1;
139+
// Used when continuing a recording from start
140+
bool swap_after_recording = false;
135141
int selected_id = -1;
136142
std::vector<path> paths;
137143
};
@@ -274,16 +280,33 @@ void path_manager_impl::start_recording()
274280
p.set_name_start();
275281
}
276282

283+
void path_manager_impl::continue_recording()
284+
{
285+
int p_index = player_at_what_start_or_end();
286+
cata_assert( p_index != -1 );
287+
set_recording_path( p_index );
288+
swap_after_recording = paths[recording_path_index].player_at_start();
289+
if( swap_after_recording ) {
290+
paths[recording_path_index].swap_start_end();
291+
}
292+
}
293+
277294
void path_manager_impl::stop_recording()
278295
{
279296
path &current_path = paths[recording_path_index];
280297
if( current_path.recorded_path.size() <= 1 ) {
281298
paths.erase( paths.begin() + recording_path_index );
282299
popup( _( "Recorded path has no length. Path erased." ) );
300+
set_recording_path( -1 );
301+
return;
302+
}
303+
if( swap_after_recording ) {
304+
current_path.swap_start_end();
305+
current_path.set_name_start();
283306
} else {
284307
current_path.set_name_end();
285-
popup( _( "Path saved." ) );
286308
}
309+
popup( _( "Path saved." ) );
287310

288311
set_recording_path( -1 );
289312
// TODO error when starts or stops at the same tile as another path ??
@@ -352,6 +375,9 @@ void path_manager_impl::auto_route_from_path() const
352375
void path_manager_impl::set_recording_path( int p_index )
353376
{
354377
cata_assert( -1 <= p_index && p_index < static_cast<int>( paths.size() ) );
378+
if( p_index == -1 ) {
379+
swap_after_recording = false;
380+
}
355381
recording_path_index = p_index;
356382
}
357383

@@ -377,6 +403,9 @@ void path_manager_ui::draw_controls()
377403
ImGui::SameLine();
378404
enabled_active_button( "START_RECORDING", !pimpl->recording_path() );
379405
ImGui::SameLine();
406+
enabled_active_button( "CONTINUE_RECORDING", !pimpl->recording_path()
407+
&& pimpl->player_at_what_start_or_end() != -1 );
408+
ImGui::SameLine();
380409
enabled_active_button( "STOP_RECORDING", pimpl->recording_path() );
381410

382411
// buttons related to selected path
@@ -459,6 +488,7 @@ void path_manager_ui::run()
459488
ctxt.register_action( "WALK_PATH" );
460489
ctxt.register_action( "START_RECORDING" );
461490
ctxt.register_action( "STOP_RECORDING" );
491+
ctxt.register_action( "CONTINUE_RECORDING" );
462492
ctxt.register_action( "DELETE_PATH" );
463493
ctxt.register_action( "MOVE_PATH_UP" );
464494
ctxt.register_action( "MOVE_PATH_DOWN" );
@@ -483,6 +513,9 @@ void path_manager_ui::run()
483513
} else if( action == "START_RECORDING" && !pimpl->recording_path() ) {
484514
pimpl->start_recording();
485515
break;
516+
} else if( action == "CONTINUE_RECORDING" && !pimpl->recording_path()
517+
&& pimpl->player_at_what_start_or_end() != -1 ) {
518+
pimpl->continue_recording();
486519
} else if( action == "STOP_RECORDING" && pimpl->recording_path() ) {
487520
pimpl->stop_recording();
488521
break;
@@ -554,6 +587,7 @@ void path_manager::deserialize( const JsonValue &jsin )
554587
{
555588
JsonObject data = jsin.get_object();
556589
data.read( "recording_path_index", pimpl->recording_path_index );
590+
data.read( "swap_after_recording", pimpl->swap_after_recording );
557591

558592
JsonArray data_paths = data.get_array( "paths" );
559593
for( int i = 0; data_paths.has_object( i ); ++i ) {
@@ -567,6 +601,7 @@ void path_manager::deserialize( const JsonValue &jsin )
567601
void path_manager::serialize( JsonOut &jsout )
568602
{
569603
jsout.member( "recording_path_index", pimpl->recording_path_index );
604+
jsout.member( "swap_after_recording", pimpl->swap_after_recording );
570605
jsout.member( "paths" );
571606
jsout.start_array();
572607
for( path &p : pimpl->paths ) {

0 commit comments

Comments
 (0)