F6: tutorial, correzioni della revisione
Unisce origin/main (audio, ere e obsolescenza, scheda dell'industria e schermata di connessione) e corregge i rilievi della revisione del tutorial (ADR 0023 aggiornato). - Chiave dell'avanzamento senza l'impronta del terreno, che il server ricalcola e che cambia giocando (città, industrie): origine della partita, seme, lato, anno d'inizio, regione e compagnia. Un tutorial ripreso dopo un anno di gioco ritrova la sua voce. - «Tutorial» apre una partita locale di prova sempre nuova in user://tutorial-server invece di riprendere l'autosalvataggio del giocatore e rifare il tutorial lì dentro; con salvataggi locali già presenti la casella «Mostra il tutorial» parte spenta. Casella e pulsante passano nella nuova ConnectScreen (MenuScreen non c'è più). - La casella spuntata vale anche su una voce chiusa o completata (stesso seme di una partita vecchia). - Contorno ritagliato dai contenitori a scorrimento, con l'elemento portato in vista; del tutto nascosto si usa il ripiego. - Pulsanti del riquadro senza fuoco: Invio e spazio restano alla partita (Costruisci, pausa) e non saltano il passo. - La base di «increase» è presa al completamento del passo precedente e gli esiti dei comandi si valutano subito: un binario costruito appena dopo conta per il passo nuovo. - Velocità contata solo dalle richieste di questo client. - Copione mancante o non valido segnalato nella partita; validazione dei null ammessi dal JSON. - Test: chiave stabile con impronta diversa, base al completamento, piano con la casella, null nel copione. 228 test (208 senza i lenti). Refs #45. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
64209afd5f
75 files changed
+7612
-571
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using Godot;
|
||||
using RailEnterprise.Client.App;
|
||||
using RailEnterprise.Client.Audio;
|
||||
using RailEnterprise.Client.Net;
|
||||
using RailEnterprise.Client.Screens;
|
||||
using RailEnterprise.Client.Tutorial;
|
||||
@@ -9,17 +10,22 @@ using static RailEnterprise.Client.App.Localization;
|
||||
namespace RailEnterprise.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Nodo radice: tema e traduzioni, dati del gioco, passaggio tra menu, collegamento e partita;
|
||||
/// Nodo radice: tema e traduzioni, dati del gioco, passaggio tra schermata di connessione e partita;
|
||||
/// alla chiusura termina la sessione e l'eventuale server locale.
|
||||
/// </summary>
|
||||
public partial class Main : Node
|
||||
{
|
||||
private const string SettingsPath = "user://settings.cfg";
|
||||
// cartelle del server locale: la partita del giocatore (la apre la schermata di connessione), la
|
||||
// partita di prova del tutorial e quella del collaudo (queste due ripartono sempre da una partita nuova)
|
||||
private const string LocalDataDir = "user://server";
|
||||
private const string TutorialDataDir = "user://tutorial-server";
|
||||
private const string AutopilotDataDir = "user://autopilot-server";
|
||||
private GameData? _data;
|
||||
private Node? _screen;
|
||||
private GameSession? _session;
|
||||
private string? _autopilot;
|
||||
// tutorial della partita che si apre: casella del menu e opzione «Tutorial» (dal primo passo)
|
||||
// tutorial della partita che si apre: casella «Mostra il tutorial» e pulsante «Tutorial» (dal primo passo)
|
||||
private bool _tutorialRequested, _tutorialRestart;
|
||||
|
||||
public override void _Ready()
|
||||
@@ -30,21 +36,27 @@ public partial class Main : Node
|
||||
Localization.Load(locale);
|
||||
GetWindow().Theme = UiTheme.Build();
|
||||
GetWindow().Title = "Rail Enterprise";
|
||||
var args = OS.GetCmdlineUserArgs();
|
||||
int i = Array.IndexOf(args, "--autopilot");
|
||||
// audio: niente nel pilota automatico e senza schermo (non rallenta il collaudo)
|
||||
var audio = new AudioManager(enabled: i < 0 && DisplayServer.GetName() != "headless");
|
||||
AddChild(audio);
|
||||
try
|
||||
{
|
||||
_data = GodotDataSource.LoadGameData();
|
||||
audio.SetEras(_data.Eras.Eras);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
GD.PrintErr($"Dati del gioco non validi: {e.Message}");
|
||||
}
|
||||
ShowMenu(_data is null ? T("Dati del gioco non trovati o non validi.") : "");
|
||||
var args = OS.GetCmdlineUserArgs();
|
||||
int i = Array.IndexOf(args, "--autopilot");
|
||||
if (i >= 0 && _data is not null)
|
||||
_autopilot = i + 1 < args.Length ? args[i + 1] : ProjectSettings.GlobalizePath("user://autopilot");
|
||||
// nel collaudo la schermata di connessione non avvia un suo server: lo avvia StartLocal qui sotto
|
||||
ShowMenu(_data is null ? T("Dati del gioco non trovati o non validi.") : "", autoStart: _autopilot is null);
|
||||
if (_autopilot is not null)
|
||||
{
|
||||
// collaudo: mappa piccola e seme fisso per il server locale
|
||||
_autopilot = i + 1 < args.Length ? args[i + 1] : ProjectSettings.GlobalizePath("user://autopilot");
|
||||
System.Environment.SetEnvironmentVariable("RE_MAP_SIZE", "64");
|
||||
System.Environment.SetEnvironmentVariable("RE_SEED", "3");
|
||||
System.Environment.SetEnvironmentVariable("RE_AUTOSAVE_MIN", "0");
|
||||
@@ -59,35 +71,48 @@ public partial class Main : Node
|
||||
AddChild(screen);
|
||||
}
|
||||
|
||||
private void ShowMenu(string status = "")
|
||||
/// <summary>Schermata iniziale e di connessione (immagine 09): server locale o in rete, stato, salvataggi.</summary>
|
||||
/// <param name="autoStart">Avvia subito la strada scelta l'ultima volta (server locale o in rete).</param>
|
||||
/// <param name="handover">Sessione di prova della schermata precedente, ripresa così com'è (cambio di lingua).</param>
|
||||
private void ShowMenu(string status = "", bool autoStart = true, GameSession? handover = null)
|
||||
{
|
||||
var menu = new MenuScreen();
|
||||
menu.LocalGame += () =>
|
||||
if (_data is null)
|
||||
{
|
||||
SetTutorial(menu.ShowTutorial, restart: false);
|
||||
StartLocal();
|
||||
// senza dati non si può aprire nessuna sessione: resta solo il messaggio
|
||||
var label = UiTheme.Text(status, 16, Palette.Danger);
|
||||
label.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.Center);
|
||||
Swap(label);
|
||||
return;
|
||||
}
|
||||
// chi aggiorna con una partita locale già salvata non è alla prima partita: casella spenta
|
||||
if (!TutorialSettings.Played && HasLocalSaves()) TutorialSettings.Played = true;
|
||||
var screen = new ConnectScreen(_data, autoStart: autoStart, handover: handover);
|
||||
screen.PlayRequested += session =>
|
||||
{
|
||||
SetTutorial(screen.ShowTutorial, restart: false);
|
||||
ShowGame(session, screen.GameScope);
|
||||
};
|
||||
menu.ConnectToServer += () =>
|
||||
{
|
||||
SetTutorial(menu.ShowTutorial, restart: false);
|
||||
ShowConnect();
|
||||
};
|
||||
menu.TutorialRequested += () =>
|
||||
screen.TutorialRequested += async () =>
|
||||
{
|
||||
// la partita di prova ha un suo server: quello della sessione di prova della schermata si chiude
|
||||
var trial = screen.TakeSession();
|
||||
if (trial is not null) await trial.DisposeAsync();
|
||||
SetTutorial(true, restart: true);
|
||||
StartLocal();
|
||||
StartLocal(tutorial: true);
|
||||
};
|
||||
menu.LanguageChanged += code =>
|
||||
screen.AudioRequested += () => AudioManager.Instance?.ShowSettings();
|
||||
screen.LanguageChanged += code =>
|
||||
{
|
||||
var cfg = new ConfigFile();
|
||||
cfg.Load(SettingsPath);
|
||||
cfg.SetValue("ui", "locale", code);
|
||||
cfg.Save(SettingsPath);
|
||||
TranslationServer.SetLocale(code);
|
||||
ShowMenu();
|
||||
// la schermata si ricrea con i testi nuovi: la sessione di prova (e il server locale) passa a lei
|
||||
ShowMenu(handover: screen.TakeSession());
|
||||
};
|
||||
Swap(menu);
|
||||
if (status.Length > 0) menu.SetStatus(status);
|
||||
Swap(screen);
|
||||
if (status.Length > 0) screen.SetStatus(status, error: true);
|
||||
}
|
||||
|
||||
private void SetTutorial(bool requested, bool restart)
|
||||
@@ -96,73 +121,72 @@ public partial class Main : Node
|
||||
_tutorialRestart = restart;
|
||||
}
|
||||
|
||||
private void ShowConnect()
|
||||
/// <summary>Vero se la partita locale del giocatore ha già dei salvataggi (file <c>.vfsave</c> del server).</summary>
|
||||
private static bool HasLocalSaves()
|
||||
{
|
||||
var screen = new ConnectScreen();
|
||||
screen.Back += () => ShowMenu();
|
||||
screen.ConnectRequested += async (uri, token, label) =>
|
||||
try
|
||||
{
|
||||
if (_data is null) return;
|
||||
screen.SetStatus(T("Collegamento in corso…"), busy: true);
|
||||
try
|
||||
{
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
|
||||
var session = await GameSession.ConnectAsync(_data, uri, token, label, cts.Token);
|
||||
ShowGame(session);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
screen.SetStatus($"{T("Collegamento non riuscito")}: {e.Message}", busy: false);
|
||||
}
|
||||
};
|
||||
Swap(screen);
|
||||
string saves = System.IO.Path.Combine(ProjectSettings.GlobalizePath(LocalDataDir), "saves");
|
||||
return Directory.Exists(saves) && Directory.EnumerateFiles(saves, "*.vfsave").Any();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async void StartLocal()
|
||||
/// <summary>
|
||||
/// Server locale da zero e subito in partita, senza la schermata di connessione: il collaudo e la partita
|
||||
/// di prova del tutorial, ciascuno nella sua cartella; la partita del giocatore non si tocca.
|
||||
/// </summary>
|
||||
/// <param name="tutorial">pulsante «Tutorial»: partita di prova nuova, con il tutorial dal primo passo</param>
|
||||
private async void StartLocal(bool tutorial = false)
|
||||
{
|
||||
if (_data is null) return;
|
||||
string? server = LocalServerLauncher.FindServer();
|
||||
if (server is null)
|
||||
{
|
||||
ShowMenu(T("Server locale non trovato: compila src/RailEnterprise.Server o imposta RE_SERVER_PATH."));
|
||||
ShowMenu(T("Server locale non trovato: compila src/RailEnterprise.Server o imposta RE_SERVER_PATH."), autoStart: false);
|
||||
return;
|
||||
}
|
||||
if (_screen is MenuScreen menu) menu.SetStatus(T("Avvio del server locale…"));
|
||||
if (tutorial && _screen is ConnectScreen connect) connect.SetStatus(T("Avvio della partita di prova del tutorial…"));
|
||||
var launcher = new LocalServerLauncher();
|
||||
try
|
||||
{
|
||||
string dataDir = ProjectSettings.GlobalizePath(_autopilot is null ? "user://server" : "user://autopilot-server");
|
||||
// il collaudo parte sempre da una partita nuova
|
||||
if (_autopilot is not null && Directory.Exists(dataDir)) Directory.Delete(dataDir, true);
|
||||
string dataDir = ProjectSettings.GlobalizePath(tutorial ? TutorialDataDir : AutopilotDataDir);
|
||||
if (Directory.Exists(dataDir)) Directory.Delete(dataDir, true);
|
||||
int port = await launcher.StartAsync(server, dataDir, TimeSpan.FromSeconds(60));
|
||||
var session = await GameSession.ConnectAsync(_data, new Uri($"ws://127.0.0.1:{port}/ws"), launcher.Token, T("Partita locale"));
|
||||
session.LocalServer = launcher;
|
||||
ShowGame(session);
|
||||
ShowGame(session, tutorial ? "tutorial" : "autopilot");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
launcher.Dispose();
|
||||
ShowMenu($"{T("Partita locale non avviata")}: {e.Message}");
|
||||
ShowMenu($"{T("Partita locale non avviata")}: {e.Message}", autoStart: false);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowGame(GameSession session)
|
||||
/// <param name="scope">origine della partita (locale, tutorial, server in rete) per la voce del tutorial</param>
|
||||
private void ShowGame(GameSession session, string scope)
|
||||
{
|
||||
_session = session;
|
||||
var game = new GameScreen(session);
|
||||
game.Exit += async () =>
|
||||
{
|
||||
// prima si chiude la partita (e il server locale), poi la schermata di connessione ne
|
||||
// avvia uno nuovo: due server sulla stessa cartella dei salvataggi non convivono
|
||||
var s = _session;
|
||||
_session = null;
|
||||
ShowMenu();
|
||||
if (s is not null) await s.DisposeAsync();
|
||||
ShowMenu();
|
||||
};
|
||||
Swap(game);
|
||||
// il pilota automatico non mostra il tutorial: le sue schermate restano quelle di sempre
|
||||
// il pilota automatico non mostra il tutorial: le sue schermate di partita restano quelle di sempre
|
||||
if (_autopilot is not null) game.AddChild(new AutoPilot(game, _autopilot));
|
||||
else
|
||||
{
|
||||
game.AddChild(new TutorialController(game, _tutorialRequested, _tutorialRestart));
|
||||
game.AddChild(new TutorialController(game, scope, _tutorialRequested, _tutorialRestart));
|
||||
TutorialSettings.Played = true;
|
||||
_tutorialRestart = false;
|
||||
}
|
||||
@@ -170,10 +194,10 @@ public partial class Main : Node
|
||||
|
||||
public override void _Notification(int what)
|
||||
{
|
||||
if (what == NotificationWMCloseRequest && _session is not null)
|
||||
{
|
||||
_session.DisposeAsync().AsTask().Wait(TimeSpan.FromSeconds(3));
|
||||
_session = null;
|
||||
}
|
||||
if (what != NotificationWMCloseRequest) return;
|
||||
// anche la sessione di prova della schermata di connessione chiude il suo server locale
|
||||
var session = _session ?? (_screen as ConnectScreen)?.TakeSession();
|
||||
_session = null;
|
||||
session?.DisposeAsync().AsTask().Wait(TimeSpan.FromSeconds(3));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user