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
6 changes: 3 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 9.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,7 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc

**/*.key
nuget/archive/
4 changes: 2 additions & 2 deletions GoRogue.Debugger/GoRogue.Debugger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<!-- Enable C# 8.0 and nullable reference features -->
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
Expand Down Expand Up @@ -62,7 +62,7 @@
<ItemGroup>
<!-- ReSharper disable once VulnerablePackage -->
<PackageReference Include="dotnet-curses" Version="1.0.2" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0">
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion GoRogue.Docs/articles/howtos/dice-rolling.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ string valid = $"{numberOfDice}d{sidesOnDie}";
Some examples of valid expressions to roll include:
* Roll 3 six-sided dice: `3d6`
* Roll an eight-sided die and add 2 to the result: `1d8+2`
* Roll a twelve-sided die, double the result, and add 3: `d12*2+3`
* Roll a twelve-sided die, double the result, and add 3: `1d12*2+3`
* Roll a twelve-sided die, halve the result, and subtract 1: `1d12/2-1`
* Roll 10 ten-sided die, and only keep the top three: `10d10k3`
* Roll 4 six-sided die, add 1 to the entire roll, and only keep the top three: `4d6+1k3`
Expand Down
5 changes: 1 addition & 4 deletions GoRogue.Docs/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@
"disableGitFeatures": false,
"xref": [
"https://thesadrogue.github.io/TheSadRogue.Primitives/xrefmap.yml"
],
"xrefService": [
"https://xref.docs.microsoft.com/query?uid={uid}"
],
]
}
}
6 changes: 3 additions & 3 deletions GoRogue.PerformanceTests/GoRogue.PerformanceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>default</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.15.0" />
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion GoRogue.Profiler/GoRogue.Profiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion GoRogue.Snippets/GoRogue.Snippets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
40 changes: 36 additions & 4 deletions GoRogue.UnitTests/DiceNotation/DiceNotationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GoRogue.DiceNotation;
using System;
using GoRogue.DiceNotation;
using JetBrains.Annotations;
using Xunit;
using XUnit.ValueTuples;
Expand All @@ -17,14 +18,21 @@ private static void AssertMinMaxValues(DiceExpression expr, int min, int max)
[AssertionMethod]
private static void AssertReturnedInRange(DiceExpression expr, int min, int max)
{
// Necessary if we're using negative numbers as multipliers
int lMin = Math.Min(min, max);
int lMax = Math.Max(min, max);

for (var i = 0; i < 100; i++)
{
var result = expr.Roll();
Assert.True(result >= min && result <= max);
Assert.True(result >= lMin && result <= lMax);
}
}

public static (string expr, int min, int max)[] DiceExpressions = new[]
// NOTE: The test case min and max values are the expected min and max values for the expression
// assuming the MINIMUM roll of the dice, and assuming the MAXIMUM roll of the dice, in that order.
// This means that they min and max values may be reversed if the expression contains a negative multiplier.
public static (string expr, int min, int max)[] DiceExpressions =
{
// Advanced Dice Expression
("1d(1d12+4)+3", 4, 19),
Expand All @@ -45,7 +53,24 @@ public static (string expr, int min, int max)[] DiceExpressions = new[]
// Single dice with add and multiply
("3*(1d6+2)", 9, 24),
// Single dice with multiply
("1d6*3", 3, 18)
("1d6*3", 3, 18),
// Unary negation (only constant)
("-1", -1, -1),
// Negative combined with other operators
("1d6+-1", 0, 5),
// Negative combined with minus
("1d6--1", 2, 7),
// Negative combined with multiply
("1d6*-1", -1, -6),
// Negative combined with multiply and paren
("-2*(1d6+7)", -16, -26)
};

public static string[] InvalidDiceExpressions =
{
"1d6*/3",
"1d6-/3",
"1d6-)3"
};

[Theory]
Expand All @@ -56,5 +81,12 @@ public void DiceExpressionValues(string expression, int min, int max)
AssertMinMaxValues(expr, min, max);
AssertReturnedInRange(expr, min, max);
}

