37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
namespace MultiversalDiplomacy.Script;
|
|
|
|
/// <summary>
|
|
/// The result of an <see cref="IScriptHandler"/> processing a line of input.
|
|
/// </summary>
|
|
/// <param name="success">Whether processing was successful.</param>
|
|
/// <param name="next">The handler to continue script processing with.</param>
|
|
/// <param name="message">If processing failed, the error message.</param>
|
|
public class ScriptResult(bool success, IScriptHandler? next, string message)
|
|
{
|
|
/// <summary>
|
|
/// Whether processing was successful.
|
|
/// </summary>
|
|
public bool Success { get; } = success;
|
|
|
|
/// <summary>
|
|
/// The handler to continue script processing with.
|
|
/// </summary>
|
|
public IScriptHandler? NextHandler { get; } = next;
|
|
|
|
/// <summary>
|
|
/// If processing failed, the error message.
|
|
/// </summary>
|
|
public string Message { get; } = message;
|
|
|
|
/// <summary>
|
|
/// Mark the processing as successful and continue processing with the next handler.
|
|
/// </summary>
|
|
public static ScriptResult Succeed(IScriptHandler next) => new(true, next, "");
|
|
|
|
/// <summary>
|
|
/// Mark the processing as a failure and optionally continue with the next handler.
|
|
/// </summary>
|
|
/// <param name="message">The reason for the processing failure.</param>
|
|
public static ScriptResult Fail(string message, IScriptHandler? next = null) => new(false, next, message);
|
|
}
|