add missing files
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using KernelPanic.Combat;
|
||||
using KernelPanic.Core;
|
||||
using KernelPanic.Data;
|
||||
using KernelPanic.Meta;
|
||||
using KernelPanic.Run;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
internal sealed class TutorialFlow : IDisposable
|
||||
{
|
||||
private readonly VisualElement _overlay;
|
||||
private readonly RunManager _run;
|
||||
private readonly CombatManager _combat;
|
||||
private readonly CardDatabase _cards;
|
||||
private readonly LanguageDeckDatabase _languages;
|
||||
private readonly SaveService _save;
|
||||
private readonly Action _returnToMenu;
|
||||
private TutorialSpotlight _spotlight;
|
||||
private Action _refresh;
|
||||
private int _lesson, _shopStep;
|
||||
private bool _leaving, _resuming;
|
||||
private string _renderKey, _error;
|
||||
public TutorialGuide Guide { get; private set; }
|
||||
public bool Reading => Guide.Reading;
|
||||
public int Lesson => _lesson;
|
||||
|
||||
public TutorialFlow(VisualElement overlay, RunManager run, CombatManager combat, CardDatabase cards,
|
||||
LanguageDeckDatabase languages, SaveService save, RunConfig config, Action returnToMenu)
|
||||
{
|
||||
_overlay = overlay; _run = run; _combat = combat; _cards = cards; _languages = languages;
|
||||
_save = save; _lesson = config.TutorialLesson; _returnToMenu = returnToMenu;
|
||||
_resuming = _lesson == 2;
|
||||
SetGuide(_lesson);
|
||||
}
|
||||
|
||||
public void SetRefresh(Action refresh) => _refresh = refresh;
|
||||
private void Redraw() { if (_refresh != null) _refresh(); else Refresh(); }
|
||||
private void SetGuide(int lesson)
|
||||
{
|
||||
_spotlight?.Dispose(); _spotlight = null;
|
||||
Guide = new TutorialGuide(lesson); _combat.TutorialGuide = Guide;
|
||||
_combat.TutorialReading = true; _renderKey = null;
|
||||
}
|
||||
public void ObserveCard(ResolutionTrack track) => Guide.CardPlayed(track);
|
||||
public void ObserveResolved(ResolutionTrack track) => Guide.CardResolved(track);
|
||||
public void ObservePhase(TurnPhase phase) => Guide.PhaseChanged(phase);
|
||||
public void UpdateState() { if (!_resuming) Guide.Update(_combat); }
|
||||
public void Review() => Redraw();
|
||||
public void AdvancePage() { if (_leaving || _resuming) return; Guide.Acknowledge(_combat); Redraw(); }
|
||||
|
||||
public void ResumeSecondWave()
|
||||
{
|
||||
if (!_resuming) return;
|
||||
_resuming = false;
|
||||
if (!_combat.ContinueTutorialWave()) throw new InvalidDataException("Training checkpoint is not a purchased first-wave shop.");
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (_leaving || _resuming) return;
|
||||
UpdateState();
|
||||
if (Guide.Active && !_combat.RunFinished)
|
||||
{
|
||||
_overlay.RemoveFromClassList("tutorial-overlay");
|
||||
_spotlight ??= new TutorialSpotlight(_overlay, AdvancePage);
|
||||
_spotlight.Show(Guide, _combat);
|
||||
return;
|
||||
}
|
||||
_spotlight?.Dispose(); _spotlight = null;
|
||||
bool cleared = _combat.AwaitingWaveContinue, lost = _combat.RunFinished;
|
||||
if (!cleared && !lost)
|
||||
{
|
||||
_overlay.RemoveFromClassList("tutorial-overlay");
|
||||
_overlay.Clear(); _overlay.style.display = DisplayStyle.None; _renderKey = null;
|
||||
return;
|
||||
}
|
||||
if (cleared && _lesson == 1 && !_run.RepositoryVisitActive)
|
||||
_run.GenerateRepositoryOffers(_cards, _languages);
|
||||
bool purchased = _run.RepositoryOffers.Any(offer => offer.Sold);
|
||||
string key = $"{_lesson}:{cleared}:{lost}:{_shopStep}:{purchased}:{_error}";
|
||||
if (_renderKey == key) return;
|
||||
_renderKey = key;
|
||||
_overlay.Clear(); _overlay.AddToClassList("tutorial-overlay"); _overlay.style.display = DisplayStyle.Flex;
|
||||
var panel = TerminalLayout.Section(lost ? "Practice ended" : _lesson == 1 ? "Wave one cleared / repository" : "Training complete", "TutorialDialog");
|
||||
panel.AddToClassList("tutorial-dialog");
|
||||
var scroll = new ScrollView(ScrollViewMode.Vertical) { name = "TutorialCopy" };
|
||||
scroll.style.flexShrink = 1; scroll.style.minHeight = 0;
|
||||
scroll.horizontalScrollerVisibility = ScrollerVisibility.Hidden; panel.Add(scroll);
|
||||
Button action;
|
||||
if (lost)
|
||||
{
|
||||
scroll.Add(TerminalLayout.BodyText("Try again. Wave two restarts from your saved shop purchase; wave one restarts with full Uptime. Your collection is safe."));
|
||||
action = new Button(RestartLesson) { text = "Retry training", name = "TutorialRetry" };
|
||||
}
|
||||
else if (_lesson == 1)
|
||||
{
|
||||
var bits = TerminalLayout.Heading($"{_run.Bits} Bits available", "TutorialShopBits"); scroll.Add(bits);
|
||||
if (_shopStep == 0)
|
||||
{
|
||||
bits.AddToClassList("tutorial-shop-highlight");
|
||||
scroll.Add(TerminalLayout.BodyText("Every enemy is gone. Between waves, the repository is your shop. Spend Bits earned in combat to improve this run; Bits are separate from your permanent currencies."));
|
||||
action = new Button(() => { _shopStep = 1; Redraw(); }) { text = "Show an upgrade", name = "TutorialShopNext" };
|
||||
}
|
||||
else
|
||||
{
|
||||
// A real card patch keeps the five-card teaching hand intact for the scheduler lesson.
|
||||
var offer = _run.RepositoryOffers.FirstOrDefault(item => item.Kind == RepositoryOfferKind.CardUpgrade);
|
||||
if (offer == null) throw new InvalidOperationException("Training shop needs a card upgrade.");
|
||||
var item = new VisualElement(); item.AddToClassList("tutorial-shop-highlight"); scroll.Add(item);
|
||||
item.Add(TerminalLayout.Heading(offer.DisplayName));
|
||||
item.Add(TerminalLayout.BodyText(offer.Description));
|
||||
item.Add(TerminalLayout.BodyText($"Price: {offer.Price} Bits. This patch stays on the card for the rest of this run."));
|
||||
var buy = new Button(() => { _run.BuyOffer(offer, _combat.PlayerState); _renderKey = null; Redraw(); })
|
||||
{ text = purchased ? "Purchased" : $"Buy / {offer.Price} Bits", name = "TutorialBuy" };
|
||||
buy.SetEnabled(!purchased && _run.Bits >= offer.Price); item.Add(buy);
|
||||
scroll.Add(TerminalLayout.BodyText(purchased
|
||||
? "Upgrade installed. Your remaining Uptime, deck and purchase carry into wave two. Normal shops also sell new cards and stat upgrades."
|
||||
: "Buy this upgrade to practice spending Bits. Then start the next wave."));
|
||||
action = new Button(Continue) { text = "Start wave two", name = "TutorialContinue" };
|
||||
action.SetEnabled(purchased);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
scroll.Add(TerminalLayout.BodyText("Both waves are clear. You have completed the combat → shop → combat loop."));
|
||||
scroll.Add(TerminalLayout.Heading($"+{TutorialCampaign.BandwidthReward:N0} Bandwidth"));
|
||||
scroll.Add(TerminalLayout.Heading($"+{TutorialCampaign.EntropyReward:N0} Entropy"));
|
||||
scroll.Add(TerminalLayout.BodyText("Enough Entropy for one standard 10-pull. This training reward is granted once per profile."));
|
||||
action = new Button(Continue) { text = "Claim rewards & finish", name = "TutorialContinue" };
|
||||
}
|
||||
if (!string.IsNullOrEmpty(_error)) scroll.Add(TerminalLayout.BodyText("Could not save: " + _error + " Retry to continue.", "TutorialSaveError"));
|
||||
action.AddToClassList("primary-action"); panel.Add(action);
|
||||
panel.RegisterCallback<KeyDownEvent>(evt => evt.StopPropagation());
|
||||
TerminalTheme.ConstrainModalFocus(panel); _overlay.Add(panel);
|
||||
(panel.Q<Button>("TutorialBuy") is { enabledSelf: true } buyButton ? buyButton : action).Focus();
|
||||
}
|
||||
|
||||
public void Continue()
|
||||
{
|
||||
if (_leaving || Guide.Active || !_combat.AwaitingWaveContinue || _combat.RunFinished) return;
|
||||
if (_lesson == 1 && !_run.RepositoryOffers.Any(offer => offer.Sold)) return;
|
||||
if (_lesson == 2 && _run.WavesCleared < 2) return;
|
||||
try
|
||||
{
|
||||
var data = _save.Load();
|
||||
if (!TutorialCampaign.Required(data)) throw new InvalidOperationException("Training is not active.");
|
||||
if (_lesson == 1)
|
||||
{
|
||||
data.tutorialCheckpoint = _run.CaptureCheckpoint(_combat);
|
||||
data.tutorialLesson = 2;
|
||||
}
|
||||
else TutorialCampaign.Complete(data);
|
||||
_save.Save(data);
|
||||
_error = null;
|
||||
if (_lesson == 2) { _leaving = true; _returnToMenu(); return; }
|
||||
_lesson = 2; SetGuide(2);
|
||||
if (!_combat.ContinueTutorialWave()) throw new InvalidOperationException("Wave two could not start. Restart to resume the saved shop.");
|
||||
Redraw();
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException || ex is InvalidOperationException || ex is OverflowException)
|
||||
{ _error = ex.Message; _renderKey = null; Redraw(); }
|
||||
}
|
||||
|
||||
public void RestartLesson() { if (!_leaving) { _leaving = true; _returnToMenu(); } }
|
||||
public void Dispose()
|
||||
{
|
||||
_spotlight?.Dispose(); _spotlight = null;
|
||||
_combat.TutorialGuide = null; _combat.TutorialReading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user