public IAction Fix(Problem problem)
 {
     var edit = new EditEntityData();
     foreach (var mo in problem.Objects)
     {
         var ed = mo.GetEntityData().Clone();
         var prop = ed.Properties.FirstOrDefault(x => x.Key.ToLowerInvariant() == "target");
         if (prop != null)
         {
             ed.Properties.Remove(prop);
             edit.AddEntity(mo, ed);
         }
     }
     return edit;
 }
示例#2
0
 public IAction Fix(Problem problem)
 {
     var edit = new EditEntityData();
     foreach (var mo in problem.Objects.OfType<Entity>().Where(x => x.GameData != null))
     {
         var ed = mo.GetEntityData().Clone();
         foreach (var prop in mo.EntityData.Properties)
         {
             if (!mo.GameData.Properties.Any(x => String.Equals(x.Name, prop.Key, StringComparison.InvariantCultureIgnoreCase)))
             {
                 ed.Properties.Remove(prop);
             }
         }
         edit.AddEntity(mo, ed);
     }
     return edit;
 }
示例#3
0
 public IAction Fix(Problem problem)
 {
     var edit = new EditEntityData();
     foreach (var mo in problem.Objects)
     {
         var ed = mo.GetEntityData().Clone();
         var dupes = from p in ed.Properties
                     group p by p.Key.ToLowerInvariant()
                     into g
                     where g.Count() > 1
                     select g;
         foreach (var prop in dupes.SelectMany(dupe => dupe.Skip(1)))
         {
             ed.Properties.Remove(prop);
         }
         edit.AddEntity(mo, ed);
     }
     return edit;
 }
        private EditEntityData GetEditEntityDataAction()
        {
            var ents = Objects.Where(x => x is Entity || x is World).ToList();
            if (!ents.Any()) return null;
            var action = new EditEntityData();

            foreach (var entity in ents)
            {
                var entityData = entity.GetEntityData().Clone();
                var changed = false;
                // Updated class
                if (Class.BackColor == Color.LightGreen)
                {
                    entityData.Name = Class.Text;
                    changed = true;
                }

                // Remove nonexistant properties
                var nonExistant = entityData.Properties.Where(x => _values.All(y => y.OriginalKey != x.Key));
                if (nonExistant.Any())
                {
                    changed = true;
                    entityData.Properties.RemoveAll(x => _values.All(y => y.OriginalKey != x.Key));
                }

                // Set updated/new properties
                foreach (var ent in _values.Where(x => x.IsModified || (x.IsAdded && !x.IsRemoved)))
                {
                    entityData.SetPropertyValue(ent.OriginalKey, ent.Value);
                    if (!String.IsNullOrWhiteSpace(ent.NewKey) && ent.NewKey != ent.OriginalKey)
                    {
                        var prop = entityData.Properties.FirstOrDefault(x => String.Equals(x.Key, ent.OriginalKey, StringComparison.InvariantCultureIgnoreCase));
                        if (prop != null && !entityData.Properties.Any(x => String.Equals(x.Key, ent.NewKey, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            prop.Key = ent.NewKey;
                        }
                    }
                    changed = true;
                }

                foreach (var ent in _values.Where(x => x.IsRemoved && !x.IsAdded))
                {
                    entityData.Properties.RemoveAll(x => x.Key == ent.OriginalKey);
                    changed = true;
                }

                // Set flags
                var flags =
                    Enumerable.Range(0, FlagsTable.Items.Count).Select(x => FlagsTable.GetItemCheckState(x)).ToList();
                var entClass = Document.GameData.Classes.FirstOrDefault(x => x.Name == entityData.Name);
                var spawnFlags = entClass == null
                                     ? null
                                     : entClass.Properties.FirstOrDefault(x => x.Name == "spawnflags");
                var opts = spawnFlags == null ? null : spawnFlags.Options;
                if (opts != null && flags.Count == opts.Count)
                {
                    var beforeFlags = entityData.Flags;
                    for (var i = 0; i < flags.Count; i++)
                    {
                        var val = int.Parse(opts[i].Key);
                        if (flags[i] == CheckState.Unchecked) entityData.Flags &= ~val; // Switch the flag off if unchecked
                        else if (flags[i] == CheckState.Checked) entityData.Flags |= val; // Switch it on if checked
                        // No change if indeterminate
                    }
                    if (entityData.Flags != beforeFlags) changed = true;
                }

                if (changed) action.AddEntity(entity, entityData);
            }

            return action.IsEmpty() ? null : action;
        }