chore: fix contract catalog analyzer warnings.
Primary constructor on ContractTemplateCatalog; concrete List return types in loader parse helpers; collection spread in NormalizeBundle; const emptyCatalog in roster gate test.pull/186/head
parent
e3988874d2
commit
93fd8864dc
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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 sealed class ContractTemplateCatalog(
|
||||
string contractsDirectory,
|
||||
IReadOnlyDictionary<string, ContractTemplateRow> byId,
|
||||
int catalogJsonFileCount)
|
||||
{
|
||||
public 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 [];
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue