Skip to content

Commit

Permalink
Bug-Fix: Cards disappear or stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmfinol committed Dec 4, 2024
1 parent 5cf3ffe commit 7b318f3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 45 deletions.
7 changes: 4 additions & 3 deletions Assets/Scripts/Cgs/CardGameView/CardDropArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private void OnTriggerEnter2D(Collider2D other)
{
var cardModel = other.GetComponent<CardModel>();
if (cardModel == null || cardModel.ParentCardZone == null ||
cardModel.ParentCardZone.Type != CardZoneType.Area)
cardModel.ParentCardZone.Type != CardZoneType.Area || cardModel.gameObject == gameObject)
return;

cardModel.DropTarget = this;
Expand All @@ -35,7 +35,7 @@ private void OnTriggerEnter2D(Collider2D other)
public void OnPointerEnter(PointerEventData eventData)
{
var cardModel = CardModel.GetPointerDrag(eventData);
if (cardModel == null)
if (cardModel == null || cardModel.gameObject == gameObject)
return;

cardModel.DropTarget = this;
Expand All @@ -54,7 +54,8 @@ public void OnDrop(PointerEventData eventData)
var cardModel = CardModel.GetPointerDrag(eventData);
if (cardModel == null
|| cardModel.ParentCardZone != null && cardModel.ParentCardZone.Type != CardZoneType.Area
|| cardModel.PlaceHolderCardZone != null && cardModel.PlaceHolderCardZone.Type != CardZoneType.Area)
|| cardModel.PlaceHolderCardZone != null && cardModel.PlaceHolderCardZone.Type != CardZoneType.Area
|| cardModel.gameObject == gameObject)
return;

var drawerViewer = DropHandler as DrawerViewer;
Expand Down
79 changes: 41 additions & 38 deletions Assets/Scripts/Cgs/CardGameView/Multiplayer/CardModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,7 @@ protected override void OnUpdatePlayable()
if (Inputs.IsOption && CardViewer.Instance.PreviewCardModel == this || HoldTime > ZoomHoldTime)
RequestZoomOnThis();

if (ParentCardZone == null && CurrentDragPhase == DragPhase.End && !IsMovingToPlaceHolder)
{
Debug.LogWarning(
"OnUpdatePlayable: ParentCardZone == null && CurrentDragPhase == DragPhase.End && !IsMovingToPlaceHolder");
if (PlaceHolder == null)
{
Debug.LogWarning("OnUpdatePlayable: PlaceHolder == null");
RecoverLostPlaceholder();
}

IsMovingToPlaceHolder = true;
}
UpdateCheckForPlaceHolder();

UpdateForMovingToPlaceHolder();
}
Expand Down Expand Up @@ -429,11 +418,10 @@ protected override void PostDragPlayable(PointerEventData eventData)
return;
}

