Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Custom splits #397

Merged
merged 18 commits into from
Jan 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4045,22 +4045,16 @@ struct HwDLL::Cmd_BXT_Splits_Delete

static void handler(const char* id_or_name)
{
// First try to find it by name, otherwise we'll try to find by id
const auto itr = std::find_if(Splits::splits.begin(), Splits::splits.end(),
[&id_or_name](const Splits::Split& s) { return !strcmp(id_or_name, s.get_name().c_str()); });

unsigned long idx = 0;
if (itr == Splits::splits.end())
idx = std::strtoul(id_or_name, nullptr, 10);
else
idx = itr - Splits::splits.begin() + 1;

if (idx == 0 || Splits::splits.size() < idx) {
HwDLL::GetInstance().ORIG_Con_Printf("There's no split with this name or id.\n");
auto split = Splits::GetSplitByNameOrId(id_or_name, true);
if (!split)
return;
}

Splits::splits.erase(Splits::splits.begin() + (idx - 1));
const auto it = std::find_if(Splits::splits.begin(), Splits::splits.end(), [&split](const Splits::Split& s) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this won't actually work if this split has an empty name, it's being deleted by id, and there's another split with an empty name before. Or if there are multiple splits with the same name. Maybe worth retaining the search as is then...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, i have reverted it

return split->get_name() == s.get_name();
});

if (it != Splits::splits.end())
Splits::splits.erase(it);
}
};

Expand Down