From 98e5c5b9b4fd01592af0db9c518c170af7143dfb Mon Sep 17 00:00:00 2001 From: MaxED Date: Wed, 15 Jun 2016 22:57:39 +0000 Subject: [PATCH] Fixed, "Select Similar" action: in some cases map elements flags were incorrectly compared resulting in map elements not being selected when they should have been. --- Source/Core/Map/Linedef.cs | 9 +++++++++ Source/Core/Map/Sector.cs | 9 +++++++++ Source/Core/Map/Sidedef.cs | 9 +++++++++ Source/Core/Map/Thing.cs | 13 +++++++++++-- .../BuilderModes/General/CopyStructures.cs | 17 ++++++++++------- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Source/Core/Map/Linedef.cs b/Source/Core/Map/Linedef.cs index 22a4e86..a2fd10d 100644 --- a/Source/Core/Map/Linedef.cs +++ b/Source/Core/Map/Linedef.cs @@ -965,6 +965,15 @@ namespace CodeImp.DoomBuilder.Map { return new Dictionary(flags); } + + //mxd. This returns enabled flags + public HashSet GetEnabledFlags() + { + HashSet result = new HashSet(); + foreach(KeyValuePair group in flags) + if(group.Value) result.Add(group.Key); + return result; + } // This clears all flags public void ClearFlags() diff --git a/Source/Core/Map/Sector.cs b/Source/Core/Map/Sector.cs index f6c1533..91a9425 100644 --- a/Source/Core/Map/Sector.cs +++ b/Source/Core/Map/Sector.cs @@ -516,6 +516,15 @@ namespace CodeImp.DoomBuilder.Map return new Dictionary(flags); } + //mxd. This returns enabled flags + public HashSet GetEnabledFlags() + { + HashSet result = new HashSet(); + foreach(KeyValuePair group in flags) + if(group.Value) result.Add(group.Key); + return result; + } + // This clears all flags public void ClearFlags() { diff --git a/Source/Core/Map/Sidedef.cs b/Source/Core/Map/Sidedef.cs index 7f5a66c..19c5684 100644 --- a/Source/Core/Map/Sidedef.cs +++ b/Source/Core/Map/Sidedef.cs @@ -323,6 +323,15 @@ namespace CodeImp.DoomBuilder.Map return new Dictionary(flags); } + //mxd. This returns enabled flags + public HashSet GetEnabledFlags() + { + HashSet result = new HashSet(); + foreach(KeyValuePair group in flags) + if(group.Value) result.Add(group.Key); + return result; + } + // This clears all flags public void ClearFlags() { diff --git a/Source/Core/Map/Thing.cs b/Source/Core/Map/Thing.cs index d33cade..6ed192c 100644 --- a/Source/Core/Map/Thing.cs +++ b/Source/Core/Map/Thing.cs @@ -649,8 +649,17 @@ namespace CodeImp.DoomBuilder.Map if (General.Map.SRB2) pos.z = value >> 4; } - // This clears all flags - public void ClearFlags() + //mxd. This returns enabled flags + public HashSet GetEnabledFlags() + { + HashSet result = new HashSet(); + foreach(KeyValuePair group in flags) + if(group.Value) result.Add(group.Key); + return result; + } + + // This clears all flags + public void ClearFlags() { BeforePropsChange(); diff --git a/Source/Plugins/BuilderModes/General/CopyStructures.cs b/Source/Plugins/BuilderModes/General/CopyStructures.cs index 42f08a3..4dd772c 100644 --- a/Source/Plugins/BuilderModes/General/CopyStructures.cs +++ b/Source/Plugins/BuilderModes/General/CopyStructures.cs @@ -804,7 +804,7 @@ namespace CodeImp.DoomBuilder.BuilderModes if(flags.CeilingTexture && source.CeilTexture != target.CeilTexture) return false; if(flags.Brightness && source.Brightness != target.Brightness) return false; if(flags.Tag && !TagsMatch(source.Tags, target.Tags)) return false; - if(flags.Flags && !FlagsMatch(source.GetFlags(), target.GetFlags())) return false; + if(flags.Flags && !FlagsMatch(source.GetEnabledFlags(), target.GetEnabledFlags())) return false; // Generalized effects require more tender loving care... if(flags.Special && source.Effect != target.Effect) @@ -871,7 +871,7 @@ namespace CodeImp.DoomBuilder.BuilderModes if(!UniFields.ValuesMatch("arg4str", source, target)) return false; } } - if(linedefflags.Flags && !FlagsMatch(source.GetFlags(), target.GetFlags())) return false; + if(linedefflags.Flags && !FlagsMatch(source.GetEnabledFlags(), target.GetEnabledFlags())) return false; if(General.Map.UDMF) { @@ -907,7 +907,7 @@ namespace CodeImp.DoomBuilder.BuilderModes if(!General.Map.UDMF) return true; // UDMF-specific properties - if(flags.Flags && !FlagsMatch(source.GetFlags(), target.GetFlags())) return false; + if(flags.Flags && !FlagsMatch(source.GetEnabledFlags(), target.GetEnabledFlags())) return false; // UI fields if(flags.UpperTextureScale && !UniFields.ValuesMatch("scalex_top", "scaley_top", source, target)) return false; @@ -949,7 +949,7 @@ namespace CodeImp.DoomBuilder.BuilderModes } } if(flags.Tag && source.Tag != target.Tag) return false; - if(flags.Flags && !FlagsMatch(source.GetFlags(), target.GetFlags())) return false; + if(flags.Flags && !FlagsMatch(source.GetEnabledFlags(), target.GetEnabledFlags())) return false; if(!General.Map.UDMF) return true; // UDMF-specific properties @@ -973,11 +973,14 @@ namespace CodeImp.DoomBuilder.BuilderModes #endregion - private static bool FlagsMatch(Dictionary flags1, Dictionary flags2) + private static bool FlagsMatch(HashSet flags1, HashSet flags2) { if(flags1.Count != flags2.Count) return false; - foreach(KeyValuePair group in flags1) - if(!flags2.ContainsKey(group.Key) || flags2[group.Key] != flags1[group.Key]) return false; + foreach(string flag in flags1) + { + if(!flags2.Contains(flag)) return false; + } + return true; }