From c570a64840d468cc73f49a8843fa108a07addc5a Mon Sep 17 00:00:00 2001 From: josh Date: Sat, 28 Nov 2026 16:04:48 -0500 Subject: [PATCH] Add fleet save slots and rotatable onboard venues --- .../Soundings/Editor/EconomyVerification.cs | 60 ++++ Assets/Soundings/Editor/SoundingsBuild.cs | 2 +- Assets/Soundings/Resources/Careers.uss | 54 ++++ Assets/Soundings/Resources/Careers.uss.meta | 12 + Assets/Soundings/Resources/Shipwork.uss | 8 + Assets/Soundings/Runtime/CareerMenus.cs | 305 ++++++++++++++++++ Assets/Soundings/Runtime/CareerMenus.cs.meta | 2 + Assets/Soundings/Runtime/CareerStore.cs | 128 ++++++++ Assets/Soundings/Runtime/CareerStore.cs.meta | 2 + Assets/Soundings/Runtime/Company.cs | 143 ++++++-- Assets/Soundings/Runtime/ConstructionPages.cs | 228 +++++++++---- Assets/Soundings/Runtime/DeckLayout.cs | 251 ++++++++++++++ Assets/Soundings/Runtime/DeckLayout.cs.meta | 2 + Assets/Soundings/Runtime/DeckPassengers.cs | 109 +------ Assets/Soundings/Runtime/DeckVenues.cs | 206 +++++++++++- Assets/Soundings/Runtime/FleetPassageSave.cs | 187 +++++++++++ .../Runtime/FleetPassageSave.cs.meta | 2 + Assets/Soundings/Runtime/FleetPassages.cs | 1 + Assets/Soundings/Runtime/Harbor.cs | 4 +- Assets/Soundings/Runtime/HarborStations.cs | 2 +- Assets/Soundings/Runtime/HelmNavigation.cs | 50 +++ Assets/Soundings/Runtime/LedgerPage.cs | 3 + Assets/Soundings/Runtime/Market.cs | 42 ++- Assets/Soundings/Runtime/OnboardEconomy.cs | 33 +- Assets/Soundings/Runtime/OnboardRounds.cs | 8 +- .../Soundings/Runtime/OnboardSessionSave.cs | 150 +++++++++ .../Runtime/OnboardSessionSave.cs.meta | 2 + Assets/Soundings/Runtime/PassageInterface.cs | 19 +- Assets/Soundings/Runtime/PassengerCrowd.cs | 7 +- Assets/Soundings/Runtime/PassengerFigure.cs | 47 ++- Assets/Soundings/Runtime/SoundingsApp.cs | 99 ++---- .../Soundings/Runtime/StationInteractions.cs | 4 +- Assets/Soundings/Runtime/VesselExterior.cs | 13 +- Assets/Soundings/Runtime/VisualSmoke.cs | 74 ++++- .../Soundings/Runtime/VoyagePresentation.cs | 13 + ProjectSettings/ProjectSettings.asset | 2 +- README.md | 6 +- 37 files changed, 1970 insertions(+), 310 deletions(-) create mode 100644 Assets/Soundings/Resources/Careers.uss create mode 100644 Assets/Soundings/Resources/Careers.uss.meta create mode 100644 Assets/Soundings/Runtime/CareerMenus.cs create mode 100644 Assets/Soundings/Runtime/CareerMenus.cs.meta create mode 100644 Assets/Soundings/Runtime/CareerStore.cs create mode 100644 Assets/Soundings/Runtime/CareerStore.cs.meta create mode 100644 Assets/Soundings/Runtime/DeckLayout.cs create mode 100644 Assets/Soundings/Runtime/DeckLayout.cs.meta create mode 100644 Assets/Soundings/Runtime/FleetPassageSave.cs create mode 100644 Assets/Soundings/Runtime/FleetPassageSave.cs.meta create mode 100644 Assets/Soundings/Runtime/OnboardSessionSave.cs create mode 100644 Assets/Soundings/Runtime/OnboardSessionSave.cs.meta diff --git a/Assets/Soundings/Editor/EconomyVerification.cs b/Assets/Soundings/Editor/EconomyVerification.cs index cf4636e..4165e63 100644 --- a/Assets/Soundings/Editor/EconomyVerification.cs +++ b/Assets/Soundings/Editor/EconomyVerification.cs @@ -11,6 +11,7 @@ namespace Soundings.Editor VerifyFinancedStartAndConstruction(); VerifyHullDeckProgression(); VerifyMultiBerthFacilities(); + VerifyRotatableFacilities(); VerifyFlagshipCampaign(); VerifyLiveCrossingSettlement(); VerifyConcurrentSettlement(); @@ -153,6 +154,65 @@ namespace Soundings.Editor "Ocean Class fits grand suites and a grand theater"); } + private static void VerifyRotatableFacilities() + { + Company company = Company.Start(false); + company.Cash = 2400000; + company.Voyages = 9; + company.Reputation = 42; + Require(company.Build(company.ActiveShip, 1, 9, Facility.ShoppingArcade) != null, + "Coastal hull cannot fit a shopping arcade"); + Require(company.Acquire(Market.Regional, false, "Silver Current") == null, "commission a Regional hull for footprint checks"); + Ship ship = company.ActiveShip; + Deck deck = ship.Decks[0]; + int columns = ship.Hull.Columns; + deck.Cells[0] = Facility.Suite; + deck.Cells[1] = Facility.Extension; + Require(company.CanLoad() && deck.AnchorAt(1, columns) == 0, "legacy row layouts load without footprint metadata"); + + const int arcade = 4; + int lowerLeft = arcade + columns - 1; + int cash = company.Cash; + Require(company.Build(ship, 0, columns, Facility.ShoppingArcade, 2) != null && company.Cash == cash, + "a turned arcade cannot cross the portside boundary"); + Require(company.Build(ship, 0, arcade, Facility.ShoppingArcade, 2) == null + && deck.AnchorAt(lowerLeft, columns) == arcade && deck.AnchorAt(lowerLeft + 1, columns) == arcade + && deck.Cells[arcade - 1] == Facility.Empty && deck.AnchorAt(1, columns) == 0, + "an L-shaped installation spans two rows while preserving the open bay and the legacy suite"); + Require(ship.RetailCapacity == Market.Facilities[(int)Facility.ShoppingArcade].Capacity, + "arcade capacity is counted once"); + + cash = company.Cash; + Require(company.Build(ship, 0, arcade - 2, Facility.Spa) != null && deck.Cells[arcade - 2] == Facility.Empty + && company.Cash == cash, "a square venue cannot overlap another venue's lower row"); + Require(company.Build(ship, 0, lowerLeft, Facility.ShoppingArcade, 1) == null + && deck.RotationAt(arcade) == 1 && deck.Cells[lowerLeft] == Facility.Empty && deck.Cells[lowerLeft + 1] == Facility.Empty + && deck.AnchorAt(lowerLeft + 2, columns) == arcade && company.Cash == cash, + "rotating an arcade through a continuation reuses its anchor without charging again"); + Require(company.Build(ship, 1, 2, Facility.Spa, 3) == null && company.Build(ship, 1, 4, Facility.WaterPark) != null, + "Regional hull fits a spa and keeps the water park locked"); + + company = JsonUtility.FromJson(JsonUtility.ToJson(company)); + Require(company.CanLoad() && company.ActiveShip.Decks[0].AnchorAt(lowerLeft + 2, columns) == arcade + && company.ActiveShip.Decks[1].RotationAt(2) == 3 + && company.ActiveShip.Decks[1].FacilityAt(columns + 3, columns) == Facility.Spa, + "saved footprints retain their anchors and rotations, including square venues"); + + Require(company.Acquire(Market.Ocean, false, "Blue Horizon") == null, "commission an Ocean Class hull for footprint checks"); + ship = company.ActiveShip; + deck = ship.Decks[1]; + columns = ship.Hull.Columns; + int farCorner = 2 + columns * 2 + 1; + FacilitySpec waterPark = Market.Facilities[(int)Facility.WaterPark]; + Require(company.Build(ship, 1, 2, Facility.WaterPark, 1) == null + && deck.AnchorAt(farCorner, columns) == 2 && ship.PoolCapacity == waterPark.Capacity, + "turning a three-by-two water park spans three rows and counts its capacity once"); + cash = company.Cash; + Require(company.Build(ship, 1, farCorner, Facility.Empty) == null + && Array.TrueForAll(deck.Cells, cell => cell == Facility.Empty) && company.Cash == cash + waterPark.Price / 4, + "clearing the far corner removes the water park and refunds it once"); + } + private static void VerifyConcurrentSettlement() { Company company = Company.Start(false); diff --git a/Assets/Soundings/Editor/SoundingsBuild.cs b/Assets/Soundings/Editor/SoundingsBuild.cs index 3d59e4e..934753f 100644 --- a/Assets/Soundings/Editor/SoundingsBuild.cs +++ b/Assets/Soundings/Editor/SoundingsBuild.cs @@ -24,7 +24,7 @@ namespace Soundings.Editor EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(ScenePath, true) }; PlayerSettings.companyName = "Soundings"; PlayerSettings.productName = "Soundings"; - PlayerSettings.bundleVersion = "0.8.0"; + PlayerSettings.bundleVersion = "0.9.0"; PlayerSettings.defaultScreenWidth = 1920; PlayerSettings.defaultScreenHeight = 1080; PlayerSettings.fullScreenMode = FullScreenMode.FullScreenWindow; diff --git a/Assets/Soundings/Resources/Careers.uss b/Assets/Soundings/Resources/Careers.uss new file mode 100644 index 0000000..cf67047 --- /dev/null +++ b/Assets/Soundings/Resources/Careers.uss @@ -0,0 +1,54 @@ +.career-save-overlay { + position: absolute; + left: 0; + right: 0; + top: 0; + bottom: 0; + align-items: center; + justify-content: center; + background-color: rgba(4, 11, 17, .72); +} +.career-save-sheet { + width: 528px; + max-width: 88%; + max-height: 78%; + padding: 26px 29px; + background-color: #13262e; + border-width: 1px; + border-top-width: 2px; + border-color: #a48b61; + border-radius: 3px; +} +.career-save-header { flex-direction: row; justify-content: space-between; align-items: center; margin-bottom: 14px; } +.career-save-title { color: #faead0; font-size: 44px; } +.action.career-save-close { min-height: 33px; padding: 4px 11px; margin-left: 16px; } +.career-save-name { flex-direction: column; margin: 0 0 16px; } +.career-save-name .unity-base-field__label { color: #d2e0df; margin-bottom: 5px; } +.career-save-name .unity-base-text-field__input { + min-height: 41px; + padding: 7px 9px; + color: #f8eace; + background-color: #081921; + border-color: #738588; + border-width: 1px; +} +.career-save-name .unity-base-text-field__input:focus { border-color: #dabb82; } +.career-save-name .unity-text-element { --unity-cursor-color: #f8eace; --unity-selection-color: #375560; } +.career-save-error { margin-bottom: 10px; white-space: normal; color: #f4b298; } +.career-save-list { max-height: 412px; flex-shrink: 1; } +.action.career-save-row { + min-height: 66px; + align-items: flex-start; + justify-content: center; + padding: 9px 14px; + margin: 0 0 6px; + background-color: #182f38; + border-left-width: 2px; +} +.action.career-save-current, .action.career-save-row:hover, .action.career-save-row:focus { border-color: #c5a46b; } +.action.career-save-row:hover, .action.career-save-row:focus { background-color: #26424b; } +.career-save-label { color: #f3e2be; font-size: 18px; } +.career-save-detail { color: #b5cacc; font-size: 13px; margin-top: 3px; } +.career-pause-actions { flex-direction: row; } +.career-pause-actions .action { flex-basis: 0; flex-grow: 1; } +.career-pause-actions #career-save { margin-right: 7px; } diff --git a/Assets/Soundings/Resources/Careers.uss.meta b/Assets/Soundings/Resources/Careers.uss.meta new file mode 100644 index 0000000..711f05b --- /dev/null +++ b/Assets/Soundings/Resources/Careers.uss.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 46e990ba4a690bfd3a9827853c3232ed +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} + disableValidation: 0 + unsupportedSelectorAction: 0 diff --git a/Assets/Soundings/Resources/Shipwork.uss b/Assets/Soundings/Resources/Shipwork.uss index eb3f6f6..f8797a6 100644 --- a/Assets/Soundings/Resources/Shipwork.uss +++ b/Assets/Soundings/Resources/Shipwork.uss @@ -139,8 +139,14 @@ .work-berth.work-room-15 { background-color: #5c4965; border-color: #b99abf; } .work-berth.work-room-16 { background-color: #256061; border-color: #82c2b8; } .work-berth.work-room-17 { background-color: #724e47; border-color: #c28d80; } +.work-berth.work-room-19 { background-color: #5a4945; border-color: #c6a189; } +.work-berth.work-room-20 { background-color: #69503b; border-color: #c19762; } +.work-berth.work-room-21 { background-color: #455e4c; border-color: #92b192; } +.work-berth.work-room-22 { background-color: #26586c; border-color: #72b5ca; } .work-berth.work-berth-join-left { margin-left: 0; border-left-width: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; } .work-berth.work-berth-join-right { margin-right: 0; border-right-width: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; } +.work-berth.work-berth-join-top { margin-top: 0; border-top-width: 0; border-top-left-radius: 0; border-top-right-radius: 0; } +.work-berth.work-berth-join-bottom { margin-bottom: 0; border-bottom-width: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; } .work-berth:hover, .work-berth:focus { background-color: #39626b; border-color: #d8ecdb; @@ -290,3 +296,5 @@ .work-fit-modes { flex-direction: row; margin: 0 0 6px; } .work-fit-modes .action { min-height: 26px; font-size: 12px; margin-right: 6px; padding: 2px 9px; } .work-fit-modes .work-selected { border-color: #caad74; color: #f0d3a7; background-color: #30494b; } +.work-fit-modes .work-tool-rotate { margin-left: auto; color: #f0d3a7; border-color: #917d55; } +.work-tool-orientation { align-self: center; color: #b4d2cb; font-size: 11px; margin-right: 5px; } diff --git a/Assets/Soundings/Runtime/CareerMenus.cs b/Assets/Soundings/Runtime/CareerMenus.cs new file mode 100644 index 0000000..93ac86f --- /dev/null +++ b/Assets/Soundings/Runtime/CareerMenus.cs @@ -0,0 +1,305 @@ +using System; +using System.Collections.Generic; +using System.IO; +using UnityEngine; +using UnityEngine.UIElements; + +namespace Soundings +{ + public sealed partial class SoundingsApp + { + private enum CareerMenu { Closed, Load, SaveAs } + private CareerMenu careerMenu; + private CareerStore careers; + private string careerId, careerName, careerNameDraft, careerError; + private CareerSave legacyCareer; + private float nextCareerAutosave; + + private void InitializeCareers() + { + string path = autoSmoke ? Path.Combine(Path.GetTempPath(), "soundings-careers-" + Guid.NewGuid().ToString("N")) + : Path.Combine(Application.persistentDataPath, "Careers"); + careers = new CareerStore(path); + if (autoSmoke || AdoptCareer(careers.Read(careers.RecentId), false)) + return; + + foreach (CareerSave candidate in careers.List()) + if (AdoptCareer(candidate, false)) + return; + + if (!PlayerPrefs.HasKey(SaveKey)) + return; + try + { + var imported = new CareerSave + { + Id = Guid.NewGuid().ToString("N"), + Name = "Imported career", + SavedUtc = DateTime.UtcNow.Ticks, + Company = JsonUtility.FromJson(PlayerPrefs.GetString(SaveKey)) + }; + if (AdoptCareer(imported, false)) + { + if (!careers.Write(imported)) + legacyCareer = imported; + return; + } + } + catch (ArgumentException error) + { + Debug.LogWarning("Could not import the previous career. " + error.Message); + } + Notify("The previous career could not be read.", true); + } + + private bool AdoptCareer(CareerSave saved, bool play) + { + if (saved?.Company == null || !saved.Company.CanLoad()) + return false; + saved.Company.RestoreHullDecks(); + if (!CanRestoreFleetPassages(saved.Company, saved.Passages)) + return false; + + if (harbor.PortCinematicActive) + harbor.EndPortCinematic(); + if (underway != null) + harbor.EndPassage(); + passageAudio.End(); + ResetFleetPassages(); + company = saved.Company; + RestoreFleetPassages(saved.Passages); + careerId = saved.Id; + careerName = saved.Name; + paused = fleetOpen = shipActionsOpen = false; + pendingStart = null; + careerMenu = CareerMenu.Closed; + title = !play; + page = Ship == null ? 2 : Mathf.Clamp(saved.Page, 0, 4); + deckIndex = Ship == null ? 0 : Mathf.Clamp(saved.DeckIndex, 0, Ship.Decks.Count - 1); + inspectedPort = Ship?.Port ?? 0; + yardSelection = 1; + selectedVoyage = 0; + ledgerRecordOffset = 0; + ledgerAccounts = worldChart = false; + tool = Facility.Cabin; + deckTools = DeckTools.GuestFacilities; + ResetWeatherSelection(); + ResetItinerary(); + nextCareerAutosave = Time.unscaledTime + 15; + if (play) + { + harbor.ResetView(true); + ResumeSelectedSavedPassage(); + careers.Select(saved.Id); + Notify(null); + Render(); + } + return true; + } + + private void LoadCareer(string id) + { + CareerSave saved = careers.Read(id) ?? (legacyCareer?.Id == id ? legacyCareer : null); + if (AdoptCareer(saved, true)) + return; + careerError = "This save could not be loaded."; + if (careerMenu == CareerMenu.Closed) + Notify(careerError, true); + Render(); + } + + private bool WriteCareer(string newName = null) + { + if (company == null) + return false; + var entry = new CareerSave + { + Id = newName != null || careerId == null ? Guid.NewGuid().ToString("N") : careerId, + Name = newName ?? careerName ?? "Soundings career", + SavedUtc = DateTime.UtcNow.Ticks, + Page = page, + DeckIndex = deckIndex, + Company = company, + Passages = CaptureFleetPassages() + }; + nextCareerAutosave = Time.unscaledTime + 15; + if (!careers.Write(entry)) + { + careerError = "The game could not write this save."; + return false; + } + careerId = entry.Id; + careerName = entry.Name; + careerError = null; + return true; + } + + private void Save() + { + if (!autoSmoke && !WriteCareer()) + Notify(careerError, true); + } + + private void AutosaveCareer() + { + if (!title && !paused && fleetPassages.Count > 0 && Time.unscaledTime >= nextCareerAutosave) + Save(); + } + + private void SaveFromPause() + { + if (WriteCareer()) + Notify($"Saved {careerName}."); + else + Notify(careerError, true); + Render(); + } + + private void SaveAndLeave(bool quit) + { + if (!WriteCareer()) + { + Notify(careerError, true); + Render(); + return; + } + if (quit) + { + title = true; + Application.Quit(); + return; + } + if (underway != null) + harbor.EndPassage(); + passageAudio.End(); + ClearActivePassage(); + paused = fleetOpen = shipActionsOpen = false; + title = true; + Notify(null); + Render(); + } + + private void OnApplicationQuit() + { + if (!autoSmoke && !title && company != null) + Save(); + } + + private void OpenCareerMenu(CareerMenu menu) + { + careerError = null; + careerMenu = menu; + careerNameDraft = menu == CareerMenu.SaveAs ? AvailableCareerName(careerName + " copy") : ""; + Render(); + } + + private void CloseCareerMenu() + { + careerError = null; + careerMenu = CareerMenu.Closed; + Render(); + } + + private string AvailableCareerName(string preferred) + { + var saves = careers.List(); + string stem = preferred.Length <= 35 ? preferred : preferred.Substring(0, 35).TrimEnd(); + string name = stem; + for (int copy = 2; HasCareerName(saves, name); copy++) + name = $"{stem} {copy}"; + return name; + } + + private static bool HasCareerName(List saves, string name) => + saves.Exists(save => string.Equals(save.Name, name, StringComparison.OrdinalIgnoreCase)); + + private bool CheckCareerName(out string name) + { + name = careerNameDraft?.Trim() ?? ""; + if (name.Length == 0) + careerError = "Give the save a name."; + else if (HasCareerName(careers.List(), name)) + careerError = "A save with that name already exists."; + else + return true; + Render(); + return false; + } + + private void StartNamedCareer() + { + if (pendingStart.HasValue && CheckCareerName(out string name)) + StartCompany(pendingStart.Value, name); + } + + private void SaveCareerCopy() + { + if (!CheckCareerName(out string name)) + return; + if (WriteCareer(name)) + { + careerMenu = CareerMenu.Closed; + Notify($"Created {careerName}."); + } + Render(); + } + + private TextField CareerNameField(VisualElement parent) + { + var name = new TextField("Save name") { name = "career-save-name", value = careerNameDraft, maxLength = 40 }; + name.AddToClassList("career-save-name"); + name.RegisterValueChangedCallback(change => careerNameDraft = change.newValue); + parent.Add(name); + return name; + } + + private void DrawCareerMenu() + { + for (int i = 0; i < root.childCount; i++) + root[i].SetEnabled(false); + var overlay = Add(root, "career-save-overlay"); + var menu = Add(overlay, "career-save-sheet"); + menu.name = "career-save-sheet"; + var header = Add(menu, "career-save-header"); + AddDisplay(header, careerMenu == CareerMenu.Load ? "Load game" : "Save as", "career-save-title"); + Button close = Action("Close Esc", CloseCareerMenu, "career-save-close", "career-save-close"); + header.Add(close); + if (!string.IsNullOrEmpty(careerError)) + AddText(menu, careerError, "career-save-error"); + + if (careerMenu == CareerMenu.SaveAs) + { + TextField name = CareerNameField(menu); + menu.Add(Action("Create save", SaveCareerCopy, "primary career-save-confirm", "career-save-confirm")); + name.schedule.Execute(() => name.Focus()); + return; + } + + List saves = careers.List(); + if (legacyCareer != null && !saves.Exists(saved => saved.Id == legacyCareer.Id)) + saves.Add(legacyCareer); + if (saves.Count == 0) + { + AddText(menu, "No saved careers yet.", "career-save-detail"); + close.schedule.Execute(() => close.Focus()); + return; + } + + var list = new ScrollView(ScrollViewMode.Vertical) { name = "career-save-list" }; + list.AddToClassList("career-save-list"); + menu.Add(list); + for (int i = 0; i < saves.Count; i++) + { + CareerSave save = saves[i]; + int sailing = save.Passages?.Length ?? 0; + Button row = Action("", () => LoadCareer(save.Id), "career-save-row", $"career-load-{i}"); + row.EnableInClassList("career-save-current", save.Id == careerId); + AddText(row, save.Name, "career-save-label"); + AddText(row, $"Day {save.Company.Day} · {save.Company.Fleet?.Count ?? 0} ships · {sailing} underway", "career-save-detail"); + list.Add(row); + if (i == 0) + row.schedule.Execute(() => row.Focus()); + } + } + } +} diff --git a/Assets/Soundings/Runtime/CareerMenus.cs.meta b/Assets/Soundings/Runtime/CareerMenus.cs.meta new file mode 100644 index 0000000..75bb4ad --- /dev/null +++ b/Assets/Soundings/Runtime/CareerMenus.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ddc7e3938e8c062669e679eac3d7d696 \ No newline at end of file diff --git a/Assets/Soundings/Runtime/CareerStore.cs b/Assets/Soundings/Runtime/CareerStore.cs new file mode 100644 index 0000000..e39a52d --- /dev/null +++ b/Assets/Soundings/Runtime/CareerStore.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using UnityEngine; + +namespace Soundings +{ + [Serializable] + internal sealed class CareerSave + { + public int Version = 1; + public string Id, Name; + public long SavedUtc; + public int Page, DeckIndex; + public Company Company; + public FleetPassageSnapshot[] Passages; + } + + internal sealed class CareerStore + { + private readonly string directory; + + internal CareerStore(string directory) => this.directory = directory; + + internal string RecentId + { + get + { + string path = Path.Combine(directory, "recent"); + try { return File.Exists(path) ? File.ReadAllText(path) : null; } + catch (Exception error) when (IsFileError(error)) { return null; } + } + } + + internal List List() + { + var result = new List(); + if (!Directory.Exists(directory)) + return result; + try + { + foreach (string file in Directory.GetFiles(directory, "*.json")) + { + CareerSave saved = Read(Path.GetFileNameWithoutExtension(file)); + if (saved != null) + result.Add(saved); + } + } + catch (Exception error) when (IsFileError(error)) + { + Debug.LogWarning("Could not list careers. " + error.Message); + } + result.Sort((a, b) => b.SavedUtc.CompareTo(a.SavedUtc)); + return result; + } + + internal CareerSave Read(string id) + { + if (!Guid.TryParseExact(id, "N", out _)) + return null; + try + { + string path = Path.Combine(directory, id + ".json"); + if (!File.Exists(path)) + return null; + CareerSave saved = JsonUtility.FromJson(File.ReadAllText(path)); + return saved is { Version: 1, Company: not null } && saved.Id == id && !string.IsNullOrWhiteSpace(saved.Name) + ? saved : null; + } + catch (Exception error) when (IsFileError(error) || error is ArgumentException) + { + Debug.LogWarning("Could not read a career. " + error.Message); + return null; + } + } + + internal bool Write(CareerSave saved) + { + try + { + Directory.CreateDirectory(directory); + ReplaceFile(Path.Combine(directory, saved.Id + ".json"), JsonUtility.ToJson(saved)); + } + catch (Exception error) when (IsFileError(error)) + { + Debug.LogWarning("Could not write a career. " + error.Message); + return false; + } + Select(saved.Id); + return true; + } + + internal void Select(string id) + { + try { ReplaceFile(Path.Combine(directory, "recent"), id); } + catch (Exception error) when (IsFileError(error)) + { + Debug.LogWarning("Could not set the most recent career. " + error.Message); + } + } + + private static void ReplaceFile(string path, string contents) + { + string temporary = path + "." + Guid.NewGuid().ToString("N") + ".tmp"; + try + { + using (var file = new FileStream(temporary, FileMode.Create, FileAccess.Write, FileShare.None)) + { + byte[] bytes = Encoding.UTF8.GetBytes(contents); + file.Write(bytes, 0, bytes.Length); + file.Flush(true); + } + if (File.Exists(path)) + File.Replace(temporary, path, null); + else + File.Move(temporary, path); + } + finally + { + if (File.Exists(temporary)) + File.Delete(temporary); + } + } + + private static bool IsFileError(Exception error) => error is IOException or UnauthorizedAccessException; + } +} diff --git a/Assets/Soundings/Runtime/CareerStore.cs.meta b/Assets/Soundings/Runtime/CareerStore.cs.meta new file mode 100644 index 0000000..9e440da --- /dev/null +++ b/Assets/Soundings/Runtime/CareerStore.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 85c3f73a7578c37c8b6aec2d085a840d \ No newline at end of file diff --git a/Assets/Soundings/Runtime/Company.cs b/Assets/Soundings/Runtime/Company.cs index 2d5fd08..78a4508 100644 --- a/Assets/Soundings/Runtime/Company.cs +++ b/Assets/Soundings/Runtime/Company.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using UnityEngine; namespace Soundings { @@ -7,10 +8,19 @@ namespace Soundings public sealed class Deck { public Facility[] Cells; + [SerializeField] private int[] owners; + [SerializeField] private int[] rotations; + public Deck(int size) => Cells = new Facility[size]; public int AnchorAt(int cell, int columns) { + if (Cells[cell] != Facility.Extension) + return cell; + if (owners != null && owners.Length != 0) + return owners[cell] - 1; + + // Older saves store runs of extension bays immediately after their room. int rowStart = cell - cell % columns; while (cell > rowStart && Cells[cell] == Facility.Extension) cell--; @@ -19,21 +29,80 @@ namespace Soundings public Facility FacilityAt(int cell, int columns) => Cells[AnchorAt(cell, columns)]; + public int RotationAt(int anchor) => rotations == null || rotations.Length == 0 ? 0 : rotations[anchor]; + + internal bool TryCellAt(int anchor, int columns, Vector2Int offset, out int bay) + { + int column = anchor % columns + offset.x; + bay = (anchor / columns + offset.y) * columns + column; + return (uint)column < (uint)columns && (uint)bay < (uint)Cells.Length; + } + + internal void SetFacility(int anchor, int columns, Facility facility, int rotation) + { + if (owners == null || owners.Length == 0) + { + var legacyOwners = new int[Cells.Length]; + for (int i = 0; i < Cells.Length; i++) + if (Cells[i] == Facility.Extension) + legacyOwners[i] = AnchorAt(i, columns) + 1; + owners = legacyOwners; + rotations = new int[Cells.Length]; + } + + foreach (Vector2Int offset in Market.Facilities[(int)Cells[anchor]].Footprint(RotationAt(anchor))) + { + TryCellAt(anchor, columns, offset, out int bay); + Cells[bay] = Facility.Empty; + owners[bay] = 0; + } + + foreach (Vector2Int offset in Market.Facilities[(int)facility].Footprint(rotation)) + { + TryCellAt(anchor, columns, offset, out int bay); + Cells[bay] = bay == anchor ? facility : Facility.Extension; + owners[bay] = bay == anchor ? 0 : anchor + 1; + } + rotations[anchor] = rotation; + } + internal bool HasValidFootprints(int columns, int hull) { - for (int anchor = 0; anchor < Cells.Length;) + bool legacy = (owners == null || owners.Length == 0) && (rotations == null || rotations.Length == 0); + if (!legacy && (owners?.Length != Cells.Length || rotations?.Length != Cells.Length)) + return false; + + var occupied = new bool[Cells.Length]; + for (int anchor = 0; anchor < Cells.Length; anchor++) { Facility facility = Cells[anchor]; - if ((uint)facility >= (uint)Facility.Extension) + int rotation = RotationAt(anchor); + if ((uint)facility >= (uint)Market.Facilities.Count || (uint)rotation > 3) + return false; + if (facility == Facility.Extension) + { + if (rotation != 0) + return false; + continue; + } + if (!legacy && owners[anchor] != 0) return false; FacilitySpec spec = Market.Facilities[(int)facility]; - if (columns - anchor % columns < spec.Length || hull < spec.MinimumHull) + if (hull < spec.MinimumHull || (spec.BayCount == 1 && rotation != 0)) return false; - for (int offset = 1; offset < spec.Length; offset++) - if (Cells[anchor + offset] != Facility.Extension) + foreach (Vector2Int offset in spec.Footprint(rotation)) + { + if (offset == Vector2Int.zero) + continue; + if (!TryCellAt(anchor, columns, offset, out int bay) || occupied[bay] + || Cells[bay] != Facility.Extension || AnchorAt(bay, columns) != anchor) return false; - anchor += spec.Length; + occupied[bay] = true; + } } + for (int bay = 0; bay < Cells.Length; bay++) + if (Cells[bay] == Facility.Extension && !occupied[bay]) + return false; return true; } } @@ -54,8 +123,10 @@ namespace Soundings internal int GrandSuiteBerths => FacilityCapacity(Facility.GrandSuite); public int Meals => (FacilityCapacity(Facility.Dining) + FacilityCapacity(Facility.Restaurant)) * 3; public int Entertainment => FacilityCapacity(Facility.Entertainment) + FacilityCapacity(Facility.GrandTheater); - public int PoolCapacity => FacilityCapacity(Facility.Amenity) + FacilityCapacity(Facility.ResortPool); + public int PoolCapacity => FacilityCapacity(Facility.Amenity) + FacilityCapacity(Facility.ResortPool) + + FacilityCapacity(Facility.Spa) + FacilityCapacity(Facility.WaterPark); public int BarCapacity => FacilityCapacity(Facility.Bar) + FacilityCapacity(Facility.CocktailLounge); + public int RetailCapacity => FacilityCapacity(Facility.Shop) + FacilityCapacity(Facility.ShoppingArcade); public int Capacity => Math.Min(Beds, Meals); public int GalleyCapacity => 168 + HullIndex * 72 + FacilityCapacity(Facility.Galley); public int FoodCapacity => 1500 + HullIndex * 640 + FacilityCapacity(Facility.Stores); @@ -100,6 +171,17 @@ namespace Soundings public int NetIncome => TicketSales + OnboardSales - OperatingCash - FuelExpense - LoanInterest; public int CashChange => TicketSales + OnboardSales - OperatingCash - LoanInterest - Principal; public int RequiredFuel => FuelBurn + Reserve; + + internal Voyage CopyForPassage(bool hasDeparturePlan) + { + var copy = (Voyage)MemberwiseClone(); + copy.Onboard = null; + copy.Plan = hasDeparturePlan && Plan != null ? new DeparturePlan + { + FoodUnits = Plan.FoodUnits, FoodCost = Plan.FoodCost, Program = Plan.Program, ProgramCost = Plan.ProgramCost + } : null; + return copy; + } } [Serializable] @@ -258,53 +340,58 @@ namespace Soundings return null; } - public string BuildBlock(Ship ship, int deckIndex, int cell, Facility plan) + public string BuildBlock(Ship ship, int deckIndex, int cell, Facility plan, int rotation = 0) { if (ship == null || (uint)deckIndex >= (uint)ship.Decks.Count || (uint)cell >= (uint)ship.Decks[deckIndex].Cells.Length) return "Select a berth on this ship."; - if ((uint)plan >= (uint)Facility.Extension) + if (plan == Facility.Extension || (uint)plan >= (uint)Market.Facilities.Count) return "Select a facility to build."; Deck deck = ship.Decks[deckIndex]; int columns = ship.Hull.Columns; - Facility previous = deck.FacilityAt(cell, columns); - if (previous == plan) - return null; + int anchor = deck.AnchorAt(cell, columns); + Facility previous = deck.Cells[anchor]; if (plan == Facility.Empty) return previous == Facility.Tank && ship.Fuel > ship.Tank - Market.Facilities[(int)Facility.Tank].Capacity ? "Burn more fuel before removing this tank." : null; FacilitySpec spec = Market.Facilities[(int)plan]; + rotation = spec.BayCount > 1 ? rotation & 3 : 0; + bool turning = previous == plan; + if (turning && rotation == deck.RotationAt(anchor)) + return null; if (ship.HullIndex < spec.MinimumHull) return $"Requires a {Market.Hulls[spec.MinimumHull].Name} hull or larger."; - if (spec.Length > columns - cell % columns) - return $"This facility needs {spec.Length} consecutive berths in one row."; - for (int offset = 0; offset < spec.Length; offset++) - if (deck.Cells[cell + offset] != Facility.Empty) - return spec.Length == 1 ? "Clear this berth before building another facility." + if (!turning && previous != Facility.Empty) + return "Clear this berth before building another facility."; + foreach (Vector2Int offset in spec.Footprint(rotation)) + { + if (!deck.TryCellAt(anchor, columns, offset, out int bay)) + return "The footprint extends beyond this deck. Try another bay or turn it."; + if (deck.Cells[bay] != Facility.Empty && !(turning && deck.AnchorAt(bay, columns) == anchor)) + return spec.BayCount == 1 ? "Clear this berth before building another facility." : "Clear every berth in the footprint before fitting this facility."; - if (AvailableCash < spec.Price) + } + if (!turning && AvailableCash < spec.Price) return "The company needs more cash."; return null; } - public string Build(Ship ship, int deckIndex, int cell, Facility plan) + public string Build(Ship ship, int deckIndex, int cell, Facility plan, int rotation = 0) { - string block = BuildBlock(ship, deckIndex, cell, plan); + string block = BuildBlock(ship, deckIndex, cell, plan, rotation); if (block != null) return block; Deck deck = ship.Decks[deckIndex]; int anchor = deck.AnchorAt(cell, ship.Hull.Columns); Facility previous = deck.Cells[anchor]; - if (previous == plan) - return null; - FacilitySpec fitted = Market.Facilities[(int)previous]; FacilitySpec selected = Market.Facilities[(int)plan]; - Cash += fitted.Price / 4 - selected.Price; - int length = plan == Facility.Empty ? fitted.Length : selected.Length; - deck.Cells[anchor] = plan; - for (int offset = 1; offset < length; offset++) - deck.Cells[anchor + offset] = plan == Facility.Empty ? Facility.Empty : Facility.Extension; + rotation = selected.BayCount > 1 ? rotation & 3 : 0; + if (previous == plan && deck.RotationAt(anchor) == rotation) + return null; + if (previous != plan) + Cash += Market.Facilities[(int)previous].Price / 4 - selected.Price; + deck.SetFacility(anchor, ship.Hull.Columns, plan, rotation); return null; } diff --git a/Assets/Soundings/Runtime/ConstructionPages.cs b/Assets/Soundings/Runtime/ConstructionPages.cs index 45b329e..63e138a 100644 --- a/Assets/Soundings/Runtime/ConstructionPages.cs +++ b/Assets/Soundings/Runtime/ConstructionPages.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; @@ -8,8 +10,18 @@ namespace Soundings private static readonly (int HullIndex, bool Used)[] Offers = { (0, true), (0, false), (1, true), (1, false), (2, false) }; - private enum DeckTools { GuestFacilities, LargerVenues, ShipSystems } + private enum DeckTools { GuestFacilities, LargerVenues, LeisureAndRetail, ShipSystems } private DeckTools deckTools; + private int toolRotation; + private Action refreshDeckPlacement; + + private static readonly Facility[] GuestTools = { Facility.Cabin, Facility.Dining, Facility.Entertainment, + Facility.Tank, Facility.Bar, Facility.Amenity, Facility.Empty }; + private static readonly Facility[] ExpandedTools = { Facility.Suite, Facility.GrandSuite, Facility.Restaurant, + Facility.GrandTheater, Facility.ResortPool, Facility.CocktailLounge, Facility.Empty }; + private static readonly Facility[] LeisureTools = { Facility.Shop, Facility.ShoppingArcade, Facility.Spa, Facility.WaterPark, Facility.Empty }; + private static readonly Facility[] SystemsTools = { Facility.Galley, Facility.Stores, Facility.Water, + Facility.Waste, Facility.Workshop, Facility.Empty }; private static readonly Color DraftGrid = new Color(.37f, .62f, .65f, .19f); private static readonly Color DraftFine = new Color(.47f, .75f, .74f, .42f); @@ -72,9 +84,9 @@ namespace Soundings var layout = Add(board, "work-berth-grid"); var placement = Add(board, "work-placement"); - var placementLabel = AddText(placement, PlacementInstruction(ship, tool), "work-placement-text"); + var placementLabel = AddText(placement, PlacementInstruction(ship, tool, toolRotation), "work-placement-text"); placementLabel.name = "berth-placement"; - DrawBerthGrid(layout, placementLabel, ship); + refreshDeckPlacement = DrawBerthGrid(layout, placementLabel, ship); var fittings = Add(work, "work-fittings"); var gauges = Add(fittings, "work-capacity-strip"); @@ -91,10 +103,13 @@ namespace Soundings AddText(gauges, rooms, "work-capacity"); AddText(gauges, $"{ship.Meals:N0} meal covers", "work-capacity"); AddText(gauges, $"{ship.Entertainment:N0} show seats", "work-capacity"); - if (deckTools == DeckTools.LargerVenues) + if (deckTools == DeckTools.LargerVenues || deckTools == DeckTools.LeisureAndRetail) { - AddText(gauges, $"{ship.PoolCapacity:N0} pool admissions", "work-capacity"); - AddText(gauges, $"{ship.BarCapacity:N0} drink orders", "work-capacity"); + AddText(gauges, $"{ship.PoolCapacity:N0} amenity admissions", "work-capacity"); + if (deckTools == DeckTools.LeisureAndRetail) + AddText(gauges, $"{ship.RetailCapacity:N0} retail orders", "work-capacity"); + else + AddText(gauges, $"{ship.BarCapacity:N0} drink orders", "work-capacity"); } else AddText(gauges, $"{ship.Tank:N0} t bunker capacity", "work-capacity"); @@ -104,21 +119,32 @@ namespace Soundings var toolMode = Add(fittings, "work-fit-modes"); AddBuildToolTab(toolMode, "Guest facilities", "facility-guests", DeckTools.GuestFacilities, Facility.Cabin); AddBuildToolTab(toolMode, "Larger venues", "facility-larger", DeckTools.LargerVenues, Facility.Suite); + AddBuildToolTab(toolMode, "Leisure & retail", "facility-leisure", DeckTools.LeisureAndRetail, Facility.Shop); AddBuildToolTab(toolMode, "Ship systems", "facility-systems", DeckTools.ShipSystems, Facility.Galley); + FacilitySpec selectedSpec = Market.Facilities[(int)tool]; + if (selectedSpec.BayCount > 1) + { + Button rotate = Action("Rotate R", RotateDeckTool, "work-tool-rotate", "facility-rotate"); + rotate.tooltip = "Turn the selected fitting clockwise by 90°"; + toolMode.Add(rotate); + AddText(toolMode, RotationLabel(selectedSpec), "work-tool-orientation").name = "facility-orientation"; + } var tools = Add(fittings, "work-tool-tray"); - var (start, end) = deckTools switch + Facility[] options = deckTools switch { - DeckTools.LargerVenues => (Facility.Suite, Facility.Extension), - DeckTools.ShipSystems => (Facility.Galley, Facility.Suite), - _ => (Facility.Cabin, Facility.Galley) + DeckTools.LargerVenues => ExpandedTools, + DeckTools.LeisureAndRetail => LeisureTools, + DeckTools.ShipSystems => SystemsTools, + _ => GuestTools }; - for (int i = (int)start; i <= (int)end; i++) + foreach (Facility option in options) { - Facility option = i == (int)end ? Facility.Empty : (Facility)i; FacilitySpec spec = Market.Facilities[(int)option]; bool locked = ship.HullIndex < spec.MinimumHull; Button button = Action("", () => { + if (tool != option) + toolRotation = 0; tool = option; Notify(null); Render(); @@ -131,9 +157,9 @@ namespace Soundings copy.pickingMode = PickingMode.Ignore; AddText(copy, spec.Name, "work-tool-name"); string price = option == Facility.Empty ? "25% refund" : Money(spec.Price); - if (spec.Length > 1) + if (spec.BayCount > 1) { - price = $"{spec.Length} bays · {price}"; + price = $"{FootprintLabel(spec, 0)} · {price}"; button.AddToClassList("work-tool-larger"); } AddText(copy, price, "work-tool-cost"); @@ -143,11 +169,12 @@ namespace Soundings } } - private void DrawBerthGrid(VisualElement layout, Label instruction, Ship ship) + private Action DrawBerthGrid(VisualElement layout, Label instruction, Ship ship) { Deck deck = ship.Decks[deckIndex]; int columns = ship.Hull.Columns; var berths = new Button[deck.Cells.Length]; + var strips = new VisualElement[ship.Hull.Rows]; int hovered = -1, focused = -1; void UpdatePreview() @@ -160,24 +187,26 @@ namespace Soundings } if (selected < 0) { - instruction.text = PlacementInstruction(ship, tool); + instruction.text = PlacementInstruction(ship, tool, toolRotation); return; } Facility room = deck.FacilityAt(selected, columns); int anchor = room == Facility.Empty ? selected : deck.AnchorAt(selected, columns); - Facility sizeOf = room == Facility.Empty ? tool : room; - int span = Market.Facilities[(int)sizeOf].Length; - string blocked = PlacementBlock(ship, selected, room); - instruction.text = BerthDescription(deck, columns, selected, room, tool, blocked); - int rowEnd = (anchor / columns + 1) * columns; - for (int i = anchor; i < Mathf.Min(rowEnd, anchor + span); i++) - berths[i].AddToClassList(blocked == null ? "work-berth-preview" : "work-berth-blocked"); + bool planning = room == Facility.Empty || room == tool; + FacilitySpec spec = Market.Facilities[(int)(planning ? tool : room)]; + int rotation = planning ? toolRotation : deck.RotationAt(anchor); + string blocked = PlacementBlock(ship, selected); + instruction.text = BerthDescription(deck, columns, selected, room, tool, toolRotation, blocked); + foreach (Vector2Int offset in spec.Footprint(rotation)) + if (deck.TryCellAt(anchor, columns, offset, out int bay)) + berths[bay].AddToClassList(blocked == null ? "work-berth-preview" : "work-berth-blocked"); } for (int row = 0; row < ship.Hull.Rows; row++) { var strip = Add(layout, "work-berth-row"); + strips[row] = strip; for (int column = 0; column < columns; column++) { int cell = row * columns + column; @@ -188,8 +217,6 @@ namespace Soundings Button berth = Action("", () => BuildAtBerth(ship, deck, cell), "work-berth work-room-" + (int)existing, "berth-" + cell); berths[cell] = berth; slot.Add(berth); - string blocked = PlacementBlock(ship, cell, existing); - berth.tooltip = BerthDescription(deck, columns, cell, existing, tool, blocked); berth.RegisterCallback(_ => { hovered = cell; UpdatePreview(); }); berth.RegisterCallback(_ => { hovered = -1; UpdatePreview(); }); berth.RegisterCallback(_ => { focused = cell; UpdatePreview(); }); @@ -197,36 +224,67 @@ namespace Soundings AddText(berth, BerthName(cell, columns), "work-berth-index"); if (existing == Facility.Empty) AddText(berth, "+", "work-berth-open"); - else if (room.Length == 1) + else if (room.BayCount == 1) AddVenueLabel(berth, existing); else { - berth.EnableInClassList("work-berth-join-left", anchor < cell); - berth.EnableInClassList("work-berth-join-right", anchor + room.Length - 1 > cell); + berth.EnableInClassList("work-berth-join-left", column > 0 && SameVenue(cell - 1)); + berth.EnableInClassList("work-berth-join-right", column + 1 < columns && SameVenue(cell + 1)); + berth.EnableInClassList("work-berth-join-top", row > 0 && SameVenue(cell - columns)); + berth.EnableInClassList("work-berth-join-bottom", row + 1 < ship.Hull.Rows && SameVenue(cell + columns)); } + bool SameVenue(int other) => deck.AnchorAt(other, columns) == anchor; } + } - for (int column = 0; column < columns; column++) + for (int anchor = 0; anchor < deck.Cells.Length; anchor++) + { + Facility room = deck.Cells[anchor]; + FacilitySpec spec = Market.Facilities[(int)room]; + if (spec.BayCount <= 1) + continue; + var (row, start, span) = CaptionRow(spec.Footprint(deck.RotationAt(anchor))); + var label = Add(strips[anchor / columns + row], "work-span-caption"); + label.pickingMode = PickingMode.Ignore; + label.style.left = Length.Percent(100f * (anchor % columns + start) / columns); + label.style.width = Length.Percent(100f * span / columns); + AddVenueLabel(label, room); + } + + Refresh(); + return Refresh; + + void Refresh() + { + for (int cell = 0; cell < berths.Length; cell++) { - Facility room = deck.Cells[row * columns + column]; - int span = Market.Facilities[(int)room].Length; - if (span <= 1) - continue; - var label = Add(strip, "work-span-caption"); - label.pickingMode = PickingMode.Ignore; - label.style.left = Length.Percent(100f * column / columns); - label.style.width = Length.Percent(100f * span / columns); - AddVenueLabel(label, room); + Facility room = deck.FacilityAt(cell, columns); + berths[cell].tooltip = BerthDescription(deck, columns, cell, room, tool, toolRotation, + PlacementBlock(ship, cell)); } + UpdatePreview(); } } - private string PlacementBlock(Ship ship, int cell, Facility existing) + private static (int Row, int First, int Span) CaptionRow(IReadOnlyList footprint) + { + (int row, int start, int span) = (0, 0, 1); + for (int first = 0; first < footprint.Count;) + { + int end = first + 1; + while (end < footprint.Count && footprint[end].y == footprint[first].y) + end++; + if (end - first > span) + (row, start, span) = (footprint[first].y, footprint[first].x, end - first); + first = end; + } + return (row, start, span); + } + + private string PlacementBlock(Ship ship, int cell) { - if (existing != Facility.Empty && tool != Facility.Empty) - return null; FacilitySpec spec = Market.Facilities[(int)tool]; - return ship.HullIndex < spec.MinimumHull ? VenueRequirement(spec) : company.BuildBlock(ship, deckIndex, cell, tool); + return ship.HullIndex < spec.MinimumHull ? VenueRequirement(spec) : company.BuildBlock(ship, deckIndex, cell, tool, toolRotation); } private void BuildAtBerth(Ship ship, Deck deck, int cell) @@ -234,15 +292,18 @@ namespace Soundings int columns = ship.Hull.Columns; int anchor = deck.AnchorAt(cell, columns); Facility previous = deck.FacilityAt(cell, columns); - string failure = company.Build(ship, deckIndex, cell, tool); - if (failure == null && previous != tool) - SetRecommendedFuel(); + int oldRotation = deck.RotationAt(anchor); FacilitySpec room = Market.Facilities[(int)(tool == Facility.Empty ? previous : tool)]; - string area = BerthRange(tool == Facility.Empty ? anchor : cell, room.Length, columns); + int footprintRotation = tool == Facility.Empty ? oldRotation : toolRotation; + string area = BerthNames(deck, columns, previous == Facility.Empty ? cell : anchor, room.Footprint(footprintRotation)); + string failure = company.Build(ship, deckIndex, cell, tool, toolRotation); + bool turned = previous == tool && previous != Facility.Empty && oldRotation != deck.RotationAt(anchor); + if (failure == null && (previous != tool || turned)) + SetRecommendedFuel(); string confirmation = tool == Facility.Empty ? $"Removed {room.Name.ToLowerInvariant()} from {area}." - : $"Built {room.Name.ToLowerInvariant()} at {area}."; - Apply(failure, previous == tool ? null : confirmation); + : $"{(turned ? "Rotated" : "Built")} {room.Name.ToLowerInvariant()} at {area}."; + Apply(failure, previous == tool && !turned ? null : confirmation); } private void AddBuildToolTab(VisualElement parent, string label, string id, DeckTools group, Facility initial) @@ -253,6 +314,7 @@ namespace Soundings return; deckTools = group; tool = initial; + toolRotation = 0; Notify(null); Render(); }, deckTools == group ? "work-selected" : "", id); @@ -273,39 +335,74 @@ namespace Soundings return $"Requires a {hull.Name} hull. Unlock the hull with {hull.Voyages} completed voyages and {hull.Reputation} reputation."; } - private static string PlacementInstruction(Ship ship, Facility selected) + private string RotationLabel(FacilitySpec spec) => $"{FootprintLabel(spec, toolRotation)} · {toolRotation * 90}°"; + + private void RotateDeckTool() + { + FacilitySpec spec = Market.Facilities[(int)tool]; + if (spec.BayCount <= 1 || root.Q