Find & Replace Mode: sector effects and linedef actions are now searched on bit by bit basis. That means map elements with partially matching Generalized effect/action can now be found.

This commit is contained in:
MaxED 2014-09-04 13:48:22 +00:00
parent f596b88376
commit bfda0c99e7
2 changed files with 113 additions and 3 deletions

View file

@ -36,6 +36,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Variables
private List<int> generalizedbits;
#endregion
#region ================== Properties
@ -46,6 +48,25 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Constructor / Destructor
//mxd
public FindLinedefTypes()
{
if (!General.Map.Config.GeneralizedActions) return;
// Get all them generalized bits
generalizedbits = new List<int>();
foreach(GeneralizedCategory cat in General.Map.Config.GenActionCategories)
{
foreach(GeneralizedOption option in cat.Options)
{
foreach(GeneralizedBit bit in option.Bits)
{
if(bit.Index > 0) generalizedbits.Add(bit.Index);
}
}
}
}
#endregion
#region ================== Methods
@ -110,6 +131,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
}
//mxd
List<int> expectedbits = GetGeneralizedBits(action);
// Where to search?
ICollection<Linedef> list = withinselection ? General.Map.Map.GetSelectedLinedefs(true) : General.Map.Map.Linedefs;
@ -117,7 +141,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
foreach(Linedef l in list)
{
// Action matches?
if(l.Action == action)
if(l.Action == action || BitsMatch(l.Action, expectedbits))
{
match = true;
argtext = "";
@ -153,6 +177,40 @@ namespace CodeImp.DoomBuilder.BuilderModes
return objs.ToArray();
}
//mxd
private List<int> GetGeneralizedBits(int effect)
{
if(!General.Map.Config.GeneralizedActions) return new List<int>();
List<int> bits = new List<int>();
foreach(GeneralizedCategory cat in General.Map.Config.GenActionCategories)
{
foreach(GeneralizedOption option in cat.Options)
{
foreach(GeneralizedBit bit in option.Bits)
{
if(bit.Index > 0 && (effect & bit.Index) == bit.Index)
bits.Add(bit.Index);
}
}
}
return bits;
}
//mxd
private bool BitsMatch(int action, List<int> expectedbits)
{
if(!General.Map.Config.GeneralizedActions) return false;
foreach(int bit in expectedbits)
{
if((action & bit) != bit) return false;
}
return true;
}
#endregion
}

View file

@ -36,6 +36,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Variables
private List<int> generalizedbits;
#endregion
#region ================== Properties
@ -46,6 +48,22 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Constructor / Destructor
//mxd
public FindSectorEffect()
{
if (!General.Map.Config.GeneralizedEffects) return;
// Get all them generalized bits
generalizedbits = new List<int>();
foreach(GeneralizedOption option in General.Map.Config.GenEffectOptions)
{
foreach(GeneralizedBit bit in option.Bits)
{
if(bit.Index > 0) generalizedbits.Add(bit.Index);
}
}
}
#endregion
#region ================== Methods
@ -86,14 +104,17 @@ namespace CodeImp.DoomBuilder.BuilderModes
int effect;
if(int.TryParse(value, out effect))
{
//mxd
List<int> expectedbits = GetGeneralizedBits(effect);
// Where to search?
ICollection<Sector> list = withinselection ? General.Map.Map.GetSelectedSectors(true) : General.Map.Map.Sectors;
// Go for all sectors
foreach(Sector s in list)
{
// Tag matches?
if(s.Effect == effect)
// Effect matches?
if(s.Effect == effect || BitsMatch(s.Effect, expectedbits))
{
// Replace
if(replacewith != null) s.Effect = replaceeffect;
@ -110,6 +131,37 @@ namespace CodeImp.DoomBuilder.BuilderModes
return objs.ToArray();
}
//mxd
private List<int> GetGeneralizedBits(int effect)
{
if (!General.Map.Config.GeneralizedEffects) return new List<int>();
List<int> bits = new List<int>();
foreach(GeneralizedOption option in General.Map.Config.GenEffectOptions)
{
foreach(GeneralizedBit bit in option.Bits)
{
if(bit.Index > 0 && (effect & bit.Index) == bit.Index)
bits.Add(bit.Index);
}
}
return bits;
}
//mxd
private bool BitsMatch(int effect, List<int> expectedbits)
{
if (!General.Map.Config.GeneralizedEffects) return false;
foreach (int bit in expectedbits)
{
if ((effect & bit) != bit) return false;
}
return true;
}
#endregion
}
}