Beispiel #1
0
        private bool AcceptsInput(AssetImportInput input)
        {
            string inputFileExt    = Path.GetExtension(input.Path);
            bool   matchingFileExt = SourceFileExts.Any(acceptedExt => string.Equals(inputFileExt, acceptedExt, StringComparison.InvariantCultureIgnoreCase));

            return(matchingFileExt);
        }
Beispiel #2
0
        private bool AcceptsInput(AssetImportInput input)
        {
            string inputFileExt    = Path.GetExtension(input.Path);
            bool   matchingFileExt = SourceFileExtPrimary.Equals(inputFileExt, StringComparison.CurrentCultureIgnoreCase);

            return(matchingFileExt);
        }
Beispiel #3
0
        protected override void ImportResource(ContentRef <AudioData> resourceRef, AssetImportInput input, IAssetImportEnvironment env)
        {
            AudioData resource = resourceRef.Res;

            // Update audio data from the input file
            resource.OggVorbisData = File.ReadAllBytes(input.Path);
        }
Beispiel #4
0
        protected override void ImportResource(ContentRef <Pixmap> resourceRef, AssetImportInput input, IAssetImportEnvironment env)
        {
            Pixmap resource = resourceRef.Res;
            // Update pixel data from the input file
            PixelData pixelData = this.LoadPixelData(input.Path);

            resource.MainLayer = pixelData;
        }
Beispiel #5
0
        protected override void ImportResource(ContentRef <Pixmap> resourceRef, AssetImportInput input, IAssetImportEnvironment env)
        {
            Pixmap resource = resourceRef.Res;

            // Retrieve import parameters
            int sheetCols   = env.GetOrInitParameter(resourceRef, "SpriteSheetColumns", 0);
            int sheetRows   = env.GetOrInitParameter(resourceRef, "SpriteSheetRows", 0);
            int frameBorder = env.GetOrInitParameter(resourceRef, "SpriteFrameBorder", 0);

            // Clamp import parameters
            if (sheetCols < 0)
            {
                sheetCols = 0;
            }
            if (sheetRows < 0)
            {
                sheetRows = 0;
            }
            if (frameBorder < 0)
            {
                frameBorder = 0;
            }
            env.SetParameter(resourceRef, "SpriteSheetColumns", sheetCols);
            env.SetParameter(resourceRef, "SpriteSheetRows", sheetRows);
            env.SetParameter(resourceRef, "SpriteFrameBorder", frameBorder);

            // Update pixel data from the input file
            PixelData pixelData = this.LoadPixelData(input.Path);

            resource.MainLayer = pixelData;

            // Generate a sprite sheet atlas
            if (sheetCols > 0 && sheetRows > 0)
            {
                this.GenerateSpriteSheetAtlas(resource, sheetCols, sheetRows, frameBorder);
            }
        }
Beispiel #6
0
        protected override void ImportResource(ContentRef <DualityFont> resourceRef, AssetImportInput input, IAssetImportEnvironment env)
        {
            DualityFont resource = resourceRef.Res;
            // Retrieve import parameters
            float               size          = env.GetOrInitParameter(resourceRef, "Size", 16.0f);
            FontStyle           style         = env.GetOrInitParameter(resourceRef, "Style", FontStyle.Regular);
            string              customCharSet = env.GetOrInitParameter(resourceRef, "CustomCharSet", string.Empty);
            List <UnicodeBlock> unicodeBlocks = env.GetOrInitParameter(resourceRef, "UnicodeBlocks", new List <UnicodeBlock>(DefaultBlocks));
            bool antialiasing = env.GetOrInitParameter(resourceRef, "AntiAlias", true);
            bool monospace    = env.GetOrInitParameter(resourceRef, "Monospace", false);

            HashSet <char> fullCharSet = new HashSet <char>();

            if (!string.IsNullOrWhiteSpace(customCharSet))
            {
                string[] blocks = customCharSet.Split(',');
                ulong    start  = 0;
                ulong    end    = 0;

                foreach (string block in blocks)
                {
                    string[] limits = block.Split(new[] { '-' }, 3);
                    if (!ulong.TryParse(limits[0], NumberStyles.HexNumber, null, out start))
                    {
                        Log.Editor.WriteError("Cannot parse value " + limits[0] + "; CustomCharSet will be ignored. Please verify the value and repeat the import.");
                    }

                    if (limits.Length == 1)
                    {
                        end = start;
                    }
                    else
                    {
                        if (limits.Length == 2 && !ulong.TryParse(limits[1], NumberStyles.HexNumber, null, out end))
                        {
                            Log.Editor.WriteError("Cannot parse value " + limits[1] + "; CustomCharSet will be ignored. Please verify the value and repeat the import.");
                        }

                        else if (limits.Length > 2)
                        {
                            Log.Editor.WriteError("Unexpected values " + limits[2] + " in range " + block + " will be ignored. Please verify the value and repeat the import.");
                        }

                        if (start > end)
                        {
                            Log.Editor.WriteWarning(start + " is bigger than " + end + "; block will be ignored. Please verify the value and repeat the import.");
                        }
                    }

                    for (char c = (char)start; c <= (char)end; c++)
                    {
                        if (!char.IsControl(c))
                        {
                            fullCharSet.Add(c);
                        }
                    }
                }
            }

            if (unicodeBlocks != null)
            {
                Type unicodeBlockType     = typeof(UnicodeBlock);
                Type unicodeRangeAttrType = typeof(UnicodeRangeAttribute);

                foreach (UnicodeBlock block in unicodeBlocks)
                {
                    UnicodeRangeAttribute range = unicodeBlockType.GetMember(block.ToString())
                                                  .First()
                                                  .GetCustomAttributes(unicodeRangeAttrType, false)
                                                  .FirstOrDefault() as UnicodeRangeAttribute;

                    if (range != null)
                    {
                        for (char c = (char)range.CharStart; c <= (char)range.CharEnd; c++)
                        {
                            if (!char.IsControl(c))
                            {
                                fullCharSet.Add(c);
                            }
                        }
                    }
                }
            }

            // Load the TrueType Font and render all the required glyphs
            byte[]           trueTypeData = File.ReadAllBytes(input.Path);
            RenderedFontData fontData     = this.RenderGlyphs(
                trueTypeData,
                size,
                style,
                new FontCharSet(new string(fullCharSet.ToArray())),
                antialiasing,
                monospace);

            // Transfer our rendered Font data to the Font Resource
            resource.SetGlyphData(
                fontData.Bitmap,
                fontData.Atlas,
                fontData.GlyphData,
                fontData.Metrics);
        }