< Summary

Class:EmbeddedFontProvider
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Font/Providers/EmbeddedFontProvider.cs
Covered lines:5
Uncovered lines:1
Coverable lines:6
Total lines:37
Line coverage:83.3% (5 of 6)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EmbeddedFontProvider()0%110100%
GetFontAsync()0%4.054085.71%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Font/Providers/EmbeddedFontProvider.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using System;
 3using System.Collections.Generic;
 4using System.Threading;
 5using TMPro;
 6using UnityEngine;
 7using Object = UnityEngine.Object;
 8
 9public class EmbeddedFontProvider : IFontAssetProvider
 10{
 11    private const string RESOURCE_FONT_FOLDER = "Fonts & Materials";
 12    private const string DEFAULT_SANS_SERIF_HEAVY = "Inter-Heavy SDF";
 13    private const string DEFAULT_SANS_SERIF_BOLD = "Inter-Bold SDF";
 14    private const string DEFAULT_SANS_SERIF_SEMIBOLD = "Inter-SemiBold SDF";
 15    private const string DEFAULT_SANS_SERIF = "Inter-Regular SDF";
 16
 117    private static readonly Dictionary<string, string> fontsMapping = new ()
 18    {
 19        { "builtin:SF-UI-Text-Regular SDF", DEFAULT_SANS_SERIF },
 20        { "builtin:SF-UI-Text-Heavy SDF", DEFAULT_SANS_SERIF_HEAVY },
 21        { "builtin:SF-UI-Text-Semibold SDF", DEFAULT_SANS_SERIF_SEMIBOLD },
 22        { "builtin:LiberationSans SDF", "LiberationSans SDF" },
 23        { "SansSerif", DEFAULT_SANS_SERIF },
 24        { "SansSerif_Heavy", DEFAULT_SANS_SERIF_HEAVY },
 25        { "SansSerif_Bold", DEFAULT_SANS_SERIF_BOLD },
 26        { "SansSerif_SemiBold", DEFAULT_SANS_SERIF_SEMIBOLD },
 27    };
 28
 29    public async UniTask<TMP_FontAsset> GetFontAsync(string src, CancellationToken cancellationToken = default)
 30    {
 3231        if (!fontsMapping.TryGetValue(src, out string fontResourceName))
 032            throw new Exception("Font doesn't correspond with any know font");
 33
 9634        Object result = await Resources.LoadAsync<TMP_FontAsset>($"{RESOURCE_FONT_FOLDER}/{fontResourceName}").WithCance
 2835        return (TMP_FontAsset)result;
 2836    }
 37}