Skip to content

[SDK-797] reformat code #274

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

Merged
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class TemplateSelectionElement : SelectionElement
{
private const string TAG = nameof(TemplateSelectionElement);
[SerializeField] private TemplateVersions templateVersions = TemplateVersions.V2;
[SerializeField] private OutfitGender gender = OutfitGender.None;
private List<AvatarTemplateData> avatarTemplates;
private AvatarTemplateFetcher avatarTemplateFetcher;
private CancellationToken ctx;
Expand All @@ -30,27 +29,26 @@ private void Awake()
avatarTemplateFetcher = new AvatarTemplateFetcher(ctx);
}


/// <summary>
/// Asynchronously loads avatar template data and creates button elements for each template.
/// Each button is created with an icon fetched from the template's image URL.
/// </summary>
public async void LoadAndCreateButtons()
{
await LoadAndCreateButtons(false);
await LoadAndCreateButtons(OutfitGender.None);
}

/// <summary>
/// Asynchronously loads avatar template data and creates button elements for each template.
/// Asynchronously loads avatar template data and creates button elements for each template based on the gender.
/// Each button is created with an icon fetched from the template's image URL.
/// <param name="gender">Gender for which the templates are loaded for</param>
/// </summary>
public async Task LoadAndCreateButtons(bool useCachedResponse)
public async Task LoadAndCreateButtons(OutfitGender gender)
{
if (!useCachedResponse || avatarTemplates == null)
{
await LoadTemplateData();
}
await LoadTemplateData();

var filteredTemplates = avatarTemplates!.Where(template => HasCorrectTemplateVersion(template) && HasCorrectGender(template)).ToList();
var filteredTemplates = avatarTemplates!.Where(template => HasCorrectTemplateVersion(template) && HasCorrectGender(template, gender)).ToList();

CreateButtons(filteredTemplates!.ToArray(), async (button, asset) =>
{
Expand All @@ -60,6 +58,7 @@ public async Task LoadAndCreateButtons(bool useCachedResponse)
button.SetIcon(texture);
});
}

private bool HasCorrectTemplateVersion(AvatarTemplateData template)
{
switch (templateVersions)
Expand All @@ -74,7 +73,7 @@ private bool HasCorrectTemplateVersion(AvatarTemplateData template)
}
}

private bool HasCorrectGender(AvatarTemplateData template)
private bool HasCorrectGender(AvatarTemplateData template, OutfitGender gender)
{
if (gender == OutfitGender.None || template.Gender == OutfitGender.None)
{
Expand Down