コード例 #1
0
        /// <summary>
        /// Factory method to create appropriate validator for the specified file.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="resources">An instance of <see cref="GameResources"/> containing all valid resources from the core game and optionally a mod.</param>
        /// <param name="expansionResourcesUsed">An instance of <see cref="GameResources"/> to which expansion resources found to be used will be added.</param>
        /// <returns></returns>
        public static XmlResourceValidator Create(ContentFile file, GameResources resources, GameResources expansionResourcesUsed = null)
        {
            switch (file.Name.ToLower())
            {
            case "craftdb.xml":
                return(new CraftXmlResourceValidator(file, resources, expansionResourcesUsed));

            case "itemdb.xml":
                return(new ItemXmlResourceValidator(file, resources, expansionResourcesUsed));

            case "mondb.xml":
                return(new MonsterXmlResourceValidator(file, resources, expansionResourcesUsed));

            case "soundfx.xml":
                return(new SoundXmlResourceValidator(file, resources, expansionResourcesUsed));

            case "spelldb.xml":
                return(new SpellXmlResourceValidator(file, resources, expansionResourcesUsed));

            case "skilldb.xml":
                return(new SkillXmlResourceValidator(file, resources, expansionResourcesUsed));

            case "rooms.xml":
                return(new RoomXmlResourceValidator(file, resources, expansionResourcesUsed));

            case "encrustdb.xml":
                return(new EncrustXmlResourceValidator(file, resources, expansionResourcesUsed));

            default:
                throw new InvalidOperationException("The specified file is not supported.");
            }
        }
コード例 #2
0
        private int GetAnimationFrameCount(ContentFile file)
        {
            var files = file.Directory.EnumerateFiles("*.png", SearchOption.TopDirectoryOnly)
                        .Where(p => Regex.IsMatch(p.Name, "^" + file.Name.Replace("0000.png", String.Empty) + @"\d{4}.png$", RegexOptions.IgnoreCase));

            return(files.Count());
        }
コード例 #3
0
        private static void AddRequirementErrors(ModValidationResult result, ContentFile modFile)
        {
            //we already loaded and used XSD validation on mod.xml annd exited if it had malformed XML, so it's safe to just load it here.
            //However we are not sure their "expansion" attributes exist or are integers.
            using (var modXml = modFile.OpenRead())
            {
                XDocument doc = XDocument.Load(modXml);

                var requireElements = doc.Root.Elements("require", true);

                //Need nullables to support left joins.
                List <int?> statedRequirements = new List <int?>();
                List <int?> knownRequirements  = result.ExpansionNumbersUsed.Select(p => new Nullable <int>(p)).ToList();

                foreach (var element in requireElements)
                {
                    var expansion = element.GetIntAttribute("expansion");
                    if (expansion != null)
                    {
                        statedRequirements.Add(expansion.Value);
                    }
                }

                //distinct list in case they repeat themselves.
                statedRequirements = statedRequirements.Distinct().ToList();

                //left join to find missing requirements.
                var missingRequirements =
                    from knownRequirement in knownRequirements
                    join statedRequirement in statedRequirements
                    on knownRequirement equals statedRequirement into statedRequirementGroup
                    from statedRequirement in statedRequirementGroup.DefaultIfEmpty()
                    where statedRequirement == null
                    select knownRequirement;

                result.ModErrors.AddRange(
                    missingRequirements.Select(
                        p =>
                        String.Format("Expansion {0} is used by your mod, but you didn't include <require expansion=\"{0}\"/> in mod.xml", p)
                        )
                    );

                //the opposite left join to find overstated requirements.
                var overstatedRequirements =
                    from overStatedRequirement in statedRequirements
                    join knownRequirement in knownRequirements
                    on overStatedRequirement equals knownRequirement into knownRequirementGroup
                    from knownRequirement in knownRequirementGroup.DefaultIfEmpty()
                    where knownRequirement == null
                    select overStatedRequirement;

                result.ModErrors.AddRange(
                    overstatedRequirements.Select(
                        p =>
                        String.Format("You have <require expansion=\"{0}\"/> in mod.xml, but expansion {0} is not used by your mod.", p)
                        )
                    );
            }
        }
コード例 #4
0
 private void AddFileResource(ContentDirectory source, FileResourceType type, ContentFile file)
 {
     this.Files.Add(
         new FileResource
     {
         Path            = file.SourceRelativePath.ToForwardSlashes(),
         ExpansionNumber = file.ExpansionNumber,
         Type            = type
     }
         );
 }
コード例 #5
0
        protected XmlResourceValidator(ContentFile file, GameResources resources, GameResources expansionResourcesUsed)
        {
            this.resources = resources;
            this.path      = file.FullName;
            this.expansionResourcesUsed = expansionResourcesUsed;

            using (Stream xmlStream = file.OpenRead())
            {
                this.doc = XDocument.Load(xmlStream, LoadOptions.SetLineInfo);
            }

            this.isCoreGame      = file.Directory.IsCoreGame;
            this.expansionNumber = file.ExpansionNumber;

            this.result = new XmlFileValidationErrorList
            {
                Path   = this.path,
                Errors = new List <XmlValidationError>()
            };
        }
