Пример #1
0
        public Bitmap DrawAtlas <T>(IAtlas <T> atlas) where T : ImageItem, IItem
        {
            _logger.LogTrace($"ImageDrawerService.DrawAtlas({atlas}) invoked.");

            using (var bitmap = new Bitmap(atlas.Width, atlas.Height))
            {
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    foreach (var ci in atlas.GetConfiguredItems())
                    {
                        graphics.DrawImage(ci.OriginalItem.Image, ci.X, ci.Y, ci.Width, ci.Height);
                    }
                }

                _logger.LogTrace($"ImageDrawerService.DrawAtlas({atlas}) finished.");
                return((Bitmap)bitmap.Clone());
            }
        }
        public IList <string> GenerateConsoleOutput <T>(IAtlas <T> atlas) where T : ITextItem, IItem
        {
            _logger.LogTrace($"AtlasConsoleOutputService.GenerateConsoleOutput({atlas}) invoked.");

            if (atlas == null)
            {
                _logger.LogTrace($"AtlasConsoleOutputService.GenerateConsoleOutput({atlas}) finished due to a null atlas being passed in.");
                return(new List <string>());
            }

            var outputList = new List <string> {
                ConstStart
            };
            var configuredItems = atlas.GetConfiguredItems();

            for (int y = 0; y < atlas.Height; y++)
            {
                string outputString = "";
                for (int x = 0; x < atlas.Width; x++)
                {
                    var item = configuredItems.Where(ci => ((ci.X <= x && ((ci.X + ci.Width) > x)) &&
                                                            (ci.Y <= y && ((ci.Y + ci.Height) > y)))).FirstOrDefault();

                    if (item != null)
                    {
                        outputString = outputString + item.OriginalItem.Character.ToString();
                    }
                    else
                    {
                        outputString = outputString + ConstEmptySpace.ToString();
                    }
                }

                outputList.Add(outputString);
            }
            outputList.Add(ConstEnd);

            _logger.LogTrace($"AtlasConsoleOutputService.GenerateConsoleOutput({atlas}) finished.");
            return(outputList);
        }
        public override bool Validate <T>(IAtlas <T> atlas, out string parameterName, out string errorMessage)
        {
            // set our default string values
            errorMessage  = null;
            parameterName = "Width";

            // get our items
            var configuredItems = atlas.GetConfiguredItems();

            // iterate through each configured item
            foreach (var ci in configuredItems)
            {
                // get the scale of the configured item, and round it.
                var ciRoundedScale = Decimal.Round(ci.Width, ConstRoundTo);

                if (!base.Validate(ciRoundedScale, "ItemWidthValidator", out errorMessage))
                {
                    return(false);
                }
            }

            // if we passed all of the checks, then we're good.
            return(true);
        }
        public override bool Validate <T>(IAtlas <T> atlas, out string parameterName, out string errorMessage)
        {
            // set our default string values
            errorMessage  = null;
            parameterName = "Count";

            // get our items
            var configuredItems = atlas.GetConfiguredItems();

            // do a null error test
            if (configuredItems == null)
            {
                errorMessage = "ItemCountValidator.Validate failed. Configured item list was null.";
                return(false);
            }

            if (!base.Validate(configuredItems.Count, "ItemCountValidator", out errorMessage))
            {
                return(false);
            }

            // if we passed all of the checks, then we're good.
            return(true);
        }