Skip to content

Commit

Permalink
Merge pull request #13 from finol-digital/development
Browse files Browse the repository at this point in the history
Release version 1.2.0
  • Loading branch information
davidmfinol authored Jun 8, 2018
2 parents 4aefa24 + 6a434bc commit da62133
Show file tree
Hide file tree
Showing 20 changed files with 560 additions and 264 deletions.
14 changes: 12 additions & 2 deletions Assets/Scripts/CGS/CardModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,12 @@ public void OnChangeRotation(Quaternion rotation)
transform.rotation = rotation;
}

public static void ResetRotation(CardStack cardStack, CardModel cardModel)
public static void Rotate90(CardModel cardModel)
{
if (cardModel == null || (cardModel.IsOnline && !cardModel.hasAuthority))
return;

cardModel.transform.rotation = Quaternion.identity;
cardModel.transform.rotation *= Quaternion.Euler(0, 0, -90);
if (cardModel.IsOnline)
cardModel.CmdUpdateRotation(cardModel.transform.rotation);
}
Expand All @@ -429,6 +429,16 @@ public static void ToggleRotation90(CardModel cardModel)
cardModel.CmdUpdateRotation(cardModel.transform.rotation);
}

public static void ResetRotation(CardStack cardStack, CardModel cardModel)
{
if (cardModel == null || (cardModel.IsOnline && !cardModel.hasAuthority))
return;

cardModel.transform.rotation = Quaternion.identity;
if (cardModel.IsOnline)
cardModel.CmdUpdateRotation(cardModel.transform.rotation);
}

public static void ShowCard(CardStack cardStack, CardModel cardModel)
{
if (cardModel == null || (cardModel.IsOnline && !cardModel.hasAuthority))
Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/CGS/Inputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public static class Inputs
public const string CardViewer = "CardViewer";
public const string Column = "Column";
public const string Delete = "Delete";
public const string Draw = "Draw";
public const string Filter = "Filter";
public const string FocusName = "FocusName";
public const string FocusText = "FocusText";
Expand Down
20 changes: 14 additions & 6 deletions Assets/Scripts/CGS/Menus/CardSearchMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,8 @@ public string Filters
filters += "set:" + SetCodeFilter + "; ";
foreach (PropertyDef property in CardGameManager.Current.CardProperties) {
switch (property.Type) {
case PropertyType.Integer:
if (IntMinPropertyFilters.ContainsKey(property.Name))
filters += property.Name + ">=" + IntMinPropertyFilters[property.Name] + "; ";
if (IntMaxPropertyFilters.ContainsKey(property.Name))
filters += property.Name + "<=" + IntMaxPropertyFilters[property.Name] + "; ";
break;
case PropertyType.ObjectEnum:
case PropertyType.ObjectEnumList:
case PropertyType.StringEnum:
case PropertyType.StringEnumList:
if (!EnumPropertyFilters.ContainsKey(property.Name))
Expand All @@ -404,6 +400,18 @@ public string Filters
if (enumDef != null)
filters += property.Name + ":=" + EnumPropertyFilters[property.Name] + "; ";
break;
case PropertyType.Integer:
if (IntMinPropertyFilters.ContainsKey(property.Name))
filters += property.Name + ">=" + IntMinPropertyFilters[property.Name] + "; ";
if (IntMaxPropertyFilters.ContainsKey(property.Name))
filters += property.Name + "<=" + IntMaxPropertyFilters[property.Name] + "; ";
break;
case PropertyType.Object:
case PropertyType.ObjectList:
case PropertyType.Number:
case PropertyType.Boolean:
case PropertyType.StringList:
case PropertyType.EscapedString:
case PropertyType.String:
default:
if (StringPropertyFilters.ContainsKey(property.Name))
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/CGS/PlayMode/Multiplayer/LobbyDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ IEnumerator WaitToStartBroadcast()
public void SearchForHost()
{
if (Application.internetReachability != NetworkReachability.ReachableViaLocalAreaNetwork) {
if (Application.internetReachability != NetworkReachability.ReachableViaCarrierDataNetwork)
if (Debug.isDebugBuild) //(Application.internetReachability != NetworkReachability.ReachableViaCarrierDataNetwork)
CardGameManager.Instance.Messenger.Show(ListenErrorMessage);
return;
}
Expand Down
23 changes: 17 additions & 6 deletions Assets/Scripts/CGS/PlayMode/PlayMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@ void Update()
if (CardInfoViewer.Instance.IsVisible || !Input.anyKeyDown || CardGameManager.TopMenuCanvas != null)
return;

if (Input.GetButtonDown(Inputs.Draw))
Deal(1);
else if (Input.GetButtonDown(Inputs.Load))
if (Input.GetButtonDown(Inputs.Load))
ShowDeckMenu();
else if (Input.GetButtonDown(Inputs.Save))
ShowDiceMenu();
else if (Input.GetButtonDown(Inputs.Filter))
ShowCardsMenu();
else if (Input.GetButtonDown(Inputs.Sort))
ShowDiceMenu();
else if (Input.GetButtonDown(Inputs.Horizontal))
{
if (Input.GetAxis(Inputs.Horizontal) > 0)
Deal(1);
else
Burn(1);
}
else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel))
PromptBackToMainMenu();
}
Expand Down Expand Up @@ -171,6 +176,12 @@ public void Deal(int cardCount)
AddCardsToHand(PopDeckCards(cardCount));
}

