public override void Load(IResourceCache cache, ResourcePath path)
        {
            if (!cache.ContentFileExists(path))
            {
                throw new FileNotFoundException("Content file does not exist for font");
            }

            switch (GameController.Mode)
            {
            case GameController.DisplayMode.Headless:
                break;

            case GameController.DisplayMode.Godot:
                if (!cache.TryGetDiskFilePath(path, out string diskPath))
                {
                    throw new InvalidOperationException("Fonts can only be loaded from disk.");
                }

                var res = Godot.ResourceLoader.Load(diskPath);
                if (!(res is Godot.DynamicFontData fontData))
                {
                    throw new InvalidDataException("Path does not point to a font.");
                }

                FontData = fontData;
                break;

            case GameController.DisplayMode.Clyde:
                FontFaceHandle = IoCManager.Resolve <IFontManagerInternal>().Load(cache.ContentFileRead(path).ToArray());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public override void Load(IResourceCache cache, ResourcePath path)
        {
            if (!GameController.OnGodot)
            {
                return;
            }

            if (!cache.ContentFileExists(path))
            {
                throw new FileNotFoundException("Content file does not exist for texture");
            }

            if (!cache.TryGetDiskFilePath(path, out string diskPath))
            {
                throw new InvalidOperationException("Textures can only be loaded from disk.");
            }

            var res = Godot.ResourceLoader.Load(diskPath);

            if (!(res is Godot.DynamicFontData fontData))
            {
                throw new InvalidDataException("Path does not point to a font.");
            }

            FontData = fontData;
        }
Beispiel #3
0
 public override void Load(IResourceCache cache, ResourcePath path)
 {
     if (!cache.ContentFileExists(path))
     {
         throw new FileNotFoundException("Content file does not exist for texture");
     }
     if (!cache.TryGetDiskFilePath(path, out string diskPath))
     {
         throw new InvalidOperationException("Textures can only be loaded from disk.");
     }
     godotTexture = new Godot.ImageTexture();
     godotTexture.Load(diskPath);
     // If it fails to load it won't change the texture dimensions, so they'll still be at zero.
     if (godotTexture.GetWidth() == 0)
     {
         throw new InvalidDataException();
     }
     // Disable filter by default because pixel art.
     godotTexture.SetFlags(godotTexture.GetFlags() & ~(int)Godot.Texture.FlagsEnum.Filter);
     Texture = new GodotTextureSource(godotTexture);
     // Primarily for tracking down iCCP sRGB errors in the image files.
     Logger.Debug($"Loaded texture {Path.GetFullPath(diskPath)}.");
 }