204 lines
12 KiB
C#
204 lines
12 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.IO;
|
||
using UnityEngine;
|
||
using UnityEngine.UIElements;
|
||
|
||
namespace Soundings
|
||
{
|
||
public sealed partial class SoundingsApp
|
||
{
|
||
private IEnumerator VisualSmoke()
|
||
{
|
||
string[] args = Environment.GetCommandLineArgs();
|
||
int index = Array.IndexOf(args, "-soundings-smoke");
|
||
if (index + 1 >= args.Length)
|
||
{
|
||
Application.Quit(1);
|
||
yield break;
|
||
}
|
||
|
||
string directory = args[index + 1];
|
||
Directory.CreateDirectory(directory);
|
||
yield return CaptureSmoke(directory, "01-title");
|
||
|
||
if (!CheckSmoke(guidedCareer, "The guide is on by default")
|
||
|| !SubmitSmoke("guide-toggle") || !CheckSmoke(!guidedCareer, "Guide can be turned off at title")
|
||
|| !SubmitSmoke("guide-toggle") || !SubmitSmoke("start-used")
|
||
|| !CheckSmoke(Ship?.Name == "MV Meridian" && guideContext == GuideStep.SetCourse, "Guided used start"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "02-harbor");
|
||
if (!SubmitSmoke("plan-voyage") || !CheckSmoke(page == 3 && destination == 1 && guideContext == GuideStep.Fare, "Set course and fare guide"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "03-passage-chart");
|
||
int fare = Ship.Fare;
|
||
if (!SubmitSmoke("fare-plus") || !CheckSmoke(Ship.Fare == fare + 50 && guideContext == GuideStep.CastOff, "Fare control and departure guide"))
|
||
yield break;
|
||
if (!SubmitSmoke("weather-swell") || !CheckSmoke(PassageWeatherFor(0, 1) == WeatherCondition.Swell, "Select forecast conditions")
|
||
|| !SubmitSmoke("weather-calm"))
|
||
yield break;
|
||
if (!SubmitSmoke("dispatch") || !CheckSmoke(underway != null && livePassage != null && Ship.Port == 0
|
||
&& company.Voyages == 0 && PassageDuration(underway) >= 120 && livePassage.Assisted && underway.Weather == WeatherCondition.Calm
|
||
&& guideContext == GuideStep.AtSea && root.Q<Button>("guide-skip") != null,
|
||
"Cast off into an assisted live crossing"))
|
||
yield break;
|
||
int mealPrice = livePassage.GetPrice(OnboardService.Meals);
|
||
int provisions = livePassage.ProvisionsRemaining;
|
||
if (!SubmitSmoke("passage-price-meals-plus") || !SubmitSmoke("passage-special-meals")
|
||
|| !CheckSmoke(livePassage.GetPrice(OnboardService.Meals) == mealPrice + 1 && livePassage.DiscountTicks(OnboardService.Meals) > 0,
|
||
"Change live prices and start a meal special"))
|
||
yield break;
|
||
MovePassageToSmoke(.30f);
|
||
if (!CheckSmoke(livePassage.CurrentEvent.HasValue && livePassage.ProvisionsRemaining < provisions,
|
||
"Service uses inventory and opens a timed event"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "04-underway");
|
||
if (!SubmitSmoke("passage-event-0") || !CheckSmoke(livePassage.Expenses > 0 && !livePassage.CurrentEvent.HasValue, "Resolve the event"))
|
||
yield break;
|
||
if (!SubmitSmoke("passage-deck-0") || !CheckSmoke(passageDeck == 0, "Inspect the cabin deck"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "05-cabin-deck");
|
||
if (!SubmitSmoke("passage-deck-1") || !CheckSmoke(passageDeck == 1, "Inspect the second guest deck"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "06-guest-deck");
|
||
if (!SubmitSmoke("passage-bridge") || !CheckSmoke(passageBridge, "Enter the first-person bridge"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "06a-bridge");
|
||
if (!SubmitSmoke("passage-deck-0") || !SubmitSmoke("passage-explore")
|
||
|| !CheckSmoke(passageExploring && passageDeck == 0, "Explore inside the cabin deck")
|
||
|| !SubmitSmoke("passage-service") || !CheckSmoke(passageServiceArea == 0, "Enter engineering"))
|
||
yield break;
|
||
int cruiseBurn = livePassage.ProjectedFuelBurn;
|
||
if (!SubmitSmoke("service-engine-0") || !CheckSmoke(livePassage.ProjectedFuelBurn < cruiseBurn, "Economy throttle saves fuel")
|
||
|| !SubmitSmoke("service-assist") || !CheckSmoke(!livePassage.Assisted, "Switch to manual operations"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "06b-engine-room");
|
||
if (!SubmitSmoke("service-area-1") || !SubmitSmoke("service-operate") || !CheckSmoke(livePassage.GalleyBoost, "Extend galley service"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "06c-galley");
|
||
if (!SubmitSmoke("service-area-2") || !CheckSmoke(passageServiceArea == 2, "Inspect stores")
|
||
|| !SubmitSmoke("service-area-3") || !SubmitSmoke("service-operate") || !CheckSmoke(livePassage.RepairCredit > 0, "Service machinery")
|
||
|| !SubmitSmoke("service-area-4") || !SubmitSmoke("service-operate") || !CheckSmoke(livePassage.PumpsBoost, "Boost freshwater pumps")
|
||
|| !SubmitSmoke("service-area-5") || !SubmitSmoke("service-operate") || !CheckSmoke(livePassage.TreatmentBoost, "Boost sewage treatment"))
|
||
yield break;
|
||
if (!SubmitSmoke("company-menu") || !CheckSmoke(paused, "Pause voyage"))
|
||
yield break;
|
||
float elapsed = passageElapsed;
|
||
yield return new WaitForSecondsRealtime(.15f);
|
||
if (!CheckSmoke(passageElapsed == elapsed, "Paused passage clock") || !SubmitSmoke("resume-game"))
|
||
yield break;
|
||
if (!SubmitSmoke("dock-now") || !CheckSmoke(Ship.Port == 1 && company.Voyages == 1 && page == 4 && guideContext == GuideStep.Review, "Arrival settles once and opens the guided log"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "07-logbook");
|
||
if (!SubmitSmoke("voyage-0") || !SubmitSmoke("log-accounts") || !SubmitSmoke("log-voyages")
|
||
|| !SubmitSmoke("guide-finish") || !CheckSmoke(company.TutorialStep == 0, "Finish first voyage guide"))
|
||
yield break;
|
||
|
||
if (!SubmitSmoke("nav-1"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "08-deck-plans");
|
||
if (!SubmitSmoke("deck-1") || !SubmitSmoke("facility-4") || !SubmitSmoke("berth-0")
|
||
|| !CheckSmoke(Ship.Decks[1].Cells[0] == Facility.Tank, "Deck placement")
|
||
|| !SubmitSmoke("add-deck") || !CheckSmoke(Ship.Decks.Count == 3 && deckIndex == 2, "Build a third deck")
|
||
|| !SubmitSmoke("facility-5") || !SubmitSmoke("berth-3") || !SubmitSmoke("facility-6") || !SubmitSmoke("berth-4")
|
||
|| !CheckSmoke(Ship.Decks[2].Cells[3] == Facility.Bar && Ship.Decks[2].Cells[4] == Facility.Amenity, "Fit a bar and amenity on a new deck")
|
||
|| !SubmitSmoke("facility-systems") || !SubmitSmoke("facility-7") || !SubmitSmoke("berth-0")
|
||
|| !CheckSmoke(Ship.Decks[2].Cells[0] == Facility.Galley, "Fit a service expansion on the new deck"))
|
||
yield break;
|
||
|
||
if (!SubmitSmoke("nav-3") || !SubmitSmoke("port-2") || !SubmitSmoke("permit")
|
||
|| !CheckSmoke(company.Permits[2], "Ports control"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "09-ports");
|
||
|
||
if (!SubmitSmoke("chart-world") || !SubmitSmoke("port-12") || !CheckSmoke(inspectedPort == 12, "Global port chart"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "10-world");
|
||
|
||
if (!SubmitSmoke("nav-0") || !SubmitSmoke("plan-voyage") || !SubmitSmoke("port-0") || !SubmitSmoke("weather-storm")
|
||
|| !SubmitSmoke("dispatch") || !CheckSmoke(underway.Weather == WeatherCondition.Storm
|
||
&& livePassage.Get(OnboardService.Amenities).Capacity == 0, "Rough sea closes outdoor amenities"))
|
||
yield break;
|
||
SelectPassageDeck(2);
|
||
if (!CheckSmoke(passageDeck == 2, "Visit the newly fitted third deck during the next crossing"))
|
||
yield break;
|
||
MovePassageToSmoke(.42f);
|
||
yield return CaptureSmoke(directory, "11-new-service-deck");
|
||
SetPassageSpeed(4);
|
||
if (!CheckSmoke(passageSpeed == 4, "Fast-forward setting"))
|
||
yield break;
|
||
MovePassageToSmoke(.95f);
|
||
float timeout = Time.realtimeSinceStartup + 15;
|
||
while (underway != null && Time.realtimeSinceStartup < timeout)
|
||
yield return null;
|
||
if (!CheckSmoke(underway == null && Ship.Port == 0 && company.Voyages == 2, "Timed passage and second settlement"))
|
||
yield break;
|
||
|
||
if (!SubmitSmoke("company-menu") || !SubmitSmoke("return-title") || !SubmitSmoke("start-financed") || !SubmitSmoke("replace")
|
||
|| !CheckSmoke(company.Debt == 500000 && company.Fleet.Count == 0 && guideContext == GuideStep.GetShip, "Guided financed start"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "12-shipyard");
|
||
if (!SubmitSmoke("buy-ship") || !CheckSmoke(Ship != null && Ship.Beds == 0 && page == 1 && guideContext == GuideStep.Cabins, "Ship commissioning and cabin guide"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "13-new-hull");
|
||
if (!SubmitSmoke("facility-1"))
|
||
yield break;
|
||
for (int i = 0; i < StarterCabinModules; i++)
|
||
if (!SubmitSmoke($"berth-{i}"))
|
||
yield break;
|
||
if (!CheckSmoke(guideContext == GuideStep.Dining, "Starter cabin block advances to dining")
|
||
|| !SubmitSmoke("facility-2") || !SubmitSmoke($"berth-{StarterCabinModules}")
|
||
|| !CheckSmoke(guideContext == GuideStep.SetCourse, "Dining advances to course planning")
|
||
|| !SubmitSmoke("nav-0") || !SubmitSmoke("plan-voyage")
|
||
|| !CheckSmoke(guideContext == GuideStep.Bunker && company.Forecast(Ship, destination).NetIncome > 0,
|
||
"Unfueled hull shows bunker lesson for a profitable first sailing"))
|
||
yield break;
|
||
yield return CaptureSmoke(directory, "14-bunker-lesson");
|
||
if (!SubmitSmoke("buy-fuel") || !CheckSmoke(Ship.Fuel > 0 && guideContext == GuideStep.Fare, "Bunkering and guide progress")
|
||
|| !SubmitSmoke("guide-skip") || !CheckSmoke(company.TutorialStep == 0, "Guide can be skipped"))
|
||
yield break;
|
||
Debug.Log($"Soundings player smoke passed at {Screen.width} × {Screen.height}.");
|
||
Application.Quit(0);
|
||
}
|
||
|
||
private void MovePassageToSmoke(float progress)
|
||
{
|
||
passageElapsed = PassageDuration(underway) * progress;
|
||
livePassage.AdvanceTo(progress);
|
||
harbor.SetPassage(progress);
|
||
UpdatePassageUi(progress);
|
||
}
|
||
|
||
private bool SubmitSmoke(string element)
|
||
{
|
||
Button button = root.Q<Button>(element);
|
||
if (!CheckSmoke(button != null && button.enabledInHierarchy, "Available control: " + element))
|
||
return false;
|
||
using NavigationSubmitEvent navigation = NavigationSubmitEvent.GetPooled();
|
||
navigation.target = button;
|
||
button.SendEvent(navigation);
|
||
return true;
|
||
}
|
||
|
||
private static bool CheckSmoke(bool condition, string label)
|
||
{
|
||
if (!condition)
|
||
{
|
||
Debug.LogError("Soundings player smoke failed: " + label);
|
||
Application.Quit(1);
|
||
}
|
||
return condition;
|
||
}
|
||
|
||
private static IEnumerator CaptureSmoke(string directory, string name)
|
||
{
|
||
yield return null;
|
||
yield return null;
|
||
yield return new WaitForEndOfFrame();
|
||
Texture2D image = ScreenCapture.CaptureScreenshotAsTexture();
|
||
File.WriteAllBytes(Path.Combine(directory, name + ".png"), image.EncodeToPNG());
|
||
Destroy(image);
|
||
}
|
||
}
|
||
}
|