Skip to content

Commit 4bbff45

Browse files
committed
refactor(GalaxyMapViewer): add CreateMapCluster and CreateMapSector methods
Class GalaxyMapViewer: +added CreateMapCluster(); +added CreateMapSector() methods for improved sector and cluster creation logic. refactor(GalaxyMapCluster): update sector creation to use CreateMapSector Class GalaxyMapCluster: ~modified sector creation logic to utilize CreateMapSector() method for better abstraction.
1 parent dde83c2 commit 4bbff45

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

src/X4Map/GalaxyMapCluster.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,17 @@ public virtual double Create(GalaxyMapViewer map)
129129
Log.Debug(
130130
$"Col: {MapPosition.Column, 3} Row: {MapPosition.Row, 3}: Creating a single Sector '{sector.Name}' in Cluster '({Cluster.Name})'"
131131
);
132-
GalaxyMapSector clusterMapSector = new(_x, _y, this, Canvas, Cluster, sector, HexagonWidth, HexagonHeight, ScaleFactor);
132+
GalaxyMapSector clusterMapSector = map.CreateMapSector(
133+
_x,
134+
_y,
135+
this,
136+
Canvas,
137+
Cluster,
138+
sector,
139+
HexagonWidth,
140+
HexagonHeight,
141+
ScaleFactor
142+
);
133143
maxInternalSizeKm = clusterMapSector.Create(map);
134144
Sectors.Add(clusterMapSector);
135145
}
@@ -314,7 +324,7 @@ public virtual double Create(GalaxyMapViewer map)
314324
break;
315325
}
316326
Log.Debug($"Sector({index}) {Cluster.Sectors[index].Name}: Corner: {corners[index]}, Position: X = {x}, Y = {y}");
317-
GalaxyMapSector clusterMapSector = new(
327+
GalaxyMapSector clusterMapSector = map.CreateMapSector(
318328
x,
319329
y,
320330
this,

src/X4Map/GalaxyMapViewer.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,37 @@ public void Connect(
257257
_zoomCommitTimer.Tick += (_, _) => CommitDeferredZoom();
258258
}
259259

260+
public virtual GalaxyMapCluster CreateMapCluster(
261+
double x,
262+
double y,
263+
MapPosition mapPosition,
264+
Canvas canvas,
265+
Cluster? cluster,
266+
Position? position,
267+
double hexagonWidth,
268+
double hexagonHeight,
269+
double scaleFactor
270+
)
271+
{
272+
return new GalaxyMapCluster(x, y, mapPosition, canvas, cluster, position, hexagonWidth, hexagonHeight, scaleFactor);
273+
}
274+
275+
public virtual GalaxyMapSector CreateMapSector(
276+
double x,
277+
double y,
278+
GalaxyMapCluster owner,
279+
Canvas canvas,
280+
Cluster cluster,
281+
Sector sector,
282+
double hexagonWidth,
283+
double hexagonHeight,
284+
double scaleFactor,
285+
bool isHalf = false
286+
)
287+
{
288+
return new GalaxyMapSector(x, y, owner, canvas, cluster, sector, hexagonWidth, hexagonHeight, scaleFactor, isHalf);
289+
}
290+
260291
public void RefreshGalaxyData()
261292
{
262293
if (_clusters.Count > 0)
@@ -439,7 +470,7 @@ protected virtual void CreateMap()
439470
MapPosition mapPosition = new(col, row);
440471
Cluster? cluster = GalaxyMapCell.GetCluster(MapCells, mapPosition);
441472
Position position = cluster != null ? cluster.Position : new Position(col * ColumnWidth, 0, row * RowHeight);
442-
GalaxyMapCluster clusterMapCluster = new(
473+
GalaxyMapCluster clusterMapCluster = CreateMapCluster(
443474
0.75 * (col - MapInfo.ColumnMin),
444475
(MapInfo.RowMax - row) * 0.5,
445476
mapPosition,

0 commit comments

Comments
 (0)