AetherDb: every booted read tool disposes its scratch; the shipped-only open is OpenShipped; save throws on an excluded package
Soul s1 findings booted-scratch-leak, shipped-named-overclaimed, save-excluded-package-not-pinned. The name OpenShipped says why, so the per-site comments on the apply paths are not needed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
509a168c3f
commit
7c247de18c
27 changed files with 126 additions and 104 deletions
|
|
@ -38,6 +38,8 @@ public sealed class BootedCatalogReadToolsTests : IDisposable
|
|||
Directory.CreateDirectory(Path.Combine(_broken.Path, "GameData", "Mods", "mod.broken"));
|
||||
File.Copy(Path.Combine(_repo, "GameData", "Aetheria.cc"), Path.Combine(_broken.Path, "GameData", "Aetheria.cc"));
|
||||
File.WriteAllBytes(Path.Combine(_broken.Path, "GameData", "Mods", "mod.broken", "ship.cc"), new byte[] { 1, 2, 3 });
|
||||
// The save viewer returns early without a run store, so the fixture holds one; the compose throws before it is read.
|
||||
File.WriteAllBytes(Path.Combine(_broken.Path, "GameData", "run.cc"), Array.Empty<byte>());
|
||||
return _broken.Path;
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +72,7 @@ public sealed class BootedCatalogReadToolsTests : IDisposable
|
|||
[InlineData("hardpoint-fit")]
|
||||
[InlineData("factions")]
|
||||
[InlineData("weapon-ammo")]
|
||||
[InlineData("save")]
|
||||
[InlineData("economy", "report")]
|
||||
[InlineData("economy", "balance")]
|
||||
public void AReadToolThrowsNamingAnExcludedPackage(params string[] args)
|
||||
|
|
@ -79,6 +82,34 @@ public sealed class BootedCatalogReadToolsTests : IDisposable
|
|||
Assert.Contains("mod.broken", error.Message);
|
||||
}
|
||||
|
||||
// A read tool's composed scratch (aetherdb-mods-*) is removed when the tool returns or throws. This class runs alone (its collection
|
||||
// disables parallelization), so no other test is making one meanwhile.
|
||||
[Theory]
|
||||
[InlineData("census")]
|
||||
[InlineData("station-fit")]
|
||||
[InlineData("loadout", "2")]
|
||||
[InlineData("hardpoint-fit")]
|
||||
[InlineData("factions")]
|
||||
[InlineData("weapon-ammo")]
|
||||
[InlineData("economy", "report")]
|
||||
public void AReadToolLeavesNoScratchBehind(params string[] args)
|
||||
{
|
||||
var before = Scratches();
|
||||
Run(args);
|
||||
Assert.Equal(before, Scratches());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheSaveViewerLeavesNoScratchBehindWhenItThrows()
|
||||
{
|
||||
var before = Scratches();
|
||||
Environment.CurrentDirectory = BrokenRoot();
|
||||
Assert.Throws<InvalidOperationException>(() => ConsoleProbe.WrittenBy(() => Program.Main(new[] { "save" })));
|
||||
Assert.Equal(before, Scratches());
|
||||
}
|
||||
|
||||
private static string[] Scratches() => Directory.GetDirectories(Path.GetTempPath(), "aetherdb-mods-*");
|
||||
|
||||
[Fact]
|
||||
public void ComposeBootedThrowsNamingAnExcludedPackage()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public sealed class ConsumablesFirstSetCommandTests : IDisposable
|
|||
|
||||
private (ConsumableItemData[] Designs, FactionProductData[] Products) Read()
|
||||
{
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var designs = db.Cache.GetAll<ConsumableItemData>().Where(c => DesignNames.Contains(c.Name)).ToArray();
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ public sealed class EconomyCommandTests
|
|||
[Fact]
|
||||
public void BalanceOnTheShippedCatalogPrintsEveryLinkAndBeltRow()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var report = EconomyBalance.Balance(db.Cache);
|
||||
var output = new StringWriter();
|
||||
EconomyCommand.Balance(db.Cache, 2, output);
|
||||
|
|
@ -352,7 +352,7 @@ public sealed class EconomyCommandTests
|
|||
[Fact]
|
||||
public void ReportOnTheShippedCatalogGoesToTheGivenWriterAndNeverToConsole()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var expected = new StringWriter();
|
||||
var expectedCode = EconomyCommand.Report(db.Cache, expected);
|
||||
var output = new StringWriter();
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public sealed class EconomyLoopTests
|
|||
[Fact]
|
||||
public void TheBallisticLadderAndItsTopGunSitInsideTheShippedBands()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var settings = new GameplaySettings();
|
||||
Assert.Equal((10f, 30f, 10f, 20f), (settings.EconomyLadderMin, settings.EconomyLadderMax, settings.EconomySortiesMin, settings.EconomySortiesMax));
|
||||
var report = EconomyLoop.Report(db.Cache, settings, new[] { Sample(1, 1734, 0, 183, 150) });
|
||||
|
|
@ -210,7 +210,7 @@ public sealed class EconomyLoopTests
|
|||
// The price the catalog authors for a simple commodity of that name.
|
||||
private static int PriceOf(string name)
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
return db.Cache.GetAll<SimpleCommodityData>().Single(c => c.Name == name).Price;
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +317,7 @@ public sealed class EconomyLoopTests
|
|||
[Fact]
|
||||
public void BalanceLoopPrintsTheLoopAndTheLaddersAndLetsTheirFaultsFailTheCommand()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var settings = AuthoredSettings.Load(db.Root).Read<GameplaySettings>("GameplaySettings");
|
||||
var report = EconomyLoop.Report(db.Cache, settings, new[] { Sample(7, 100, 100, 0, 60) });
|
||||
var plain = new StringWriter();
|
||||
|
|
|
|||
|
|
@ -26,14 +26,14 @@ public sealed class GenericDesignsCommandTests : IDisposable
|
|||
|
||||
private void Edit(Action<AetherDb> edit)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
try { edit(db); }
|
||||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
||||
private T Read<T>(Func<AetherDb, T> read)
|
||||
{
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try { return read(db); }
|
||||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public sealed class InspectionScannerCommandTests : IDisposable
|
|||
|
||||
private (GearData[] Designs, string[] Products) Read()
|
||||
{
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var designs = db.Cache.GetAll<GearData>().Where(g => g.Name == DesignName).ToArray();
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public sealed class LaunchSuppressorCommandTests : IDisposable
|
|||
|
||||
private (GearData[] Designs, string[] Products) Read()
|
||||
{
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var designs = db.Cache.GetAll<GearData>().Where(g => DesignNames.Contains(g.Name)).ToArray();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public sealed class LauncherAmmunitionCatalogTests
|
|||
[Fact]
|
||||
public void EveryShippedLauncherReloadsFromMissilesAndMissilesCanBeMade()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var missiles = db.Cache.GetAll<SimpleCommodityData>().Single(c => c.Name == "Missiles");
|
||||
var key = db.Cache.RefOf(missiles).Key;
|
||||
var launchers = db.Cache.GetAll<WeaponItemData>().SelectMany(i => i.Behaviors.OfType<WeaponData>().Where(IsLauncher).Select(d => (i.Name, d))).ToArray();
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public sealed class MinorPowersTests : IDisposable
|
|||
Assert.Equal(0, MinorPowerFactionsCommand.Run(new[] { "apply" }, _root));
|
||||
var landed = File.ReadAllBytes(CatalogPath);
|
||||
Assert.NotEqual(before, landed);
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var factions = db.Cache.GetAll<Faction>().ToArray();
|
||||
|
|
@ -108,7 +108,7 @@ public sealed class MinorPowersTests : IDisposable
|
|||
public void ANameHeldUnderAnotherKeyIsRefusedWithNothingWritten()
|
||||
{
|
||||
StripTheMinorPowers();
|
||||
var squatter = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var squatter = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
squatter.Cache.Commit(batch => batch.Upsert(typeof(Faction), new Faction { Name = "Megiddo", ShortName = "Megiddo" }));
|
||||
squatter.Cache.Dispose();
|
||||
var before = File.ReadAllBytes(CatalogPath);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public sealed class MunitionsSourcingCatalogTests
|
|||
[Fact]
|
||||
public void EveryRoundFiringGunNamesAnAmmunitionCommodityAndHoldsARealMagazine()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var guns = db.Cache.GetAll<WeaponItemData>()
|
||||
.SelectMany(i => i.Behaviors.OfType<WeaponData>().Where(d => FiresRounds(i, d)).Select(d => (i.Name, d))).ToArray();
|
||||
Assert.True(guns.Length >= 14, $"fixture: the catalog holds its round-firing guns ({guns.Length})");
|
||||
|
|
@ -34,7 +34,7 @@ public sealed class MunitionsSourcingCatalogTests
|
|||
[Fact]
|
||||
public void EveryDrawnAmmunitionHasAFiniteProductionDepth()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var depth = EconomyChecks.Deep(db.Cache);
|
||||
var drawn = db.Cache.GetAll<WeaponItemData>().SelectMany(i => i.Behaviors.OfType<WeaponData>()).Where(d => d.AmmoType.IsSet())
|
||||
.Select(d => d.AmmoType.Key.Value).Distinct().ToArray();
|
||||
|
|
@ -47,7 +47,7 @@ public sealed class MunitionsSourcingCatalogTests
|
|||
[Fact]
|
||||
public void TheMunitionsChainHasNoSourceSinkFault()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var chain = new HashSet<string>(ChainOf(db.Cache), System.StringComparer.Ordinal);
|
||||
Assert.True(chain.Count >= 25, $"fixture: the chain is walked ({chain.Count} goods)");
|
||||
var faults = EconomyChecks.SourceSink(db.Cache).Where(f => chain.Contains(KeyOfRecipe(f.Record))).ToArray();
|
||||
|
|
|
|||
|
|
@ -42,14 +42,14 @@ public sealed class PiratesFactionCommandTests : IDisposable
|
|||
|
||||
private int AllFactionsButThePirates()
|
||||
{
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try { return db.Cache.GetAll<Faction>().Count(f => f.Name != "Pirates"); }
|
||||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
||||
private (Faction[] Pirates, FactionProductData[] Products) Read()
|
||||
{
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var pirates = db.Cache.GetAll<Faction>().Where(faction => faction.Name == "Pirates").ToArray();
|
||||
|
|
@ -80,7 +80,7 @@ public sealed class PiratesFactionCommandTests : IDisposable
|
|||
Assert.Equal(AllFactionsButThePirates(), faction.Allegiance.Count);
|
||||
Assert.All(faction.Allegiance.Values, value => Assert.Equal(1f, value));
|
||||
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var expected = new (string Design, string Name, string Description)[]
|
||||
|
|
@ -118,7 +118,7 @@ public sealed class PiratesFactionCommandTests : IDisposable
|
|||
[Fact]
|
||||
public void An_existing_Pirates_faction_is_topped_up_with_allegiance_and_nothing_else()
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
db.Cache.Commit(batch => batch.Upsert(typeof(Faction), new Faction { Name = "Pirates", ShortName = "Mine", Description = "authored by hand" }));
|
||||
var key = db.Cache.RefOf(db.Cache.GetAll<Faction>().Single(f => f.Name == "Pirates")).Key;
|
||||
db.Cache.Dispose();
|
||||
|
|
@ -135,14 +135,14 @@ public sealed class PiratesFactionCommandTests : IDisposable
|
|||
Assert.Empty(products);
|
||||
var topped = File.ReadAllBytes(CatalogPath);
|
||||
|
||||
var late = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var late = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
late.Cache.Commit(batch => batch.Upsert(typeof(Faction), new Faction { Name = "Latecomer", ShortName = "Late" }));
|
||||
var lateRef = late.Cache.RefOf(late.Cache.GetAll<Faction>().Single(f => f.Name == "Latecomer"));
|
||||
var others = late.Cache.GetAll<Faction>().Count(f => f.Name != "Pirates");
|
||||
late.Cache.Dispose();
|
||||
|
||||
Assert.Equal(0, Program.PiratesFaction(apply: true, root: _root));
|
||||
var check = AetherDb.Open(root: _root);
|
||||
var check = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var after = check.Cache.GetAll<Faction>().Single(f => f.Name == "Pirates");
|
||||
|
|
@ -163,7 +163,7 @@ public sealed class PiratesFactionCommandTests : IDisposable
|
|||
[Fact]
|
||||
public void A_missing_design_refuses_and_lands_nothing()
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
var autocannon = db.Cache.GetAll<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
autocannon.Name = "Autocannon (renamed)";
|
||||
db.Cache.Commit(batch => batch.Upsert(typeof(WeaponItemData), autocannon, db.Cache.RefOf(autocannon).Key));
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ public sealed class PlaceNamesTests : IDisposable
|
|||
Assert.Equal(0, PlaceNamesCommand.Run(new[] { "apply" }, root));
|
||||
var landed = File.ReadAllBytes(CatalogOf(root));
|
||||
Assert.NotEqual(before, landed);
|
||||
var db = AetherDb.Open(root: root);
|
||||
var db = AetherDb.OpenShipped(root: root);
|
||||
try
|
||||
{
|
||||
foreach (var row in PlaceNamesCommand.Table)
|
||||
|
|
@ -308,7 +308,7 @@ public sealed class PlaceNamesTests : IDisposable
|
|||
Assert.Equal(landed, File.ReadAllBytes(CatalogOf(root)));
|
||||
|
||||
// Aya's ShortName changed under its key: identity is the key, so the row no longer describes that faction.
|
||||
var squatter = AetherDb.Open(catalogWritable: true, root: root);
|
||||
var squatter = AetherDb.OpenShipped(catalogWritable: true, root: root);
|
||||
var aya = squatter.Cache.GetAll<Faction>().Single(f => f.ShortName == "Aya");
|
||||
aya.ShortName = "Ayx";
|
||||
squatter.Cache.Commit(batch => batch.Upsert(typeof(Faction), aya, squatter.Cache.RefOf(aya).Key));
|
||||
|
|
@ -325,7 +325,7 @@ public sealed class PlaceNamesTests : IDisposable
|
|||
var root = ScratchWithoutLists();
|
||||
Assert.Equal(0, PlaceNamesCommand.Run(new[] { "apply" }, root));
|
||||
var row = PlaceNamesCommand.Table.First();
|
||||
var edited = AetherDb.Open(catalogWritable: true, root: root);
|
||||
var edited = AetherDb.OpenShipped(catalogWritable: true, root: root);
|
||||
var faction = edited.Cache.GetAll<Faction>().Single(f => edited.Cache.RefOf(f).Key.Value == row.RecordKey);
|
||||
faction.Places = row.Names.Reverse().Select(n => new FactionPlace { Name = n }).ToArray();
|
||||
edited.Cache.Commit(batch => batch.Upsert(typeof(Faction), faction, edited.Cache.RefOf(faction).Key));
|
||||
|
|
@ -333,7 +333,7 @@ public sealed class PlaceNamesTests : IDisposable
|
|||
|
||||
Assert.Equal(0, PlaceNamesCommand.Run(new[] { "apply" }, root));
|
||||
|
||||
var db = AetherDb.Open(root: root);
|
||||
var db = AetherDb.OpenShipped(root: root);
|
||||
try { Assert.Equal(row.Names, db.Cache.GetAll<Faction>().Single(f => db.Cache.RefOf(f).Key.Value == row.RecordKey).Places.Select(p => p.Name)); }
|
||||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
|
||||
private Dictionary<string, string> Read()
|
||||
{
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var products = db.Cache.GetAll<FactionProductData>().ToArray();
|
||||
|
|
@ -189,7 +189,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
|
||||
Reset(flattened: true, unnamed: true);
|
||||
Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root));
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
Dictionary<string, Dictionary<string, float>> after;
|
||||
try { after = Read(db.Cache.GetAll<EquippableItemData>().ToArray()); }
|
||||
finally { db.Cache.Dispose(); }
|
||||
|
|
@ -201,7 +201,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
public void A_seller_with_one_of_two_roles_authored_gains_only_the_missing_role()
|
||||
{
|
||||
Reset(flattened: false, unnamed: false);
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
var autocannon = db.Cache.GetAll<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
var seller = db.Cache.GetAll<FactionProductData>().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key) && p.Roles.Count == 2);
|
||||
var kept = seller.Roles.OrderBy(r => r.Role, StringComparer.Ordinal).First();
|
||||
|
|
@ -213,7 +213,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
db.Cache.Dispose();
|
||||
|
||||
Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root));
|
||||
db = AetherDb.Open(root: _root);
|
||||
db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var after = db.Cache.GetAll<FactionProductData>().Single(p => p.Name == sellerName);
|
||||
|
|
@ -228,7 +228,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
public void A_binned_seller_gains_no_roles()
|
||||
{
|
||||
Reset(flattened: false, unnamed: false);
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
var autocannon = db.Cache.GetAll<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
var seller = db.Cache.GetAll<FactionProductData>().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key) && p.Roles.Count == 2);
|
||||
var sellerName = seller.Name;
|
||||
|
|
@ -246,7 +246,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
db.Cache.Dispose();
|
||||
|
||||
Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root));
|
||||
db = AetherDb.Open(root: _root);
|
||||
db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
Assert.Equal(2, db.Cache.GetAll<FactionProductData>().Single(p => p.Name == sellerName).Roles.Count);
|
||||
|
|
@ -259,7 +259,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
[Fact]
|
||||
public void The_census_reports_a_roleless_seller_and_never_a_bin()
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
var autocannon = db.Cache.GetAll<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
var seller = db.Cache.GetAll<FactionProductData>().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key));
|
||||
var sellerName = seller.Name;
|
||||
|
|
@ -275,7 +275,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
});
|
||||
db.Cache.Dispose();
|
||||
|
||||
db = AetherDb.Open(root: _root);
|
||||
db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var gaps = Program.RoleGaps(db.Cache, db.Cache.GetAll<EquippableItemData>().ToArray(), db.Cache.GetAll<FactionProductData>().ToArray()).ToArray();
|
||||
|
|
@ -289,7 +289,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
[Fact]
|
||||
public void A_binned_seller_gains_no_roles_from_roles_migrate()
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
var autocannon = db.Cache.GetAll<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
var seller = db.Cache.GetAll<FactionProductData>().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key));
|
||||
var bin = new FactionProductData
|
||||
|
|
@ -301,7 +301,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
db.Cache.Dispose();
|
||||
|
||||
Assert.Equal(0, Program.RolesMigrate(apply: true, root: _root));
|
||||
db = AetherDb.Open(root: _root);
|
||||
db = AetherDb.OpenShipped(root: _root);
|
||||
try { Assert.Empty(db.Cache.GetAll<FactionProductData>().Single(p => p.Name == "Binned " + seller.Name).Roles); }
|
||||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
|
@ -310,7 +310,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
[Fact]
|
||||
public void A_binned_seller_gains_no_roles_from_sensor_stat_set()
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
var sensor = db.Cache.GetAll<EquippableItemData>().Where(d => d.Behaviors != null && d.Behaviors.OfType<SensorData>().Any()).OrderBy(d => d.Name, StringComparer.Ordinal).First();
|
||||
var seller = db.Cache.GetAll<FactionProductData>().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Bin == null && p.Design.Key.Equals(db.Cache.RefOf(sensor).Key));
|
||||
var bin = new FactionProductData
|
||||
|
|
@ -322,7 +322,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
db.Cache.Dispose();
|
||||
|
||||
Assert.Equal(0, Program.SensorStatSet(apply: true, root: _root));
|
||||
db = AetherDb.Open(root: _root);
|
||||
db = AetherDb.OpenShipped(root: _root);
|
||||
try { Assert.Empty(db.Cache.GetAll<FactionProductData>().Single(p => p.Name == "Binned " + seller.Name).Roles); }
|
||||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
|
@ -331,7 +331,7 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
public void A_design_the_catalog_does_not_hold_refuses_and_lands_nothing()
|
||||
{
|
||||
Reset(flattened: false, unnamed: false);
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: true, root: _root);
|
||||
var autocannon = db.Cache.GetAll<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
autocannon.Name = "Autocannon (renamed)";
|
||||
db.Cache.Commit(batch => batch.Upsert(typeof(WeaponItemData), autocannon, db.Cache.RefOf(autocannon).Key));
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public sealed class ShipSchemaPinTests
|
|||
var scad = File.ReadAllText(Locate("tools", "blender", "aetheria_ships", "factions", file));
|
||||
var literal = Regex.Match(scad, @"^[A-Z]+_LANG = \[[^;]*""([^""]+)""\];", RegexOptions.Multiline);
|
||||
Assert.True(literal.Success, $"{file} has no *_LANG with a maker as its last element");
|
||||
var db = AetherDb.Open(root: AetherDb.FindRoot());
|
||||
var db = AetherDb.OpenShipped(root: AetherDb.FindRoot());
|
||||
try
|
||||
{
|
||||
var record = Assert.Single(db.Cache.GetAll<Faction>().Where(f => f.Name == faction));
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public sealed class SmokeHullCommandTests : IDisposable
|
|||
|
||||
private (HullData[] Hulls, HullData Longinus, EquippableItemData[] Fitted, int Products) Read()
|
||||
{
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var hulls = db.Cache.GetAll<HullData>().Where(h => h.Name == HullName).ToArray();
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public sealed class SmokeRoundsCommandTests : IDisposable
|
|||
|
||||
private (WeaponItemData[] Smoke, WeaponItemData LightLaser, WeaponItemData ChargedScatterBlaster, int Products) Read()
|
||||
{
|
||||
var db = AetherDb.Open(root: _root);
|
||||
var db = AetherDb.OpenShipped(root: _root);
|
||||
try
|
||||
{
|
||||
var smoke = db.Cache.GetAll<WeaponItemData>().Where(w => Names.Contains(w.Name)).ToArray();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public sealed class StationKindDescriptionTests
|
|||
[Fact]
|
||||
public void EveryRawGoodAKindExtractsIsNamedInItsDescription()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var cache = db.Cache;
|
||||
var unnamed = cache.GetAll<RecipeData>().Where(recipe => Recipes.IsRaw(cache, recipe) && recipe.StationKind.IsSet())
|
||||
.Select(recipe => (Kind: cache.Get(recipe.StationKind), Output: cache.Get(recipe.Output)))
|
||||
|
|
@ -25,7 +25,7 @@ public sealed class StationKindDescriptionTests
|
|||
[Fact]
|
||||
public void MiningExtractsDiamondAndVolatilesAmmonia()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var cache = db.Cache;
|
||||
string RawAt(string kindId) => string.Join(",", cache.GetAll<RecipeData>()
|
||||
.Where(recipe => Recipes.IsRaw(cache, recipe) && recipe.StationKind.IsSet() && recipe.StationKind.Key.Equals(StationKindData.KeyOf(kindId)))
|
||||
|
|
@ -41,7 +41,7 @@ public sealed class StationKindDescriptionTests
|
|||
[Fact]
|
||||
public void EveryCommodityAStationKindNamesIsMadeOrTakenByARecipe()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var c = db.Cache;
|
||||
var used = c.GetAll<RecipeData>().SelectMany(r => r.Inputs.Select(i => i.Commodity.Key.Value).Append(r.Output.Key.Value)).ToHashSet();
|
||||
var commodities = c.GetAll<SimpleCommodityData>().ToArray();
|
||||
|
|
@ -59,7 +59,7 @@ public sealed class StationKindDescriptionTests
|
|||
[Fact]
|
||||
public void TheShippedDescriptionsAreTheAuthoredTable()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
foreach (var id in new[] { "mining", "volatiles", "agriculture", "habitat-support", "power" })
|
||||
Assert.Equal(StationKindsCatalog.DescriptionOf(id), db.Cache.Get<StationKindData>(StationKindData.KeyOf(id)).Description);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ public sealed class StationKindsCatalogTests : IDisposable
|
|||
|
||||
var warned = new List<string>();
|
||||
var applied = new StringWriter();
|
||||
using (var db = AetherDb.Open(catalogWritable: true, root: root, warn: warned.Add))
|
||||
using (var db = AetherDb.OpenShipped(catalogWritable: true, root: root, warn: warned.Add))
|
||||
{
|
||||
Assert.Contains(warned, line => line.Contains("Zenith"));
|
||||
Assert.Contains(warned, line => line.Contains("Second Station"));
|
||||
|
|
@ -94,7 +94,7 @@ public sealed class StationKindsCatalogTests : IDisposable
|
|||
}
|
||||
Assert.Throws<InvalidOperationException>(() => AetheriaStores.Open(catalog));
|
||||
|
||||
using (var db = AetherDb.Open(catalogWritable: true, root: root, warn: _ => { }))
|
||||
using (var db = AetherDb.OpenShipped(catalogWritable: true, root: root, warn: _ => { }))
|
||||
{
|
||||
var dry = new StringWriter();
|
||||
Assert.Equal(0, StationKindsCatalog.SetHullKind(db.Cache, "Second Station", "mining", false, dry));
|
||||
|
|
@ -112,7 +112,7 @@ public sealed class StationKindsCatalogTests : IDisposable
|
|||
public void SetHullKindRefusesWhatIsNotAStationHullOrAHeldKind()
|
||||
{
|
||||
var root = SeedRoot("Zenith");
|
||||
using var db = AetherDb.Open(catalogWritable: true, root: root, warn: _ => { });
|
||||
using var db = AetherDb.OpenShipped(catalogWritable: true, root: root, warn: _ => { });
|
||||
StationKindsCatalog.Run(db.Cache, true, new StringWriter());
|
||||
string Refusal(string hull, string kind)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||
using GameCult.Caching;
|
||||
|
||||
// Opens the catalog through AetheriaStores, the game's own store composition: OpenBooted for a read tool (the catalog the game boots),
|
||||
// Open for the shipped GameData/Aetheria.cc alone, which attaches read-only unless a command writes it, so a command that only reads cannot write. A station hull with no kind does not lock the
|
||||
// OpenShipped for the shipped GameData/Aetheria.cc alone, which attaches read-only unless a command writes it, so a command that only reads cannot write. A station hull with no kind does not lock the
|
||||
// catalog: it is named to warn (stderr by default) and the commands that repair it stay reachable.
|
||||
public sealed class AetherDb : IDisposable
|
||||
{
|
||||
|
|
@ -61,7 +61,7 @@ public sealed class AetherDb : IDisposable
|
|||
|
||||
// The shipped GameData/Aetheria.cc alone, which is what an apply path (and its dry run) reads and writes. With no root given, walks up
|
||||
// from the working directory to the game folder: the first folder whose GameData holds Aetheria.cc.
|
||||
public static AetherDb Open(bool catalogWritable = false, bool withRun = false, string root = null, Action<string> warn = null) =>
|
||||
public static AetherDb OpenShipped(bool catalogWritable = false, bool withRun = false, string root = null, Action<string> warn = null) =>
|
||||
new AetherDb(root ?? FindRoot(), false, withRun, warn, catalogWritable);
|
||||
|
||||
// The catalog the game boots (see ComposeBooted), read-only: every read tool opens this.
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public static class EconomyPrices
|
|||
}
|
||||
// The shipped file alone, on purpose: a package's hull price is read from its ship.cc below, so a composed catalog would list the
|
||||
// same hull twice, and the second catalog an old side is compared against is a shipped file.
|
||||
using var db = AetherDb.Open();
|
||||
using var db = AetherDb.OpenShipped();
|
||||
var now = Read(db.Cache, mods ?? Path.Combine(db.Root, "GameData", "Mods"));
|
||||
if (other == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public static class HardpointRotationCommand
|
|||
{
|
||||
var apply = args.Contains("apply");
|
||||
var positional = args.Where(a => a != "apply").ToArray();
|
||||
using var db = AetherDb.Open(catalogWritable: apply);
|
||||
using var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
var code = Run(db.Cache, positional, apply, Console.Out);
|
||||
if (apply && code == 0) db.Cache.FlushAsync().GetAwaiter().GetResult();
|
||||
return code;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public static class MinorPowerFactionsCommand
|
|||
public static int Run(string[] args, string root = null)
|
||||
{
|
||||
var apply = args.Contains("apply");
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var existing = db.Cache.GetAll<Faction>().ToArray();
|
||||
|
||||
// Refuse before any write: a name or short name held by a faction under another key.
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public static class PlaceNamesCommand
|
|||
internal static int Run(string[] args, string root, Row[] table)
|
||||
{
|
||||
var apply = args.Contains("apply");
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var factions = db.Cache.GetAll<Faction>().ToArray();
|
||||
var keyOf = factions.ToDictionary(f => db.Cache.RefOf(f).Key.Value, StringComparer.Ordinal);
|
||||
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public static class ProductLinesCommand
|
|||
return 1;
|
||||
}
|
||||
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var designs = db.Cache.GetAll<CraftedItemData>().ToArray();
|
||||
var factions = db.Cache.GetAll<Faction>().ToArray();
|
||||
var products = db.Cache.GetAll<FactionProductData>().ToArray();
|
||||
|
|
@ -204,7 +204,7 @@ public static class ProductLinesCommand
|
|||
// so the same command is the first apply and the replay onto a merged catalog.
|
||||
internal static int RunTiers(IReadOnlyList<TierRow> tiers, bool apply, string root)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var designs = db.Cache.GetAll<CraftedItemData>().ToArray();
|
||||
var products = db.Cache.GetAll<FactionProductData>().ToArray();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public static class Program
|
|||
case "shield-catalog":
|
||||
{
|
||||
var apply = args.Contains("apply");
|
||||
using var db = AetherDb.Open(catalogWritable: apply);
|
||||
using var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
var code = ShieldCatalog.Run(db.Cache, apply, Console.Out);
|
||||
if (apply) db.Cache.FlushAsync().GetAwaiter().GetResult();
|
||||
return code;
|
||||
|
|
@ -67,8 +67,8 @@ public static class Program
|
|||
case "inspection-scanner": return InspectionScannerCatalog(args.Contains("apply"));
|
||||
case "product-lines": return ProductLinesCommand.Run(args.Skip(1).ToArray());
|
||||
case "minor-power-factions": return MinorPowerFactionsCommand.Run(args.Skip(1).ToArray());
|
||||
case "station-reactor-spread": return StationReactorSpreadCommand.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out);
|
||||
case "assembly-from-maker": return AssemblyFromMakerCommand.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out);
|
||||
case "station-reactor-spread": return StationReactorSpreadCommand.Run(AetherDb.OpenShipped(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out);
|
||||
case "assembly-from-maker": return AssemblyFromMakerCommand.Run(AetherDb.OpenShipped(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out);
|
||||
case "place-names":
|
||||
Console.OutputEncoding = new System.Text.UTF8Encoding(false);
|
||||
return PlaceNamesCommand.Run(args.Skip(1).ToArray());
|
||||
|
|
@ -77,7 +77,7 @@ public static class Program
|
|||
var apply = args.Contains("apply");
|
||||
// Shipped file alone, on purpose: every form here (the kinds report included) is the dry run of an apply that writes the shipped
|
||||
// file, so it reads what apply would change; its report is identical over the composed catalog.
|
||||
using var db = AetherDb.Open(catalogWritable: apply);
|
||||
using var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
int code;
|
||||
if (args.Length > 1 && args[1] == "hull")
|
||||
{
|
||||
|
|
@ -99,12 +99,12 @@ public static class Program
|
|||
if (args.Length < 2 || args[1] != "resave") { Console.WriteLine("catalog resave [apply]"); return 1; }
|
||||
var apply = args.Contains("apply");
|
||||
// Shipped file alone, on purpose: a resave restamps GameData/Aetheria.cc itself, so a composed catalog would write the packages into it.
|
||||
using var db = AetherDb.Open(catalogWritable: apply);
|
||||
using var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
return CatalogResaveCommand.Run(db.Cache, apply, Console.Out);
|
||||
}
|
||||
case "economy": return EconomyCommand.Run(args.Skip(1).ToArray(), Console.Out);
|
||||
case "auto-guns": return AutoGunsCatalog.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out);
|
||||
case "doctrine-catalog": return DoctrineCatalog.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out);
|
||||
case "auto-guns": return AutoGunsCatalog.Run(AetherDb.OpenShipped(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out);
|
||||
case "doctrine-catalog": return DoctrineCatalog.Run(AetherDb.OpenShipped(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out);
|
||||
default:
|
||||
Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, hardpoint-rotation \"<hull>\" <x>,<y> <rotation> [apply], loadout [seed], loadout-commit <name> <hull product> [<x>,<y>,<rotation>,<design>[@<product>]]... [--group <i>,<j>...]... [--replace] [--boss-of <faction>], save, settings, settings-dump, dangling [clear <Type.Member>]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], range-falloff [apply] [--effective <fraction>] [--end <multiplier>], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate|compose, mine-launcher [apply], smoke-hull [apply], smoke-rounds [apply], roles-backfill [apply], pd-gear [apply], consumables-first-set [apply], launch-suppressor [apply], pirates-faction [apply], verse-grammar [apply], generic-designs [apply], sensor-stat-set [apply], inspection-scanner [apply], minor-power-factions [apply], place-names [apply], product-lines weapons|minor-powers|gear|tiers [apply], doctrine-catalog [apply], auto-guns [apply], assembly-from-maker [apply], shield-catalog [apply], station-kinds [hull \"<name>\" <kind> | facilities \"<hull>\" <x>,<y>:<footprint>...] [apply], economy report|prices|author <batch>... [apply]|balance");
|
||||
return 1;
|
||||
|
|
@ -114,7 +114,7 @@ public static class Program
|
|||
// Designs by kind and manufacturer, designs no product sells, and products with authored role quality.
|
||||
private static int Census()
|
||||
{
|
||||
var db = AetherDb.OpenBooted();
|
||||
using var db = AetherDb.OpenBooted();
|
||||
var items = db.Cache.GetAll<EquippableItemData>().ToArray();
|
||||
var products = db.Cache.GetAll<FactionProductData>()
|
||||
.OrderBy(p => db.Cache.RefOf(p).Key.Value, StringComparer.Ordinal).ToArray();
|
||||
|
|
@ -373,7 +373,7 @@ public static class Program
|
|||
// the operator review table (grouped by item kind) either way.
|
||||
public static int RolesMigrate(bool apply, string root = null)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var items = db.Cache.GetAll<EquippableItemData>().ToArray();
|
||||
var products = db.Cache.GetAll<FactionProductData>().ToArray();
|
||||
var changedDesigns = new List<(object Document, CultRecordKey Key)>();
|
||||
|
|
@ -537,7 +537,7 @@ public static class Program
|
|||
// generation equips hardpoint gear first and only the first of those is guaranteed.
|
||||
private static int StationFit()
|
||||
{
|
||||
var db = AetherDb.OpenBooted();
|
||||
using var db = AetherDb.OpenBooted();
|
||||
var bays = db.Cache.GetAll<DockingBayData>().ToArray();
|
||||
var failures = 0;
|
||||
foreach (var hull in db.Cache.GetAll<HullData>().Where(h => h.HullType == HullType.Station))
|
||||
|
|
@ -663,7 +663,7 @@ public static class Program
|
|||
var clear = new HashSet<string>(args.Select((arg, i) => (arg, i))
|
||||
.Where(p => p.arg == "clear" && p.i + 1 < args.Length)
|
||||
.Select(p => args[p.i + 1]));
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
|
||||
var changed = new List<(object Document, CultRecordKey Key)>();
|
||||
var found = 0;
|
||||
|
|
@ -771,7 +771,7 @@ public static class Program
|
|||
// Galaxy.NamePlaces falls back to catalogue designations for a faction without one.
|
||||
private static int Factions()
|
||||
{
|
||||
var db = AetherDb.OpenBooted();
|
||||
using var db = AetherDb.OpenBooted();
|
||||
var products = db.Cache.GetAll<FactionProductData>().ToArray();
|
||||
Console.WriteLine($"{"faction",-26} {"short",-13} {"places",-22} {"boss loadout",-14} {"influence",-9} {"doctrine",-10} products");
|
||||
var broken = 0;
|
||||
|
|
@ -800,16 +800,7 @@ public static class Program
|
|||
return 0;
|
||||
}
|
||||
|
||||
AetherDb db;
|
||||
try
|
||||
{
|
||||
db = AetherDb.OpenBooted(withRun: true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"save does not open: {e.GetType().Name}: {e.Message}");
|
||||
return 1;
|
||||
}
|
||||
using var db = AetherDb.OpenBooted(withRun: true);
|
||||
|
||||
var run = db.Cache.GetGlobal<SavedGame>();
|
||||
if (run?.Zones == null)
|
||||
|
|
@ -860,7 +851,7 @@ public static class Program
|
|||
private static int Loadout(string[] args)
|
||||
{
|
||||
var seed = uint.TryParse(args.FirstOrDefault(), out var parsed) ? parsed : 1u;
|
||||
var db = AetherDb.OpenBooted();
|
||||
using var db = AetherDb.OpenBooted();
|
||||
var settings = new GameplaySettings
|
||||
{
|
||||
DefaultEntitySettings = new EntitySettings(),
|
||||
|
|
@ -935,7 +926,7 @@ public static class Program
|
|||
// operator review either way).
|
||||
private static int ShieldMigrate(bool apply)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
|
||||
// ShieldData nests inside either host's Behaviors list (GearData: an equipped item with a hardpoint
|
||||
// Shape to size from; ConsumableItemData: a consumable effect with no Shape -- cells reads 0 there, and
|
||||
|
|
@ -1033,7 +1024,7 @@ public static class Program
|
|||
// same contract as ShieldMigrate.
|
||||
private static int BrownoutMigrate(bool apply)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
const float gentleExponent = 1f;
|
||||
|
||||
// (behaviour type, target performance-stat field, short label) -- one of these is also a request field
|
||||
|
|
@ -1120,7 +1111,7 @@ public static class Program
|
|||
// otherwise. Dry run unless passed "apply", same contract as ShieldMigrate/BrownoutMigrate.
|
||||
private static int FiringArcMigrate(bool apply)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
|
||||
var hulls = db.Cache.GetAll<HullData>().Where(h => h.Name == "Turret").ToArray();
|
||||
if (hulls.Length == 0)
|
||||
|
|
@ -1173,7 +1164,7 @@ public static class Program
|
|||
// against the catalog and not against names.
|
||||
private static int WeaponAmmo()
|
||||
{
|
||||
var db = AetherDb.OpenBooted();
|
||||
using var db = AetherDb.OpenBooted();
|
||||
Console.WriteLine($"{"weapon",-28} {"behaviour",-20} {"energy",-11} {"mag",5} {"reload",6} ammo");
|
||||
foreach (var item in db.Cache.GetAll<WeaponItemData>().OrderBy(i => i.Name, StringComparer.Ordinal))
|
||||
foreach (var w in item.Behaviors.OfType<WeaponData>())
|
||||
|
|
@ -1197,7 +1188,7 @@ public static class Program
|
|||
}
|
||||
var fraction = Option("--effective", .5f);
|
||||
var end = Option("--end", 0f);
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
// A record is rewritten only when what it would store differs from what is stored: that is what drops the retired
|
||||
// key 7 from a record the command leaves otherwise unchanged, and what makes a second apply change no byte.
|
||||
var persisted = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(Path.Combine(db.Root, "GameData", "Aetheria.cc")))
|
||||
|
|
@ -1252,7 +1243,7 @@ public static class Program
|
|||
// Dry run unless passed "apply", same contract as the other *-migrate commands.
|
||||
private static int TargetingCatalog(bool apply)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
|
||||
Faction FactionByShortName(string shortName)
|
||||
{
|
||||
|
|
@ -1467,7 +1458,7 @@ public static class Program
|
|||
// Dry run unless passed "apply", same contract as the other *-migrate commands.
|
||||
private static int TargetingCatalog6c(bool apply)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
|
||||
Faction FactionByShortName(string shortName)
|
||||
{
|
||||
|
|
@ -1577,7 +1568,7 @@ public static class Program
|
|||
// Dry run unless passed "apply", same contract as the other *-migrate commands.
|
||||
private static int TargetingCatalog6d(bool apply)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
|
||||
GearData DesignByName(string name)
|
||||
{
|
||||
|
|
@ -1638,7 +1629,7 @@ public static class Program
|
|||
// each carries several products, and branding lives in the products alone. Dry run unless passed "apply".
|
||||
private static int PdGearCatalog(bool apply)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
var weapons = db.Cache.GetAll<WeaponItemData>().ToArray();
|
||||
|
||||
var designNames = new[] { "Point Defense Gun", "Point Defense Laser", "Flak Gun" };
|
||||
|
|
@ -1784,7 +1775,7 @@ public static class Program
|
|||
// "apply"; idempotent, so a second apply writes nothing and a catalog another cut changed is rerun, never merged.
|
||||
internal static int SensorStatSet(bool apply, string root = null)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var designs = db.Cache.GetAll<EquippableItemData>().ToArray();
|
||||
var products = db.Cache.GetAll<FactionProductData>().ToArray();
|
||||
Faction MakerOf(FactionProductData p) => db.Cache.Get(p.Manufacturer);
|
||||
|
|
@ -1941,7 +1932,7 @@ public static class Program
|
|||
public static int SmokeHullCatalog(bool apply, string root = null)
|
||||
{
|
||||
const string name = "Smoke Test Hull";
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
if (db.Cache.GetAll<HullData>().Any(h => h.Name == name))
|
||||
{
|
||||
Console.WriteLine($"\"{name}\" is already authored; nothing to do.");
|
||||
|
|
@ -2004,7 +1995,7 @@ public static class Program
|
|||
// (Velocity 150) so a scenario can kill the target while one is in the air. Dry run unless passed "apply".
|
||||
public static int SmokeRoundsCatalog(bool apply, string root = null)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var weapons = db.Cache.GetAll<WeaponItemData>().ToArray();
|
||||
var names = new[] { "Smoke Proximity", "Smoke Delayed", "Smoke Refused", "Smoke Refused Beam", "Smoke Refused Charge" };
|
||||
var already = names.Count(name => weapons.Any(w => w.Name == name));
|
||||
|
|
@ -2100,7 +2091,7 @@ public static class Program
|
|||
private static int MineLauncherCatalog(bool apply)
|
||||
{
|
||||
const string name = "Mine Launcher";
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply);
|
||||
const float minimumTemperature = 173.15f, maximumTemperature = 473.15f, optimalTemperature = 249.65f, plateauWidth = 36f;
|
||||
if (db.Cache.GetAll<GearData>().SingleOrDefault(gear => gear.Name == name) is { } authored)
|
||||
{
|
||||
|
|
@ -2229,7 +2220,7 @@ public static class Program
|
|||
|
||||
public static int RolesBackfill(bool apply, string root = null)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var items = db.Cache.GetAll<EquippableItemData>().ToArray();
|
||||
var products = db.Cache.GetAll<FactionProductData>().ToArray();
|
||||
var targets = BackfillDesigns.Select(name => items.Where(i => i.Name == name).ToArray())
|
||||
|
|
@ -2342,7 +2333,7 @@ public static class Program
|
|||
|
||||
public static int PiratesFaction(bool apply, string root = null)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
|
||||
var existing = db.Cache.GetAll<Faction>().FirstOrDefault(f => f.Name == "Pirates");
|
||||
if (existing != null)
|
||||
|
|
@ -2460,7 +2451,7 @@ public static class Program
|
|||
// unless passed "apply".
|
||||
public static int ConsumablesFirstSetCatalog(bool apply, string root = null)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var designNames = new[] { "Thruster Overdrive", "Coolant Vent" };
|
||||
var already = designNames.Count(name => db.Cache.GetAll<ConsumableItemData>().Any(c => c.Name == name));
|
||||
if (already == designNames.Length)
|
||||
|
|
@ -2722,7 +2713,7 @@ public static class Program
|
|||
// shipped product text ending in the authoring note loses it. Dry run unless passed "apply".
|
||||
public static int GenericDesigns(bool apply, string root = null)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var designs = db.Cache.GetAll<EquippableItemData>().ToArray();
|
||||
var products = db.Cache.GetAll<FactionProductData>().ToArray();
|
||||
string MakerOf(FactionProductData product) => db.Cache.Get(product.Manufacturer)?.ShortName;
|
||||
|
|
@ -2827,7 +2818,7 @@ public static class Program
|
|||
// unless passed "apply".
|
||||
public static int LaunchSuppressorCatalog(bool apply, string root = null)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
var designNames = new[] { "Launch Suppressor", "Launch Baffle" };
|
||||
var template = db.Cache.GetAll<GearData>().Single(g => g.Name == "Targeting Computer");
|
||||
|
||||
|
|
@ -2961,7 +2952,7 @@ public static class Program
|
|||
// 1x1 tool. Dry run unless passed "apply"; a catalog that is neither untouched nor fully authored is refused.
|
||||
public static int InspectionScannerCatalog(bool apply, string root = null)
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: apply, root: root);
|
||||
var db = AetherDb.OpenShipped(catalogWritable: apply, root: root);
|
||||
const string designName = "Inspection Scanner";
|
||||
const string scanArray = "scan array";
|
||||
var template = db.Cache.GetAll<GearData>().Single(g => g.Name == "Targeting Computer");
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ public static class ShipAuthoringCommands
|
|||
if (judged == "records and model") ShipModCatalog.Bind(hull, ship, products, Path.GetDirectoryName(full), full);
|
||||
// Shipped file alone, on purpose: a package is judged against the shipped catalog it will be composed over, never against itself.
|
||||
// Compose's verdict on a package's bins and its offered hull's schematic; the author sees it here, before compose.
|
||||
using var catalog = products.Length > 0 || hull.HullType == HullType.Station ? AetherDb.Open().Cache : null;
|
||||
using var catalog = products.Length > 0 || hull.HullType == HullType.Station ? AetherDb.OpenShipped().Cache : null;
|
||||
if (ShipModCatalog.MarketFault(catalog, ship, products) is { } fault) throw new InvalidOperationException(fault);
|
||||
// A station package names a kind the shipped catalog holds (the rule Compose applies), so Package refuses it before compose does.
|
||||
if (hull.HullType == HullType.Station && StationKinds.HullKindFault(catalog, hull) is { } kindFault)
|
||||
|
|
@ -235,7 +235,7 @@ public static class ShipAuthoringCommands
|
|||
internal static (CultRecordKey Key, string Name) ShippedFaction(string text)
|
||||
{
|
||||
// Shipped file alone, on purpose: this resolves a shipped faction, the one a package names by key.
|
||||
using var catalog = AetherDb.Open().Cache;
|
||||
using var catalog = AetherDb.OpenShipped().Cache;
|
||||
var matches = catalog.GetAll<Faction>()
|
||||
.Where(faction => string.Equals(faction.Name, text, StringComparison.Ordinal) ||
|
||||
string.Equals(faction.ShortName, text, StringComparison.Ordinal) ||
|
||||
|
|
@ -249,7 +249,7 @@ public static class ShipAuthoringCommands
|
|||
private static HullData ShippedHull(string name, params HullType[] allowed)
|
||||
{
|
||||
// Shipped file alone, on purpose: --like copies a shipped hull, not a package's.
|
||||
using var catalog = AetherDb.Open().Cache;
|
||||
using var catalog = AetherDb.OpenShipped().Cache;
|
||||
var hull = catalog.GetAll<HullData>().FirstOrDefault(candidate => candidate.Name == name) ??
|
||||
throw new InvalidOperationException($"--like: the shipped catalog has no hull named '{name}'.");
|
||||
if (!allowed.Contains(hull.HullType))
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ public static class ShipAuthoringPush
|
|||
// kindless draft that stays kindless is not, so it still takes stats and price (and needs no catalog).
|
||||
if (derived.Kind.IsSet() || held.Kind.IsSet())
|
||||
// Shipped file alone, on purpose: a station kind is the shipped catalog's, the rule Compose applies to a package.
|
||||
using (var catalog = AetherDb.Open().Cache)
|
||||
using (var catalog = AetherDb.OpenShipped().Cache)
|
||||
if (StationKinds.HullKindFault(catalog, derived) is { } fault) throw new InvalidOperationException($"{shipId}: {fault}");
|
||||
FlatDiff(lines, key, HullFields(held), HullFields(derived));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue