add menu item that checks for invalid ship paths and removes them from the current project (#28)

This commit is contained in:
Andrew DeLisa 2019-01-02 16:36:22 -05:00 committed by GrapeshotGames
parent 1db4ee1af8
commit c8c4c54884
2 changed files with 50 additions and 1 deletions

View file

@ -92,6 +92,7 @@
this.foregroundScaleBox = new System.Windows.Forms.NumericUpDown();
this.label5 = new System.Windows.Forms.Label();
this.atlasLocation = new System.Windows.Forms.Label();
this.cullInvalidPathsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.tileScaleBox)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.foregroundScaleBox)).BeginInit();
@ -280,7 +281,8 @@
this.editAllDiscoveryZonesToolStripMenuItem,
this.editSpawnPointsToolStripMenuItem,
this.editServerTemplatesToolStripMenuItem,
this.editLocksToolStripMenuItem});
this.editLocksToolStripMenuItem,
this.cullInvalidPathsToolStripMenuItem});
this.editToolStripMenuItem1.Name = "editToolStripMenuItem1";
this.editToolStripMenuItem1.Size = new System.Drawing.Size(39, 20);
this.editToolStripMenuItem1.Text = "Edit";
@ -760,6 +762,13 @@
this.atlasLocation.TabIndex = 36;
this.atlasLocation.Text = "Atlas Location";
//
// cullInvalidPathsToolStripMenuItem
//
this.cullInvalidPathsToolStripMenuItem.Name = "cullInvalidPathsToolStripMenuItem";
this.cullInvalidPathsToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
this.cullInvalidPathsToolStripMenuItem.Text = "Cull Invalid Paths";
this.cullInvalidPathsToolStripMenuItem.Click += new System.EventHandler(this.cullInvalidPathsToolStripMenuItem_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -887,6 +896,7 @@
private System.Windows.Forms.ToolStripMenuItem editServerTemplatesToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem editLocksToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem cullInvalidPathsToolStripMenuItem;
}
}

View file

@ -2356,6 +2356,45 @@ namespace ServerGridEditor
var editForm = new EditAllLocksForm(this);
editForm.ShowDialog();
}
private void cullInvalidPathsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (currentProject == null)
return;
// hold on to the count of culled paths for display purposes
var invalidCount = 0;
// determine the maximum X and Y coordinate that would be valid for this grid
var maxWidth = currentProject.cellSize * currentProject.numOfCellsX;
var maxHeight = currentProject.cellSize * currentProject.numOfCellsY;
var maxDimensions = new PointF(maxWidth, maxHeight);
// remove any path with any node with a coordinate below origin or above the calculated maximum
currentProject.shipPaths.RemoveAll((path) =>
{
foreach (var node in path.Nodes)
{
if (node.worldX < 0 || node.worldX > maxDimensions.X || node.worldY < 0 ||
node.worldY > maxDimensions.Y)
{
invalidCount++;
return true;
}
}
return false;
});
if (invalidCount > 0)
{
MessageBox.Show($"Found and removed {invalidCount} invalid paths!", "Invalid Paths Culled", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Did not find any invalid paths to cull!", "No Invalid Paths", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
public class Config