using UnityEditor;
using UnityEngine;
namespace SplashEdit.EditorCode
{
///
/// Enumerates the pipeline target for builds.
///
public enum BuildTarget
{
Emulator, // PCSX-Redux with PCdrv
RealHardware, // Send .ps-exe over serial via Unirom
ISO // Build a CD image
}
///
/// Enumerates the build configuration.
///
public enum BuildMode
{
Debug,
Release
}
///
/// Centralized EditorPrefs-backed settings for the SplashEdit pipeline.
/// All settings are project-scoped using a prefix derived from the project path.
///
public static class SplashSettings
{
// Prefix all keys with project path hash to support multiple projects
internal static string Prefix => "SplashEdit_" + Application.dataPath.GetHashCode().ToString("X8") + "_";
// --- Build settings ---
public static BuildTarget Target
{
get => (BuildTarget)EditorPrefs.GetInt(Prefix + "Target", (int)BuildTarget.Emulator);
set => EditorPrefs.SetInt(Prefix + "Target", (int)value);
}
public static BuildMode Mode
{
get => (BuildMode)EditorPrefs.GetInt(Prefix + "Mode", (int)BuildMode.Release);
set => EditorPrefs.SetInt(Prefix + "Mode", (int)value);
}
// --- Toolchain paths ---
public static string NativeProjectPath
{
get => EditorPrefs.GetString(Prefix + "NativeProjectPath", "");
set => EditorPrefs.SetString(Prefix + "NativeProjectPath", value);
}
public static string MIPSToolchainPath
{
get => EditorPrefs.GetString(Prefix + "MIPSToolchainPath", "");
set => EditorPrefs.SetString(Prefix + "MIPSToolchainPath", value);
}
// --- PCSX-Redux ---
public static string PCSXReduxPath
{
get
{
string custom = EditorPrefs.GetString(Prefix + "PCSXReduxPath", "");
if (!string.IsNullOrEmpty(custom))
return custom;
// Fall back to auto-downloaded location
if (SplashBuildPaths.IsPCSXReduxInstalled())
return SplashBuildPaths.PCSXReduxBinary;
return "";
}
set => EditorPrefs.SetString(Prefix + "PCSXReduxPath", value);
}
public static string PCSXReduxPCdrvBase
{
get => EditorPrefs.GetString(Prefix + "PCSXReduxPCdrvBase", SplashBuildPaths.BuildOutputDir);
set => EditorPrefs.SetString(Prefix + "PCSXReduxPCdrvBase", value);
}
// --- Serial / Real Hardware ---
public static string SerialPort
{
get => EditorPrefs.GetString(Prefix + "SerialPort", "COM3");
set => EditorPrefs.SetString(Prefix + "SerialPort", value);
}
public static int SerialBaudRate
{
get => EditorPrefs.GetInt(Prefix + "SerialBaudRate", 115200);
set => EditorPrefs.SetInt(Prefix + "SerialBaudRate", value);
}
// --- VRAM Layout (hardcoded 320x240, dual-buffered, vertical) ---
public static int ResolutionWidth
{
get => 320;
set { } // no-op, hardcoded
}
public static int ResolutionHeight
{
get => 240;
set { } // no-op, hardcoded
}
public static bool DualBuffering
{
get => true;
set { } // no-op, hardcoded
}
public static bool VerticalLayout
{
get => true;
set { } // no-op, hardcoded
}
// --- Clean Build ---
public static bool CleanBuild
{
get => EditorPrefs.GetBool(Prefix + "CleanBuild", true);
set => EditorPrefs.SetBool(Prefix + "CleanBuild", value);
}
// --- Export settings ---
public static float DefaultGTEScaling
{
get => EditorPrefs.GetFloat(Prefix + "GTEScaling", 100f);
set => EditorPrefs.SetFloat(Prefix + "GTEScaling", value);
}
// --- ISO Build ---
///
/// Optional path to a Sony license file (.dat) for the ISO image.
/// If empty, the ISO will be built without license data (homebrew-only).
/// The file must be in raw 2336-byte sector format (from PsyQ SDK LCNSFILE).
///
public static string LicenseFilePath
{
get => EditorPrefs.GetString(Prefix + "LicenseFilePath", "");
set => EditorPrefs.SetString(Prefix + "LicenseFilePath", value);
}
///
/// Volume label for the ISO image (up to 31 characters, uppercase).
///
public static string ISOVolumeLabel
{
get => EditorPrefs.GetString(Prefix + "ISOVolumeLabel", "PSXSPLASH");
set => EditorPrefs.SetString(Prefix + "ISOVolumeLabel", value);
}
///
/// Resets all settings to defaults by deleting all prefixed keys.
///
public static void ResetAll()
{
string[] keys = new[]
{
"Target", "Mode", "NativeProjectPath", "MIPSToolchainPath",
"PCSXReduxPath", "PCSXReduxPCdrvBase", "SerialPort", "SerialBaudRate",
"ResWidth", "ResHeight", "DualBuffering", "VerticalLayout",
"GTEScaling", "AutoValidate",
"LicenseFilePath", "ISOVolumeLabel"
};
foreach (string key in keys)
{
EditorPrefs.DeleteKey(Prefix + key);
}
}
}
}