[Theory]
[MemberDataEnumerable(nameof(InvalidDiceExpressions))]
public void DiceExpressionInvalid(string expression)
{
Assert.Throws<InvalidOperationException>(() => Dice.Parse(expression));
}
}
}
8 changes: 4 additions & 4 deletions GoRogue.UnitTests/Effects/AdvancedEffectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public void EffectToString()
public void EffectTriggerAdd()
{
var effectTrigger = new AdvancedEffectTrigger<int>();
Assert.Equal(0, effectTrigger.Effects.Count);
Assert.Empty(effectTrigger.Effects);

effectTrigger.Add(new AdvancedIntEffect("Test Effect 1", 1, Args));
Assert.Equal(1, effectTrigger.Effects.Count);
Assert.Single(effectTrigger.Effects);

effectTrigger.Add(new AdvancedIntEffect("Test Effect 2", 2, Args));
Assert.Equal(2, effectTrigger.Effects.Count);
Expand All @@ -80,7 +80,7 @@ public void EffectTriggerEffects()

effectTrigger.Add(effect2);
effectTrigger.TriggerEffects(5);
Assert.Equal(1, effectTrigger.Effects.Count);
Assert.Single(effectTrigger.Effects);
Assert.Equal(multiDuration - 1, effectTrigger.Effects[0].Duration);
Assert.Equal(1, effect1.Duration);

Expand All @@ -101,7 +101,7 @@ public void EffectTriggerEffects()
Assert.Equal(2, secEffectTrigger.Effects.Count);

secEffectTrigger.TriggerEffects(5);
Assert.Equal(1, secEffectTrigger.Effects.Count);
Assert.Single(secEffectTrigger.Effects);
Assert.Equal(1, secEffectTrigger.Effects[0].Duration); // Must have cancelled
}
}
Expand Down
8 changes: 4 additions & 4 deletions GoRogue.UnitTests/Effects/EffectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void EffectToString()
public void EffectTriggerAdd()
{
var effectTrigger = new EffectTrigger();
Assert.Equal(0, effectTrigger.Effects.Count);
Assert.Empty(effectTrigger.Effects);

effectTrigger.Add(new IntEffect("Test Effect 1", 1));
Assert.Equal(1, effectTrigger.Effects.Count);
Assert.Single(effectTrigger.Effects);

effectTrigger.Add(new IntEffect("Test Effect 2", 2));
Assert.Equal(2, effectTrigger.Effects.Count);
Expand All @@ -78,7 +78,7 @@ public void EffectTriggerEffects()

effectTrigger.Add(effect2);
effectTrigger.TriggerEffects();
Assert.Equal(1, effectTrigger.Effects.Count);
Assert.Single(effectTrigger.Effects);
Assert.Equal(multiDuration - 1, effectTrigger.Effects[0].Duration);
Assert.Equal(1, effect1.Duration);

Expand All @@ -99,7 +99,7 @@ public void EffectTriggerEffects()
Assert.Equal(2, secEffectTrigger.Effects.Count);

secEffectTrigger.TriggerEffects();
Assert.Equal(1, secEffectTrigger.Effects.Count);
Assert.Single(secEffectTrigger.Effects);
Assert.Equal(1, secEffectTrigger.Effects[0].Duration); // Must have cancelled
}
}
Expand Down
22 changes: 22 additions & 0 deletions GoRogue.UnitTests/GameFramework/GameFrameworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,28 @@ public void TransparencyViewUpdatesOnRemove()
Assert.True(map.TransparencyView[1, 1]);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void TransparencyViewUpdatesOnChange(bool useCachedGridViews)
{
var map = new Map(10, 10, 1, Distance.Chebyshev, useCachedGridViews: useCachedGridViews);

var obj = new GameObject((1, 1), 0, false, isTransparent: true);
map.SetTerrain(obj);

var obj2 = new GameObject((1, 1), 1, true, false);
map.AddEntity(obj2);

Assert.False(map.TransparencyView[obj2.Position]);

obj2.IsTransparent = true;
Assert.True(map.TransparencyView[obj2.Position]);

obj2.IsTransparent = false;
Assert.False(map.TransparencyView[obj2.Position]);
}

