Materialize reports each zone through the run's progress sink; "Done!" is RunStart.Begin's last word, after every zone exists
Galaxy keeps the progressCallback generation reports to (Galaxy.Progress) and no longer says Done! itself. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6c92f46471
commit
d697a77160
4 changed files with 45 additions and 8 deletions
|
|
@ -21,6 +21,10 @@ public class Galaxy
|
|||
|
||||
// The zones the player has entered: what the player knows of a zone's contents (the sector map shows them for these
|
||||
// and for no other). Every zone has contents from the start of a run, so contents say nothing of a visit.
|
||||
// The run's progress sink, the one generation reports to. RunStart.Begin reports the run's last steps through it and
|
||||
// ends with "Done!", so the loading screen's last word comes after every zone exists. Null for a restored galaxy.
|
||||
public Action<string> Progress { get; }
|
||||
|
||||
public HashSet<GalaxyZone> VisitedZones = new HashSet<GalaxyZone>();
|
||||
|
||||
public SectorBackgroundSettings Background { get; }
|
||||
|
|
@ -139,6 +143,7 @@ public class Galaxy
|
|||
InfluenceScale = 1;
|
||||
Background = background;
|
||||
Log = log;
|
||||
Progress = progressCallback;
|
||||
var factions = cache.GetAll<Faction>();
|
||||
Seed = seed != 0 ? seed : throw new ArgumentOutOfRangeException(nameof(seed), "a generated galaxy takes its run's seed from GalaxyStage, never zero");
|
||||
var random = new Random(Seed);
|
||||
|
|
@ -168,8 +173,6 @@ public class Galaxy
|
|||
|
||||
NamePlaces(ref random, progressCallback);
|
||||
|
||||
progressCallback?.Invoke("Done!");
|
||||
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
}
|
||||
|
||||
// Each zone's index and the links as indices: the graph Provinces reads.
|
||||
|
|
@ -244,6 +247,7 @@ public class Galaxy
|
|||
|
||||
Background = background;
|
||||
Log = log;
|
||||
Progress = progressCallback;
|
||||
Seed = seed != 0 ? seed : throw new ArgumentOutOfRangeException(nameof(seed), "a generated galaxy takes its run's seed from GalaxyStage, never zero");
|
||||
var random = new Random(Seed);
|
||||
|
||||
|
|
@ -333,8 +337,6 @@ public class Galaxy
|
|||
|
||||
NamePlaces(ref random, progressCallback);
|
||||
|
||||
progressCallback?.Invoke("Done!");
|
||||
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
}
|
||||
|
||||
private GalaxyZone[] GenerateZones(int zoneCount, ref Random random, Action<string> progressCallback = null)
|
||||
|
|
|
|||
|
|
@ -43,10 +43,13 @@ public static class RunStart
|
|||
// generated station gear, hardpoint fit, facilities, consumable stock, and the ships and turrets of its ambient
|
||||
// populace). This makes them exist across the whole region from tick zero; they stay until the production that should
|
||||
// supply them exists, and follow-up conjuring-site-deletions deletes them.
|
||||
public static void Materialize(ItemManager itemManager, ZoneGenerationSettings zoneSettings, PlanetSettings planetSettings, Galaxy galaxy)
|
||||
// `progress` hears "Materializing zones: k of n" as each zone is reached, the loading screen's last long step.
|
||||
public static void Materialize(ItemManager itemManager, ZoneGenerationSettings zoneSettings, PlanetSettings planetSettings, Galaxy galaxy,
|
||||
Action<string> progress = null)
|
||||
{
|
||||
for (var i = 0; i < galaxy.Zones.Length; i++)
|
||||
{
|
||||
progress?.Invoke($"Materializing zones: {i + 1} of {galaxy.Zones.Length}");
|
||||
var zone = galaxy.Zones[i];
|
||||
if (zone.PackedContents == null)
|
||||
{
|
||||
|
|
@ -70,7 +73,9 @@ public static class RunStart
|
|||
var arena = BuildArena(itemManager, planetSettings, galaxy);
|
||||
enter();
|
||||
var staged = Stage(itemManager, arena, scenario, startingHull, failures);
|
||||
if (staged != null) Materialize(itemManager, zoneSettings, planetSettings, galaxy);
|
||||
if (staged == null) return null;
|
||||
Materialize(itemManager, zoneSettings, planetSettings, galaxy, galaxy.Progress);
|
||||
galaxy.Progress?.Invoke("Done!"); // generation's last word comes after the last zone exists
|
||||
return staged;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -187,4 +187,34 @@ public sealed partial class RunStartTests
|
|||
Assert.Equal(new[] { Array.IndexOf(restored.Zones, restored.Entrance) },
|
||||
restored.VisitedZones.Select(zone => Array.IndexOf(restored.Zones, zone)));
|
||||
}
|
||||
|
||||
// The loading screen hears every step: each zone as Materialize reaches it, and "Done!" once, after the last zone.
|
||||
[Fact]
|
||||
public void MaterializeReportsEachZoneAndDoneComesLast()
|
||||
{
|
||||
var heard = new List<string>();
|
||||
var scenario = new DemoTerminus();
|
||||
var galaxy = RunStart.Generate(scenario, Inputs(() => 1, heard.Add));
|
||||
Assert.DoesNotContain("Done!", heard);
|
||||
var failures = new List<string>();
|
||||
var staged = RunStart.Begin(_items, _zoneSettings, _planetSettings, galaxy, scenario, _startingHull, failures,
|
||||
() => galaxy.VisitedZones.Add(galaxy.Entrance));
|
||||
Assert.NotNull(staged);
|
||||
var count = galaxy.Zones.Length;
|
||||
var zones = heard.Where(line => line.StartsWith("Materializing zones: ")).ToList();
|
||||
Assert.Equal(Enumerable.Range(1, count).Select(k => $"Materializing zones: {k} of {count}"), zones);
|
||||
Assert.Equal(1, heard.Count(line => line == "Done!"));
|
||||
Assert.Equal("Done!", heard[heard.Count - 1]);
|
||||
Assert.True(heard.IndexOf(zones[0]) > heard.Count(line => line != "Done!" && !line.StartsWith("Materializing")) - 1, "generation reports precede materialization");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AFailedStartReportsNeitherZonesNorDone()
|
||||
{
|
||||
var heard = new List<string>();
|
||||
var scenario = new Scripted(true, _ => { }, generate: stage => new DemoTerminus().Generate(stage));
|
||||
var galaxy = RunStart.Generate(scenario, Inputs(() => 1, heard.Add));
|
||||
Assert.Null(RunStart.Begin(_items, _zoneSettings, _planetSettings, galaxy, scenario, _startingHull, new List<string>(), () => { }));
|
||||
Assert.DoesNotContain(heard, line => line.StartsWith("Materializing") || line == "Done!");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,14 +48,14 @@ public sealed partial class RunStartTests
|
|||
private static IEnumerable<Scenario> EveryScenario => Scenarios.Modes.Concat(Scenarios.Development).Concat(Scenarios.Tests);
|
||||
|
||||
// The galaxy inputs the menu hands to RunStart, read from the authored settings.
|
||||
private GalaxyStage Inputs(Func<uint> clock = null)
|
||||
private GalaxyStage Inputs(Func<uint> clock = null, Action<string> progress = null)
|
||||
{
|
||||
var authored = AuthoredSettings.Load(FindRepoRoot());
|
||||
return new GalaxyStage(
|
||||
authored.Read<SectorGenerationSettings>("SectorGenerationSettings"),
|
||||
authored.Read<SectorBackgroundSettings>("SectorBackgroundSettings"),
|
||||
authored.Read<SectorBackgroundSettings>("CastBackgroundSettings"),
|
||||
_cache, _ => { }, null, clock);
|
||||
_cache, _ => { }, progress, clock);
|
||||
}
|
||||
|
||||
// What MainMenu.Launch and StartGame do with a scenario: its galaxy, its arena, then staging. beforeStaging stands in
|
||||
|
|
|
|||
Loading…
Reference in a new issue