using Godot;
using RailEnterprise.Core.Data;
namespace RailEnterprise.Client.App;
/// File dati del gioco dentro il progetto Godot (res://data, copiati dalla build del client).
public sealed class GodotDataSource(string root = "res://data") : IDataSource
{
public string Description => root;
public bool Exists(string relativePath) => Godot.FileAccess.FileExists($"{root}/{relativePath}");
public string ReadText(string relativePath)
{
using var f = Godot.FileAccess.Open($"{root}/{relativePath}", Godot.FileAccess.ModeFlags.Read)
?? throw new FileNotFoundException(relativePath);
return f.GetAsText();
}
/// Dati del gioco: res://data se presenti, altrimenti la cartella data del repository.
public static GameData LoadGameData()
{
var source = new GodotDataSource();
return source.Exists("goods.json") ? GameData.Load(source) : GameData.LoadDefault();
}
}