示例#1
0
        protected void DrawItemToTileSet(Bitmap image, bool isFullSize, MainTileAlignment mainTileAlignment, Bitmap floorImage = null)
        {
            if (isFullSize)
            {
                if (image.Width == Program.MaxTileSize.Width && image.Height == Program.MaxTileSize.Height)
                {
                    DrawImageToTileSet(image);
                }
                else
                {
                    using (Bitmap targetBitmap = new Bitmap(Program.MaxTileSize.Width, Program.MaxTileSize.Height))
                    {
                        targetBitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
                        using (Graphics gTargetBitmap = Graphics.FromImage(targetBitmap))
                        {
                            int x = 0;
                            if (image.Width == 2 * Program.MaxTileSize.Width)
                            {
                                x = mainTileAlignment == MainTileAlignment.Left ? 0: Program.MaxTileSize.Width;
                            }
                            else if (image.Width == 3 * Program.MaxTileSize.Width)
                            {
                                x = Program.MaxTileSize.Width;
                            }

                            int       y       = image.Height - targetBitmap.Height;
                            Rectangle srcrect = new Rectangle(x, y, Program.MaxTileSize.Width, Program.MaxTileSize.Height);
                            gTargetBitmap.DrawImage(image, 0, 0, srcrect, GraphicsUnit.Pixel);
                            DrawImageToTileSet(targetBitmap);
                        }
                    }
                }
            }
            else
            {
                using (Bitmap targetBitmap = new Bitmap(Program.MaxTileSize.Width, Program.MaxTileSize.Height))
                {
                    targetBitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
                    using (Graphics gTargetBitmap = Graphics.FromImage(targetBitmap))
                    {
                        int x = targetBitmap.Width - image.Width;
                        int y = targetBitmap.Height - image.Height;
                        gTargetBitmap.DrawImage(image, x, y);
                        if (floorImage != null)
                        {
                            if (floorImage.Size != Program.ItemSize)
                            {
                                throw new WrongSizeException(floorImage.Size, Program.ItemSize,
                                                             string.Format("floorImage is of wrong size. It should be {0}x{1} but it is {2}x{3}",
                                                                           Program.ItemSize.Width, Program.ItemSize.Height, floorImage.Width, floorImage.Height));
                            }
                            gTargetBitmap.DrawImage(floorImage, 0, 0);
                        }
                        DrawImageToTileSet(targetBitmap);
                    }
                }
            }
        }
        public override void CompileOne(string[] splitLine)
        {
            if (splitLine.Length < _lineLength)
            {
                throw new Exception(string.Format("Broken Cmap line '{0}' has too few elements.", string.Join(',', splitLine)));
            }

            var map  = splitLine[1];
            var name = splitLine[2];
            var desc = splitLine[3];

            if (desc == _noDescription)
            {
                desc = "";
            }

            int widthInTiles  = int.Parse(splitLine[4]);
            int heightInTiles = int.Parse(splitLine[5]);
            MainTileAlignment mainTileAlignment = GetMainTileAlignment(splitLine[6]);

            var subDir2 = map.ToFileName();
            var name2   = name.Substring(2) + _brokenSuffix;

            var      dirPath      = Path.Combine(BaseDirectory.FullName, subDir2);
            var      fileName     = map.ToFileName() + "_" + name2.ToFileName() + Program.ImageFileExtension;
            var      relativePath = Path.Combine(_subDirName, subDir2, fileName);
            var      filePath     = Path.Combine(dirPath, fileName);
            FileInfo file         = new FileInfo(filePath);

            if (file.Exists)
            {
                WriteCmapTileNameSuccess(relativePath, desc);
                using (var image = new Bitmap(Image.FromFile(file.FullName)))
                {
                    if (image.Size == Program.MaxTileSize)
                    {
                        DrawImageToTileSet(image);
                    }
                    else
                    {
                        DrawMainTileToTileSet(image, widthInTiles, heightInTiles, mainTileAlignment, file);
                    }
                    StoreTileFile(file, image.Size);
                }
            }
            else
            {
                Console.WriteLine("File '{0}' not found. Creating Missing Broken Cmap tile.", file.FullName);
                WriteCmapTileNameErrorFileNotFound(relativePath, desc, "Creating Missing Broken Cmap tile.");

                using (var image = MissingBrokenCmapTileCreator.CreateTileWithTextLines(_missingBrokenCmapType, name2))
                {
                    DrawImageToTileSet(image);
                }
            }
            IncreaseCurXY();
        }
        public override void CompileOne(string[] splitLine)
        {
            if (splitLine.Length < _lineLength)
            {
                throw new Exception(string.Format("Animation line '{0}' has too few elements.", string.Join(',', splitLine)));
            }

            var animation            = splitLine[1];
            var frame                = splitLine[2];
            var originalTileNumber   = int.Parse(splitLine[3]);
            int subIndex             = 0;
            int widthInTiles         = int.Parse(splitLine[4]);
            int heightInTiles        = int.Parse(splitLine[5]);
            int mainTileAlignmentInt = int.Parse(splitLine[6]);

            if (!Enum.IsDefined(typeof(MainTileAlignment), mainTileAlignmentInt))
            {
                throw new Exception(string.Format("MainTileAlignment '{0}' is invalid. Should be 0 or 1.", mainTileAlignmentInt));
            }
            MainTileAlignment mainTileAlignment = (MainTileAlignment)mainTileAlignmentInt;

            TileData originalTileData              = GetTileFile(originalTileNumber, subIndex);
            Point?   originalFilePointInTiles      = originalTileData != null ? originalTileData.PointInTiles : null;
            Size?    originalFileBitmapSizeInTiles = originalTileData != null ? originalTileData.BitmapSizeInTiles : null;
            bool     flipHorizontal = originalTileData != null ? originalTileData.FlipHorizontal : false;
            bool     flipVertical   = originalTileData != null ? originalTileData.FlipVertical : false;

            var dirPath        = Path.Combine(BaseDirectory.FullName, animation.ToFileName());
            var fileName       = animation.ToFileName() + "_" + frame.ToFileName() + Program.ImageFileExtension;
            var fileName2      = frame.ToFileName() + Program.ImageFileExtension;
            var fileNameFloor  = animation.ToFileName() + "_" + frame.ToFileName() + _floorSuffix + Program.ImageFileExtension;
            var fileNameFloor2 = frame.ToFileName() + _floorSuffix + Program.ImageFileExtension;

            var      relativePath   = Path.Combine(_subDirName, animation.ToFileName(), fileName);
            var      relativePath2  = Path.Combine(_subDirName, animation.ToFileName(), fileName2);
            var      filePath       = Path.Combine(dirPath, fileName);
            FileInfo file           = new FileInfo(filePath);
            var      filePath2      = Path.Combine(dirPath, fileName2);
            FileInfo file2          = new FileInfo(filePath2);
            var      filePathFloor  = Path.Combine(dirPath, fileNameFloor);
            FileInfo fileFloor      = new FileInfo(filePathFloor);
            var      filePathFloor2 = Path.Combine(dirPath, fileNameFloor2);
            FileInfo fileFloor2     = new FileInfo(filePathFloor2);

            FileInfo template              = null;
            FileInfo template2             = null;
            string   templateRelativePath  = null;
            string   templateRelativePath2 = null;

            if (originalTileData != null)
            {
                var originalFileNameWithoutExtension = Path.GetFileNameWithoutExtension(originalTileData.File.Name).ToFileName();
                var templateDir   = Path.Combine(BaseDirectory.FullName, originalFileNameWithoutExtension);
                var templateName  = originalFileNameWithoutExtension + "_" + frame.ToFileName() + Program.ImageFileExtension;
                var templateName2 = frame.ToFileName() + Program.ImageFileExtension;

                templateRelativePath  = Path.Combine(_subDirName, originalFileNameWithoutExtension, templateName);
                templateRelativePath2 = Path.Combine(_subDirName, originalFileNameWithoutExtension, templateName2);
                var templatePath = Path.Combine(templateDir, templateName);
                template = new FileInfo(templatePath);
                var templatePath2 = Path.Combine(templateDir, templateName2);
                template2 = new FileInfo(templatePath2);
            }

            if (file.Exists || file2.Exists)
            {
                if (!file.Exists && file2.Exists)
                {
                    file         = file2;
                    fileFloor    = fileFloor2;
                    relativePath = relativePath2;
                }

                using (var image = new Bitmap(Image.FromFile(file.FullName)))
                {
                    if (originalFileBitmapSizeInTiles.HasValue && (originalFileBitmapSizeInTiles.Value.Width > 1 || originalFileBitmapSizeInTiles.Value.Height > 1))
                    {
                        Size rightSize = new Size(originalFileBitmapSizeInTiles.Value.Width * Program.MaxTileSize.Width, originalFileBitmapSizeInTiles.Value.Height * Program.MaxTileSize.Height);
                        if (image.Size != rightSize)
                        {
                            throw new WrongSizeException(image.Size, rightSize, string.Format("Image '{0}' should be {1}x{2} but is in reality {3}x{4}",
                                                                                              file.FullName, rightSize.Width, rightSize.Height, image.Width, image.Height));
                        }
                        Point pointInPixels = new Point(originalFilePointInTiles.Value.X * Program.MaxTileSize.Width, originalFilePointInTiles.Value.Y * Program.MaxTileSize.Height);
                        CropAndDrawImageToTileSet(image, pointInPixels, Program.MaxTileSize, file, flipHorizontal, flipVertical);
                        StoreTileFile(file, image.Size);
                    }
                    else
                    {
                        if (image.Size == Program.ItemSize)
                        {
                            var           baseTileData             = GetTileFile(originalTileNumber);
                            var           floorTileData            = baseTileData.FloorTileData;
                            FloorTileData floorTileDataReplacement = floorTileData != null ? new FloorTileData(fileFloor, floorTileData.HasTileFile, floorTileData.SubType, floorTileData.NameOrDesc) : null;

                            using (var floorImage = GetFloorTile(fileFloor, floorTileData, animation, frame))
                            {
                                DrawItemToTileSet(image, false, mainTileAlignment, floorImage);
                                StoreTileFile(file, image.Size, floorTileDataReplacement);
                            }
                        }
                        else if (image.Size == Program.MaxTileSize)
                        {
                            DrawImageToTileSet(image);
                            StoreTileFile(file, image.Size);
                        }
                        else
                        {
                            DrawMainTileToTileSet(image, widthInTiles, heightInTiles, mainTileAlignment, file);
                            StoreTileFile(file, image.Size);
                        }
                    }
                }

                Console.WriteLine("Compiled Animation '{0}' successfully.", relativePath);
                WriteTileNameSuccess(relativePath);
            }
            else if (template != null && template2 != null && (template.Exists || template2.Exists))
            {
                if (!template.Exists && template2.Exists)
                {
                    template             = template2;
                    templateRelativePath = templateRelativePath2;
                }

                var templateData = originalTileData.TemplateData;

                if (templateData == null)
                {
                    throw new Exception(string.Format("TemplateData for Tile {0} is null.", originalTileNumber));
                }

                using (var image = CreateBitmapFromTemplate(template, templateData.TemplateColor, originalTileData.BitmapSize))
                {
                    if (originalFileBitmapSizeInTiles.HasValue && (originalFileBitmapSizeInTiles.Value.Width > 1 || originalFileBitmapSizeInTiles.Value.Height > 1))
                    {
                        Size rightSize = new Size(originalFileBitmapSizeInTiles.Value.Width * Program.MaxTileSize.Width, originalFileBitmapSizeInTiles.Value.Height * Program.MaxTileSize.Height);
                        if (image.Size != rightSize)
                        {
                            throw new WrongSizeException(image.Size, rightSize, string.Format("Image '{0}' should be {1}x{2} but is in reality {3}x{4}",
                                                                                              template.FullName, rightSize.Width, rightSize.Height, image.Width, image.Height));
                        }
                        Point pointInPixels = new Point(originalFilePointInTiles.Value.X * Program.MaxTileSize.Width, originalFilePointInTiles.Value.Y * Program.MaxTileSize.Height);
                        CropAndDrawImageToTileSet(image, pointInPixels, Program.MaxTileSize, file, flipHorizontal, flipVertical);
                        StoreTileFile(template, image.Size);
                    }
                    else
                    {
                        if (image.Size == Program.ItemSize)
                        {
                            var floorTileData = originalTileData.FloorTileData;

                            FileInfo templateFloor  = null;
                            FileInfo templateFloor2 = null;
                            if (floorTileData != null && floorTileData.FloorFile != null)
                            {
                                var floorFileWithoutExtension = Path.GetFileNameWithoutExtension(floorTileData.FloorFile.Name).ToFileName();
                                var templateDirFloor          = Path.Combine(BaseDirectory.FullName, floorFileWithoutExtension);
                                var templateNameFloor         = floorFileWithoutExtension + "_" + frame.ToFileName() + Program.ImageFileExtension;
                                var templateNameFloor2        = frame.ToFileName() + Program.ImageFileExtension;
                                var templatePathFloor         = Path.Combine(templateDirFloor, templateNameFloor);
                                templateFloor = new FileInfo(templatePathFloor);
                                var templatePathFloor2 = Path.Combine(templateDirFloor, templateNameFloor2);
                                templateFloor2 = new FileInfo(templatePathFloor2);

                                if (!templateFloor.Exists && templateFloor2.Exists)
                                {
                                    templateFloor        = templateFloor2;
                                    templateRelativePath = templateRelativePath2;
                                }
                            }

                            FloorTileData floorTileDataReplacement = floorTileData != null ? new FloorTileData(templateFloor, floorTileData.HasTileFile, floorTileData.SubType, floorTileData.NameOrDesc) : null;

                            using (var floorImage = GetFloorTileFromTemplate(templateFloor, templateData, floorTileData))
                            {
                                DrawItemToTileSet(image, false, mainTileAlignment, floorImage);
                                StoreTileFile(file, image.Size, floorTileDataReplacement);
                            }
                        }
                        else if (image.Size == Program.MaxTileSize)
                        {
                            DrawImageToTileSet(image);
                            StoreTileFile(file, image.Size);
                        }
                        else
                        {
                            DrawMainTileToTileSet(image, widthInTiles, heightInTiles, mainTileAlignment, file);
                            StoreTileFile(file, image.Size);
                        }
                    }
                }

                Console.WriteLine("Created Animation {0} from Template {1} successfully.", relativePath, templateRelativePath);
                WriteTileNameTemplateGenerationSuccess(relativePath, templateRelativePath);
            }
            else
            {
                Console.WriteLine("File '{0}' not found. Creating Missing Animation.", file.FullName);
                WriteTileNameErrorFileNotFound(relativePath, "Creating Missing Animation.");

                using (var image = MissingAnimationCreator.CreateTile(_missingAnimationType, animation, frame))
                {
                    DrawImageToTileSet(image);
                }
            }

            IncreaseCurXY();
        }
        public override void CompileOne(string[] splitLine)
        {
            if (splitLine.Length < _lineLength)
            {
                throw new Exception(string.Format("Cmap line '{0}' has too few elements.", string.Join(',', splitLine)));
            }

            var map  = splitLine[1];
            var name = splitLine[2];
            var desc = splitLine[3];

            if (desc == _noDescription)
            {
                desc = "";
            }

            int widthInTiles  = int.Parse(splitLine[4]);
            int heightInTiles = int.Parse(splitLine[5]);
            MainTileAlignment mainTileAlignment = GetMainTileAlignment(splitLine[6]);

            var subDir2 = map.ToFileName();
            var name2   = name.Substring(2);

            var      dirPath      = Path.Combine(BaseDirectory.FullName, subDir2);
            var      fileName     = map.ToFileName() + "_" + name2.ToFileName() + Program.ImageFileExtension;
            var      relativePath = Path.Combine(_subDirName, subDir2, fileName);
            var      cmapName     = name.Substring(2).ToFileName();
            var      filePath     = Path.Combine(dirPath, fileName);
            FileInfo file         = new FileInfo(filePath);

            if (file.Exists)
            {
                WriteCmapTileNameSuccess(relativePath, desc);
                using (var image = new Bitmap(Image.FromFile(file.FullName)))
                {
                    if (image.Size == Program.MaxTileSize)
                    {
                        DrawImageToTileSet(image);
                    }
                    else
                    {
                        DrawMainTileToTileSet(image, widthInTiles, heightInTiles, mainTileAlignment, file);
                    }
                    StoreTileFile(file, image.Size);
                }
            }
            else if (name.StartsWith(_boomerangString))
            {
                string suffix = name.Substring(name.Length - 2, 2);

                if (!_boomerangMissileData.ContainsKey(suffix))
                {
                    throw new Exception(string.Format("_boomerangMissileData does not contain suffix '{0}'.", suffix));
                }

                MissileDirection missileDirection = _boomerangMissileData[suffix].Direction;

                string   sourceRelativePath = @"Objects\weapons\boomerang\weapon_boomerang.png";
                string   sourceFullPath     = Path.Combine(Program.InputDirectory.FullName, sourceRelativePath);
                FileInfo sourceFile         = new FileInfo(sourceFullPath);

                bool isTileMissing = false;

                using (var missileBitmap = ItemMissileCreator.CreateMissileFromFile(sourceFile, name.ToProperCaseFirst(), missileDirection, out isTileMissing))
                {
                    if (!isTileMissing)
                    {
                        Console.WriteLine("Autogenerated Cmap Missile Tile {0} Successfully.", relativePath);
                        WriteTileNameAutogenerationSuccess(sourceRelativePath, relativePath, _boomerangCmapMissileType);
                        StoreTileFile(sourceFile, missileBitmap.Size);
                    }
                    else
                    {
                        Console.WriteLine("Autogenerated Missing Cmap Missile Tile {0}.", relativePath);
                        WriteTileNameAutogenerationError(sourceRelativePath, relativePath, _boomerangCmapMissileType);
                    }
                    DrawImageToTileSet(missileBitmap);
                }
            }
            else
            {
                Console.WriteLine("File '{0}' not found. Creating Missing Cmap tile.", file.FullName);
                WriteCmapTileNameErrorFileNotFound(relativePath, desc, "Creating Missing Cmap tile.");

                using (var image = MissingCmapTileCreator.CreateTile(_missingCmapType, null, name2))
                {
                    DrawImageToTileSet(image);
                }
            }
            IncreaseCurXY();
        }
