Skip to content

Commit

Permalink
Merge pull request #152 from finol-digital/develop
Browse files Browse the repository at this point in the history
v1.116
  • Loading branch information
davidmfinol authored Aug 10, 2024
2 parents 9f81d5f + 758fb3d commit a5b77df
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 89 deletions.
13 changes: 13 additions & 0 deletions Assets/Prefabs/CardGameView/Viewer/Playable Viewer.prefab

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Scripts/Cgs/AotTypeEnforcer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public void Awake()
cardGame.AutoUpdateUrl = new Uri(UnityFileMethods.FilePrefix);
cardGame.BannerImageFileType = string.Empty;
cardGame.BannerImageUrl = new Uri(UnityFileMethods.FilePrefix);
cardGame.CardBackFaceImageUrls = new List<CardBackFaceImageUrl>();
var cardBackFaceImageUrl = new CardBackFaceImageUrl(string.Empty, new Uri(UnityFileMethods.FilePrefix));
cardGame.CardBackFaceImageUrls.Add(cardBackFaceImageUrl);
cardGame.CardBackImageFileType = string.Empty;
cardGame.CardBackImageUrl = new Uri(UnityFileMethods.FilePrefix);
cardGame.CardDataIdentifier = string.Empty;
Expand Down
81 changes: 49 additions & 32 deletions Assets/Scripts/Cgs/CardGameView/Multiplayer/CardModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cgs.CardGameView.Viewer;
Expand Down Expand Up @@ -152,6 +151,8 @@ public CardZone PlaceHolderCardZone

private CardZone _placeHolderCardZone;

private bool IsMovingToPlaceHolder { get; set; }

