Пример #1
0
        internal void HandleCache(TinyToken cachedFontRoot)
        {
            if (!matches(cachedFontRoot))
            {
                return;
            }

            foreach (var cacheEntry in cachedFontRoot.Values <TinyObject>("Cache"))
            {
                var path = cacheEntry.Value <string>("Path");
                var hash = cacheEntry.Value <string>("Hash");

                var fullPath = Path.Combine(mapsetDirectory, path);
                if (!File.Exists(fullPath) || HashHelper.GetFileMd5(fullPath) != hash)
                {
                    continue;
                }

                textureCache.Add(cacheEntry.Value <string>("Text"), new FontTexture(
                                     path,
                                     cacheEntry.Value <float>("OffsetX"),
                                     cacheEntry.Value <float>("OffsetY"),
                                     cacheEntry.Value <int>("BaseWidth"),
                                     cacheEntry.Value <int>("BaseHeight"),
                                     cacheEntry.Value <int>("Width"),
                                     cacheEntry.Value <int>("Height")
                                     ));
            }
        }
Пример #2
0
        internal void HandleCache(TinyToken cachedFontRoot)
        {
            if (!matches(cachedFontRoot))
            {
                return;
            }

            foreach (var cacheEntry in cachedFontRoot.Values <TinyObject>("Cache"))
            {
                var path = cacheEntry.Value <string>("Path");
                var hash = cacheEntry.Value <string>("Hash");

                var fullPath = Path.Combine(mapsetDirectory, path);
                if (!File.Exists(fullPath) || HashHelper.GetFileMd5(fullPath) != hash)
                {
                    continue;
                }

                var text = cacheEntry.Value <string>("Text");
                if (text.Contains('\ufffd'))
                {
                    Trace.WriteLine($"Ignoring invalid font texture \"{text}\" ({path})");
                    continue;
                }
                if (textureCache.ContainsKey(text))
                {
                    throw new InvalidDataException($"The font texture for \"{text}\" ({path}) has been cached multiple times");
                }

                textureCache.Add(text, new FontTexture(
                                     path,
                                     cacheEntry.Value <float>("OffsetX"),
                                     cacheEntry.Value <float>("OffsetY"),
                                     cacheEntry.Value <int>("BaseWidth"),
                                     cacheEntry.Value <int>("BaseHeight"),
                                     cacheEntry.Value <int>("Width"),
                                     cacheEntry.Value <int>("Height")
                                     ));
            }
        }