コード例 #6
0
        private static void AddRequirementErrors( ModValidationResult result, ContentFile modFile )
        {
            //we already loaded and used XSD validation on mod.xml annd exited if it had malformed XML, so it's safe to just load it here.
            //However we are not sure their "expansion" attributes exist or are integers.
            using ( var modXml = modFile.OpenRead() )
            {
                XDocument doc = XDocument.Load( modXml );

                var requireElements = doc.Root.Elements( "require", true );

                //Need nullables to support left joins.
                List<int?> statedRequirements = new List<int?>();
                List<int?> knownRequirements = result.ExpansionNumbersUsed.Select( p => new Nullable<int>( p ) ).ToList();

                foreach ( var element in requireElements )
                {
                    var expansion = element.GetIntAttribute( "expansion" );
                    if ( expansion != null )
                    {
                        statedRequirements.Add( expansion.Value );
                    }
                }

                //distinct list in case they repeat themselves.
                statedRequirements = statedRequirements.Distinct().ToList();

                //left join to find missing requirements.
                var missingRequirements =
                    from knownRequirement in knownRequirements
                    join statedRequirement in statedRequirements
                    on knownRequirement equals statedRequirement into statedRequirementGroup
                    from statedRequirement in statedRequirementGroup.DefaultIfEmpty()
                    where statedRequirement == null
                    select knownRequirement;

                result.ModErrors.AddRange(
                    missingRequirements.Select(
                        p =>
                        String.Format( "Expansion {0} is used by your mod, but you didn't include <require expansion=\"{0}\"/> in mod.xml", p )
                    )
                );

                //the opposite left join to find overstated requirements.
                var overstatedRequirements =
                    from overStatedRequirement in statedRequirements
                    join knownRequirement in knownRequirements
                    on overStatedRequirement equals knownRequirement into knownRequirementGroup
                    from knownRequirement in knownRequirementGroup.DefaultIfEmpty()
                    where knownRequirement == null
                    select overStatedRequirement;

                result.ModErrors.AddRange(
                    overstatedRequirements.Select(
                        p =>
                        String.Format( "You have <require expansion=\"{0}\"/> in mod.xml, but expansion {0} is not used by your mod.", p )
                    )
                );
            }
        }
コード例 #7
0
 public MonsterXmlResourceValidator(ContentFile file, GameResources resources, GameResources expansionResourcesUsed)
     : base(file, resources, expansionResourcesUsed)
 {
 }
コード例 #8
0
 /// <summary>
 /// Factory method to create appropriate validator for the specified file.
 /// </summary>
 /// <param name="file"></param>
 /// <param name="resources">An instance of <see cref="GameResources"/> containing all valid resources from the core game and optionally a mod.</param>
 /// <param name="expansionResourcesUsed">An instance of <see cref="GameResources"/> to which expansion resources found to be used will be added.</param>
 /// <returns></returns>
 public static XmlResourceValidator Create( ContentFile file, GameResources resources, GameResources expansionResourcesUsed = null )
 {
     switch ( file.Name.ToLower() )
     {
         case "craftdb.xml":
             return new CraftXmlResourceValidator( file, resources, expansionResourcesUsed );
         case "itemdb.xml":
             return new ItemXmlResourceValidator( file, resources, expansionResourcesUsed );
         case "mondb.xml":
             return new MonsterXmlResourceValidator( file, resources, expansionResourcesUsed );
         case "soundfx.xml":
             return new SoundXmlResourceValidator( file, resources, expansionResourcesUsed );
         case "spelldb.xml":
             return new SpellXmlResourceValidator( file, resources, expansionResourcesUsed );
         case "skilldb.xml":
             return new SkillXmlResourceValidator( file, resources, expansionResourcesUsed );
         case "rooms.xml":
             return new RoomXmlResourceValidator( file, resources, expansionResourcesUsed );
         default:
             throw new InvalidOperationException( "The specified file is not supported." );
     }
 }
コード例 #9
0
        protected XmlResourceValidator( ContentFile file, GameResources resources, GameResources expansionResourcesUsed )
        {
            this.resources = resources;
            this.path = file.FullName;
            this.expansionResourcesUsed = expansionResourcesUsed;

            using ( Stream xmlStream = file.OpenRead() )
            {
                this.doc = XDocument.Load( xmlStream, LoadOptions.SetLineInfo );
            }

            this.isCoreGame = file.Directory.IsCoreGame;
            this.expansionNumber = file.ExpansionNumber;

            this.result = new XmlFileValidationErrorList
            {
                Path = this.path,
                Errors = new List<XmlValidationError>()
            };
        }
コード例 #10
0
 public SpellXmlResourceValidator( ContentFile file, GameResources resources, GameResources expansionResourcesUsed )
     : base(file, resources, expansionResourcesUsed)
 {
 }