mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-23 04:12:12 +00:00
Map Analysis: added "Check unused things" check.
Map Analysis, internal: some ErrorCheckers and ErrorResult had inconsistent namespaces. Thing Edit forms, internal: optimized missing flags check a bit.
This commit is contained in:
parent
b90b7b8a79
commit
bc1c32d52e
10 changed files with 197 additions and 12 deletions
|
@ -635,17 +635,18 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
foreach(KeyValuePair<string, Dictionary<string, ThingFlagsCompare>> group in General.Map.Config.ThingFlagsCompare)
|
||||
{
|
||||
if(group.Value.Count < 2) continue;
|
||||
int enabledcount = 0;
|
||||
bool haveflags = false;
|
||||
|
||||
foreach(CheckBox cb in flags.Checkboxes)
|
||||
{
|
||||
if (group.Value.ContainsKey(cb.Tag.ToString()) && cb.CheckState != CheckState.Unchecked)
|
||||
{
|
||||
enabledcount++;
|
||||
haveflags = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (enabledcount == 0)
|
||||
if (!haveflags)
|
||||
{
|
||||
switch(group.Key)
|
||||
{
|
||||
|
|
|
@ -864,16 +864,17 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
foreach(KeyValuePair<string, Dictionary<string, ThingFlagsCompare>> group in General.Map.Config.ThingFlagsCompare)
|
||||
{
|
||||
if(group.Value.Count < 2) continue;
|
||||
int enabledcount = 0;
|
||||
bool haveflags = false;
|
||||
|
||||
foreach(CheckBox cb in flags.Checkboxes)
|
||||
{
|
||||
if(group.Value.ContainsKey(cb.Tag.ToString()) && cb.CheckState != CheckState.Unchecked) {
|
||||
enabledcount++;
|
||||
haveflags = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(enabledcount == 0)
|
||||
if(!haveflags)
|
||||
{
|
||||
switch(group.Key)
|
||||
{
|
||||
|
|
|
@ -237,6 +237,7 @@
|
|||
<Compile Include="ErrorChecks\CheckUnknownTextures.cs" />
|
||||
<Compile Include="ErrorChecks\CheckUnknownThings.cs" />
|
||||
<Compile Include="ErrorChecks\CheckUnusedTextures.cs" />
|
||||
<Compile Include="ErrorChecks\CheckUnusedThings.cs" />
|
||||
<Compile Include="ErrorChecks\ResultMissingFlat.cs" />
|
||||
<Compile Include="ErrorChecks\ResultNoErrors.cs" />
|
||||
<Compile Include="ErrorChecks\ResultSectorInvalid.cs" />
|
||||
|
@ -248,6 +249,7 @@
|
|||
<Compile Include="ErrorChecks\ResultUnknownTexture.cs" />
|
||||
<Compile Include="ErrorChecks\ResultUnknownThing.cs" />
|
||||
<Compile Include="ErrorChecks\ResultUnusedTexture.cs" />
|
||||
<Compile Include="ErrorChecks\ResultUnusedThing.cs" />
|
||||
<Compile Include="ErrorChecks\ResultVertexOverlappingLine.cs" />
|
||||
<Compile Include="ErrorChecks\ResultVertexOverlappingVertex.cs" />
|
||||
<Compile Include="FindReplace\BaseFindLinedef.cs" />
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using CodeImp.DoomBuilder.Map;
|
||||
using System.Threading;
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks
|
||||
namespace CodeImp.DoomBuilder.BuilderModes
|
||||
{
|
||||
[ErrorChecker("Check unconnected vertices", true, 50)]
|
||||
public class CheckStrayVertices : ErrorChecker
|
||||
|
|
|
@ -12,7 +12,7 @@ using CodeImp.DoomBuilder.VisualModes;
|
|||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks
|
||||
namespace CodeImp.DoomBuilder.BuilderModes
|
||||
{
|
||||
[ErrorChecker("Check texture alignment", true, 1000)]
|
||||
public class CheckTextureAlignment : ErrorChecker
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System.Threading;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks {
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes
|
||||
{
|
||||
[ErrorChecker("Check unknown things", true, 50)]
|
||||
public class CheckUnknownThings : ErrorChecker {
|
||||
|
||||
|
|
93
Source/Plugins/BuilderModes/ErrorChecks/CheckUnusedThings.cs
Normal file
93
Source/Plugins/BuilderModes/ErrorChecks/CheckUnusedThings.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
#region ================== Namespaces
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using CodeImp.DoomBuilder.Config;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes
|
||||
{
|
||||
[ErrorChecker("Check unused things", true, 50)]
|
||||
public class CheckUnusedThings : ErrorChecker
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
private const int PROGRESS_STEP = 10;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Destructor
|
||||
|
||||
public CheckUnusedThings()
|
||||
{
|
||||
// Total progress is done when all things are checked
|
||||
SetTotalProgress(General.Map.Map.Things.Count / PROGRESS_STEP);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This runs the check
|
||||
public override void Run()
|
||||
{
|
||||
int progress = 0;
|
||||
int stepprogress = 0;
|
||||
bool udmf = General.Map.UDMF;
|
||||
|
||||
// Go for all things
|
||||
foreach(Thing t in General.Map.Map.Things)
|
||||
{
|
||||
List<string> messages = new List<string>();
|
||||
foreach(KeyValuePair<string, Dictionary<string, ThingFlagsCompare>> group in General.Map.Config.ThingFlagsCompare)
|
||||
{
|
||||
if(group.Value.Count < 2) continue;
|
||||
bool haveflags = false;
|
||||
|
||||
foreach(KeyValuePair<string, ThingFlagsCompare> flags in group.Value)
|
||||
{
|
||||
if((udmf && t.Fields.ContainsKey(flags.Key) && (bool)t.Fields[flags.Key].Value)
|
||||
|| t.IsFlagSet(flags.Key))
|
||||
{
|
||||
haveflags = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!haveflags) messages.Add(GetDescription(group.Key));
|
||||
}
|
||||
|
||||
if(messages.Count > 0)
|
||||
{
|
||||
string msg = " is not used " + string.Join(", ", messages.ToArray());
|
||||
SubmitResult(new ResultUnusedThing(t, msg));
|
||||
}
|
||||
|
||||
// Handle thread interruption
|
||||
try { Thread.Sleep(0); } catch(ThreadInterruptedException) { return; }
|
||||
|
||||
// We are making progress!
|
||||
if((++progress / PROGRESS_STEP) > stepprogress)
|
||||
{
|
||||
stepprogress = (progress / PROGRESS_STEP);
|
||||
AddProgress(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDescription(string group)
|
||||
{
|
||||
switch(group)
|
||||
{
|
||||
case "skills": return "in any skill level";
|
||||
case "gamemodes": return "in any game mode";
|
||||
case "classes": return "by any class";
|
||||
default: return "by any class, skill or game mode";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ using System.Drawing;
|
|||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks
|
||||
namespace CodeImp.DoomBuilder.BuilderModes
|
||||
{
|
||||
public class ResultStrayVertex : ErrorResult
|
||||
{
|
||||
|
|
|
@ -6,7 +6,8 @@ using CodeImp.DoomBuilder.Rendering;
|
|||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks {
|
||||
namespace CodeImp.DoomBuilder.BuilderModes
|
||||
{
|
||||
public class ResultUnknownThing : ErrorResult
|
||||
{
|
||||
|
||||
|
|
87
Source/Plugins/BuilderModes/ErrorChecks/ResultUnusedThing.cs
Normal file
87
Source/Plugins/BuilderModes/ErrorChecks/ResultUnusedThing.cs
Normal file
|
@ -0,0 +1,87 @@
|
|||
#region ================== Namespaces
|
||||
|
||||
using System;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
using CodeImp.DoomBuilder.Rendering;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes
|
||||
{
|
||||
public class ResultUnusedThing : ErrorResult
|
||||
{
|
||||
#region ================== Variables
|
||||
|
||||
private readonly Thing thing;
|
||||
private readonly string details;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public override int Buttons { get { return 2; } }
|
||||
public override string Button1Text { get { return "Delete Thing"; } }
|
||||
public override string Button2Text { get { return "Apply default flags"; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Destructor
|
||||
|
||||
public ResultUnusedThing(Thing t, string details)
|
||||
{
|
||||
// Initialize
|
||||
this.thing = t;
|
||||
this.details = details;
|
||||
this.viewobjects.Add(t);
|
||||
this.hidden = t.IgnoredErrorChecks.Contains(this.GetType());
|
||||
this.description = "This thing is not used by any class, skill or game mode.";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This sets if this result is displayed in ErrorCheckForm (mxd)
|
||||
internal override void Hide(bool hide)
|
||||
{
|
||||
hidden = hide;
|
||||
Type t = this.GetType();
|
||||
if(hide) thing.IgnoredErrorChecks.Add(t);
|
||||
else if(thing.IgnoredErrorChecks.Contains(t)) thing.IgnoredErrorChecks.Remove(t);
|
||||
}
|
||||
|
||||
// This must return the string that is displayed in the listbox
|
||||
public override string ToString()
|
||||
{
|
||||
return "Thing " + thing.Index + " (" + General.Map.Data.GetThingInfo(thing.Type).Title + ") at " + thing.Position.x + ", " + thing.Position.y + details;
|
||||
}
|
||||
|
||||
// Rendering
|
||||
public override void RenderOverlaySelection(IRenderer2D renderer)
|
||||
{
|
||||
renderer.RenderThing(thing, renderer.DetermineThingColor(thing), 1.0f);
|
||||
}
|
||||
|
||||
// This removes the thing
|
||||
public override bool Button1Click(bool batchMode)
|
||||
{
|
||||
if(!batchMode) General.Map.UndoRedo.CreateUndo("Delete thing");
|
||||
thing.Dispose();
|
||||
General.Map.IsChanged = true;
|
||||
General.Map.ThingsFilter.Update();
|
||||
return true;
|
||||
}
|
||||
|
||||
// This sets default flags
|
||||
public override bool Button2Click(bool batchMode)
|
||||
{
|
||||
if(!batchMode) General.Map.UndoRedo.CreateUndo("Set default thing flags");
|
||||
foreach(string f in General.Map.Config.DefaultThingFlags) thing.SetFlag(f, true);
|
||||
General.Map.IsChanged = true;
|
||||
General.Map.ThingsFilter.Update();
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue