{
  "Name": "LoadBMFont",
  "_id": "be33b3c9-8686-4a52-a257-90dbddee6a7a",
  "Namespace": "lib.geometry.generate.dependencies",
  "Description": "Loads a bitmap font set generated by BMFont (http://www.angelcode.com/products/bmfont/)",
  "Inputs": [
    {
      "Name": "FontPath",
      "MetaInstanceID": "47ee34eb-11d9-480f-8a88-4e41d1b44972",
      "DefaultValue": {
        "Type": "Text",
        "Value": "assets-common/image/BitmapFont.fnt"
      },
      "MetaID": "c522a66e-3260-4692-b3e3-79fd0361fa3d",
      "IsMultiInput": "False",
      "Relevance": "Required",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    }
  ],
  "Outputs": [
    {
      "Name": "FontImage",
      "MetaInstanceID": "94afc4d0-e65c-4894-b4b9-a284f37b51d3",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    },
    {
      "Name": "FontInfo",
      "MetaInstanceID": "d4ed9bd0-962d-45cf-b493-bf327e3f1dfc",
      "MetaID": "9701d534-b3ff-4889-a250-84aece4a7d76"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "a6dbf3b2-bd46-4e2e-b205-bcd53e880c72",
      "MetaID": "4045aca4-ff15-43c4-9e12-f8d17a0171f9",
      "Name": "LoadBMFontFunc",
      "Version": "cc92c952-dbbe-4807-9178-6aaea35f3a35",
      "Type": "Float",
      "IsMultiInput": "True",
      "Script": [
        "//>>> _using",
        "using System;",
        "using System.Collections.Generic;",
        "using System.Linq;",
        "using System.Text;",
        "using SharpDX;",
        "using SharpDX.Direct3D11;",
        "using SharpDX.Windows;",
        "//<<< _using",
        "using System.IO;",
        "using BmFont;",
        "",
        "namespace Framefield.Core.ID4045aca4_ff15_43c4_9e12_f8d17a0171f9",
        "{",
        "    public class Class_LoadBMFont : OperatorPart.Function",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            FontPath = 0",
        "        }",
        "        //<<< _inputids",
        "",
        "        //>>> _outputids",
        "        private enum OutputId",
        "        {",
        "            FontImage = 0,",
        "            FontInfo = 1",
        "        }",
        "        //<<< _outputids",
        "",
        "        public override void Dispose()",
        "        {",
        "            Utilities.DisposeObj(ref _fontImageResource);",
        "        }",
        "",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx) ",
        "        {",
        "            //>>> _params",
        "            var FontPath = inputs[(int)InputId.FontPath].Eval(context).Text;",
        "            //<<< _params",
        "",
        "            if (FontPath == _lastFontPath)",
        "                Changed = false;",
        "",
        "            _lastFontPath = FontPath;",
        "",
        "            if (Changed)",
        "            {",
        "                Dispose();",
        "                ReadFont(FontPath);",
        "",
        "                Changed = false;",
        "            }",
        "",
        "            if (_fontImageResource != null)",
        "            {",
        "                switch ((OutputId)outputIdx)",
        "                {",
        "                    case OutputId.FontImage:",
        "                        context.Image = _fontImageResource.Image;",
        "                        break;",
        "                    case OutputId.FontInfo:",
        "                        context.Dynamic = _fontFile;",
        "                        break;",
        "                }",
        "            }",
        "            else",
        "            {",
        "                switch (outputIdx)",
        "                {",
        "                    case (int)OutputId.FontImage:",
        "                        context.Image = null;",
        "                        break;",
        "                    case (int)OutputId.FontInfo:",
        "                        context.Dynamic = null;",
        "                        break;",
        "                }",
        "            }",
        "",
        "            return context;",
        "        }",
        "",
        "        private void ReadFont(string fontPath)",
        "        {",
        "            var fi = new FileInfo(fontPath);",
        "            if (fi.Extension.ToLower() != \".fnt\")",
        "            {",
        "                Logger.Error(this, \"No valid font file '{0}'\", fontPath);",
        "                return;",
        "            }",
        "",
        "            if (!fi.Exists)",
        "            {",
        "                Logger.Error(this, \"Font file not found '{0}'\", fontPath);",
        "                return;",
        "            }",
        "",
        "            _fontFile = FontLoader.Load(fi.FullName);",
        "",
        "            var firstPage = _fontFile.Pages[0];",
        "            var fontImagePath = fi.DirectoryName + @\"\\\" + firstPage.File;",
        "            if (!File.Exists(fontImagePath))",
        "            {",
        "                Logger.Error(this, \"Font image file not found '{0}'\", fontPath);",
        "                return;",
        "            }",
        "",
        "            _fontImageResource = ResourceManager.ReadImage(fontImagePath);",
        "        }",
        "",
        "        private ImageResource _fontImageResource;",
        "        private string _lastFontPath = string.Empty;",
        "        private FontFile _fontFile;",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "a6dbf3b2-bd46-4e2e-b205-bcd53e880c72",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "94afc4d0-e65c-4894-b4b9-a284f37b51d3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "47ee34eb-11d9-480f-8a88-4e41d1b44972",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "a6dbf3b2-bd46-4e2e-b205-bcd53e880c72"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "a6dbf3b2-bd46-4e2e-b205-bcd53e880c72",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "d4ed9bd0-962d-45cf-b493-bf327e3f1dfc"
    }
  ]
}