Merge pull request #186 from ViPro-Technologies/chore/neo-145-contract-catalog-analyzer-warnings

chore: fix contract catalog analyzer warnings
pull/189/head
VinPropane 2026-06-20 19:53:37 -04:00 committed by GitHub
commit f18309809a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 30 deletions

View File

@ -155,7 +155,7 @@ public class ContractTemplateCatalogLoaderTests
{
// Arrange
var (_, contractsDir, schemaPath) = CreateTempContentLayout();
var emptyCatalog = """{"schemaVersion": 1, "contractTemplates": []}""";
const string emptyCatalog = """{"schemaVersion": 1, "contractTemplates": []}""";
File.WriteAllText(Path.Combine(contractsDir, "prototype_contract_templates.json"), emptyCatalog, Encoding.UTF8);
// Act
var ex = Record.Exception(() => LoadCatalog(contractsDir, schemaPath));

View File

@ -3,25 +3,19 @@ using System.Collections.ObjectModel;
namespace NeonSprawl.Server.Game.Contracts;
/// <summary>In-memory contract template catalog loaded at startup (NEO-145). Game code should prefer <see cref="IContractTemplateRegistry"/> for lookups.</summary>
public sealed class ContractTemplateCatalog
{
public ContractTemplateCatalog(
public sealed class ContractTemplateCatalog(
string contractsDirectory,
IReadOnlyDictionary<string, ContractTemplateRow> byId,
int catalogJsonFileCount)
{
ContractsDirectory = contractsDirectory;
ById = new ReadOnlyDictionary<string, ContractTemplateRow>(new Dictionary<string, ContractTemplateRow>(byId, StringComparer.Ordinal));
CatalogJsonFileCount = catalogJsonFileCount;
}
{
/// <summary>Absolute path to the directory that was enumerated for <c>*_contract_templates.json</c> catalogs.</summary>
public string ContractsDirectory { get; }
public string ContractsDirectory { get; } = contractsDirectory;
public IReadOnlyDictionary<string, ContractTemplateRow> ById { get; }
public IReadOnlyDictionary<string, ContractTemplateRow> ById { get; } =
new ReadOnlyDictionary<string, ContractTemplateRow>(new Dictionary<string, ContractTemplateRow>(byId, StringComparer.Ordinal));
public int DistinctTemplateCount => ById.Count;
/// <summary>Number of <c>*_contract_templates.json</c> files under <see cref="ContractsDirectory"/>.</summary>
public int CatalogJsonFileCount { get; }
public int CatalogJsonFileCount { get; } = catalogJsonFileCount;
}

View File

@ -233,7 +233,7 @@ public static class ContractTemplateCatalogLoader
return new QuestRewardBundleRow(itemGrants, skillXpGrants, reputationGrants);
}
private static IReadOnlyList<ReputationGrantRow> ParseReputationGrantRows(JsonArray? array)
private static List<ReputationGrantRow> ParseReputationGrantRows(JsonArray? array)
{
if (array is null || array.Count == 0)
return [];
@ -252,7 +252,7 @@ public static class ContractTemplateCatalogLoader
return rows;
}
private static IReadOnlyList<RewardGrantRow> ParseItemGrantRows(JsonArray? array)
private static List<RewardGrantRow> ParseItemGrantRows(JsonArray? array)
{
if (array is null || array.Count == 0)
return [];
@ -271,7 +271,7 @@ public static class ContractTemplateCatalogLoader
return rows;
}
private static IReadOnlyList<QuestSkillXpGrantRow> ParseSkillXpGrantRows(JsonArray? array)
private static List<QuestSkillXpGrantRow> ParseSkillXpGrantRows(JsonArray? array)
{
if (array is null || array.Count == 0)
return [];

View File

@ -237,18 +237,9 @@ public static class PrototypeE7M4ContractCatalogRules
private static NormalizedBundle NormalizeBundle(QuestRewardBundleRow bundle) =>
new(
bundle.ItemGrants
.OrderBy(g => g.ItemId, StringComparer.Ordinal)
.ThenBy(g => g.Quantity)
.ToArray(),
bundle.SkillXpGrants
.OrderBy(g => g.SkillId, StringComparer.Ordinal)
.ThenBy(g => g.Amount)
.ToArray(),
bundle.ReputationGrants
.OrderBy(g => g.FactionId, StringComparer.Ordinal)
.ThenBy(g => g.Amount)
.ToArray());
[.. bundle.ItemGrants.OrderBy(g => g.ItemId, StringComparer.Ordinal).ThenBy(g => g.Quantity)],
[.. bundle.SkillXpGrants.OrderBy(g => g.SkillId, StringComparer.Ordinal).ThenBy(g => g.Amount)],
[.. bundle.ReputationGrants.OrderBy(g => g.FactionId, StringComparer.Ordinal).ThenBy(g => g.Amount)]);
private static bool BundlesEqual(NormalizedBundle left, NormalizedBundle right)
{