Class ScyllaSquareGrid<TCell>.Builder
Fluent builder for constructing ScyllaSquareGrid<TCell> instances with configurable size, layout, default cell values, and optional thread-safety.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaSquareGrid<TCell>.Builder
Remarks
WithLayout(SquareGridLayout) is mandatory; calling Build() or BuildConcrete() without it throws InvalidOperationException.
Build() returns an IScyllaGrid<TCoord, TCell> interface, which may be backed by a ScyllaSquareGrid<TCell>.SynchronizedScyllaSquareGrid wrapper when Synchronized(object) has been called. Use BuildConcrete() when the concrete type is needed and synchronization is not required.
var grid = ScyllaSquareGrid<int>.CreateBuilder()
.WithSize(16, 16)
.WithLayout(new SquareGridLayout(1f, 1f))
.WithDefaultValue(0)
.Build();
Methods
Build()
Builds the grid and returns it as an IScyllaGrid<TCoord, TCell>.
Declaration
public IScyllaGrid<SquareCoord, TCell> Build()
Returns
| Type | Description |
|---|---|
| IScyllaGrid<SquareCoord, TCell> | An IScyllaGrid<TCoord, TCell> representing the fully configured grid. |
Remarks
If Synchronized(object) was called the returned value is a ScyllaSquareGrid<TCell>.SynchronizedScyllaSquareGrid; otherwise it is the concrete ScyllaSquareGrid<TCell>. The default value fill, if configured, is applied before wrapping.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when WithLayout(SquareGridLayout) has not been called. |
BuildConcrete()
Builds the grid and returns it as the concrete ScyllaSquareGrid<TCell> type.
Declaration
public ScyllaSquareGrid<TCell> BuildConcrete()
Returns
| Type | Description |
|---|---|
| ScyllaSquareGrid<TCell> | The configured ScyllaSquareGrid<TCell> with the default value fill applied if WithDefaultValue(TCell) was called. |
Remarks
Use this overload when the concrete type is needed (e.g., to access the indexer or GetEnumerator() without boxing). Throws if Synchronized(object) was called, because a synchronized grid cannot be expressed as the concrete type - use Build() in that case.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when Synchronized(object) was called (the concrete type cannot be synchronized - use Build() instead), or when WithLayout(SquareGridLayout) has not been called. |
Synchronized(object)
Configures the builder to wrap the constructed grid in a ScyllaSquareGrid<TCell>.SynchronizedScyllaSquareGrid so that all operations are thread-safe.
Declaration
public ScyllaSquareGrid<TCell>.Builder Synchronized(object syncRoot = null)
Parameters
| Type | Name | Description |
|---|---|---|
| object | syncRoot | An optional external lock object to share. When |
Returns
| Type | Description |
|---|---|
| ScyllaSquareGrid<TCell>.Builder | This builder instance for method chaining. |
WithDefaultValue(TCell)
Specifies a value to fill all cells with immediately after the grid is constructed.
Declaration
public ScyllaSquareGrid<TCell>.Builder WithDefaultValue(TCell value)
Parameters
| Type | Name | Description |
|---|---|---|
| TCell | value | The default cell value. Passed to Fill(TCell) after construction. |
Returns
| Type | Description |
|---|---|
| ScyllaSquareGrid<TCell>.Builder | This builder instance for method chaining. |
WithLayout(SquareGridLayout)
Sets the spatial layout used for world-space coordinate conversion.
Declaration
public ScyllaSquareGrid<TCell>.Builder WithLayout(SquareGridLayout layout)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareGridLayout | layout | The SquareGridLayout to assign. This call is required before Build() or BuildConcrete(). |
Returns
| Type | Description |
|---|---|
| ScyllaSquareGrid<TCell>.Builder | This builder instance for method chaining. |
WithSize(int, int)
Sets the grid dimensions.
Declaration
public ScyllaSquareGrid<TCell>.Builder WithSize(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | The number of columns. Must be at least 1. |
| int | height | The number of rows. Must be at least 1. |
Returns
| Type | Description |
|---|---|
| ScyllaSquareGrid<TCell>.Builder | This builder instance for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |