XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using Newtonsoft.Json.Linq;
using XFEWarframe.Desktop.Editing;

namespace XFEWarframe.Player.ViewModels;

public partial class InventoryPageViewModel
{
    private SuggestionProvider? suggestions;
    public SuggestionProvider Suggestions => suggestions ??= new(async query =>
    {
        if (!Account.IsLoggedIn) return [];
        return (await App.Accounts.InventoryAsync(query, Category?.Key ?? "", 0)).Items
            .Select(x => (object)new SearchSuggestion(x.Name, x.Type)).ToArray();
    });
}

public partial class ItemCatalogPageViewModel
{
    private SuggestionProvider? suggestions;
    public SuggestionProvider Suggestions => suggestions ??= new(async query =>
    {
        if (!Account.IsLoggedIn || !Account.ItemGrantEnabled) return [];
        return (await App.Accounts.CatalogAsync(query, Category?.Key ?? "", 0)).Items
            .Select(x => (object)new SearchSuggestion(x.Name, x.Type)).ToArray();
    });
}

public partial class EditorPageViewModel
{
    private SuggestionProvider? suggestions;
    public SuggestionProvider Suggestions => suggestions ??= new(async query =>
    {
        if (!Account.IsLoggedIn) return [];
        if (!Account.EditingEnabled)
            return (await AccountService.InventoryAsync(query, Category?.Key ?? "", 0)).Items
                .Select(x => (object)new SearchSuggestion(x.Name, x.Type)).ToArray();
        var data = await AccountService.ReadEditorAsync(Category?.Key ?? "Suits", query, null, 0);
        return (data["items"] as JArray ?? []).Select(x => (object)new SearchSuggestion(x.Value<string>("name")!, x.Value<string>("key")!)).ToArray();
    });
}

public partial class RivenPageViewModel
{
    private SuggestionProvider? ownedSuggestions;
    public SuggestionProvider OwnedSuggestions => ownedSuggestions ??= SuggestionProvider.OwnedRivens((query, skip) => AccountService.ReadEditorAsync("Upgrades", query, null, skip));
}