private void SetIsNameVisible(bool value)
{
nameLabel.SetActive(value);
Expand Down Expand Up @@ -241,6 +242,11 @@ protected override void OnUpdatePlayable()
{
if (Inputs.IsOption && CardViewer.Instance.PreviewCardModel == this || HoldTime > ZoomHoldTime)
RequestZoomOnThis();

if (CurrentDragPhase == DragPhase.End && !IsProcessingSecondaryDragAction && PlaceHolder != null)
IsMovingToPlaceHolder = true;

UpdateForMovingToPlaceHolder();
}

private void RequestZoomOnThis()
Expand Down Expand Up @@ -408,7 +414,10 @@ protected override void OnEndDragPlayable(PointerEventData eventData)
protected override void PostDragPlayable(PointerEventData eventData)
{
if (IsProcessingSecondaryDragAction)
{
Debug.Log("PostDragPlayable::IsProcessingSecondaryDragAction");
return;
}

if (DropTarget != null)
{
Expand Down Expand Up @@ -454,7 +463,7 @@ protected override void PostDragPlayable(PointerEventData eventData)
DropTarget = null;

if (PlaceHolder != null)
StartCoroutine(MoveToPlaceHolder());
IsMovingToPlaceHolder = true;
else if (ParentCardZone == null)
Discard();
else if (ParentCardZone.type == CardZoneType.Area)
Expand Down Expand Up @@ -601,6 +610,44 @@ public void UpdateParentCardZoneScrollRect()
cardZone.UpdateScrollRect(CurrentDragPhase, CurrentPointerEventData);
}

private void UpdateForMovingToPlaceHolder()
{
if (!IsMovingToPlaceHolder)
return;

if (PlaceHolder != null && Vector3.Distance(transform.position, PlaceHolder.position) > 1)
{
var distance = MovementSpeed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, PlaceHolder.position, distance);
}
else
FinishMovingToPlaceHolder();
}

private void FinishMovingToPlaceHolder()
{
if (PlaceHolder == null)
{
Debug.Log($"Discarding {gameObject.name} MoveToPlaceHolder");
Discard();
return;
}

var previousParentCardZone = ParentCardZone;
var cachedTransform = transform;
cachedTransform.SetParent(PlaceHolder.parent);
cachedTransform.SetSiblingIndex(PlaceHolder.GetSiblingIndex());
cachedTransform.localScale = Vector3.one;
if (previousParentCardZone != null)
previousParentCardZone.OnRemove(this);
if (ParentCardZone != null)
ParentCardZone.OnAdd(this);

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

private void ParentToCanvas(Vector3 targetPosition)
{
Debug.Log($"ParentToCanvas {gameObject.name}");
Expand Down Expand Up @@ -632,36 +679,6 @@ private void ParentToCanvas(Vector3 targetPosition)
Destroy(gameObject);
}

private IEnumerator MoveToPlaceHolder()
{
while (PlaceHolder != null && Vector3.Distance(transform.position, PlaceHolder.position) > 1)
{
var distance = MovementSpeed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, PlaceHolder.position, distance);
yield return null;
}

if (PlaceHolder == null)
{
Debug.Log($"Discarding {gameObject.name} MoveToPlaceHolder");
Discard();
yield break;
}

var previousParentCardZone = ParentCardZone;
var cachedTransform = transform;
cachedTransform.SetParent(PlaceHolder.parent);
cachedTransform.SetSiblingIndex(PlaceHolder.GetSiblingIndex());
cachedTransform.localScale = Vector3.one;
if (previousParentCardZone != null)
previousParentCardZone.OnRemove(this);
if (ParentCardZone != null)
ParentCardZone.OnAdd(this);

PlaceHolder = null;
Visibility.blocksRaycasts = true;
}

[PublicAPI]
public void OnChangeId(CgsNetString oldValue, CgsNetString newValue)
{
Expand Down
41 changes: 4 additions & 37 deletions Assets/Scripts/Cgs/CardGameView/Multiplayer/Die.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,16 @@ public class Die : CgsNetPlayable
{
public override string DeletePrompt => "Delete die?";

public const int DefaultMin = 1;
public const int DefaultMax = 6;
public const int DefaultValue = 6;

private const float RollTotalTime = 1.0f;
private const float RollPeriodTime = 0.05f;

public Text valueText;
public Image dieImage;

public int Min
{
get => IsSpawned ? _minNetworkVariable.Value : _min;
set
{
var oldMin = _min;
_min = value;
if (_min > Max)
_min = Max;
if (Value < _min)
Value = _min;
if (IsSpawned)
UpdateMinServerRpc(_min);
else
OnChangeMin(oldMin, _min);
}
}

private int _min = DefaultMin;
private NetworkVariable<int> _minNetworkVariable;
private static int Min => 1;

public int Max
{
Expand All @@ -53,7 +34,7 @@ public int Max
var oldMax = _max;
_max = value;
if (_max < Min)
_max = _min;
_max = Min;
if (Value > _max)
Value = _max;
if (IsSpawned)
Expand Down Expand Up @@ -88,7 +69,7 @@ public int Value
}
}

private int _value = DefaultMin;
private int _value = DefaultValue;
private NetworkVariable<int> _valueNetworkVariable;

public Color DieColor
Expand All @@ -115,8 +96,6 @@ public Color DieColor

protected override void OnAwakePlayable()
{
_minNetworkVariable = new NetworkVariable<int>();
_minNetworkVariable.OnValueChanged += OnChangeMin;
_maxNetworkVariable = new NetworkVariable<int>();
_maxNetworkVariable.OnValueChanged += OnChangeMax;
_valueNetworkVariable = new NetworkVariable<int>();
Expand Down Expand Up @@ -166,18 +145,6 @@ protected override void OnPointerUpSelectPlayable(PointerEventData eventData)
EventSystem.current.SetSelectedGameObject(gameObject, eventData);
}

[ServerRpc(RequireOwnership = false)]
private void UpdateMinServerRpc(int value)
{
_minNetworkVariable.Value = value;
}

[PublicAPI]
public void OnChangeMin(int oldValue, int newValue)
{
_min = newValue;
}

[ServerRpc(RequireOwnership = false)]
private void UpdateMaxServerRpc(int value)
{
Expand Down
30 changes: 26 additions & 4 deletions Assets/Scripts/Cgs/CardGameView/Viewer/PlayableViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public CgsNetPlayable SelectedPlayable
public List<Text> valueTexts;
public InputField dieValueInputField;
public InputField dieMaxInputField;
public Dropdown dieDropdown;

public bool IsVisible
{
Expand Down Expand Up @@ -114,10 +115,7 @@ private void Update()
IncrementDie();

if (IsVisible)
{
dieValueInputField.text = Dice.Value.ToString();
dieMaxInputField.text = Dice.Max.ToString();
}
RedisplayDie();
}
else if (SelectedPlayable is CardStack)
{
Expand Down Expand Up @@ -185,10 +183,34 @@ public void Redisplay()
stackActionPanel.interactable = IsVisible && _selectedPlayable is CardStack;
stackActionPanel.blocksRaycasts = IsVisible && _selectedPlayable is CardStack;

if (Dice != null)
RedisplayDie();
}

private void RedisplayDie()
{
if (Dice == null)
{
Debug.LogWarning("Attempted to redisplay die without Dice!");
return;
}

dieValueInputField.text = Dice.Value.ToString();
dieMaxInputField.text = Dice.Max.ToString();
if (Mathf.Approximately(Dice.DieColor.r, 1) && Mathf.Approximately(Dice.DieColor.g, 1) &&
Mathf.Approximately(Dice.DieColor.b, 1) && dieDropdown.value != 0)
dieDropdown.value = 0;
else if (Mathf.Approximately(Dice.DieColor.r, 1) && Mathf.Approximately(Dice.DieColor.g, 0) &&
Mathf.Approximately(Dice.DieColor.b, 0) && dieDropdown.value != 1)
dieDropdown.value = 1;
else if (Mathf.Approximately(Dice.DieColor.r, 0) && Mathf.Approximately(Dice.DieColor.g, 1) &&
Mathf.Approximately(Dice.DieColor.b, 0) && dieDropdown.value != 2)
dieDropdown.value = 2;
else if (Mathf.Approximately(Dice.DieColor.r, 0) && Mathf.Approximately(Dice.DieColor.g, 0) &&
Mathf.Approximately(Dice.DieColor.b, 1) && dieDropdown.value != 3)
dieDropdown.value = 3;
else if (Dice.DieColor is {r: < 1, g: < 1, b: < 1} && dieDropdown.value != 4)
dieDropdown.value = 4;
}

public void Preview(CgsNetPlayable playable)
Expand Down
10 changes: 6 additions & 4 deletions Assets/Scripts/Cgs/Menu/CardGameEditorMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ public string GameName
[UsedImplicitly]
public string Width
{
get => _width.ToString(CultureInfo.InvariantCulture);
get => _width.ToString(CultureInfo.CurrentCulture);
set
{
if (float.TryParse(value, out var width) && width > 0)
if (float.TryParse(value, NumberStyles.Float, CultureInfo.CurrentCulture, out var width)
&& width is > 0 and < 10)
_width = width;
else
Debug.LogWarning("Attempted to set invalid card width: " + value);
Expand All @@ -86,10 +87,11 @@ public string Width
[UsedImplicitly]
public string Height
{
get => _height.ToString(CultureInfo.InvariantCulture);
get => _height.ToString(CultureInfo.CurrentCulture);
set
{
if (float.TryParse(value, out var height) && height > 0)
if (float.TryParse(value, NumberStyles.Float, CultureInfo.CurrentCulture, out var height)
&& height is > 0 and < 10)
_height = height;
else
Debug.LogWarning("Attempted to set invalid card height: " + value);
Expand Down
8 changes: 4 additions & 4 deletions Assets/Scripts/Cgs/Play/Multiplayer/CgsNetPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,16 +564,16 @@ private void DespawnCardServerRpc(NetworkObjectReference toDespawn)

#region Dice

public void RequestNewDie(Vector2 position, Quaternion rotation, int min, int max, Vector3 color)
public void RequestNewDie(Vector2 position, Quaternion rotation, int max, int value, Vector3 color)
{
CreateDieServerRpc(position, rotation, min, max, color);
CreateDieServerRpc(position, rotation, max, value, color);
}

[ServerRpc]
// ReSharper disable once MemberCanBeMadeStatic.Local
private void CreateDieServerRpc(Vector2 position, Quaternion rotation, int min, int max, Vector3 color)
private void CreateDieServerRpc(Vector2 position, Quaternion rotation, int max, int value, Vector3 color)
{
PlayController.Instance.CreateDie(position, rotation, min, max, new Color(color.x, color.y, color.z));
PlayController.Instance.CreateDie(position, rotation, max, value, new Color(color.x, color.y, color.z));
}

#endregion
Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/Cgs/Play/PlayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,22 +456,22 @@ public void CreateDefaultDie()
{
if (CgsNetManager.Instance.IsOnline && CgsNetManager.Instance.LocalPlayer != null)
CgsNetManager.Instance.LocalPlayer.RequestNewDie(Vector2.zero,
CgsNetManager.Instance.LocalPlayer.DefaultRotation, Die.DefaultMin,
PlaySettings.DieFaceCount, new Vector3(Color.white.r, Color.white.g, Color.white.b));
CgsNetManager.Instance.LocalPlayer.DefaultRotation, PlaySettings.DieFaceCount, Die.DefaultValue,
new Vector3(Color.white.r, Color.white.g, Color.white.b));
else
CreateDie(Vector2.zero, Quaternion.identity, Die.DefaultMin, PlaySettings.DieFaceCount, Color.white);
CreateDie(Vector2.zero, Quaternion.identity, PlaySettings.DieFaceCount, Die.DefaultValue, Color.white);
}

public Die CreateDie(Vector2 position, Quaternion rotation, int min, int max, Color color)
public Die CreateDie(Vector2 position, Quaternion rotation, int max, int value, Color color)
{
var die = Instantiate(diePrefab, playAreaCardZone.transform).GetOrAddComponent<Die>();
if (CgsNetManager.Instance.IsOnline)
die.MyNetworkObject.Spawn();

die.Position = position;
die.Rotation = rotation;
die.Min = min;
die.Max = max;
die.Value = value;
die.DieColor = color;

return die;
Expand Down
Loading

0 comments on commit a5b77df

Please sign in to comment.