示例#5
0
        public override void CompileOne(string[] splitLine)
        {
            if (splitLine.Length < _lineLength)
            {
                throw new Exception(string.Format("Artifact line '{0}' has too few elements.", string.Join(',', splitLine)));
            }

            var type       = splitLine[1];
            var name       = splitLine[2];
            var desc       = splitLine[3];
            var desc2      = splitLine[5];
            var nameOrDesc = name;

            if (!string.IsNullOrWhiteSpace(desc))
            {
                nameOrDesc = desc;
            }
            else if (!string.IsNullOrWhiteSpace(desc2))
            {
                nameOrDesc = desc2;
            }

            if (!_typeSuffix.ContainsKey(type))
            {
                throw new Exception(string.Format("Artifact Type '{0}' unknown. Line: '{1}'.", type, string.Join(',', splitLine)));
            }

            string direction        = null;
            bool   isFullSizeBitmap = true;

            if (type == _typeMissile)
            {
                direction = splitLine[6];
                if (!_missileData.ContainsKey(direction))
                {
                    throw new Exception(string.Format("Invalid direction '{0}'. Line: '{1}'.", direction, string.Join(',', splitLine)));
                }
            }
            else
            {
                isFullSizeBitmap = int.Parse(splitLine[6]) > 0;
            }

            int widthInTiles         = int.Parse(splitLine[7]);
            int heightInTiles        = int.Parse(splitLine[8]);
            int mainTileAlignmentInt = int.Parse(splitLine[9]);

            if (!Enum.IsDefined(typeof(MainTileAlignment), mainTileAlignmentInt))
            {
                throw new Exception(string.Format("MainTileAlignment '{0}' is invalid. Should be 0 or 1.", mainTileAlignmentInt));
            }
            MainTileAlignment mainTileAlignment = (MainTileAlignment)mainTileAlignmentInt;

            int   colorCode     = int.Parse(splitLine[10]);
            Color templateColor = GetColorFromColorCode(colorCode);

            int    subTypeCode        = int.Parse(splitLine[11]);
            string subTypeName        = splitLine[12];
            string objectType         = splitLine[13];
            var    objectTypeSingular = GetSingular(objectType);

            int  hasFloorTileInt = int.Parse(splitLine[14]);
            bool hasFloorTile    = hasFloorTileInt > 0;

            if (type == _typeMissile)
            {
                //Autogenerate missile icon
                var subDir2         = name.ToFileName();
                var fileNameBase    = name.ToFileName() + Program.ImageFileExtension;
                var fileNameMissile = name.ToFileName() + _missileSuffix + Program.ImageFileExtension;
                var fileNameFloor   = name.ToFileName() + _floorSuffix + Program.ImageFileExtension;

                if (!_missileData.ContainsKey(direction))
                {
                    throw new Exception(string.Format("_missileData does not contain direction '{0}'.", direction));
                }

                MissileDirection missileDirection = _missileData[direction].Direction;

                string   dirPath          = Path.Combine(BaseDirectory.FullName, subDir2);
                var      relativePathBase = Path.Combine(_subDirName, subDir2, fileNameBase);
                var      filePathBase     = Path.Combine(dirPath, fileNameBase);
                FileInfo fileBase         = new FileInfo(filePathBase);

                var      relativePathFloor = Path.Combine(_subDirName, subDir2, fileNameFloor);
                var      filePathFloor     = Path.Combine(dirPath, fileNameFloor);
                FileInfo fileFloor         = new FileInfo(filePathFloor);

                var      relativePathMissile = Path.Combine(_subDirName, subDir2, fileNameMissile);
                var      filePathMissile     = Path.Combine(dirPath, fileNameMissile);
                FileInfo fileMissile         = new FileInfo(filePathMissile);

                var targetSubDir2  = name.ToFileName();
                var targetFileName = name.ToFileName() +
                                     _typeSuffix[type] +
                                     _missileData[direction].FileSuffix + Program.ImageFileExtension;
                var targetRelativePath = Path.Combine(_subDirName, targetSubDir2, targetFileName);

                bool isTileMissing = false;

                FileInfo file         = null;
                string   relativePath = null;
                if (fileMissile.Exists)
                {
                    file         = fileMissile;
                    relativePath = relativePathMissile;
                }
                else if (fileFloor.Exists)
                {
                    file         = fileFloor;
                    relativePath = relativePathFloor;
                }
                else
                {
                    file         = fileBase;
                    relativePath = relativePathBase;
                }

                using (var missileBitmap = ItemMissileCreator.CreateMissileFromFile(file, nameOrDesc.ToProperCaseFirst(), missileDirection, out isTileMissing))
                {
                    if (!isTileMissing)
                    {
                        Console.WriteLine("Autogenerated Artifact Missile Tile {0} successfully.", relativePath);
                        WriteTileNameAutogenerationSuccess(relativePath, targetRelativePath, _missileAutogenerateType);
                    }
                    else
                    {
                        Console.WriteLine("Autogenerated Missing Artifact Missile Tile {0}.", relativePath);
                        WriteTileNameAutogenerationError(relativePath, targetRelativePath, _missileAutogenerateType);
                    }
                    DrawImageToTileSet(missileBitmap);
                    StoreTileFile(file, missileBitmap.Size);
                    IncreaseCurXY();
                }
            }
            else
            {
                var subDir2  = name.ToFileName();
                var dirPath  = Path.Combine(BaseDirectory.FullName, subDir2);
                var fileName = name.ToFileName() + _typeSuffix[type] + Program.ImageFileExtension;

                var      relativePath = Path.Combine(_subDirName, subDir2, fileName);
                var      filePath     = Path.Combine(dirPath, fileName);
                FileInfo file         = new FileInfo(filePath);

                string   fileNameFloor     = name.ToFileName() + _typeSuffix[type] + _floorSuffix + Program.ImageFileExtension;
                string   relativePathFloor = Path.Combine(_subDirName, subDir2, fileNameFloor);
                string   filePathFloor     = Path.Combine(dirPath, fileNameFloor);
                FileInfo fileFloor         = hasFloorTile ? new FileInfo(filePathFloor) : null;

                //-----------------------------------------------
                // Template 1 is found under Artifacts directory
                //-----------------------------------------------
                string templateFileName = null;
                if (string.IsNullOrEmpty(subTypeName))
                {
                    templateFileName = objectTypeSingular.ToFileName() + _typeSuffix[type] + _templateSuffix + Program.ImageFileExtension;
                }
                else
                {
                    templateFileName = objectTypeSingular.ToFileName() + _typeSuffix[type] + _templateSuffix + "_" + subTypeName.ToDashed() + Program.ImageFileExtension;
                }

                string   templateDirPath      = BaseDirectory.FullName;
                string   templateRelativePath = Path.Combine(_subDirName, templateFileName);
                string   templateFilePath     = Path.Combine(templateDirPath, templateFileName);
                FileInfo templateFile         = new FileInfo(templateFilePath);

                //---------------------------------------------
                // Template 2 is found under Objects directory
                //---------------------------------------------
                string template2SubDir = objectType.ToFileName();

                string template2FileName = null;
                if (string.IsNullOrEmpty(subTypeName))
                {
                    template2FileName = objectTypeSingular.ToFileName() + _typeSuffix[type] + _templateSuffix + Program.ImageFileExtension;
                }
                else
                {
                    template2FileName = objectTypeSingular.ToFileName() + _typeSuffix[type] + _templateSuffix + "_" + subTypeName.ToDashed() + Program.ImageFileExtension;
                }

                string   template2DirPath      = Path.Combine(ObjectBaseDirectory.FullName, template2SubDir);
                string   template2RelativePath = Path.Combine(_objectSubDirName, template2SubDir, template2FileName);
                string   template2FilePath     = Path.Combine(template2DirPath, template2FileName);
                FileInfo template2File         = new FileInfo(template2FilePath);

                var subType = "";
                if (type != _typeNormal)
                {
                    subType = type;
                }

                if (file.Exists)
                {
                    using (var image = new Bitmap(Image.FromFile(file.FullName)))
                    {
                        using (var floorImage = GetFloorTile(fileFloor, hasFloorTile, subType, nameOrDesc, file))
                        {
                            DrawItemToTileSet(image, isFullSizeBitmap, mainTileAlignment, floorImage);
                            StoreTileFile(file, image.Size, new FloorTileData(fileFloor, hasFloorTile, subType, nameOrDesc));
                        }
                    }

                    Console.WriteLine("Compiled Artifact '{0}' successfully.", relativePath);
                    WriteTileNameSuccess(relativePath);
                }
                else if (templateFile.Exists)
                {
                    string templateFileNameFloor = null;
                    if (string.IsNullOrEmpty(subTypeName))
                    {
                        templateFileNameFloor = objectTypeSingular.ToFileName() + _typeSuffix[type] + _templateFloorSuffix + Program.ImageFileExtension;
                    }
                    else
                    {
                        templateFileNameFloor = objectTypeSingular.ToFileName() + _typeSuffix[type] + _templateFloorSuffix + "_" + subTypeName.ToDashed() + Program.ImageFileExtension;
                    }
                    string   templateFilePathFloor = Path.Combine(templateDirPath, templateFileNameFloor);
                    FileInfo templateFileFloor     = new FileInfo(templateFilePathFloor);

                    using (var image = CreateItemFromTemplate(templateFile, templateColor, subTypeCode, subTypeName))
                    {
                        using (var floorTemplateImage = GetFloorTileFromTemplate(templateFileFloor, templateColor, subTypeCode, subTypeName, hasFloorTile, subType, nameOrDesc, templateFile))
                        {
                            DrawItemToTileSet(image, isFullSizeBitmap, mainTileAlignment, floorTemplateImage);
                            StoreTileFile(templateFile, image.Size, false, true,
                                          new TemplateData(templateColor, subTypeCode, subTypeName),
                                          new FloorTileData(templateFileFloor, hasFloorTile, subType, nameOrDesc));
                        }
                    }

                    Console.WriteLine("Created Object {0} from Template {1} successfully.", relativePath, templateRelativePath);
                    WriteTileNameTemplateGenerationSuccess(relativePath, templateRelativePath);
                }
                else if (template2File.Exists)
                {
                    string template2FileNameFloor = null;
                    if (string.IsNullOrEmpty(subTypeName))
                    {
                        template2FileNameFloor = objectTypeSingular.ToFileName() + _typeSuffix[type] + _templateFloorSuffix + Program.ImageFileExtension;
                    }
                    else
                    {
                        template2FileNameFloor = objectTypeSingular.ToFileName() + _typeSuffix[type] + _templateFloorSuffix + "_" + subTypeName.ToDashed() + Program.ImageFileExtension;
                    }
                    string   template2FilePathFloor = Path.Combine(template2DirPath, template2FileNameFloor);
                    FileInfo template2FileFloor     = new FileInfo(template2FilePathFloor);

                    using (var image = CreateItemFromTemplate(template2File, templateColor, subTypeCode, subTypeName))
                    {
                        using (var floorTemplateImage = GetFloorTileFromTemplate(template2FileFloor, templateColor, subTypeCode, subTypeName, hasFloorTile, subType, nameOrDesc, template2File))
                        {
                            DrawItemToTileSet(image, isFullSizeBitmap, mainTileAlignment, floorTemplateImage);
                            StoreTileFile(template2File, image.Size, false, true,
                                          new TemplateData(templateColor, subTypeCode, subTypeName),
                                          new FloorTileData(template2FileFloor, hasFloorTile, subType, nameOrDesc));
                        }
                    }

                    Console.WriteLine("Created Object {0} from Template {1} successfully.", relativePath, template2RelativePath);
                    WriteTileNameTemplateGenerationSuccess(relativePath, template2RelativePath);
                }
                else
                {
                    Console.WriteLine("File '{0}' not found. Creating Missing Artifact icon.", file.FullName);
                    WriteTileNameErrorFileNotFound(relativePath, "Creating Missing Artifact icon.");

                    var missingTileCreator = isFullSizeBitmap ? MissingArtifactTileCreator : MissingArtifactFloorTileCreator;
                    using (var image = missingTileCreator.CreateTile(_artifactMissingTileType, subType, nameOrDesc))
                    {
                        using (var floorImage = GetFloorTile(fileFloor, hasFloorTile, subType, nameOrDesc, file))
                        {
                            DrawItemToTileSet(image, isFullSizeBitmap, mainTileAlignment, floorImage);
                        }
                    }
                }

                IncreaseCurXY();
            }
        }
        public Bitmap CreateStatueMainTileFromFile(FileInfo sourceFile, int widthInTiles, int heightInTiles, MainTileAlignment mainTileAlignment, string name, string genderDesc, out bool isUnknown)
        {
            isUnknown = false;
            if (!sourceFile.Exists)
            {
                Console.WriteLine("Source File '{0}' not found. Creating Missing Statue file.", sourceFile.FullName);
                isUnknown = true;
            }
            if (!isUnknown)
            {
                using (Bitmap sourceBitmap = (Bitmap)Image.FromFile(sourceFile.FullName))
                {
                    if (sourceBitmap.Width != widthInTiles * Program.MaxTileSize.Width || sourceBitmap.Height != heightInTiles * Program.MaxTileSize.Height)
                    {
                        throw new WrongSizeException(sourceBitmap.Size, new Size(widthInTiles * Program.MaxTileSize.Width, heightInTiles * Program.MaxTileSize.Height),
                                                     string.Format("Monster Tile '{0}' is wrong size ({1}x{2}). It should be {3}x{4}.", sourceFile.FullName,
                                                                   sourceBitmap.Width, sourceBitmap.Height, widthInTiles * Program.MaxTileSize.Width, heightInTiles * Program.MaxTileSize.Height));
                    }

                    bool isOneTile;
                    var  point = Program.GetMainTileLocationInPixels(widthInTiles, heightInTiles, mainTileAlignment, out isOneTile);

                    if (isOneTile)
                    {
                        return(CreateStatueBitmap(sourceBitmap));
                    }

                    using (var croppedBitmap = sourceBitmap.Clone(new Rectangle(point, Program.MaxTileSize), sourceBitmap.PixelFormat))
                    {
                        return(CreateStatueBitmap(croppedBitmap));
                    }
                }
            }
            else
            {
                return(MissingStatueTileCreator.CreateTileWithTextLines(_missingTileType, _missingTileSubType, name, genderDesc));
            }
        }
