Tuesday, 16 September 2025 12:26:13
This commit is contained in:
@@ -5,31 +5,41 @@ using System.Collections.Generic;
|
||||
public partial class Desk : Node2D
|
||||
{
|
||||
public Vector2 _topLeft, _cellDimensions, _gridDimensions;
|
||||
public Sprite2D _light, _dark;
|
||||
public Cell _light, _dark;
|
||||
Node2D _grid;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_grid = GetNode<Node2D>("Cells");
|
||||
_light = GetNode<Sprite2D>("Light");
|
||||
_dark = GetNode<Sprite2D>("Dark");
|
||||
_light = GetNode<Cell>("Light");
|
||||
_dark = GetNode<Cell>("Dark");
|
||||
|
||||
_cellDimensions = new Vector2(50, 50);
|
||||
|
||||
}
|
||||
|
||||
public Vector2 GetPositionFromAddress(int ROW, int COLUMN)
|
||||
public Cell GetCellFromAddress(int ROW, int COLUMN)
|
||||
{
|
||||
|
||||
if (_grid.HasNode("R" + ROW))
|
||||
{
|
||||
Node2D row = _grid.GetNode<Node2D>("R" + ROW);
|
||||
if (row.HasNode("C" + COLUMN))
|
||||
{
|
||||
Sprite2D column = row.GetNode<Sprite2D>("C" + COLUMN);
|
||||
return column.GlobalPosition;
|
||||
Cell column = row.GetNode<Cell>("C" + COLUMN);
|
||||
return column;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Vector2 GetPositionFromAddress(int ROW, int COLUMN)
|
||||
{
|
||||
|
||||
Cell cell = GetCellFromAddress(ROW, COLUMN);
|
||||
if (cell != null)
|
||||
{
|
||||
return cell.GlobalPosition;
|
||||
}
|
||||
return new Vector2(-1, -1);
|
||||
}
|
||||
|
||||
@@ -39,7 +49,7 @@ public partial class Desk : Node2D
|
||||
_topLeft = Globals.Instance._screenCenter - _cellDimensions * _gridDimensions / 2 + _cellDimensions / 2;
|
||||
Vector2 position;
|
||||
Node2D row;
|
||||
Sprite2D column;
|
||||
Cell column;
|
||||
for (int i = 0; i < _gridDimensions.Y; i++)
|
||||
{
|
||||
if (i <= _grid.GetChildCount())
|
||||
@@ -51,10 +61,12 @@ public partial class Desk : Node2D
|
||||
for (int j = 0; j < _gridDimensions.X; j++)
|
||||
{
|
||||
position = _topLeft + new Vector2(_cellDimensions.X * j, _cellDimensions.Y * i);
|
||||
column = (Sprite2D)((i + j) % 2 == 0 ? _light : _dark).Duplicate();
|
||||
column = (Cell)((i + j) % 2 == 0 ? _light : _dark).Duplicate();
|
||||
column.Name = "C" + (j + 1);
|
||||
column.GlobalPosition = position;
|
||||
column.Visible = true;
|
||||
column._row = i + 1;
|
||||
column._column = j + 1;
|
||||
row = _grid.GetNode<Node2D>("R" + (i + 1));
|
||||
row.AddChild(column);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user