@@ -178,6 +178,39 @@ void checkImage(ToolState* state)
178178 }
179179}
180180
181+ void removeCreature (void * s)
182+ {
183+ ToolState* state = (ToolState*)s;
184+ std::vector<dnd::Creature> creatures = {state->current_creature };
185+ if (std::filesystem::exists (
186+ " creatures/" + state->current_creature .original_list + " .json" )) {
187+ creatures = parse_creatures_from_file (
188+ " creatures/" + state->current_creature .original_list + " .json" );
189+
190+ auto it = std::remove_if (creatures.begin (), creatures.end (),
191+ [state](const dnd::Creature& c) {
192+ return c.get_name () == state->current_creature .get_name ();
193+ });
194+ if (it != creatures.end ()) {
195+ creatures.erase (it, creatures.end ());
196+ }
197+ save_creatures_to_file (
198+ creatures,
199+ " creatures/" + state->current_creature .original_list + " .json" );
200+ }
201+
202+ // remove from state list
203+ auto it = std::remove_if (state->creatures .begin (), state->creatures .end (),
204+ [state](const dnd::Creature& c) {
205+ return c.get_name () == state->current_creature .get_name () &&
206+ c.original_list == state->current_creature .original_list ;
207+ });
208+ if (it != state->creatures .end ()) {
209+ state->creatures .erase (it, state->creatures .end ());
210+ state->reload_creatures = true ;
211+ }
212+ }
213+
181214void saveCreature (void * s) {
182215 ToolState* state = (ToolState*)s;
183216 std::vector<dnd::Creature> creatures = {state->current_creature };
@@ -290,6 +323,10 @@ void displayCreatureEdit(void* s) {
290323 ImGui::InputText (" List Name" , listNameBuffer, sizeof (listNameBuffer));
291324
292325 state->current_creature .original_list = std::string (listNameBuffer);
326+ if (ImGui::Button (" Remove from" ))
327+ {
328+
329+ }
293330 ImGui::SameLine ();
294331 if (ImGui::Button (" Save to" )) {
295332 saveCreature (s);
0 commit comments