[Fact]
public void GetObjectsAt()
{
Expand Down
19 changes: 11 additions & 8 deletions GoRogue.UnitTests/GoRogue.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>

<!-- Enable C# 8.0 nullable reference feature -->
Expand All @@ -18,22 +18,25 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0">
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RoyT.AStar" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.2.1" />
<PackageReference Include="XUnit.ValueTuples" Version="1.0.1" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions GoRogue.UnitTests/MapGeneration/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void ConstructionValidSizes(int width, int height)
Assert.Equal(height, generator.Context.Height);

Assert.NotNull(generator.GenerationSteps);
Assert.Equal(0, generator.GenerationSteps.Count);
Assert.Empty(generator.GenerationSteps);
}

[Theory]
Expand Down Expand Up @@ -125,7 +125,7 @@ public void AddStepAddsToList()
var step = new MockGenerationStep(null);

_generator.AddStep(step);
Assert.Equal(1, _generator.GenerationSteps.Count);
Assert.Single(_generator.GenerationSteps);
Assert.Same(step, _generator.GenerationSteps[0]);

var step2 = new MockGenerationStep(null);
Expand Down
11 changes: 9 additions & 2 deletions GoRogue/DiceNotation/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static ITerm EvaluatePostfix(IEnumerable<string> postfix)
var operands = new Stack<ITerm>();

foreach (var str in postfix)
if (char.IsDigit(str[0]))
if (char.IsDigit(str[0]) || str.Length > 1) // Operators are all 1 character so > 1 must mean a number like -10
operands.Push(new ConstantTerm(int.Parse(str)));
else // Is an operator
{
Expand Down Expand Up @@ -113,10 +113,16 @@ private static IEnumerable<string> ToPostfix(string infix)
var operators = new Stack<char>();

var charIndex = 0;
var lastWasOperator = true;
while (charIndex < infix.Length)
if (char.IsDigit(infix[charIndex])) // Is an operand
if (char.IsDigit(infix[charIndex]) || (lastWasOperator && infix[charIndex] == '-')) // Is an operand
{
lastWasOperator = false;

string number = "";
number += infix[charIndex];
charIndex++;

while (charIndex < infix.Length && char.IsDigit(infix[charIndex]))
{
number += infix[charIndex];
Expand All @@ -127,6 +133,7 @@ private static IEnumerable<string> ToPostfix(string infix)
}
else // Separate so we can increment charIndex differently
{
lastWasOperator = true;
switch (infix[charIndex])
{
case '(':
Expand Down
5 changes: 2 additions & 3 deletions GoRogue/GameFramework/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ private Map(ISettableGridView<IGameObject?> terrainLayer, Distance distanceMeasu

if (useCachedGridViews)
{

_cachedTransparencyView = new BitArrayView(_terrain.Width, _terrain.Height);
TransparencyView = _cachedTransparencyView;
_cachedWalkabilityView = new BitArrayView(_terrain.Width, _terrain.Height);
Expand Down Expand Up @@ -355,15 +354,15 @@ private void Map_ObjectRemovedSyncViews(object? sender, ItemEventArgs<IGameObjec
: FullIsTransparent(e.Position);

e.Item.WalkabilityChanged -= Item_WalkabilityChangedSyncView;
e.Item.TransparencyChanged += Item_TransparencyChangedSyncView;
e.Item.TransparencyChanged -= Item_TransparencyChangedSyncView;
}

private void Item_WalkabilityChangedSyncView(object? sender, ValueChangedEventArgs<bool> e) => _cachedWalkabilityView![((IGameObject)sender!).Position] = e.NewValue;

private void Item_TransparencyChangedSyncView(object? sender, ValueChangedEventArgs<bool> e)
{
var obj = (IGameObject)sender!;
if (e.NewValue)
if (e.NewValue != e.OldValue)
_cachedTransparencyView![obj.Position] = LayersBlockingTransparency == 1
? _terrain[obj.Position]?.IsTransparent ?? true
: FullIsTransparent(obj.Position);
Expand Down
Loading