示例#7
0
        public override void CompileOne(string[] splitLine)
        {
            if (splitLine.Length < _monsterLineLength)
            {
                throw new Exception(string.Format("Monster line '{0}' has too few elements.", string.Join(',', splitLine)));
            }

            var gender = splitLine[1];

            if (!_genderData.ContainsKey(gender))
            {
                throw new Exception(string.Format("Invalid gender '{0}' in monster line '{1}'.", gender, string.Join(',', splitLine)));
            }

            var type = splitLine[2];

            if (!_typeData.ContainsKey(type))
            {
                throw new Exception(string.Format("Invalid type '{0}' in monster line '{1}'.", type, string.Join(',', splitLine)));
            }

            var name                            = splitLine[3];
            var widthInTiles                    = int.Parse(splitLine[4]);
            var heightInTiles                   = int.Parse(splitLine[5]);
            var mainTileAligntmentInt           = int.Parse(splitLine[6]);
            MainTileAlignment mainTileAlignment = (MainTileAlignment)mainTileAligntmentInt;

            if (type == _type_statue)
            {
                var sourceSubDir2 = name.ToLower().Replace(" ", "_");

                var      sourceMonsterDirPath = Path.Combine(BaseDirectory.FullName, sourceSubDir2);
                var      sourceFileName       = name.ToLower().Replace(" ", "_") + _genderData[gender].Suffix + Program.ImageFileExtension;
                var      sourceRelativePath   = Path.Combine(_subDirName, sourceSubDir2, sourceFileName);
                FileInfo sourceFile           = new FileInfo(Path.Combine(sourceMonsterDirPath, sourceFileName));

                var    destSubDirPath       = Path.Combine(name.ToLower().Replace(" ", "_"));
                string destFileName         = name.ToLower().Replace(" ", "_") + _genderData[gender].Suffix + _typeData[type].Suffix + Program.ImageFileExtension;
                var    destFileRelativePath = Path.Combine(_subDirName, destSubDirPath, destFileName);

                bool isUnknown;
                using (var image = StatueCreator.CreateStatueMainTileFromFile(sourceFile,
                                                                              widthInTiles, heightInTiles, mainTileAlignment, name, _genderData[gender].Description, out isUnknown))
                {
                    if (!isUnknown)
                    {
                        Console.WriteLine("Autogenerated Monster Statue Tile {0} successfully.", destFileRelativePath);
                        WriteTileNameAutogenerationSuccess(sourceRelativePath, destFileRelativePath, type);
                    }
                    else
                    {
                        Console.WriteLine("Monster file '{0}' not found for statue creation. Creating a Missing Monster Tile.", sourceFile.FullName);
                        WriteTileNameAutogenerationError(sourceRelativePath, destFileRelativePath, type);
                    }
                    DrawImageToTileSet(image);
                    StoreTileFile(sourceFile, image.Size, true);
                    IncreaseCurXY();
                }
            }
            else
            {
                var subDir2        = name.ToLower().Replace(" ", "_");
                var monsterDirPath = Path.Combine(BaseDirectory.FullName, subDir2);

                if (!_typeData.ContainsKey(type))
                {
                    throw new Exception(string.Format("Unknown monster type '{0}'.", type));
                }

                var fileName = name.ToLower().Replace(" ", "_") +
                               _genderData[gender].Suffix +
                               _typeData[type].Suffix +
                               Program.ImageFileExtension;

                var      relativePath = Path.Combine(_subDirName, subDir2, fileName);
                var      filePath     = Path.Combine(monsterDirPath, fileName);
                FileInfo file         = new FileInfo(filePath);

                var fileName2 = name.ToLower().Replace(" ", "_") +
                                _genderData[gender].Suffix +
                                _typeData[_typeNormal].Suffix +
                                Program.ImageFileExtension;

                var      relativePath2 = Path.Combine(_subDirName, subDir2, fileName2);
                var      filePath2     = Path.Combine(monsterDirPath, fileName2);
                FileInfo file2         = new FileInfo(filePath2);

                if (file.Exists)
                {
                    string typeDesc = _typeData[type].Description;
                    if (string.IsNullOrEmpty(typeDesc))
                    {
                        typeDesc = "Normal";
                    }
                    Console.WriteLine("Created Monster {0} Tile '{1}' successfully.", typeDesc, relativePath);
                    WriteTileNameSuccess(relativePath);

                    using (var image = new Bitmap(Image.FromFile(file.FullName)))
                    {
                        if (image.Width != widthInTiles * Program.MaxTileSize.Width || image.Height != heightInTiles * Program.MaxTileSize.Height)
                        {
                            throw new WrongSizeException(image.Size, new Size(widthInTiles * Program.MaxTileSize.Width, heightInTiles * Program.MaxTileSize.Height),
                                                         string.Format("Monster Tile '{0}' is wrong size ({1}x{2}). It should be {3}x{4}.", file.FullName,
                                                                       image.Width, image.Height, widthInTiles * Program.MaxTileSize.Width, heightInTiles * Program.MaxTileSize.Height));
                        }
                        DrawMainTileToTileSet(image, widthInTiles, heightInTiles, mainTileAlignment, file);
                        StoreTileFile(file, image.Size);
                    }
                }
                else if (file2.Exists)
                {
                    string typeDesc = _typeData[_typeNormal].Description;
                    if (string.IsNullOrEmpty(typeDesc))
                    {
                        typeDesc = "Normal";
                    }
                    Console.WriteLine("Replaced Monster {0} Tile {1} with a corresponding normal tile {2}.", typeDesc, relativePath, relativePath2);
                    WriteTileNameSuccess(relativePath2);

                    using (var image = new Bitmap(Image.FromFile(file2.FullName)))
                    {
                        if (image.Width != widthInTiles * Program.MaxTileSize.Width || image.Height != heightInTiles * Program.MaxTileSize.Height)
                        {
                            throw new WrongSizeException(image.Size, new Size(widthInTiles * Program.MaxTileSize.Width, heightInTiles * Program.MaxTileSize.Height),
                                                         string.Format("Monster Tile '{0}' is wrong size ({1}x{2}). It should be {3}x{4}.", file2.FullName,
                                                                       image.Width, image.Height, widthInTiles * Program.MaxTileSize.Width, heightInTiles * Program.MaxTileSize.Height));
                        }
                        DrawMainTileToTileSet(image, widthInTiles, heightInTiles, mainTileAlignment, file2);
                        StoreTileFile(file2, image.Size);
                    }
                }
                else
                {
                    if (type == _type_corpse)
                    {
                        Console.WriteLine("Corpse file '{0}' not found. Creating a Missing Corpse Tile.", file.FullName);
                        WriteTileNameErrorFileNotFound(relativePath, "Creating a Missing Corpse Tile.");

                        using (var image = MissingCorpseTileCreator.CreateTile(_missingCorpseTileType, name, _genderData[gender].Description))
                        {
                            DrawImageToTileSet(image);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Monster file '{0}' not found. Creating a Missing Monster Tile.", file.FullName);
                        WriteTileNameErrorFileNotFound(relativePath, "Creating a Missing Monster Tile.");

                        using (var image = MissingMonsterTileCreator.CreateTileWithTextLines(_missingMonsterTileType, _typeData[type].Description, name, _genderData[gender].Description))
                        {
                            DrawImageToTileSet(image);
                        }
                    }
                }
                IncreaseCurXY();
            }
        }
示例#8
0
        public override void CompileOne(string[] splitLine)
        {
            if (splitLine.Length < 2)
            {
                throw new Exception(string.Format("Misc line '{0}' has less than 2 elements.", string.Join(',', splitLine)));
            }

            var type = splitLine[1];

            string subDir2           = null;
            string fileName          = null;
            string name              = "";
            Point? pointInTiles      = null;
            Size?  bitmapSizeInTiles = null;

            string templateSubDir   = null;
            string templateFileName = null;
            Color  templatecolor    = Color.Empty;
            Size   templateSize     = Size.Empty;

            bool flipHorizontal = false;
            bool flipVertical   = false;

            if (type == _miscInvisible)
            {
                if (splitLine.Length < _invisibleLength)
                {
                    throw new Exception(string.Format("Misc Invisible line '{0}' has less than {1} elements.", string.Join(',', splitLine), _invisibleLength));
                }

                var type2 = splitLine[2];
                subDir2  = type.ToFileName();
                fileName = type.ToFileName() + "_" + type2.ToFileName() + Program.ImageFileExtension;
                name     = type2;
            }
            else if (type == _miscExplode)
            {
                if (splitLine.Length < _explodeLength)
                {
                    throw new Exception(string.Format("Misc Explode line '{0}' has less than {1} elements.", string.Join(',', splitLine), _explodeLength));
                }

                var type2     = splitLine[2];
                var direction = splitLine[3];
                int xInTiles  = int.Parse(splitLine[4]);
                int yInTiles  = int.Parse(splitLine[5]);
                pointInTiles = new Point(xInTiles, yInTiles);
                int widthInTiles  = int.Parse(splitLine[6]);
                int heightInTiles = int.Parse(splitLine[7]);
                bitmapSizeInTiles = new Size(widthInTiles, heightInTiles);

                if (widthInTiles > 1 || heightInTiles > 1)
                {
                    subDir2  = Path.Combine(type.ToFileName(), type2.ToFileName());
                    fileName = type.ToFileName() + "_" + type2.ToFileName() + Program.ImageFileExtension;
                    name     = type2 + " " + direction;
                }
                else
                {
                    subDir2  = Path.Combine(type.ToFileName(), type2.ToFileName());
                    fileName = type.ToFileName() + "_" + type2.ToFileName() + "_" + direction.ToFileName() + Program.ImageFileExtension;
                    name     = type2 + " " + direction;
                }
            }
            else if (type == _miscZap)
            {
                if (splitLine.Length < _zapLength)
                {
                    throw new Exception(string.Format("Misc Zap line '{0}' has less than {1} elements.", string.Join(',', splitLine), _zapLength));
                }

                var type2     = splitLine[2];
                var direction = splitLine[3];
                int xInTiles  = int.Parse(splitLine[4]);
                int yInTiles  = int.Parse(splitLine[5]);
                pointInTiles = new Point(xInTiles, yInTiles);
                int widthInTiles  = int.Parse(splitLine[6]);
                int heightInTiles = int.Parse(splitLine[7]);
                bitmapSizeInTiles = new Size(widthInTiles, heightInTiles);
                int targetBitmapWidthInTiles  = int.Parse(splitLine[8]);                               //Not used
                int targetBitmapHeightInTiles = int.Parse(splitLine[9]);                               //Not used
                MainTileAlignment targetBitmapMainTileAlignment = GetMainTileAlignment(splitLine[10]); //Not used
                int flipHorizontalInt = int.Parse(splitLine[11]);
                flipHorizontal = flipHorizontalInt > 0;
                int flipVerticalInt = int.Parse(splitLine[12]);
                flipVertical = flipVerticalInt > 0;
                int colorCode = int.Parse(splitLine[13]);
                templatecolor = GetColorFromColorCode(colorCode);

                if (widthInTiles > 1 || heightInTiles > 1)
                {
                    subDir2  = Path.Combine(type.ToFileName(), type2.ToFileName());
                    fileName = type.ToFileName() + "_" + type2.ToFileName() + Program.ImageFileExtension;
                    name     = type2 + " " + direction;
                }
                else
                {
                    subDir2  = Path.Combine(type.ToFileName(), type2.ToFileName());
                    fileName = type.ToFileName() + "_" + type2.ToFileName() + "_" + direction.ToFileName() + Program.ImageFileExtension;
                    name     = type2 + " " + direction;
                }

                templateSubDir = type.ToFileName();
                if (type2.EndsWith(_breathSuffix))
                {
                    templateFileName = type.ToFileName() + _templateSuffix + _breathSuffix + Program.ImageFileExtension;
                }
                else
                {
                    templateFileName = type.ToFileName() + _templateSuffix + Program.ImageFileExtension;
                }

                templateSize = new Size(widthInTiles * Program.MaxTileSize.Width, heightInTiles * Program.MaxTileSize.Height);
            }
            else if (type == _miscSwallow)
            {
                if (splitLine.Length < _swallowLength)
                {
                    throw new Exception(string.Format("Misc Swallow line '{0}' has less than {1} elements.", string.Join(',', splitLine), _swallowLength));
                }

                var monster   = splitLine[2];
                var direction = splitLine[3];
                int xInTiles  = int.Parse(splitLine[4]);
                int yInTiles  = int.Parse(splitLine[5]);
                pointInTiles = new Point(xInTiles, yInTiles);
                int widthInTiles  = int.Parse(splitLine[6]);
                int heightInTiles = int.Parse(splitLine[7]);
                bitmapSizeInTiles = new Size(widthInTiles, heightInTiles);

                if (widthInTiles > 1 || heightInTiles > 1)
                {
                    subDir2  = Path.Combine(type.ToFileName(), monster.ToFileName());
                    fileName = monster.ToFileName() + "_" + type.ToFileName() + Program.ImageFileExtension;
                    name     = monster + " " + direction;
                }
                else
                {
                    subDir2  = Path.Combine(type.ToFileName(), monster.ToFileName());
                    fileName = monster.ToFileName() + "_" + type.ToFileName() + "_" + direction.ToFileName() + Program.ImageFileExtension;
                    name     = monster + " " + direction;
                }
            }
            else if (type == _miscWarning)
            {
                if (splitLine.Length < _warningLength)
                {
                    throw new Exception(string.Format("Misc Warning line '{0}' has less than {1} elements.", string.Join(',', splitLine), _warningLength));
                }

                var level = splitLine[2];
                subDir2  = type.ToFileName();
                fileName = level.ToFileName() + Program.ImageFileExtension;
                name     = level;
            }
            else if (type == _miscWorm)
            {
                if (splitLine.Length < _wormLength)
                {
                    throw new Exception(string.Format("Misc Worm line '{0}' has less than {1} elements.", string.Join(',', splitLine), _wormLength));
                }

                var type2     = splitLine[2];
                var direction = splitLine[3];
                int xInTiles  = int.Parse(splitLine[4]);
                int yInTiles  = int.Parse(splitLine[5]);
                pointInTiles = new Point(xInTiles, yInTiles);
                int widthInTiles  = int.Parse(splitLine[6]);
                int heightInTiles = int.Parse(splitLine[7]);
                bitmapSizeInTiles = new Size(widthInTiles, heightInTiles);

                if (widthInTiles > 1 || heightInTiles > 1)
                {
                    subDir2  = Path.Combine(type.ToFileName(), type2.ToFileName());
                    fileName = type.ToFileName() + "_" + type2.ToFileName() + Program.ImageFileExtension;
                    name     = type2 + " " + direction;
                }
                else
                {
                    subDir2  = Path.Combine(type.ToFileName(), type2.ToFileName());
                    fileName = type.ToFileName() + "_" + type2.ToFileName() + "_" + direction.ToFileName() + Program.ImageFileExtension;
                    name     = type2 + " " + direction;
                }
            }
            else
            {
                //Other type
                if (splitLine.Length == 3)
                {
                    name     = splitLine[2];
                    subDir2  = type.ToFileName();
                    fileName = name.ToFileName() + Program.ImageFileExtension;
                }
                else if (splitLine.Length >= 4)
                {
                    var category = splitLine[2];
                    var name2    = splitLine[3];
                    subDir2  = Path.Combine(type.ToFileName(), category.ToFileName());
                    fileName = category.ToFileName() + "_" + name2.ToFileName() + Program.ImageFileExtension;
                    name     = category + " " + name2;
                }
                else
                {
                    throw new Exception(string.Format("Misc line too short: {0} elements. Line is: '{1}'", splitLine.Length, string.Join(',', splitLine)));
                }
            }

            var      dirPath      = Path.Combine(BaseDirectory.FullName, subDir2);
            var      relativePath = Path.Combine(_subDirName, subDir2, fileName);
            var      filePath     = Path.Combine(dirPath, fileName);
            FileInfo file         = new FileInfo(filePath);

            string   templateFilePath     = null;
            string   templateRelativePath = null;
            FileInfo templateFile         = null;

            if (templateSubDir != null && templateFileName != null)
            {
                templateFilePath     = Path.Combine(BaseDirectory.FullName, templateSubDir, templateFileName);
                templateRelativePath = Path.Combine(_subDirName, templateSubDir, templateFileName);
                templateFile         = new FileInfo(templateFilePath);
            }

            if (file.Exists)
            {
                using (var image = new Bitmap(Image.FromFile(file.FullName)))
                {
                    if (bitmapSizeInTiles.HasValue && (bitmapSizeInTiles.Value.Width > 1 || bitmapSizeInTiles.Value.Height > 1))
                    {
                        Size rightSize = new Size(bitmapSizeInTiles.Value.Width * Program.MaxTileSize.Width, bitmapSizeInTiles.Value.Height * Program.MaxTileSize.Height);
                        if (image.Size != rightSize)
                        {
                            throw new WrongSizeException(image.Size, rightSize, string.Format("Image '{0}' should be {1}x{2} but is in reality {3}x{4}",
                                                                                              file.FullName, rightSize.Width, rightSize.Height, image.Width, image.Height));
                        }
                        Point pointInPixels = new Point(pointInTiles.Value.X * Program.MaxTileSize.Width, pointInTiles.Value.Y * Program.MaxTileSize.Height);
                        CropAndDrawImageToTileSet(image, pointInPixels, Program.MaxTileSize, file, flipHorizontal, flipVertical);
                    }
                    else
                    {
                        DrawImageToTileSet(image);
                    }
                    StoreTileFile(file, image.Size, pointInTiles, bitmapSizeInTiles, flipHorizontal, flipVertical);
                }

                Console.WriteLine("Compiled Misc Tile {0} successfully.", relativePath);
                WriteTileNameSuccess(relativePath);
            }
            else if (templateFile != null && templateFile.Exists)
            {
                using (var image = CreateBitmapFromTemplate(templateFile, templatecolor, templateSize, 0, null))
                {
                    if (bitmapSizeInTiles.HasValue && (bitmapSizeInTiles.Value.Width > 1 || bitmapSizeInTiles.Value.Height > 1))
                    {
                        Size rightSize = new Size(bitmapSizeInTiles.Value.Width * Program.MaxTileSize.Width, bitmapSizeInTiles.Value.Height * Program.MaxTileSize.Height);
                        if (image.Size != rightSize)
                        {
                            throw new WrongSizeException(image.Size, rightSize, string.Format("Image '{0}' should be {1}x{2} but is in reality {3}x{4}",
                                                                                              file.FullName, rightSize.Width, rightSize.Height, image.Width, image.Height));
                        }
                        Point pointInPixels = new Point(pointInTiles.Value.X * Program.MaxTileSize.Width, pointInTiles.Value.Y * Program.MaxTileSize.Height);
                        CropAndDrawImageToTileSet(image, pointInPixels, Program.MaxTileSize, file, flipHorizontal, flipVertical);
                    }
                    else
                    {
                        DrawImageToTileSet(image);
                    }
                    StoreTileFile(file, image.Size, pointInTiles, bitmapSizeInTiles, false, true, new TemplateData(templatecolor, 0, null), null, flipHorizontal, flipVertical);
                }

                Console.WriteLine("Created Misc Tile {0} from Template {1} successfully.", relativePath, templateRelativePath);
                WriteTileNameTemplateGenerationSuccess(relativePath, templateRelativePath);
            }
            else
            {
                using (var image = MissingMiscTileCreator.CreateTile(_missingTileType, type, name))
                {
                    DrawImageToTileSet(image);
                }

                Console.WriteLine("File '{0}' not found. Creating Missing Misc tile.", file.FullName);
                WriteTileNameErrorFileNotFound(relativePath, "Creating Missing Misc tile.");
            }

            IncreaseCurXY();
        }
        public static Point GetEnlargementTileLocationInPixels(EnlargementTilePosition tilePosition, int enlargementWidthInTiles, int enlargementHeightInTiles, MainTileAlignment mainTileAlignment)
        {
            var tilePoint = GetEnlargementTileLocation(tilePosition, enlargementWidthInTiles, enlargementHeightInTiles, mainTileAlignment);
            int x         = tilePoint.X * MaxTileSize.Width;
            int y         = tilePoint.Y * MaxTileSize.Height;

            return(new Point(x, y));
        }
示例#10
0
        public static Point GetEnlargementTileLocation(EnlargementTilePosition tilePosition, int enlargementWidthInTiles, int enlargementHeightInTiles, MainTileAlignment mainTileAlignment)
        {
            int xTile = 0;
            int yTile = 0;

            if (tilePosition == EnlargementTilePosition.TopLeft)
            {
                xTile = 0;
                yTile = 0;
            }
            else if (tilePosition == EnlargementTilePosition.TopCenter)
            {
                yTile = 0;
                if (enlargementWidthInTiles == 1)
                {
                    xTile = 0;
                }
                else if (enlargementWidthInTiles == 2)
                {
                    if (mainTileAlignment == MainTileAlignment.Left)
                    {
                        xTile = 0;
                    }
                    else
                    {
                        xTile = 1;
                    }
                }
                else
                {
                    xTile = 1;
                }
            }
            else if (tilePosition == EnlargementTilePosition.TopRight)
            {
                yTile = 0;
                if (enlargementWidthInTiles == 2)
                {
                    xTile = 1;
                }
                else if (enlargementWidthInTiles == 3)
                {
                    xTile = 2;
                }
            }
            else if (tilePosition == EnlargementTilePosition.MiddleLeft)
            {
                if (enlargementHeightInTiles == 1)
                {
                    yTile = 0;
                }
                else
                {
                    yTile = 1;
                }
                xTile = 0;
            }
            else if (tilePosition == EnlargementTilePosition.MiddleRight)
            {
                if (enlargementHeightInTiles == 1)
                {
                    yTile = 0;
                }
                else
                {
                    yTile = 1;
                }
                if (enlargementWidthInTiles == 2)
                {
                    xTile = 1;
                }
                else if (enlargementWidthInTiles == 3)
                {
                    xTile = 2;
                }
            }

            return(new Point(xTile, yTile));
        }
示例#11
0
        public static Point GetMainTileLocationInPixels(int widthInTiles, int heightInTiles, MainTileAlignment mainTileAlignment, out bool isOneTile)
        {
            var pointInTiles = GetMainTileLocation(widthInTiles, heightInTiles, mainTileAlignment, out isOneTile);

            return(new Point(pointInTiles.X * MaxTileSize.Width, pointInTiles.Y * MaxTileSize.Height));
        }
示例#12
0
        public static Point GetMainTileLocation(int widthInTiles, int heightInTiles, MainTileAlignment mainTileAlignment, out bool isOneTile)
        {
            int xTile = 0;
            int yTile = 0;

            isOneTile = false;
            if (widthInTiles == 1 && heightInTiles == 1)
            {
                isOneTile = true;
                return(Point.Empty);
            }
            else if (widthInTiles == 1 && heightInTiles == 2)
            {
                xTile = 0;
                yTile = 1;
            }
            else if (widthInTiles == 2)
            {
                if (mainTileAlignment == MainTileAlignment.Left)
                {
                    xTile = 0;
                }
                else
                {
                    xTile = 1;
                }
                if (heightInTiles == 1)
                {
                    yTile = 0;
                }
                else if (heightInTiles == 2)
                {
                    yTile = 1;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else if (widthInTiles == 3)
            {
                xTile = 1;
                if (heightInTiles == 1)
                {
                    yTile = 0;
                }
                else if (heightInTiles == 2)
                {
                    yTile = 1;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            return(new Point(xTile, yTile));
        }
        public override void CompileOne(string[] splitLine)
        {
            if (splitLine.Length < _lineLength)
            {
                throw new Exception(string.Format("Replacement line '{0}' has too few elements.", string.Join(',', splitLine)));
            }

            var replacementName      = splitLine[1];
            var tileName             = splitLine[2];
            var baseTileNumber       = int.Parse(splitLine[3]); //Not used
            int widthInTiles         = int.Parse(splitLine[4]);
            int heightInTiles        = int.Parse(splitLine[5]);
            int mainTileAlignmentInt = int.Parse(splitLine[6]);

            if (!Enum.IsDefined(typeof(MainTileAlignment), mainTileAlignmentInt))
            {
                throw new Exception(string.Format("MainTileAlignment '{0}' is invalid. Should be 0 or 1.", mainTileAlignmentInt));
            }
            MainTileAlignment mainTileAlignment = (MainTileAlignment)mainTileAlignmentInt;

            var      dirPath  = Path.Combine(BaseDirectory.FullName, replacementName.ToFileName());
            var      fileName = replacementName.ToFileName() + "_" + tileName.ToFileName() + Program.ImageFileExtension;
            var      filePath = Path.Combine(dirPath, fileName);
            FileInfo file     = new FileInfo(filePath);

            var      fileName2 = tileName.ToFileName() + Program.ImageFileExtension;
            var      filePath2 = Path.Combine(dirPath, fileName2);
            FileInfo file2     = new FileInfo(filePath2);

            var relativePath  = Path.GetRelativePath(Program.InputDirectory.FullName, file.FullName);
            var relativePath2 = Path.GetRelativePath(Program.InputDirectory.FullName, file2.FullName);

            if (file.Exists || file2.Exists)
            {
                if (!file.Exists && file2.Exists)
                {
                    fileName     = fileName2;
                    filePath     = filePath2;
                    file         = file2;
                    relativePath = relativePath2;
                }

                Console.WriteLine("Compiled Replacement '{0}' successfully.", relativePath);
                WriteTileNameSuccess(relativePath);

                using (var image = new Bitmap(Image.FromFile(file.FullName)))
                {
                    if (image.Size == Program.ItemSize)
                    {
                        var      fileNameFloor = replacementName.ToFileName() + "_" + tileName.ToFileName() + _floorSuffix + Program.ImageFileExtension;
                        var      filePathFloor = Path.Combine(dirPath, fileNameFloor);
                        FileInfo fileFloor     = new FileInfo(filePathFloor);

                        var baseTileData  = GetTileFile(baseTileNumber);
                        var floorTileData = baseTileData.FloorTileData;

                        FloorTileData floorTileDataReplacement = floorTileData != null ? new FloorTileData(fileFloor, floorTileData.HasTileFile, floorTileData.SubType, floorTileData.NameOrDesc) : null;

                        using (var floorImage = GetFloorTile(fileFloor, floorTileData, replacementName, tileName))
                        {
                            DrawItemToTileSet(image, false, mainTileAlignment, floorImage);
                            StoreTileFile(file, image.Size, floorTileDataReplacement);
                        }
                    }
                    else if (image.Size == Program.MaxTileSize)
                    {
                        DrawImageToTileSet(image);
                        StoreTileFile(file, image.Size);
                    }
                    else
                    {
                        DrawMainTileToTileSet(image, widthInTiles, heightInTiles, mainTileAlignment, file);
                        StoreTileFile(file, image.Size);
                    }
                }
            }
            else
            {
                Console.WriteLine("File '{0}' and file '{1}' not found. Creating Missing Replacement Tile.", file.FullName, file2.FullName);
                WriteTileNameErrorFileNotFound(relativePath + " OR " + relativePath2, "Creating Missing Replacement Tile.");

                using (var image = MissingReplacementCreator.CreateTileWithTextLines(_missingReplacementType, replacementName, tileName))
                {
                    DrawImageToTileSet(image);
                }
            }
            IncreaseCurXY();
        }
        protected void DrawMainTileToTileSet(Bitmap image, int widthInTiles, int heightInTiles, MainTileAlignment mainTileAlignment, FileInfo file)
        {
            Size rightSize = new Size(widthInTiles * Program.MaxTileSize.Width, heightInTiles * Program.MaxTileSize.Height);

            if (image.Size != rightSize)
            {
                throw new WrongSizeException(image.Size, rightSize, string.Format("Image '{0}' should be size {1}x{2} but is actually {3}x{4}.", file.FullName,
                                                                                  rightSize.Width, rightSize.Height, image.Width, image.Height));
            }

            bool isOneTile;
            var  point = Program.GetMainTileLocationInPixels(widthInTiles, heightInTiles, mainTileAlignment, out isOneTile);

            if (isOneTile)
            {
                DrawImageToTileSet(image);
                return;
            }

            using (var croppedBitmap = image.Clone(new Rectangle(point, Program.MaxTileSize), image.PixelFormat))
            {
                DrawImageToTileSet(croppedBitmap);
            }
        }