Table of Contents

Class ManipulationResult

Namespace
MoonBark.GridPlacement.Core.Types
Assembly
MoonBark.GridPlacement.Core.dll

Result of a manipulation operation, capturing outcome, positions, and metadata.

Role in state pattern: Contained within ManipulationApplicationState.LastResult to describe the most recent manipulation attempt. Updated after each phase transition (Start, UpdateTarget, Confirm, Cancel).

For the complete pattern explanation and result lifecycle, see: docs/core/guides/application-state-pattern.md

Properties:

Factory methods: Use Success(), Success(type, orig, new), Failed(msg), or Failure(msg, type) to construct results. Avoid mutable setters in new code; prefer object initializer or builder pattern when adding data.

Compatibility note: This class is mutable and contains alias properties (IsValid/Message/Data) for backward compatibility with older code. New code should prefer IsSuccess, ErrorMessage, and Metadata for clarity.

public class ManipulationResult
Inheritance
ManipulationResult
Inherited Members

Constructors

ManipulationResult()

Initializes a new instance of the ManipulationResult class.

public ManipulationResult()

ManipulationResult(bool, string)

Initializes a new instance of the ManipulationResult class.

public ManipulationResult(bool success, string errorMessage = "")

Parameters

success bool

Whether the operation succeeded.

errorMessage string

An optional error message if failed.

Properties

AffectedPositions

Gets or sets the list of grid positions additionally affected by this operation.

public List<CoreVector2I> AffectedPositions { get; set; }

Property Value

List<CoreVector2I>

Remarks

Use AddAffectedPosition(CoreVector2I) to populate. For a simple move, this may be empty. For area operations (e.g., demolish with cascade), this lists all cells modified.

Data

Gets or sets additional data (alias for Metadata; kept for compatibility).

public Dictionary<string, object> Data { get; set; }

Property Value

Dictionary<string, object>

ErrorMessage

Gets or sets the error message if the operation failed.

public string ErrorMessage { get; set; }

Property Value

string

IsSuccess

Gets or sets whether the operation was successful.

public bool IsSuccess { get; set; }

Property Value

bool

IsValid

Gets whether the operation was valid (alias for IsSuccess; kept for compatibility).

public bool IsValid { get; set; }

Property Value

bool

ManipulationType

Gets or sets the type of manipulation that was performed.

public ManipulationAction ManipulationType { get; set; }

Property Value

ManipulationAction

Message

Gets or sets the message (alias for ErrorMessage; kept for compatibility).

public string Message { get; set; }

Property Value

string

Metadata

Gets or sets arbitrary metadata about this manipulation result.

public Dictionary<string, object> Metadata { get; set; }

Property Value

Dictionary<string, object>

Remarks

Use AddMetadata(string, object) to add key-value pairs. Can store any serializable object. Examples: "resourceCost": 100, "durationMs": 2500, "entityCount": 5.

NewPosition

Gets or sets the new position after manipulation.

public CoreVector2I NewPosition { get; set; }

Property Value

CoreVector2I

OriginalPosition

Gets or sets the original position before manipulation.

public CoreVector2I OriginalPosition { get; set; }

Property Value

CoreVector2I

Timestamp

Gets or sets the timestamp of the operation.

public DateTime Timestamp { get; set; }

Property Value

DateTime

ValidationErrors

Gets or sets validation error messages (for compatibility with validation frameworks).

public List<string> ValidationErrors { get; set; }

Property Value

List<string>

Methods

AddAffectedPosition(CoreVector2I)

Adds an affected position to this result.

public void AddAffectedPosition(CoreVector2I position)

Parameters

position CoreVector2I

The grid position that was affected by the manipulation.

Remarks

Call this during manipulation execution to build a list of all cells modified. Useful for area operations, cascading changes, or UI range indicators.

AddMetadata(string, object)

Adds metadata to this result.

public void AddMetadata(string key, object value)

Parameters

key string

The metadata key.

value object

The metadata value (any serializable object).

Remarks

Use this to attach arbitrary data without adding dedicated properties. Examples: "resourceCost": 100, "durationMs": 2500, "entityCount": 5.

Failed(string)

Creates a failed result with an error message.

public static ManipulationResult Failed(string errorMessage)

Parameters

errorMessage string

The reason for failure.

Returns

ManipulationResult

A failed result.

Failure(string, ManipulationAction)

Creates a failed result with error message and manipulation type (alias for Failed).

public static ManipulationResult Failure(string errorMessage, ManipulationAction type = ManipulationAction.Build)

Parameters

errorMessage string

The reason for failure.

type ManipulationAction

Optional manipulation action type (for context).

Returns

ManipulationResult

A failed result.

Success()

Creates a successful result with no additional data.

public static ManipulationResult Success()

Returns

ManipulationResult

A successful ManipulationResult.

Success(ManipulationAction, CoreVector2I, CoreVector2I)

Creates a successful result with position data.

public static ManipulationResult Success(ManipulationAction type, CoreVector2I originalPos, CoreVector2I newPos)

Parameters

type ManipulationAction

The type of manipulation performed.

originalPos CoreVector2I

The origin grid cell.

newPos CoreVector2I

The resulting grid cell after manipulation.

Returns

ManipulationResult

A successful result populated with positional data.

Success(string)

Creates a successful result with a message (alias for Successful(string)).

public static ManipulationResult Success(string message)

Parameters

message string

Returns

ManipulationResult

Successful()

Creates a successful result (alias for Success(); kept for compatibility).

public static ManipulationResult Successful()

Returns

ManipulationResult

A successful result.

Successful(string)

Creates a successful result with a message.

public static ManipulationResult Successful(string message)

Parameters

message string

A descriptive message (e.g., "Build successful").

Returns

ManipulationResult

A successful result with the specified message.