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:
- IsSuccess / IsValid: overall outcome
- ManipulationType: which action was attempted
- OriginalPosition → NewPosition: positional delta
- AffectedPositions: any other grid cells affected
- Metadata: extensible key-value for any extra data
- ErrorMessage: human-readable failure reason if !IsSuccess
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
successboolWhether the operation succeeded.
errorMessagestringAn 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
ErrorMessage
Gets or sets the error message if the operation failed.
public string ErrorMessage { get; set; }
Property Value
IsSuccess
Gets or sets whether the operation was successful.
public bool IsSuccess { get; set; }
Property Value
IsValid
Gets whether the operation was valid (alias for IsSuccess; kept for compatibility).
public bool IsValid { get; set; }
Property Value
ManipulationType
Gets or sets the type of manipulation that was performed.
public ManipulationAction ManipulationType { get; set; }
Property Value
Message
Gets or sets the message (alias for ErrorMessage; kept for compatibility).
public string Message { get; set; }
Property Value
Metadata
Gets or sets arbitrary metadata about this manipulation result.
public Dictionary<string, object> Metadata { get; set; }
Property Value
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
ValidationErrors
Gets or sets validation error messages (for compatibility with validation frameworks).
public List<string> ValidationErrors { get; set; }
Property Value
Methods
AddAffectedPosition(CoreVector2I)
Adds an affected position to this result.
public void AddAffectedPosition(CoreVector2I position)
Parameters
positionCoreVector2IThe 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
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
errorMessagestringThe 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
errorMessagestringThe reason for failure.
typeManipulationActionOptional 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
typeManipulationActionThe type of manipulation performed.
originalPosCoreVector2IThe origin grid cell.
newPosCoreVector2IThe 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
messagestring
Returns
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
messagestringA descriptive message (e.g., "Build successful").
Returns
- ManipulationResult
A successful result with the specified message.