Skip to content

Commit

Permalink
some doc and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Nov 23, 2023
1 parent a3ebff7 commit a9feed5
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ namespace SS3D.Systems.Tile.TileMapCreator
/// </summary>
public class BuildGhostManager : NetworkActor
{

/// <summary>
/// The last direction registered by a build ghost.
/// </summary>
private Direction _lastRegisteredDirection;

private InputSystem _inputSystem;
Expand All @@ -36,22 +38,34 @@ public class BuildGhostManager : NetworkActor

private bool _isPlacingItem = false;

/// <summary>
/// Snapped position are positions in the center of tiles, to display tile objects ghosts properly.
/// </summary>
private Vector3 _lastSnappedPosition;

/// <summary>
/// The snapped position of the mouse, in the middle of a tile, when the player starts dragging with the mouse.
/// </summary>
private Vector3 _dragStartPostion;


private bool _isDragging;


/// <summary>
/// Is the player currently dragging ?
/// </summary>
public bool IsDragging => _isDragging;


private GenericObjectSo _selectedObject;


/// <summary>
/// List of build ghosts currently displaying in game.
/// </summary>
public List<BuildGhost> _ghosts = new();

[SerializeField]
private TileMapCreator _menu;
private TileMapMenu _menu;

protected override void OnStart()
{
Expand Down Expand Up @@ -103,16 +117,21 @@ public void Update()
_lastSnappedPosition = position;
}

/// <summary>
/// Rotate all existing ghosts in the next allowed rotation.
/// </summary>
public void SetNextRotation()
{
foreach (var ghost in _ghosts)
{
ghost.SetNextRotation();
}

_lastRegisteredDirection = _ghosts.First().Direction;
}

/// <summary>
/// Instantiate in the correct position and rotation a single build ghost.
/// </summary>
public BuildGhost CreateGhost(GameObject prefab, Vector3 position)
{
var _ghostObject = Instantiate(prefab);
Expand All @@ -123,6 +142,9 @@ public BuildGhost CreateGhost(GameObject prefab, Vector3 position)
return buildGhost;
}

/// <summary>
/// Destroy all existing ghosts.
/// </summary>
public void DestroyGhosts()
{
for (int i = _ghosts.Count - 1; i >= 0; i--)
Expand Down Expand Up @@ -258,6 +280,9 @@ private void ActivateGhosts()
}
}

/// <summary>
/// Starting from a given position, create tile ghosts along a line defined by dragging.
/// </summary>
private void LineDrag(Vector3 position)
{
Vector2 firstPoint = new(_dragStartPostion.x, _dragStartPostion.z);
Expand All @@ -272,6 +297,7 @@ private void LineDrag(Vector3 position)
}
}


[ServerRpc(RequireOwnership = false)]
private void RpcSendCanBuild(string tileObjectSoName, Vector3 placePosition, Direction dir, bool replaceExisting, NetworkConnection conn)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
namespace SS3D.Systems.Tile.UI
{
/// <summary>
/// Tab that holds information for each item/tile in the TileMapCreator UI.
/// TODO : rename to tile map creator slot.
/// Slot that holds information for each item/tile in the TileMapCreator UI.
/// They get created when the tilemap menu spawns.
/// </summary>
public class TileMapCreatorTab : MonoBehaviour
public class TileMapCreatorSlot : MonoBehaviour
{
private GenericObjectSo _genericObjectSo;
private TileMapCreator.TileMapCreator _menu;

private BuildGhostManager _ghostManager;
/// <summary>
/// Load an UI icon and string for the item/tile.
Expand All @@ -24,7 +24,7 @@ public void Setup(GenericObjectSo genericObjectSo)
GetComponent<Image>().sprite = genericObjectSo.icon;
transform.localScale = Vector3.one;
GetComponentInChildren<TMP_Text>().text = genericObjectSo.nameString;
_menu = GetComponentInParent<TileMapCreator.TileMapCreator>();

_ghostManager = GetComponentInParent<BuildGhostManager>();
}

Expand Down
Loading

0 comments on commit a9feed5

Please sign in to comment.