Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: single seed #90

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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: 0 additions & 1 deletion Server/Components/Pages/GamePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
private MapDisplayData _mapDisplayData = new();
private MapData? _map;
private List<IPathfindingNode>? _path { get; set; }
private NoiseParameters _noiseParameters = new();

protected override async Task OnInitializedAsync()
{
Expand Down Expand Up @@ -194,9 +193,9 @@
{ "Equipment", _equipment },
{ "Inventory", _inventory }
};
MapParameters mapParameters = MapParametersService.ReadMapParametersFromJson(

Check warning on line 196 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Converting null literal or possible null value to non-nullable type.
"Config/MapParameters/Normal.json");
_map = await MapGeneratorService.GetMap(mapParameters);

Check warning on line 198 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Possible null reference argument for parameter 'mapParameters' in 'Task<MapData> IMapGeneratorService.GetMap(MapParameters mapParameters)'.
_mapDisplayData.ShowColorMap = true;

_mapPopupParameters = new()
Expand Down
4 changes: 3 additions & 1 deletion Server/Modules/Items/Services/ItemGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Json;
using Fracture.Server.Modules.AI.Services;
using Fracture.Server.Modules.Items.Models;
using Fracture.Server.Modules.NoiseGenerator.Models;
using Fracture.Server.Modules.Shared;
using Fracture.Server.Modules.Shared.Configuration;
using Microsoft.FeatureManagement;
Expand All @@ -16,17 +17,18 @@
private readonly IAIInstructionProvider? _ai;
private readonly IFeatureManager _featureManager;

public ItemGenerator(

Check warning on line 20 in Server/Modules/Items/Services/ItemGenerator.cs

View workflow job for this annotation

GitHub Actions / Checks

Non-nullable field '_featureManager' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
INameGenerator nameGenerator,
PrefixesGenerator prefixes,
NoiseParameters noiseParameters,
IAIInstructionProvider? ai = null
)
{
_nameGenerator = nameGenerator;
_prefixes = prefixes;
_ai = ai;

_rnd = new Random();
_rnd = new Random(noiseParameters.Seed);

var configData = File.ReadAllText("itemgeneratorconfig.json");
_modifiers = JsonSerializer.Deserialize<List<RarityModifier>>(configData)!;
Expand Down Expand Up @@ -79,7 +81,7 @@

prompt += $"Item is a reward for defeating {enemy}.";

return await _ai.GenerateInstructionResponse(prompt);

Check warning on line 84 in Server/Modules/Items/Services/ItemGenerator.cs

View workflow job for this annotation

GitHub Actions / Checks

Dereference of a possibly null reference.
}

public async Task<Item> Generate()
Expand Down
4 changes: 1 addition & 3 deletions Server/Modules/MapGenerator/Services/MapGeneratorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ public async Task<MapData> GetMap(MapParameters mapParameters)
private MapData GenerateMap(MapParameters mapParameters)
{
var noiseParameters = mapParameters.NoiseParameters;
noiseParameters.Seed = noiseParameters.UseRandomSeed
? _rnd.Next(-100000, 100000)
: noiseParameters.Seed;
int width = 64;
int height = 64;
bool useFalloff = true;
int _seed = noiseParameters.Seed;

var grid = new Node[width, height];

Expand Down
25 changes: 0 additions & 25 deletions Server/Modules/MapGenerator/UI/NoiseParametersView.razor

This file was deleted.

3 changes: 0 additions & 3 deletions Server/Modules/MapGenerator/UI/NoiseParametersView.razor.css

This file was deleted.

7 changes: 0 additions & 7 deletions Server/Modules/MapGenerator/UI/TileInfoView.razor

This file was deleted.

3 changes: 0 additions & 3 deletions Server/Modules/MapGenerator/UI/TileInfoView.razor.css

This file was deleted.

3 changes: 0 additions & 3 deletions Server/Modules/NoiseGenerator/Models/NoiseParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ public class NoiseParameters
public float Boost { get; set; }
public float Falloff { get; set; }
public bool FalloffType { get; set; }

public bool UseRandomSeed { get; set; } = true;
public bool GenerateNew { get; set; } = true;
}
14 changes: 2 additions & 12 deletions Server/Modules/NoiseGenerator/Services/CustomPerlin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,13 @@ public static float PerlinOctaves(

public static float[,] GenerateNoiseMap(
int size,
int? seed = null,
int seed,
int octaves = 1,
float persistence = 0.5f,
float lacunarity = 2.0f,
float scale = 1.0f
)
{ // Noise map generation
// can be called with a seed or without it
int actualSeed = seed ?? new Random().Next();

float[,] map = new float[size, size];

for (int y = 0; y < size; y++)
Expand All @@ -110,14 +107,7 @@ public static float PerlinOctaves(
{
float scaledX = x / (float)Math.PI / scale;
float scaledY = y / (float)Math.PI / scale;
map[x, y] = PerlinOctaves(
scaledX,
scaledY,
actualSeed,
octaves,
persistence,
lacunarity
);
map[x, y] = PerlinOctaves(scaledX, scaledY, seed, octaves, persistence, lacunarity);
}
}
return map;
Expand Down
1 change: 1 addition & 0 deletions Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Fracture.Server.Modules.Items.Models;
using Fracture.Server.Modules.Items.Services;
using Fracture.Server.Modules.MapGenerator.Services;
using Fracture.Server.Modules.NoiseGenerator.Models;
using Fracture.Server.Modules.Shared;
using Fracture.Server.Modules.Shared.Configuration;
using Fracture.Server.Modules.Shared.NameGenerators;
Expand Down
Loading