Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add sorting feature and related conf #174

Merged
merged 3 commits into from
Sep 7, 2024
Merged

feat: add sorting feature and related conf #174

merged 3 commits into from
Sep 7, 2024

Conversation

Helias
Copy link
Member

@Helias Helias commented Sep 4, 2024

closes #133

I tested it in-game with few items

@Helias Helias requested a review from Nyeriah September 4, 2024 18:40
@Nyeriah
Copy link
Member

Nyeriah commented Sep 4, 2024

@Ceikry


if (sConfigMgr->GetOption<bool>("Transmogrification.EnableSortByQualityAndName", true)) {
const std::string acore_world_name = sConfigMgr->GetOption<std::string>("Transmogrification.AcoreWorldName", "acore_world");
query = "SELECT custom_unlocked_appearances.account_id, custom_unlocked_appearances.item_template_id, " + acore_world_name + ".item_template.name, " + acore_world_name + ".item_template.Quality FROM custom_unlocked_appearances INNER JOIN " + acore_world_name + ".item_template ON custom_unlocked_appearances.item_template_id=" + acore_world_name + ".item_template.entry ORDER BY " + acore_world_name + ".item_template.Quality DESC, " + acore_world_name + ".item_template.name ASC;";
Copy link
Member

Choose a reason for hiding this comment

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

This query will perform very badly with this cross-db join

Copy link
Member Author

Choose a reason for hiding this comment

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

I know, I do not know how to improve it
would be better to convert it into a left join?

@Ceikry
Copy link
Contributor

Ceikry commented Sep 4, 2024

Couldn't you just sort the generated vector of allowed items instead? Sure you sort multiple times but it's a cheap sort on such a small collection and wouldn't be nearly as messy.

something like this (you can and should probably make the name comparison better)

bool CmpTmog (Item* i1, Item* i2)
{
    const ItemTemplate* i1t = i1->GetTemplate();
    const ItemTemplate* i2t = i2->GetTemplate();
    return i1t->Name1[0] > i2t->Name1[0] || i1t->Quality > i2t->Quality;
}

    sort(allowedItems.begin(), allowedItems.end(), CmpTmog);

@Ceikry
Copy link
Contributor

Ceikry commented Sep 4, 2024

Couldn't you just sort the generated vector of allowed items instead? Sure you sort multiple times but it's a cheap sort on such a small collection and wouldn't be nearly as messy.

something like this (you can and should probably make the name comparison better)

bool CmpTmog (Item* i1, Item* i2)
{
    const ItemTemplate* i1t = i1->GetTemplate();
    const ItemTemplate* i2t = i2->GetTemplate();
    return i1t->Name1[0] > i2t->Name1[0] || i1t->Quality > i2t->Quality;
}

    sort(allowedItems.begin(), allowedItems.end(), CmpTmog);

in fact I would advise mildly reworking this to use string::compare for the name comparisons.

@Helias
Copy link
Member Author

Helias commented Sep 4, 2024

I will try that, thank you!

@Helias
Copy link
Member Author

Helias commented Sep 5, 2024

I restored the code as it was before and added that sort(allowedItems.begin(), allowedItems.end(), CmpTmog); before return allowedItems but it seems not working

@Helias
Copy link
Member Author

Helias commented Sep 5, 2024

if I remove i1t->Quality > i2t->Quality it orders the items per name, so I think that in some way I could sort them, I will look better into this, thanks a lot for the input

@Ceikry
Copy link
Contributor

Ceikry commented Sep 5, 2024

Yeah you might have to tweak the conditions for the comparison to be a bit more intelligent, I just kinda slapped an example together from what I remembered about C++ sorting

@Helias
Copy link
Member Author

Helias commented Sep 5, 2024

now it works
image
image
image
image

src/transmog_scripts.cpp Outdated Show resolved Hide resolved
@Nyeriah
Copy link
Member

Nyeriah commented Sep 7, 2024

Way much better, good job! 👍

@Nyeriah Nyeriah merged commit 3b7bac8 into master Sep 7, 2024
1 check passed
@Helias Helias deleted the sort-feature branch September 7, 2024 11:27
@Helias
Copy link
Member Author

Helias commented Sep 7, 2024

thanks you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion: Sort unlocked transmogs by name or quality (or both)
3 participants