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
1 change: 1 addition & 0 deletions BlazorRogue.Tests/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ public void ParseLoadsGameConfigDefaults()
var configuration = ParseConfiguration();

Assert.Equal(0, configuration.StartingLevelNumber);
Assert.Equal(12, configuration.PlayerSightRadius);
Assert.False(configuration.DebugMode);
Assert.Equal(-1002, configuration.DebugLevelNumber);
}
Expand Down
1 change: 1 addition & 0 deletions Data/game-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"starting_level": 0,
"player_sight_radius": 12,
"debug_mode": false,
"debug_level": -1002
}
20 changes: 20 additions & 0 deletions Entities/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ public LiquidType LiquidTypeById(string id) =>
/// </summary>
public int StartingLevelNumber { get; private set; } = DefaultStartingLevelNumber;

/// <summary>Player sight radius when <c>game-config.json</c> doesn't say otherwise.</summary>
internal const int DefaultPlayerSightRadius = 6;

/// <summary>
/// How many tiles the player can see (and wake monsters) around themselves, from
/// <c>Data/game-config.json</c>'s <c>player_sight_radius</c>. Defaults to
/// <see cref="DefaultPlayerSightRadius"/>; must be positive.
/// </summary>
public int PlayerSightRadius { get; private set; } = DefaultPlayerSightRadius;

/// <summary>
/// Initial value for <see cref="Game.DebugMode"/> (verbose combat rolls in the message log),
/// from <c>Data/game-config.json</c>'s <c>debug_mode</c>. Defaults to <c>false</c>; toggle it
Expand Down Expand Up @@ -361,6 +371,16 @@ void ParseGameConfig(JsonDocumentOptions options)
{
StartingLevelNumber = RequireNonNullInt(startingLevelElement, "starting_level");
}
if (root.TryGetProperty("player_sight_radius", out var sightRadiusElement))
{
PlayerSightRadius = RequireNonNullInt(sightRadiusElement, "player_sight_radius");
if (PlayerSightRadius < 1)
{
throw new InvalidOperationException(
$"game-config.json 'player_sight_radius' must be positive, but is {PlayerSightRadius}."
);
}
}
if (root.TryGetProperty("debug_mode", out var debugModeElement))
{
DebugMode = debugModeElement.GetBoolean();
Expand Down
10 changes: 6 additions & 4 deletions Pages/GamePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,9 @@ else
windowYOffset = Math.Clamp(optimalYOffset, 0, game.Map.Height - windowHeight);

// optional: keep move buffer proportional after resize
windowMoveBufferX = Math.Min(Map.PlayerSightRadius + 1, Math.Max(1, windowWidth / 3));
windowMoveBufferY = Math.Min(Map.PlayerSightRadius + 1, Math.Max(1, windowHeight / 3));
int sightRadius = game.Configuration.PlayerSightRadius;
windowMoveBufferX = Math.Min(sightRadius + 1, Math.Max(1, windowWidth / 3));
windowMoveBufferY = Math.Min(sightRadius + 1, Math.Max(1, windowHeight / 3));
}

private async Task ToggleRenderMode()
Expand Down Expand Up @@ -850,8 +851,9 @@ else
// guarded on `session is null` so neither is dereferenced before that.
Game game = null!;

int windowMoveBufferX = Map.PlayerSightRadius + 1;
int windowMoveBufferY = Map.PlayerSightRadius + 1;
// Placeholders until FitMapToViewportAsync derives them from the configured sight radius.
int windowMoveBufferX = BlazorRogue.Entities.Configuration.DefaultPlayerSightRadius + 1;
int windowMoveBufferY = BlazorRogue.Entities.Configuration.DefaultPlayerSightRadius + 1;

int windowWidth = 25;
int windowHeight = 20;
Expand Down
2 changes: 1 addition & 1 deletion World/Generation/FenceGalleryMapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected override Tuple<int, int> CreateLayout()
// twice) for a fresh goblin and try approaching more directly.
_ = AddMonsterAt(enclosureX0 + 2, enclosureY0 + 1, configuration.MonsterTypes["goblin"]);

// Sight radius is only Map.PlayerSightRadius (6) - too small to see the whole gallery from
// Sight radius is only game-config.json's player_sight_radius - may be too small to see the whole gallery from
// one spot regardless, but this puts the swatch row mostly in view on arrival, with the
// enclosure a short walk south.
return Tuple.Create(8, 6);
Expand Down
3 changes: 1 addition & 2 deletions World/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class Map
// Set via AddPlayer() shortly after Map construction (DungeonGenerator always calls it before
// the map is used); null! avoids forcing nullable-checks on every consumer of this property.
public Moveable Player { get; private set; } = null!;
public const int PlayerSightRadius = 6;
public const int PlayerSightRadiusSquared = PlayerSightRadius * PlayerSightRadius;
public int PlayerSightRadius => Game.Configuration.PlayerSightRadius;

public List<string> DebugInfo = [];

Expand Down
Loading