Skip to content

Commit 89bc882

Browse files
committed
Removing of creatures from a list
1 parent 25a7799 commit 89bc882

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

CreatureEdit.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
181214
void 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);

CreatureList.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ void displayCreatures(void* s) {
6060
creature.get_max_hit_points(),
6161
creature.get_hit_dice().value().c_str());
6262
if (state->encounter_planner) {
63+
if (ImGui::Button("Add")) {
64+
state->current_encounter.add_creature(creature);
65+
}
66+
ImGui::SameLine();
6367
if (ImGui::Button("Edit")) {
6468
state->clear_image = true;
6569
state->current_creature = creature;
6670
// Focus on the edit tab
6771
ImGui::SetWindowFocus("Creature Edit");
6872
}
69-
ImGui::SameLine();
70-
if (ImGui::Button("Add"))
71-
{
72-
state->current_encounter.add_creature(creature);
73-
}
7473
} else if (state->encounter_battler) {
7574
if (ImGui::Button("View")) {
7675
state->clear_image = true;

0 commit comments

Comments
 (0)