@@ -219,6 +219,41 @@ void displayCreatureEdit(void* s) {
219219 ImGui::Text (" No Image" );
220220 }
221221
222+ char listNameBuffer[256 ];
223+ strncpy (listNameBuffer, state->current_creature .original_list .c_str (),
224+ sizeof (listNameBuffer));
225+ listNameBuffer[sizeof (listNameBuffer) - 1 ] = ' \0 ' ;
226+
227+ ImGui::InputText (" List Name" , listNameBuffer, sizeof (listNameBuffer));
228+
229+ state->current_creature .original_list = std::string (listNameBuffer);
230+ ImGui::SameLine ();
231+ if (ImGui::Button (" Save to list" )) {
232+ std::vector<dnd::Creature> creatures = {state->current_creature };
233+ if (std::filesystem::exists (
234+ " creatures/" + state->current_creature .original_list + " .json" )) {
235+ creatures = parse_creatures_from_file (
236+ " creatures/" + state->current_creature .original_list + " .json" );
237+
238+ bool found = false ;
239+ for (size_t i = 0 ; i < creatures.size (); i++) {
240+ if (creatures[i].get_name () == state->current_creature .get_name ()) {
241+ creatures[i] = state->current_creature ;
242+ found = true ;
243+ break ;
244+ }
245+ }
246+ if (!found) {
247+ creatures.push_back (state->current_creature );
248+ }
249+ }
250+ // Save back to file
251+
252+ save_creatures_to_file (
253+ creatures,
254+ " creatures/" + state->current_creature .original_list + " .json" );
255+ }
256+
222257 ImGui::Separator ();
223258
224259 Size size = state->current_creature .get_size ().value_or (Size::MEDIUM );
@@ -573,42 +608,5 @@ void displayCreatureEdit(void* s) {
573608 }
574609 state->current_creature .set_image_url (std::string (imageUrlBuffer));
575610
576- char listNameBuffer[256 ];
577- strncpy (listNameBuffer, state->current_creature .original_list .c_str (),
578- sizeof (listNameBuffer));
579- listNameBuffer[sizeof (listNameBuffer) - 1 ] = ' \0 ' ;
580-
581- ImGui::Separator ();
582-
583- ImGui::InputText (" List Name" , listNameBuffer, sizeof (listNameBuffer));
584-
585- state->current_creature .original_list = std::string (listNameBuffer);
586- ImGui::SameLine ();
587- if (ImGui::Button (" Save to list" ))
588- {
589- std::vector<dnd::Creature> creatures = {state->current_creature };
590- if (std::filesystem::exists (
591- " creatures/" + state->current_creature .original_list + " .json" )) {
592- creatures = parse_creatures_from_file (
593- " creatures/" + state->current_creature .original_list + " .json" );
594-
595- bool found = false ;
596- for (size_t i = 0 ; i < creatures.size (); i++) {
597- if (creatures[i].get_name () == state->current_creature .get_name ()) {
598- creatures[i] = state->current_creature ;
599- found = true ;
600- break ;
601- }
602- }
603- if (!found) {
604- creatures.push_back (state->current_creature );
605- }
606- }
607- // Save back to file
608-
609- save_creatures_to_file (creatures, " creatures/" +
610- state->current_creature .original_list + " .json" );
611- }
612-
613611 ImGui::EndChild ();
614612}
0 commit comments