if (DropTarget != null)
if (DropTarget != null && DropTarget.gameObject != gameObject)
{
var dropTargetCardModel = DropTarget.GetComponent<CardModel>();

var shouldDeleteOnDropTarget = false;
if (Visibility.blocksRaycasts && ParentCardZone != null && ParentCardZone.Type == CardZoneType.Area
|| PlaceHolderCardZone != null && PlaceHolderCardZone.Type == CardZoneType.Area
|| dropTargetCardModel != null && dropTargetCardModel.ParentCardZone != null &&
Expand All @@ -445,18 +433,17 @@ protected override void PostDragPlayable(PointerEventData eventData)
if (isPointerOverDropTarget)
{
DropTarget.OnDrop(eventData);
shouldDeleteOnDropTarget = PlaySettings.AutoStackCards || dropTargetCardModel == null;
Debug.LogWarning("shouldDeleteOnDropTarget: " + shouldDeleteOnDropTarget);
var shouldDeleteOnDropTarget = PlaySettings.AutoStackCards || dropTargetCardModel == null;

if (shouldDeleteOnDropTarget)
{
Debug.Log("PostDragPlayable::shouldDeleteOnDropTarget");
RequestDelete();
return;
}
}
}

if (shouldDeleteOnDropTarget)
{
Debug.Log("PostDragPlayable::shouldDeleteOnDropTarget");
RequestDelete();
return;
}

if (dropTargetCardModel != null && dropTargetCardModel.ParentCardZone != null &&
dropTargetCardModel.ParentCardZone.Type == CardZoneType.Area)
{
Expand Down Expand Up @@ -579,7 +566,8 @@ protected override void UpdatePosition()
if (IsStatic)
return;

if (DropTarget != null && DropTarget.isBlocker && ParentCardZone != null)
if (DropTarget != null && DropTarget.isBlocker && DropTarget.gameObject != gameObject
&& ParentCardZone != null)
ParentToCanvas(targetPosition);

if (PlaceHolderCardZone != null)
Expand Down Expand Up @@ -625,6 +613,20 @@ public void UpdateParentCardZoneScrollRect()
cardZone.UpdateScrollRect(CurrentDragPhase, CurrentPointerEventData);
}

private void UpdateCheckForPlaceHolder()
{
if (ParentCardZone != null || CurrentDragPhase != DragPhase.End)
return;

if (PlaceHolder == null)
{
Debug.LogWarning("UpdateCheckForPlaceHolder: PlaceHolder == null");
RecoverLostPlaceholder();
}

IsMovingToPlaceHolder = true;
}

private void UpdateForMovingToPlaceHolder()
{
if (!IsMovingToPlaceHolder)
Expand All @@ -639,6 +641,20 @@ private void UpdateForMovingToPlaceHolder()
FinishMovingToPlaceHolder();
}

private void RecoverLostPlaceholder()
{
if (PlayController.Instance == null)
{
Debug.LogWarning("RecoverLostPlaceholder: PlayController.Instance == null");
RequestDelete();
return;
}

PlaceHolderCardZone = PlayController.Instance.playAreaCardZone;
if (!Vector2.zero.Equals(Position))
PlaceHolder.localPosition = Position;
}

private void FinishMovingToPlaceHolder()
{
if (PlaceHolder == null)
Expand All @@ -657,24 +673,11 @@ private void FinishMovingToPlaceHolder()
if (ParentCardZone != null)
ParentCardZone.OnAdd(this);

PlaceHolder = null;
PlaceHolderCardZone = null;
Visibility.blocksRaycasts = true;
IsMovingToPlaceHolder = false;
}

private void RecoverLostPlaceholder()
{
if (PlayController.Instance == null)
{
RequestDelete();
return;
}

PlaceHolderCardZone = PlayController.Instance.playAreaCardZone;
if (!Vector2.zero.Equals(Position))
PlaceHolder.localPosition = Position;
}

private void ParentToCanvas(Vector3 targetPosition)
{
Debug.Log($"ParentToCanvas {gameObject.name}");
Expand Down
7 changes: 3 additions & 4 deletions Assets/Scripts/Cgs/CardGameView/Multiplayer/CgsNetPlayable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ public Quaternion Rotation
public PointerEventData CurrentPointerEventData { get; protected set; }
public Dictionary<int, Vector2> PointerPositions { get; } = new();
protected Dictionary<int, Vector2> PointerDragOffsets { get; } = new();

protected bool DidSelectOnDown { get; set; }
protected bool DidDrag { get; set; }
protected DragPhase CurrentDragPhase { get; private set; }
protected bool DidDrag { get; set; }
protected bool DidSelectOnDown { get; set; }
protected float HoldTime { get; private set; }

private float _disownedTime;
private Vector2 _previousPosition;

public bool ToDelete { get; protected set; }
public bool ToDelete { get; private set; }

public virtual string ViewValue => "<Playable:Value>";

Expand Down

0 comments on commit 7b318f3

Please sign in to comment.