public void Burn(int cardCount)
{
foreach(Card card in PopDeckCards(cardCount))
CatchDiscard(card);
}

public List<Card> PopDeckCards(int cardCount)
{
List<Card> cards = new List<Card>(cardCount);
Expand Down Expand Up @@ -204,7 +215,7 @@ public void AddCardToPlay(CardStack cardStack, CardModel cardModel)

public void SetPlayActions(CardStack cardStack, CardModel cardModel)
{
cardModel.DoubleClickAction = CardModel.ToggleRotation90;
cardModel.DoubleClickAction = CardModel.Rotate90;
cardModel.SecondaryDragAction = cardModel.Rotate;
}

Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/CardGameDef/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,20 @@ public int CompareTo(Card other)
{
switch (property.Def.Type)
{
case PropertyType.ObjectEnum:
case PropertyType.ObjectEnumList:
case PropertyType.StringEnum:
case PropertyType.StringEnumList:
case PropertyType.Integer:
int thisValue = GetPropertyValueInt(property.Def.Name);
int otherValue = other.GetPropertyValueInt(property.Def.Name);
return thisValue.CompareTo(otherValue);
case PropertyType.Object:
case PropertyType.ObjectList:
case PropertyType.Number:
case PropertyType.Boolean:
case PropertyType.StringList:
case PropertyType.EscapedString:
case PropertyType.String:
default:
return string.Compare(property.Value, other.Properties[property.Def.Name].Value, StringComparison.Ordinal);
Expand Down
118 changes: 92 additions & 26 deletions Assets/Scripts/CardGameDef/CardGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public class CardGame
[JsonProperty]
public int AllCardsUrlPageCount { get; set; } = 1;

[JsonProperty]
public string AllCardsUrlPageCountIdentifier { get; set; } = "";

[JsonProperty]
public int AllCardsUrlPageCountDivisor { get; set; } = 1;

[JsonProperty]
public string AllCardsUrlPageIdentifier { get; set; } = "?page=";

Expand Down Expand Up @@ -153,6 +159,9 @@ public class CardGame
[JsonProperty]
public UnityEngine.Vector2 PlayAreaSize { get; set; } = new UnityEngine.Vector2(23.5f, 20.25f);

[JsonProperty]
public bool ReprintsInCardObjectList { get; set; }

[JsonProperty]
public string RulesUrl { get; set; } = "";

Expand Down Expand Up @@ -212,7 +221,8 @@ public IEnumerator Download()
Directory.Delete(initialDirectory, true);
}

yield return UnityExtensionMethods.SaveUrlToFile(AllCardsUrl, CardsFilePath
string cardsUrl = AllCardsUrl + (AllCardsUrlPageCount > 1 ? AllCardsUrlPageIdentifier + "1" : string.Empty);
yield return UnityExtensionMethods.SaveUrlToFile(cardsUrl, CardsFilePath
+ (AllCardsZipped ? UnityExtensionMethods.ZipExtension : string.Empty));
if (AllCardsZipped)
UnityExtensionMethods.ExtractZip(CardsFilePath + UnityExtensionMethods.ZipExtension, FilePathBase);
Expand Down Expand Up @@ -302,6 +312,11 @@ public void LoadJsonFromFile(string file, LoadJTokenDelegate load, string dataId
JToken root = JToken.Parse(File.ReadAllText(file));
foreach (JToken jToken in !string.IsNullOrEmpty(dataId) ? root[dataId] : root as JArray ?? (IJEnumerable<JToken>)((JObject)root).PropertyValues())
load(jToken, Set.DefaultCode);

if (!string.IsNullOrEmpty(AllCardsUrlPageCountIdentifier) && root[AllCardsUrlPageCountIdentifier] != null)
AllCardsUrlPageCount = root.Value<int>(AllCardsUrlPageCountIdentifier);
if (AllCardsUrlPageCountDivisor > 0)
AllCardsUrlPageCount = UnityEngine.Mathf.CeilToInt(((float)AllCardsUrlPageCount) / AllCardsUrlPageCountDivisor);
}

public void LoadCardFromJToken(JToken cardJToken, string defaultSetCode)
Expand All @@ -314,31 +329,68 @@ public void LoadCardFromJToken(JToken cardJToken, string defaultSetCode)
return;

string cardName = cardJToken.Value<string>(CardNameIdentifier) ?? string.Empty;
string cardSet = cardJToken.Value<string>(CardSetIdentifier) ?? defaultSetCode;
Dictionary<string, PropertyDefValuePair> cardProperties = new Dictionary<string, PropertyDefValuePair>();
foreach (PropertyDef property in CardProperties)
{
PropertyDefValuePair newPropertyEntry = new PropertyDefValuePair() { Def = property };
try
{
if (property.Type == PropertyType.StringEnumList)
{
string listValue = string.Empty;
foreach (JToken jToken in cardJToken[property.Name])
{
if (!string.IsNullOrEmpty(listValue))
listValue += EnumDef.Delimiter;
listValue += jToken.Value<string>() ?? string.Empty;
}
newPropertyEntry.Value = listValue;
}
else if (property.Type == PropertyType.EscapedString)
string listValue = string.Empty;
JObject jObject = null;
switch (property.Type)
{
newPropertyEntry.Value = (cardJToken.Value<string>(property.Name) ?? string.Empty).Replace("\\", "");
}
else
{
newPropertyEntry.Value = cardJToken.Value<string>(property.Name) ?? string.Empty;
case PropertyType.ObjectEnumList:
listValue = string.Empty;
foreach (JToken jToken in cardJToken[property.Name])
{
if (!string.IsNullOrEmpty(listValue))
listValue += EnumDef.Delimiter;
jObject = jToken as JObject;
listValue += jObject?.Value<string>("id") ?? string.Empty;
}
newPropertyEntry.Value = listValue;
break;
case PropertyType.ObjectList:
listValue = string.Empty;
foreach (JToken jToken in cardJToken[property.Name])
{
if (!string.IsNullOrEmpty(listValue))
listValue += EnumDef.Delimiter;
jObject = jToken as JObject;
listValue += jObject?.ToString() ?? string.Empty;
}
newPropertyEntry.Value = listValue;
break;
case PropertyType.ObjectEnum:
jObject = cardJToken[property.Name] as JObject;
newPropertyEntry.Value = jObject.Value<string>("id") ?? string.Empty;
break;
case PropertyType.Object:
jObject = cardJToken[property.Name] as JObject;
newPropertyEntry.Value = jObject?.ToString() ?? string.Empty;
break;
case PropertyType.StringEnumList:
case PropertyType.StringList:
listValue = string.Empty;
foreach (JToken jToken in cardJToken[property.Name])
{
if (!string.IsNullOrEmpty(listValue))
listValue += EnumDef.Delimiter;
listValue += jToken.Value<string>() ?? string.Empty;
}
newPropertyEntry.Value = listValue;
break;
case PropertyType.EscapedString:
newPropertyEntry.Value = (cardJToken.Value<string>(property.Name) ?? string.Empty).Replace("\\", "");
break;
case PropertyType.StringEnum:
case PropertyType.Number:
case PropertyType.Integer:
case PropertyType.Boolean:
case PropertyType.String:
default:
newPropertyEntry.Value = cardJToken.Value<string>(property.Name) ?? string.Empty;
break;
}
}
catch
Expand All @@ -348,15 +400,29 @@ public void LoadCardFromJToken(JToken cardJToken, string defaultSetCode)
cardProperties[property.Name] = newPropertyEntry;
}

Card newCard = new Card(cardId, cardName, cardSet, cardProperties);
if (CardNames.Contains(cardName))
newCard.IsReprint = true;
HashSet<string> setCodes = new HashSet<string>();
if (ReprintsInCardObjectList)
{
foreach (JToken jToken in cardJToken[CardSetIdentifier])
{
JObject setObject = jToken as JObject;
setCodes.Add(setObject?.Value<string>(SetCodeIdentifier) ?? Set.DefaultCode);
}
}
else
CardNames.Add(cardName);
LoadedCards[newCard.Id] = newCard;
setCodes.Add(cardJToken.Value<string>(CardSetIdentifier) ?? defaultSetCode);

if (!Sets.ContainsKey(cardSet))
LoadedSets[cardSet] = new Set(cardSet);
foreach(string cardSet in setCodes)
{
Card newCard = new Card(setCodes.Count > 1 ? (cardId + "_" + cardSet) : cardId, cardName, cardSet, cardProperties);
if (CardNames.Contains(cardName))
newCard.IsReprint = true;
else
CardNames.Add(cardName);
LoadedCards[newCard.Id] = newCard;
if (!Sets.ContainsKey(cardSet))
LoadedSets[cardSet] = new Set(cardSet);
}
}

public void LoadSetFromJToken(JToken setJToken, string defaultSetCode)
Expand Down
8 changes: 4 additions & 4 deletions Assets/Scripts/CardGameDef/PropertyDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace CardGameDef
{
public enum PropertyType
{
Object,
EscapedString,
String,
Number,
Integer,
EscapedString,
Boolean,
Integer,
Number,
Object,
StringEnum,
StringList,
StringEnumList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
"cardImageUrl": "https://cardgamesim.finoldigital.com/games/Standard/sets/{cardSet}/{cardId}.{cardImageFileType}",
"cardProperties": [{
"name": "rank",
"display": "Rank",
"type": "stringEnum"
},
{
"name": "suit",
"display": "Suit",
"type": "stringEnum"
},
{
"name": "color",
"display": "Color",
"type": "stringEnum"
}
],
Expand Down
1 change: 1 addition & 0 deletions ProjectSettings/GraphicsSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ GraphicsSettings:
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16002, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
Expand Down
20 changes: 2 additions & 18 deletions ProjectSettings/InputManager.asset
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ InputManager:
descriptiveNegativeName:
negativeButton: left
positiveButton: right
altNegativeButton:
altPositiveButton:
altNegativeButton: a
altPositiveButton: d
gravity: 3
dead: 0.001
sensitivity: 3
Expand Down Expand Up @@ -181,22 +181,6 @@ InputManager:
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Draw
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: d
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: FocusName
descriptiveName:
Expand Down
Loading

0 comments on commit da62133

Please sign in to comment.