Exemplo n.º 1
0
        public void MergeYamlD()
        {
            var res = MiniYaml.MergeLiberal(parentList, childList).Last();

            Assert.That(res.Key, Is.EqualTo("Child"));
            InheritanceTest(res.Value.Nodes);
        }
Exemplo n.º 2
0
        public void Run(Action <string> emitError, Action <string> emitWarning, Map map)
        {
            var sequences = MiniYaml.MergeLiberal(map.SequenceDefinitions, Game.ModData.Manifest.Sequences.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal));

            foreach (var actorInfo in map.Rules.Actors)
            {
                foreach (var renderInfo in actorInfo.Value.Traits.WithInterface <RenderSimpleInfo>())
                {
                    var image = renderInfo.Image ?? actorInfo.Value.Name;
                    if (!sequences.Any(s => s.Key == image.ToLowerInvariant()) && !actorInfo.Value.Name.Contains("^"))
                    {
                        emitWarning("Sprite image {0} from actor {1} has no sequence definition.".F(image, actorInfo.Value.Name));
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Run(Action <string> emitError, Action <string> emitWarning, Map map)
        {
            this.emitWarning = emitWarning;

            sequenceDefinitions = MiniYaml.MergeLiberal(map.SequenceDefinitions,
                                                        Game.ModData.Manifest.Sequences.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal));

            var races = map.Rules.Actors["world"].Traits.WithInterface <FactionInfo>().Select(f => f.InternalName).ToArray();

            foreach (var actorInfo in map.Rules.Actors)
            {
                foreach (var renderInfo in actorInfo.Value.Traits.WithInterface <RenderSpritesInfo>())
                {
                    foreach (var race in races)
                    {
                        var image = renderInfo.GetImage(actorInfo.Value, map.Rules.Sequences[map.Tileset], race);
                        if (sequenceDefinitions.All(s => s.Key != image.ToLowerInvariant()) && !actorInfo.Value.Name.Contains("^"))
                        {
                            emitWarning("Sprite image {0} from actor {1} on tileset {2} using race {3} has no sequence definition."
                                        .F(image, actorInfo.Value.Name, map.Tileset, race));
                        }
                    }
                }

                foreach (var traitInfo in actorInfo.Value.Traits.WithInterface <ITraitInfo>())
                {
                    var fields = traitInfo.GetType().GetFields();
                    foreach (var field in fields)
                    {
                        if (field.HasAttribute <SequenceReferenceAttribute>())
                        {
                            var sequences = LintExts.GetFieldValues(traitInfo, field, emitError);
                            foreach (var sequence in sequences)
                            {
                                if (string.IsNullOrEmpty(sequence))
                                {
                                    continue;
                                }

                                var renderInfo = actorInfo.Value.Traits.WithInterface <RenderSpritesInfo>().FirstOrDefault();
                                if (renderInfo == null)
                                {
                                    continue;
                                }

                                foreach (var race in races)
                                {
                                    var sequenceReference = field.GetCustomAttributes <SequenceReferenceAttribute>(true).FirstOrDefault();
                                    if (sequenceReference != null && !string.IsNullOrEmpty(sequenceReference.ImageReference))
                                    {
                                        var imageField = fields.FirstOrDefault(f => f.Name == sequenceReference.ImageReference);
                                        if (imageField != null)
                                        {
                                            foreach (var imageOverride in LintExts.GetFieldValues(traitInfo, imageField, emitError))
                                            {
                                                if (!string.IsNullOrEmpty(imageOverride) && sequenceDefinitions.All(s => s.Key != imageOverride.ToLowerInvariant()))
                                                {
                                                    emitWarning("Custom sprite image {0} from actor {1} has no sequence definition.".F(imageOverride, actorInfo.Value.Name));
                                                }
                                                else
                                                {
                                                    CheckDefintions(imageOverride, sequenceReference, actorInfo, sequence, race, field, traitInfo);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var image = renderInfo.GetImage(actorInfo.Value, map.SequenceProvider, race);
                                        CheckDefintions(image, sequenceReference, actorInfo, sequence, race, field, traitInfo);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Run(Action <string> emitError, Action <string> emitWarning, Map map)
        {
            if (map != null && !map.SequenceDefinitions.Any())
            {
                return;
            }

            this.emitWarning = emitWarning;

            var sequenceSource = map != null ? map.SequenceDefinitions : new List <MiniYamlNode>();

            sequenceDefinitions = MiniYaml.MergeLiberal(sequenceSource,
                                                        Game.ModData.Manifest.Sequences.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal));

            var rules             = map == null ? Game.ModData.DefaultRules : map.Rules;
            var races             = rules.Actors["world"].Traits.WithInterface <FactionInfo>().Select(f => f.InternalName).ToArray();
            var sequenceProviders = map == null ? rules.Sequences.Values : new[] { rules.Sequences[map.Tileset] };

            foreach (var actorInfo in rules.Actors)
            {
                foreach (var renderInfo in actorInfo.Value.Traits.WithInterface <RenderSpritesInfo>())
                {
                    foreach (var race in races)
                    {
                        foreach (var sequenceProvider in sequenceProviders)
                        {
                            var image = renderInfo.GetImage(actorInfo.Value, sequenceProvider, race);
                            if (sequenceDefinitions.All(s => s.Key != image.ToLowerInvariant()) && !actorInfo.Value.Name.Contains("^"))
                            {
                                emitWarning("Sprite image {0} from actor {1} on tileset {2} using race {3} has no sequence definition."
                                            .F(image, actorInfo.Value.Name, map.Tileset, race));
                            }
                        }
                    }
                }

                foreach (var traitInfo in actorInfo.Value.Traits.WithInterface <ITraitInfo>())
                {
                    var fields = traitInfo.GetType().GetFields();
                    foreach (var field in fields)
                    {
                        if (field.HasAttribute <SequenceReferenceAttribute>())
                        {
                            var sequences = LintExts.GetFieldValues(traitInfo, field, emitError);
                            foreach (var sequence in sequences)
                            {
                                if (string.IsNullOrEmpty(sequence))
                                {
                                    continue;
                                }

                                var renderInfo = actorInfo.Value.Traits.WithInterface <RenderSpritesInfo>().FirstOrDefault();
                                if (renderInfo == null)
                                {
                                    continue;
                                }

                                foreach (var race in races)
                                {
                                    var sequenceReference = field.GetCustomAttributes <SequenceReferenceAttribute>(true).FirstOrDefault();
                                    if (sequenceReference != null && !string.IsNullOrEmpty(sequenceReference.ImageReference))
                                    {
                                        var imageField = fields.FirstOrDefault(f => f.Name == sequenceReference.ImageReference);
                                        if (imageField != null)
                                        {
                                            foreach (var imageOverride in LintExts.GetFieldValues(traitInfo, imageField, emitError))
                                            {
                                                if (!string.IsNullOrEmpty(imageOverride) && sequenceDefinitions.All(s => s.Key != imageOverride.ToLowerInvariant()))
                                                {
                                                    emitWarning("Custom sprite image {0} from actor {1} has no sequence definition.".F(imageOverride, actorInfo.Value.Name));
                                                }
                                                else
                                                {
                                                    CheckDefintions(imageOverride, sequenceReference, actorInfo, sequence, race, field, traitInfo);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        foreach (var sequenceProvider in sequenceProviders)
                                        {
                                            var image = renderInfo.GetImage(actorInfo.Value, sequenceProvider, race);
                                            CheckDefintions(image, sequenceReference, actorInfo, sequence, race, field, traitInfo);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                foreach (var weaponInfo in rules.Weapons)
                {
                    var projectileInfo = weaponInfo.Value.Projectile;
                    if (projectileInfo == null)
                    {
                        continue;
                    }

                    var fields = projectileInfo.GetType().GetFields();
                    foreach (var field in fields)
                    {
                        if (field.HasAttribute <SequenceReferenceAttribute>())
                        {
                            var sequences = LintExts.GetFieldValues(projectileInfo, field, emitError);
                            foreach (var sequence in sequences)
                            {
                                if (string.IsNullOrEmpty(sequence))
                                {
                                    continue;
                                }

                                var sequenceReference = field.GetCustomAttributes <SequenceReferenceAttribute>(true).FirstOrDefault();
                                if (sequenceReference != null && !string.IsNullOrEmpty(sequenceReference.ImageReference))
                                {
                                    var imageField = fields.FirstOrDefault(f => f.Name == sequenceReference.ImageReference);
                                    if (imageField != null)
                                    {
                                        foreach (var imageOverride in LintExts.GetFieldValues(projectileInfo, imageField, emitError))
                                        {
                                            if (!string.IsNullOrEmpty(imageOverride))
                                            {
                                                var definitions = sequenceDefinitions.FirstOrDefault(n => n.Key == imageOverride.ToLowerInvariant());
                                                if (definitions == null)
                                                {
                                                    emitWarning("Can't find sequence definition for projectile image {0} at weapon {1}.".F(imageOverride, weaponInfo.Key));
                                                }
                                                else if (!definitions.Value.Nodes.Any(n => n.Key == sequence))
                                                {
                                                    emitWarning("Projectile sprite image {0} from weapon {1} does not define sequence {2} from field {3} of {4}"
                                                                .F(imageOverride, weaponInfo.Key, sequence, field.Name, projectileInfo));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void MergeYamlB()
        {
            var res = MiniYaml.MergeLiberal(parent, child);

            InheritanceTest(res.Nodes);
        }