Skip to content

Commit

Permalink
Automated code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
soopercool101 committed Oct 3, 2019
1 parent 275ba0d commit f366939
Show file tree
Hide file tree
Showing 71 changed files with 454 additions and 366 deletions.
23 changes: 14 additions & 9 deletions BrawlCrate/BrawlAPI/BrawlAPI.cs
Expand Up @@ -90,10 +90,10 @@ static BrawlAPI()
/// </summary>
internal static readonly string[] DepreciatedStrings = new[]
{
"BrawlBox", // BrawlBox namespace is "BrawlCrate" in this program
"bboxapi", // API system is now named "BrawlAPI"
"PluginLoader", // Renamed to better reflect what it does (loaders do not have to be parsers)
"AddLoader" // Renamed to better reflect what it does (loaders do not have to be parsers)
"BrawlBox", // BrawlBox namespace is "BrawlCrate" in this program
"bboxapi", // API system is now named "BrawlAPI"
"PluginLoader", // Renamed to better reflect what it does (loaders do not have to be parsers)
"AddLoader" // Renamed to better reflect what it does (loaders do not have to be parsers)
};

/// <summary>
Expand Down Expand Up @@ -288,7 +288,8 @@ public static void PythonInstall(bool manual = false, bool force = false)
{
// Search the new installation path for Python
foreach (DirectoryInfo d in Directory
.CreateDirectory(Environment.SpecialFolder.ApplicationData.ToString()).GetDirectories().Reverse())
.CreateDirectory(Environment.SpecialFolder.ApplicationData.ToString())
.GetDirectories().Reverse())
{
if (d.FullName.StartsWith(
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\Python") &&
Expand Down Expand Up @@ -440,7 +441,8 @@ private static void ResourceTree_SelectionChanged(object sender, EventArgs e)
{
TreeViewMS resourceTree = (TreeViewMS) sender;
Type type = resourceTree.SelectedType;
if (resourceTree.SelectedNodes.Count > 1 && type != null && type.GetInterfaces().Contains(typeof(MultiSelectableWrapper)))
if (resourceTree.SelectedNodes.Count > 1 && type != null &&
type.GetInterfaces().Contains(typeof(MultiSelectableWrapper)))
{
// Get the correct multi-select context menu
ContextMenuStrip menu = type == typeof(GenericWrapper)
Expand All @@ -455,7 +457,8 @@ private static void ResourceTree_SelectionChanged(object sender, EventArgs e)
menu.Items.RemoveAt(menu.Items.Count - 1);
}

if (menu != null && MultiSelectContextMenuHooks.ContainsKey(type) && MultiSelectContextMenuHooks[type].Length > 0)
if (menu != null && MultiSelectContextMenuHooks.ContainsKey(type) &&
MultiSelectContextMenuHooks[type].Length > 0)
{
foreach (ToolStripMenuItem item in MultiSelectContextMenuHooks[type])
{
Expand Down Expand Up @@ -511,7 +514,8 @@ private static void ResourceTree_SelectionChanged(object sender, EventArgs e)
{
// Remove plugins list as necessary
while (wrapper.ContextMenuStrip != null && wrapper.ContextMenuStrip.Items.Count > 0 &&
(wrapper.ContextMenuStrip.Items[wrapper.ContextMenuStrip.Items.Count - 1].Text.Equals("Plugins") ||
(wrapper.ContextMenuStrip.Items[wrapper.ContextMenuStrip.Items.Count - 1].Text
.Equals("Plugins") ||
wrapper.ContextMenuStrip.Items[wrapper.ContextMenuStrip.Items.Count - 1] is ToolStripSeparator))
{
wrapper.ContextMenuStrip.Items.RemoveAt(wrapper.ContextMenuStrip.Items.Count - 1);
Expand Down Expand Up @@ -563,7 +567,8 @@ private static void ResourceTree_SelectionChanged(object sender, EventArgs e)
}

if (wrapper.ContextMenuStrip.Items.Count == 0 ||
!wrapper.ContextMenuStrip.Items[wrapper.ContextMenuStrip.Items.Count - 1].Text.Equals("Plugins"))
!wrapper.ContextMenuStrip.Items[wrapper.ContextMenuStrip.Items.Count - 1].Text
.Equals("Plugins"))
{
if (wrapper.ContextMenuStrip.Items.Count != 0)
{
Expand Down
2 changes: 1 addition & 1 deletion BrawlCrate/BrawlAPI/ExposedMembers.cs
Expand Up @@ -732,7 +732,7 @@ public static void AddMultiSelectContextMenuItem(Type wrapper, params ToolStripM
/// These should be defined as much as possible in the script itself.
/// </param>
public static void AddMultiSelectContextMenuItem(Type wrapper, string subMenuName, string description,
EventHandler conditional, params ToolStripMenuItem[] items)
EventHandler conditional, params ToolStripMenuItem[] items)
{
if (conditional != null)
{
Expand Down
7 changes: 4 additions & 3 deletions BrawlCrate/BrawlManagers/CostumeManager/PortraitMap.cs
Expand Up @@ -338,8 +338,8 @@ public int CharBustTexFor(string name)
public IEnumerable<string> GetKnownFighterNames()
{
return (from f in KnownFighters select f.Name)
.Concat(from f in additionalFighters select f.Name)
.Distinct();
.Concat(from f in additionalFighters select f.Name)
.Distinct();
}

public virtual bool ContainsMapping(int index)
Expand All @@ -358,7 +358,8 @@ public int[] GetPortraitMappings(int charBustTexIndex)
private int GetCharBustTexIndex(string name)
{
IEnumerable<Fighter> q = additionalFighters.Concat(KnownFighters)
.Where(f => string.Equals(f.Name, name, StringComparison.InvariantCultureIgnoreCase));
.Where(f => string.Equals(f.Name, name,
StringComparison.InvariantCultureIgnoreCase));
if (!q.Any())
{
throw new Exception("No known fighter found with name " + name + ".");
Expand Down
Expand Up @@ -13,7 +13,7 @@ public partial class CustomSongVolumeEditor : UserControl
{
private static Image SPEAKER =
new Bitmap(Assembly.GetExecutingAssembly()
.GetManifestResourceStream("BrawlCrate.BrawlManagers.SongManager.speaker.png"));
.GetManifestResourceStream("BrawlCrate.BrawlManagers.SongManager.speaker.png"));

public bool ChangeMadeSinceCSVLoaded { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion BrawlCrate/BrawlManagers/StageManager/IconsToMenumain.cs
Expand Up @@ -46,7 +46,7 @@ public static void Copy(ResourceNode scSelmap, ResourceNode muMenumain, CustomSS
else
{
Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("BrawlCrate.StageManager.XX.png");
.GetManifestResourceStream("BrawlCrate.StageManager.XX.png");
if (stream != null)
{
Image.FromStream(stream).Save(xx_png);
Expand Down
2 changes: 1 addition & 1 deletion BrawlCrate/BrawlManagers/StageManager/ImagePreviewPanel.cs
Expand Up @@ -163,7 +163,7 @@ private static Bitmap replaceBorder(Bitmap icon)
else
{
Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("BrawlCrate.StageManager.border.png");
.GetManifestResourceStream("BrawlCrate.StageManager.border.png");
if (stream == null)
{
MessageBox.Show(
Expand Down
3 changes: 2 additions & 1 deletion BrawlCrate/BrawlManagers/StageManager/PortraitViewer.cs
Expand Up @@ -1375,7 +1375,8 @@ private void lblPMAlt_DragDrop(object sender, DragEventArgs e)
if (overlayFile != null)
{
Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("BrawlCrate.StageManager." + overlayFile);
.GetManifestResourceStream(
"BrawlCrate.StageManager." + overlayFile);
if (stream != null)
{
Image overlayImage = Image.FromStream(stream) as Bitmap;
Expand Down
8 changes: 4 additions & 4 deletions BrawlCrate/ColorSmash/ColorSmash.cs
Expand Up @@ -27,7 +27,7 @@ public static void ColorSmashTex0(object sender, EventArgs e)
{
if (n is TEX0Wrapper tw)
{
TEX0Node t = (TEX0Node)tw.Resource;
TEX0Node t = (TEX0Node) tw.Resource;
if (paletteCount < 256)
{
if (!t.HasPalette || t.GetPaletteNode() == null)
Expand All @@ -37,11 +37,10 @@ public static void ColorSmashTex0(object sender, EventArgs e)
else if (t.HasPalette && t.GetPaletteNode() != null &&
t.GetPaletteNode().Palette.Entries.Length > paletteCount)
{
paletteCount = (short)Math.Min(t.GetPaletteNode().Palette.Entries.Length, 256);
paletteCount = (short) Math.Min(t.GetPaletteNode().Palette.Entries.Length, 256);
}
}
}

}

if (paletteCount == 0)
Expand All @@ -63,7 +62,7 @@ public static void ColorSmashTex0()
ColorSmashTex0(null);
}

public static void ColorSmashTex0(int? paletteCount)
public static void ColorSmashTex0(int? paletteCount)
{
// If this was selected via keycode when it's invalid, return without error
if (!CanRunColorSmash || MainForm.Instance.resourceTree.SelectedNodes.Count <= 1)
Expand Down Expand Up @@ -127,6 +126,7 @@ public static void ColorSmashTex0(int? paletteCount)
{
paletteCount = 0;
}

foreach (TreeNode n in MainForm.Instance.resourceTree.SelectedNodes)
{
// If this was selected via keycode when it's invalid, return without error
Expand Down
9 changes: 5 additions & 4 deletions BrawlCrate/Discord/DiscordSettings.cs
Expand Up @@ -183,7 +183,7 @@ public static void Update()
DiscordController.presence.details = WorkString + " UI";
}
else if (Program.RootPath.Substring(0, Program.RootPath.LastIndexOf('\\'))
.EndsWith("\\stage\\adventure"))
.EndsWith("\\stage\\adventure"))
{
DiscordController.presence.details = WorkString + " a subspace stage";
}
Expand All @@ -201,7 +201,7 @@ public static void Update()
}
else if (rootName.StartsWith("home_", StringComparison.OrdinalIgnoreCase)
&& Program.RootPath.Substring(0, Program.RootPath.LastIndexOf('\\'))
.EndsWith("\\system\\homebutton"))
.EndsWith("\\system\\homebutton"))
{
DiscordController.presence.details = WorkString + " the home menu";
}
Expand All @@ -212,7 +212,7 @@ public static void Update()
else if ((MainForm.Instance.RootNode.Name.StartsWith("Itm") ||
Program.RootPath.Substring(0, Program.RootPath.LastIndexOf('\\')).EndsWith("\\item") ||
Program.RootPath.Substring(0, Program.RootPath.LastIndexOf('\\'))
.Substring(0, Program.RootPath.LastIndexOf('\\')).EndsWith("\\item"))
.Substring(0, Program.RootPath.LastIndexOf('\\')).EndsWith("\\item"))
&& (rootName.EndsWith("Brres") || rootName.EndsWith("Param")))
{
DiscordController.presence.details = WorkString + " an item";
Expand Down Expand Up @@ -252,7 +252,8 @@ public static void Update()
DiscordController.presence.state = string.IsNullOrEmpty(Program.RootPath)
? ""
: Program.RootPath.Substring(Program.RootPath.LastIndexOf('\\') + 1,
Program.RootPath.LastIndexOf('\\') - Program.RootPath.LastIndexOf('.'));
Program.RootPath.LastIndexOf('\\') -
Program.RootPath.LastIndexOf('.'));
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion BrawlCrate/NodeWrappers/BaseWrapper.cs
Expand Up @@ -133,7 +133,8 @@ public void Link(ResourceNode res)
}
}

SelectedImageIndex = ImageIndex = Icons.getImageIndex(res.ResourceFileType);//((int)res.ResourceFileType & 0xFF);
SelectedImageIndex =
ImageIndex = Icons.getImageIndex(res.ResourceFileType); //((int)res.ResourceFileType & 0xFF);

res.SelectChild += OnSelectChild;
res.ChildAdded += OnChildAdded;
Expand Down
6 changes: 4 additions & 2 deletions BrawlCrate/NodeWrappers/BrawlEx/CSSCWrapper.cs
Expand Up @@ -108,8 +108,10 @@ public void NewEntry()

node._name =
"Fit" + BrawlLib.BrawlCrate.FighterNameGenerators.InternalNameFromID(
((CSSCNode) _resource)._cosmeticSlot, BrawlLib.BrawlCrate.FighterNameGenerators.cosmeticIDIndex,
"+S") + node._costumeID.ToString("00") + (BrawlExColorID.Colors.Length > node._colorID
((CSSCNode) _resource)._cosmeticSlot,
BrawlLib.BrawlCrate.FighterNameGenerators.cosmeticIDIndex,
"+S") + node._costumeID.ToString("00") +
(BrawlExColorID.Colors.Length > node._colorID
? " - " + BrawlExColorID.Colors[node._colorID].Name
: "");
_resource.AddChild(node);
Expand Down
6 changes: 5 additions & 1 deletion BrawlCrate/NodeWrappers/CollisionObjectWrapper.cs
Expand Up @@ -19,14 +19,17 @@ public override void Duplicate()
{
return;
}

string tempPath = Path.GetTempFileName();
_resource.Export(tempPath + ".coll");
CollisionNode cNode = NodeFactory.FromFile(null, tempPath + ".coll", typeof(CollisionNode)) as CollisionNode;
CollisionNode cNode =
NodeFactory.FromFile(null, tempPath + ".coll", typeof(CollisionNode)) as CollisionNode;
if (cNode == null)
{
MessageBox.Show("The node could not be duplicated correctly.");
return;
}

int n = 0;
int index = _resource.Index;
// Copy the name directly in cases where name isn't saved
Expand All @@ -39,6 +42,7 @@ public override void Duplicate()
// Set the name based on the number of duplicate nodes found
cNode.Children[0].Name = $"{_resource.Name} ({++n})";
}

// Place the node in the same containing parent, after the last duplicated node.
_resource.Parent.InsertChild(cNode.Children[0], true, index + 1);
}
Expand Down
4 changes: 2 additions & 2 deletions BrawlCrate/NodeWrappers/FolderWrapper.cs
Expand Up @@ -45,7 +45,7 @@ public FolderWrapper()
{
ContextMenuStrip = _menu;
}

public override void Delete()
{
if (Parent == null || Form.ActiveForm != MainForm.Instance)
Expand All @@ -64,4 +64,4 @@ public override void Delete()
Directory.Delete(dir, true);
}
}
}
}
15 changes: 11 additions & 4 deletions BrawlCrate/NodeWrappers/GenericWrapper.cs
Expand Up @@ -228,6 +228,7 @@ public virtual void ExportSelected()
{
return;
}

Dictionary<Type, string> extensions = new Dictionary<Type, string>();
List<ResourceNode> nodes = new List<ResourceNode>();
foreach (TreeNode tNode in MainForm.Instance.resourceTree.SelectedNodes)
Expand All @@ -253,7 +254,8 @@ public virtual void ExportSelected()
}
}

string invalidChars = System.Text.RegularExpressions.Regex.Escape(new string(Path.GetInvalidFileNameChars()));
string invalidChars =
System.Text.RegularExpressions.Regex.Escape(new string(Path.GetInvalidFileNameChars()));
string invalidRegStr = string.Format(@"([{0}]*\.+$)|([{0}]+)", invalidChars);
foreach (ResourceNode n in nodes)
{
Expand All @@ -263,7 +265,8 @@ public virtual void ExportSelected()
ext = ext.Insert(0, ".");
}

n.Export($"{folder}\\{System.Text.RegularExpressions.Regex.Replace($"{n.Name}{ext ?? ""}", invalidRegStr, "")}");
n.Export(
$"{folder}\\{System.Text.RegularExpressions.Regex.Replace($"{n.Name}{ext ?? ""}", invalidRegStr, "")}");
}

MessageBox.Show($"{nodes.Count} nodes successfully exported to {folder}", "Export Selected");
Expand Down Expand Up @@ -341,6 +344,7 @@ public virtual void Duplicate()
{
return;
}

string tempPath = Path.GetTempFileName();
_resource.Export(tempPath);
ResourceNode rNode2 = NodeFactory.FromFile(null, tempPath, _resource.GetType());
Expand All @@ -349,16 +353,18 @@ public virtual void Duplicate()
MessageBox.Show("The node could not be duplicated correctly.");
return;
}

int n = 0;
int index = _resource.Index;
// Copy ARCEntryNode data, which is contained in the containing ARC, not the node itself
if (rNode2 is ARCEntryNode)
{
((ARCEntryNode) rNode2).FileIndex = ((ARCEntryNode) _resource).FileIndex;
((ARCEntryNode) rNode2).FileType = ((ARCEntryNode) _resource).FileType;
((ARCEntryNode)rNode2).GroupID = ((ARCEntryNode)_resource).GroupID;
((ARCEntryNode)rNode2).RedirectIndex = ((ARCEntryNode)_resource).RedirectIndex;
((ARCEntryNode) rNode2).GroupID = ((ARCEntryNode) _resource).GroupID;
((ARCEntryNode) rNode2).RedirectIndex = ((ARCEntryNode) _resource).RedirectIndex;
}

// Copy the name directly in cases where name isn't saved
rNode2.Name = _resource.Name;
// Set the name programatically (based on Windows' implementation)
Expand All @@ -369,6 +375,7 @@ public virtual void Duplicate()
// Set the name based on the number of duplicate nodes found
rNode2.Name = $"{_resource.Name} ({++n})";
}

// Place the node in the same containing parent, after the last duplicated node.
_resource.Parent.InsertChild(rNode2, true, index + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion BrawlCrate/NodeWrappers/MDL0/MDL0MaterialWrapper.cs
Expand Up @@ -126,7 +126,7 @@ private void ExportShader()
string[] t = ShaderGenerator.GenTEVFragShader();
System.IO.File.WriteAllText(s.FileName,
ShaderGenerator.CombineFragShader(m, t, mat.ActiveShaderStages)
.Replace("\n", Environment.NewLine));
.Replace("\n", Environment.NewLine));
}

ShaderGenerator.ClearTarget();
Expand Down

0 comments on commit f366939

Please sign in to comment.