Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
607 changes: 342 additions & 265 deletions Data/GalaxyDatabase.cs

Large diffs are not rendered by default.

41 changes: 37 additions & 4 deletions NMSE.Tests/DataLayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,16 @@ public void CompanionDatabase_Entries_HaveValidIds()
// --- GalaxyDatabase ----------------------------------------------

[Fact]
public void GalaxyDatabase_Has257Galaxies()
public void GalaxyDatabase_Has256Galaxies()
{
Assert.Equal(257, GalaxyDatabase.Galaxies.Length);
Assert.Equal(256, GalaxyDatabase.Galaxies.Length);
}

[Theory]
[InlineData(0, "Euclid")]
[InlineData(1, "Hilbert Dimension")]
[InlineData(9, "Eissentam")]
[InlineData(255, "Odyalutai")]
[InlineData(256, "Yilsrussimil")]
public void GalaxyDatabase_GetGalaxyName_ReturnsCorrectName(int index, string expected)
{
Assert.Equal(expected, GalaxyDatabase.GetGalaxyName(index));
Expand Down Expand Up @@ -234,11 +233,45 @@ public void GalaxyDatabase_GetGalaxyType_OutOfRange_ReturnsNormal()
Assert.Equal("Normal", GalaxyDatabase.GetGalaxyType(257));
}

[Fact]
public void GalaxyDatabase_GetGalaxyCore_OutOfRange_ReturnsUnknown()
{
Assert.Equal("Unknown", GalaxyDatabase.GetGalaxyCore(-1));
Assert.Equal("Unknown", GalaxyDatabase.GetGalaxyCore(257));
}

[Fact]
public void GalaxyDatabase_GetGalaxyCoreColor_OutOfRange_Returns000000()
{
Assert.Equal("#000000", GalaxyDatabase.GetGalaxyCoreColor(-1));
Assert.Equal("#000000", GalaxyDatabase.GetGalaxyCoreColor(257));
}

[Theory]
[InlineData(0, "White")]
[InlineData(1, "Deep Pink")]
[InlineData(9, "Orange")]
[InlineData(255, "Magenta")]
public void GalaxyDatabase_GetGalaxyCore_ReturnsCorrectColorName(int index, string expected)
{
Assert.Equal(expected, GalaxyDatabase.GetGalaxyCore(index));
}

/// Should this be case insenstive?
[Theory]
[InlineData(0, "#ffffff")]
[InlineData(1, "#ff1493")]
[InlineData(9, "#f97306")]
[InlineData(255, "#c20078")]
public void GalaxyDatabase_GetGalaxyCoreColor_ReturnsCorrectColorHex(int index, string expected)
{
Assert.Equal(expected, GalaxyDatabase.GetGalaxyCoreColor(index));
}

