Align runtime bucket matching with helper normalization
- Normalize tile bucket keys by stripping non-alphanumerics and lowercasing - Use normalized alias lookup when resolving canonical directional wall buckets - Prevent runtime misses when bucket names differ by underscores/spaces/casing
This commit is contained in:
@@ -2,6 +2,7 @@ using DataServer.Data;
|
|||||||
using DataServer.Data.Entities;
|
using DataServer.Data.Entities;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace GameServer.Dungeon;
|
namespace GameServer.Dungeon;
|
||||||
@@ -632,7 +633,7 @@ public class DungeonGeneratorVNext
|
|||||||
|
|
||||||
var bucketNamesById = buckets.ToDictionary(b => b.Id, b => b.Name);
|
var bucketNamesById = buckets.ToDictionary(b => b.Id, b => b.Name);
|
||||||
var bucketIdsByName = buckets
|
var bucketIdsByName = buckets
|
||||||
.GroupBy(b => b.Name.Trim().ToLowerInvariant())
|
.GroupBy(b => NormalizeBucketKey(b.Name))
|
||||||
.ToDictionary(g => g.Key, g => g.First().Id);
|
.ToDictionary(g => g.Key, g => g.First().Id);
|
||||||
|
|
||||||
bool TileAllowedByPalette(TileDefinition t)
|
bool TileAllowedByPalette(TileDefinition t)
|
||||||
@@ -740,7 +741,7 @@ public class DungeonGeneratorVNext
|
|||||||
{
|
{
|
||||||
foreach (var name in alias.Value)
|
foreach (var name in alias.Value)
|
||||||
{
|
{
|
||||||
if (!bucketIdsByName.TryGetValue(name, out int id)) continue;
|
if (!bucketIdsByName.TryGetValue(NormalizeBucketKey(name), out int id)) continue;
|
||||||
if (allowedBucketIds.Count > 0 && !allowedBucketIds.Contains(id)) continue;
|
if (allowedBucketIds.Count > 0 && !allowedBucketIds.Contains(id)) continue;
|
||||||
resolved[alias.Key] = id;
|
resolved[alias.Key] = id;
|
||||||
break;
|
break;
|
||||||
@@ -834,6 +835,24 @@ public class DungeonGeneratorVNext
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string NormalizeBucketKey(string? value)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb = new StringBuilder(value.Length);
|
||||||
|
foreach (char c in value)
|
||||||
|
{
|
||||||
|
if (char.IsLetterOrDigit(c))
|
||||||
|
{
|
||||||
|
sb.Append(char.ToLowerInvariant(c));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
private static IEnumerable<string> ResolveDirectionalFallbackBuckets(int mask8)
|
private static IEnumerable<string> ResolveDirectionalFallbackBuckets(int mask8)
|
||||||
{
|
{
|
||||||
// Bit order N, NE, E, SE, S, SW, W, NW.
|
// Bit order N, NE, E, SE, S, SW, W, NW.
|
||||||
|
|||||||
Reference in New Issue
Block a user