Editor/Data/ArchDataRoot.cs
using Editor;

namespace Sunless.Architecture;

// Where authored arch data is read from and written to. The game names the folder through IArchHost, and the author
// can point it somewhere else in the tool's settings - so a project filing data beside its assets needs no override.
public static class ArchDataRoot {
	public static string Default => Asked();

	public static string Current => Sanitised( EditorCookie.Get( Key, "" ), Default );

	public static void Set( string root ) => EditorCookie.Set( Key, root == Default ? "" : Sanitised( root, "" ) );

	public static void Reset() => EditorCookie.Set( Key, "" );

	public static string For( string folder ) => $"{Current}/{folder}";

	static string Asked() => Sanitised( ArchHostSettled.Now.DataRoot, ArchHost.StockDataRoot );

	static string Sanitised( string root, string fallback ) {
		var trimmed = root?.Replace( '\\', '/' ).Trim().Trim( '/' );

		return string.IsNullOrWhiteSpace( trimmed ) ? fallback : trimmed;
	}

	const string Key = "arch.data.root";
}