Skip to content

Commit c8ddda2

Browse files
committed
refactor(GalaxyMapCluster): change ReAssign method to virtual
Class GalaxyMapCluster: ~ReAssign(GalaxyMapViewer, Cluster?): made virtual for extensibility Class GalaxyMapCluster: ~Clear(GalaxyMapViewer, Canvas): renamed from Remove for clarity refactor(GalaxyMapSector): rename Remove method to Clear Class GalaxyMapSector: ~Clear(GalaxyMapViewer, Canvas): renamed from Remove for consistency refactor(GalaxyMapViewer): update method calls to use Clear Class GalaxyMapViewer: ~GalaxyMapClusterReassign(GalaxyMapCluster, Cluster?): added method for reassignment Class GalaxyMapViewer: ~Clear(GalaxyMapViewer, Canvas): updated calls to Clear instead of Remove
1 parent 1dac890 commit c8ddda2

3 files changed

Lines changed: 45 additions & 12 deletions

File tree

src/X4Map/GalaxyMapCluster.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public virtual double Create(GalaxyMapViewer map)
353353
return maxInternalSizeKm; // Return the maximum internal size of the sectors in the cluster
354354
}
355355

356-
public void ReAssign(GalaxyMapViewer map, Cluster? cluster)
356+
public virtual void ReAssign(GalaxyMapViewer map, Cluster? cluster)
357357
{
358358
Cluster = cluster;
359359
if (Hexagon != null)
@@ -375,23 +375,20 @@ public void ReAssign(GalaxyMapViewer map, Cluster? cluster)
375375
Hexagon.Stroke = Cluster != null ? (Cluster.Source == "New" ? Brushes.DarkGreen : Brushes.Black) : Brushes.DarkGray;
376376
Hexagon.Tag = Cluster != null ? Cluster.Name : "Empty Map Cell";
377377
Hexagon.DataContext = Cluster == null ? this : Cluster;
378-
if (Cluster != null && Cluster.Source != "New")
379-
{
380-
Create(map);
381-
}
382378
}
383379
}
384380

385-
public virtual void Remove(GalaxyMapViewer map, Canvas canvas)
381+
public virtual void Clear(GalaxyMapViewer map, Canvas canvas)
386382
{
387383
if (Hexagon != null)
388384
{
389385
canvas.Children.Remove(Hexagon);
386+
Hexagon = null;
390387
}
391388

392389
foreach (GalaxyMapSector sector in Sectors)
393390
{
394-
sector.Remove(map, canvas);
391+
sector.Clear(map, canvas);
395392
}
396393
}
397394

src/X4Map/GalaxyMapSector.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,14 @@ public override double Create(GalaxyMapViewer map)
196196
return SectorMapHelper.InternalSizeKm;
197197
}
198198

199-
public override void Remove(GalaxyMapViewer map, Canvas canvas)
199+
public override void Clear(GalaxyMapViewer map, Canvas canvas)
200200
{
201201
if (Grid != null)
202202
{
203203
canvas.Children.Remove(Grid);
204+
Grid = null;
205+
TextBlock = null;
206+
Hexagon = null;
204207
}
205208
foreach (SectorMapItem item in SectorMapHelper.Items)
206209
{

src/X4Map/GalaxyMapViewer.cs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,19 @@ double scaleFactor
275275
return newCluster;
276276
}
277277

278+
public virtual void GalaxyMapClusterReassign(GalaxyMapCluster galaxyCluster, Cluster? cluster)
279+
{
280+
if (galaxyCluster == null)
281+
{
282+
return;
283+
}
284+
if (!_clusters.Contains(galaxyCluster))
285+
{
286+
_clusters.Add(galaxyCluster);
287+
}
288+
galaxyCluster.ReAssign(this, cluster);
289+
}
290+
278291
public virtual GalaxyMapSector CreateMapSector(
279292
double x,
280293
double y,
@@ -299,12 +312,12 @@ public void RefreshGalaxyData()
299312
{
300313
foreach (GalaxyMapSector sector in _sectors)
301314
{
302-
sector.Remove(this, GalaxyCanvas);
315+
sector.Clear(this, GalaxyCanvas);
303316
}
304317
_sectors.Clear();
305318
foreach (GalaxyMapCluster cluster in _clusters)
306319
{
307-
cluster.Remove(this, GalaxyCanvas);
320+
cluster.Clear(this, GalaxyCanvas);
308321
}
309322
_clusters.Clear();
310323
foreach (GalaxyMapInterConnection connection in InterConnections)
@@ -575,7 +588,7 @@ public void RemoveCluster(GalaxyMapCluster cluster)
575588
{
576589
return;
577590
}
578-
cluster.Remove(this, GalaxyCanvas);
591+
cluster.Clear(this, GalaxyCanvas);
579592
_clusters.Remove(cluster);
580593
foreach (GalaxyMapSector sector in cluster.Sectors)
581594
{
@@ -590,7 +603,7 @@ public void RemoveSector(GalaxyMapSector sector)
590603
{
591604
return;
592605
}
593-
sector.Remove(this, GalaxyCanvas);
606+
sector.Clear(this, GalaxyCanvas);
594607
_sectors.Remove(sector);
595608
GalaxyMapCluster? ownerCluster = _clusters.Find(cl => cl.Sectors.Contains(sector));
596609
if (ownerCluster != null)
@@ -724,6 +737,26 @@ public virtual void UpdateMap()
724737
}
725738
}
726739

740+
public GalaxyMapCluster? GetClusterByMacro(string macro)
741+
{
742+
return _clusters.Find(cluster => StringHelper.EqualsIgnoreCase(cluster.Macro, macro));
743+
}
744+
745+
public GalaxyMapSector? GetSectorByMacro(string macro)
746+
{
747+
return _sectors.Find(sector => StringHelper.EqualsIgnoreCase(sector.Macro, macro));
748+
}
749+
750+
public GalaxyMapCluster? GetClusterBySectorMacro(string sectorMacro)
751+
{
752+
GalaxyMapSector? sector = GetSectorByMacro(sectorMacro);
753+
if (sector != null)
754+
{
755+
return _clusters.Find(cluster => cluster.Sectors.Contains(sector));
756+
}
757+
return null;
758+
}
759+
727760
protected void GalaxyMapViewer_SizeChanged(object sender, SizeChangedEventArgs e)
728761
{
729762
if (ActualWidth != 0 && ActualHeight != 0 && _canvasWidthBase != 0 && _canvasHeightBase != 0)

0 commit comments

Comments
 (0)