[Theory]
[InlineData(0, "Euclid (1)")]
[InlineData(9, "Eissentam (10)")]
[InlineData(255, "Odyalutai (256)")]
[InlineData(256, "Yilsrussimil (257)")]
public void GalaxyDatabase_GetGalaxyDisplayName_ReturnsNameWithNumber(int index, string expected)
{
Assert.Equal(expected, GalaxyDatabase.GetGalaxyDisplayName(index));
Expand Down
6 changes: 3 additions & 3 deletions NMSE.Tests/LogicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3677,7 +3677,7 @@ public void GalaxyDatabase_GetGalaxyName_ReturnsExpectedNames()
[Fact]
public void GalaxyDatabase_GetGalaxyName_HandlesOutOfRange()
{
// All 257 galaxies are now in the database; out of range returns Unknown
// All 256 galaxies are now in the database; out of range returns Unknown
Assert.Equal("Drundemiso", GalaxyDatabase.GetGalaxyName(199));
Assert.Equal("Unknown", GalaxyDatabase.GetGalaxyName(257));
Assert.Equal("Unknown", GalaxyDatabase.GetGalaxyName(-1));
Expand Down Expand Up @@ -3742,9 +3742,9 @@ public void SettlementLogic_Stats_HaveCorrectStructure()
}

[Fact]
public void GalaxyDatabase_Has257Galaxies()
public void GalaxyDatabase_Has256Galaxies()
{
Assert.Equal(257, GalaxyDatabase.Galaxies.Length);
Assert.Equal(256, GalaxyDatabase.Galaxies.Length);
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions NMSE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@

<ItemGroup>
<EmbeddedResource Include="Resources\app\NMSGeoSans_Kerned.ttf" />
<EmbeddedResource Include="Resources\app\NMS_Glyphs_Mono.ttf" />
<!-- Copy the ICO file to the output directory so the app can load it
from disk at runtime. This is the most reliable icon-loading path
(no ResourceManager, no embedded-resource naming quirks).
Expand Down
Binary file added Resources/app/NMS_Glyphs_Mono.ttf
Binary file not shown.
10 changes: 10 additions & 0 deletions Resources/app/NMS_Glyphs_Mono_license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This font was downloaded from the NMS Wiki (Miraheze)
https://nms.miraheze.org/wiki/File:NMS-Glyphs-Mono.ttf
Creation is credited to: Stephan vd Feest aka Ghuyajil

As per https://github.com/DemmyDemon/nms-glyph/blob/main/LICENSE and
https://www.reddit.com/r/NMSCoordinateExchange/comments/aaz8c4/download_nmsglyphs_fonts_for_your_posters/
the font seems to be freely available under a permissive license.

If you are the creator and this is no longer the case,
please open an GitHub Issue and it will be promptly removed.
6 changes: 4 additions & 2 deletions UI/Panels/CataloguePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,8 @@ private void OnLocationSelectionChanged(object? sender, EventArgs e)
int realityIndex = _locationsGrid.Rows[rowIdx].Cells["Galaxy"].Tag is int ri ? ri : 0;
string galaxyType = GalaxyDatabase.GetGalaxyType(realityIndex);
_locGalaxyDot.Text = string.IsNullOrEmpty(galaxy) ? "" : " \u25CF";
_locGalaxyDot.ForeColor = GalaxyDatabase.GetGalaxyTypeColor(galaxyType);
string hexColor = GalaxyDatabase.GetGalaxyCoreColor(realityIndex);
_locGalaxyDot.ForeColor = System.Drawing.ColorTranslator.FromHtml(hexColor);
}

/// <summary>
Expand All @@ -863,7 +864,8 @@ private void OnLocationGalaxyCellPainting(object? sender, DataGridViewCellPainti
{
int realityIndex = _locationsGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag is int ri ? ri : 0;
string galaxyType = GalaxyDatabase.GetGalaxyType(realityIndex);
Color dotColor = GalaxyDatabase.GetGalaxyTypeColor(galaxyType);
string hexColor = GalaxyDatabase.GetGalaxyCoreColor(realityIndex);
Color dotColor = System.Drawing.ColorTranslator.FromHtml(hexColor);

var font = e.CellStyle?.Font ?? _locationsGrid.DefaultCellStyle.Font ?? _locationsGrid.Font;
var textColor = e.State.HasFlag(DataGridViewElementStates.Selected)
Expand Down
6 changes: 4 additions & 2 deletions UI/Panels/MainStatsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ private void LoadCoordinates(JsonObject playerState, JsonObject saveData)
string galaxyType = GalaxyDatabase.GetGalaxyType(realityIndex);
_galaxyField.Text = $"{GalaxyDatabase.GetGalaxyDisplayName(realityIndex)} ({galaxyType})";
_galaxyDotLabel.Text = "\u25CF";
_galaxyDotLabel.ForeColor = GalaxyDatabase.GetGalaxyTypeColor(galaxyType);
string hexColor = GalaxyDatabase.GetGalaxyCoreColor(realityIndex);
_galaxyDotLabel.ForeColor = System.Drawing.ColorTranslator.FromHtml(hexColor);

var galactic = addr.GetObject("GalacticAddress");
if (galactic == null) return;
Expand Down Expand Up @@ -604,7 +605,8 @@ private void RefreshCoordinateDisplay()
string galaxyType = GalaxyDatabase.GetGalaxyType(realityIndex);
_galaxyField.Text = $"{GalaxyDatabase.GetGalaxyDisplayName(realityIndex)} ({galaxyType})";
_galaxyDotLabel.Text = " \u25CF";
_galaxyDotLabel.ForeColor = GalaxyDatabase.GetGalaxyTypeColor(galaxyType);
string hexColor = GalaxyDatabase.GetGalaxyCoreColor(realityIndex);
_galaxyDotLabel.ForeColor = System.Drawing.ColorTranslator.FromHtml(hexColor);
_portalCodeField.Text = CoordinateHelper.VoxelToPortalCode(voxelX, voxelY, voxelZ, solarIdx, planetIdx);
_portalCodeDecField.Text = CoordinateHelper.PortalHexToDec(_portalCodeField.Text);
CoordinateHelper.UpdateGlyphPanel(_portalGlyphPanel, _portalCodeField.Text);
Expand Down
64 changes: 64 additions & 0 deletions UI/Util/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ public static class FontManager
private static PrivateFontCollection? _fontCollection;
private static FontFamily? _nmsFont;
private static bool _initialized;

private static PrivateFontCollection? _glyphFontCollection;
private static FontFamily? _glyphFont;
private static bool _glyphInitialized;

private const string FontResourceName = "NMSE.Resources.app.NMSGeoSans_Kerned.ttf";
private const string GlyphFontResourceName = "NMSE.Resources.app.NMS_Glyphs_Mono.ttf";

/// <summary>The loaded NMS GeoSans font family, or null if loading failed.</summary>
public static FontFamily? NmsFont
Expand All @@ -37,6 +42,27 @@ public static Font CreateFont(float size, FontStyle style = FontStyle.Regular)
return new Font(family, size, style);
}

/// <summary>The loaded NMS portal glyph font family, or null if loading failed.</summary>
public static FontFamily? GlyphFont
{
get
{
EnsureGlyphInitialized();
return _glyphFont;
}
}

/// <summary>
/// Creates a Font using the embedded NMS portal glyph font at the given size.
/// Falls back to Consolas if the embedded font could not be loaded.
/// </summary>
public static Font CreateGlyphFont(float size)
{
EnsureGlyphInitialized();
var family = _glyphFont ?? FontFamily.GenericMonospace;
return new Font(family, size, FontStyle.Regular);
}

/// <summary>
/// Creates a heading font (bold) at the specified size using the NMS GeoSans font.
/// </summary>
Expand Down Expand Up @@ -100,4 +126,42 @@ private static void EnsureInitialized()
System.Diagnostics.Debug.WriteLine($"FontManager: failed to load font: {ex.Message}");
}
}

private static void EnsureGlyphInitialized()
{
if (_glyphInitialized) return;
_glyphInitialized = true;

try
{
var assembly = typeof(FontManager).Assembly;
using var stream = assembly.GetManifestResourceStream(GlyphFontResourceName);
if (stream == null)
{
System.Diagnostics.Debug.WriteLine($"FontManager: embedded resource '{GlyphFontResourceName}' not found.");
return;
}

byte[] fontData = new byte[stream.Length];
stream.ReadExactly(fontData);

_glyphFontCollection = new PrivateFontCollection();
var handle = GCHandle.Alloc(fontData, GCHandleType.Pinned);
try
{
_glyphFontCollection.AddMemoryFont(handle.AddrOfPinnedObject(), fontData.Length);
}
finally
{
handle.Free();
}

if (_glyphFontCollection.Families.Length > 0)
_glyphFont = _glyphFontCollection.Families[0];
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"FontManager: failed to load glyph font: {ex.Message}");
}
}
}
Loading