void Start() { Debug.Log("ImportJSON:Start()"); cards = new Dictionary <string, CardLevelSheet>(); decks = new List <Deck>(); TextAsset txt = (TextAsset)Resources.Load("cards", typeof(TextAsset)); string content = txt.text; List <System.Object> dict = MiniJSON.Json.Deserialize(JSON.Parse(content).ToString()) as List <System.Object>; foreach (var c in dict) { Debug.Log(c); CardLevelSheet card = new CardLevelSheet((Dictionary <string, System.Object>)c); cards.Add(card.ID, card); } txt = (TextAsset)Resources.Load("decks", typeof(TextAsset)); content = txt.text; Dictionary <string, System.Object> deckDictionary = MiniJSON.Json.Deserialize(JSON.Parse(content).ToString()) as Dictionary <string, System.Object>; foreach (KeyValuePair <string, System.Object> kvp in deckDictionary) { Deck d = new Deck(kvp.Key, (List <System.Object>)kvp.Value); Debug.Log(kvp.Key); decks.Add(d); } }
void DisplayLargeCardView(string id) { // todo: don't replace "'" with "" here. replace that when reading data from Google Drive Debug.Log("MatchController:CardPointerClick()"); largeCardViewObj = GameObject.Instantiate(LargeCardViewPrefab); largeCardViewObj.transform.SetParent(Canvas.transform, false); largeCardView = (LargeCardView)largeCardViewObj.GetComponent("LargeCardView"); CardLevelSheet c = GameManager.Instance.CardData[id]; largeCardView.Id = c.ID; largeCardView.SetCost(c.Cost); largeCardView.SetLevel(c.Level); largeCardView.SetName(c.Name); largeCardView.SetType(c.Type); largeCardView.SetSubtype(c.Subtype); largeCardView.SetText(c.Text); largeCardView.PreviousDel = LUVPrevious; largeCardView.NextDel = LUVNext; largeCardView.BackDel = LUVBack; largeCardView.Image.sprite = Resources.Load <Sprite> (c.Art); // todo: SetImage and make Image not settable publicly largeCardView.SetRarity(c.Rarity); largeCardView.SetFaction(c.Faction); largeCardViewVisible = true; }
void DisplayConfirm() { if (!isDisplayingConfirm) { GameObject confirmObject = (GameObject)Instantiate(ConfirmPrefab); confirmObject.transform.SetParent(Canvas.transform, false); ConfirmView confirmView = (ConfirmView)(confirmObject.GetComponent("ConfirmView")); CardLevelSheet c = cardLevelSheets[mediumCardView]; confirmView.SetMessage("Are you sure you want to summon '" + c.ID + "'?"); confirmView.AcceptDel = DoAccept; confirmView.DeclineDel = DoDecline; isDisplayingConfirm = true; selectedTileView = currentTile; foreach (CardView cv in cards) { if (cv.Id == c.ID) { cv.gameObject.SetActive(false); } } GameObject.Destroy(mediumCardObject); GameObject.Destroy(mediumCardView); isMediumCardDragging = false; } }
void CardPointerEnter(CardView v) { if (mediumCardObject == null && mediumCardView == null) { Debug.Log("MatchController:CardPointerEnter()"); v.gameObject.SetActive(false); mediumCardObject = (GameObject)Instantiate(CardPrefab); CardLevelSheet card = new CardLevelSheet(cardLevelSheets[v]); mediumCardView = (CardView)(mediumCardObject.GetComponent("CardView")); mediumCardView.Id = card.ID; mediumCardView.transform.SetParent(Canvas.transform, false); mediumCardView.BeginDragDel = MediumCardBeginDrag; mediumCardView.EndDragDel = MediumCardEndDrag; mediumCardView.DragDel = MediumCardDrag; mediumCardView.PointerClickDel = MediumCardPointerClick; mediumCardView.PointerEnterDel = MediumCardPointerEnter; mediumCardView.PointerExitDel = MediumCardPointerExit; mediumCardView.SetCost(card.Cost); mediumCardView.SetLevel(card.Level); mediumCardView.SetType(card.Type); mediumCardView.SetSubtype(card.Subtype); mediumCardView.SetName(card.Name); mediumCardView.SetText(card.Text); mediumCardView.SetImage(Resources.Load <Sprite> (card.Art)); mediumCardView.SetRarity(card.Rarity); mediumCardView.SetFaction(card.Faction); mediumCardView.transform.localScale = new Vector3(2, 2, 1); mediumCardView.transform.position = Input.mousePosition; cardLevelSheets[mediumCardView] = card; } }
void SetLUVText(LargeCardView v, int level) { Card c = GameManager.Instance.Cards[v.Id]; CardLevelSheet cs = c.GetLevelSheet(level); v.SetLevel(cs.Level); v.SetLevel(cs.Level); v.SetText(cs.Text); }
void DoDecline(ConfirmView v) { GameObject.Destroy(v.gameObject); isDisplayingConfirm = false; CardLevelSheet s = cardLevelSheets[mediumCardView]; cardLevelSheets.Remove(mediumCardView); foreach (CardView cv in cards) { if (cv.Id == s.ID) { cv.gameObject.SetActive(true); } } mapView.Clear(); }
public CardLevelSheet(CardLevelSheet c) { Art = c.Art; Type = c.Type; Cost = c.Cost; Faction = c.Faction; ID = c.ID; Keyword = c.Keyword; Level = c.Level; Name = c.Name; NextID = c.NextID; PrevID = c.PrevID; Rarity = c.Rarity; Set = c.Set; Subtype = c.Subtype; Text = c.Text; }
public Unit(int i, Dictionary <string, System.Object> d) : base(new Point(1, 1), UNIT_LAYER) { Point location = new Point(int.MinValue, int.MinValue); foreach (KeyValuePair <string, System.Object> e in d) { Debug.Log("hello"); if (e.Key == "Id") { // todo: make sure Id is Match Unit Id and not the CardLevelSheet Id MatchId = i; Id = (string)e.Value; CardLevelSheet s = GameManager.Instance.CardData[Id]; Name = s.Name; Type = s.Type; Subtype = s.Subtype; LevelOneText = s.Text; LevelTwoText = s.Text; LevelThreeText = s.Text; IsSelected = false; } else if (e.Key == "Location") { int x = int.MinValue; int y = int.MinValue; Dictionary <string, System.Object> d2 = (Dictionary <string, System.Object>)e.Value; foreach (KeyValuePair <string, System.Object> e2 in d2) { if (e2.Key == "x") { x = int.Parse((string)e2.Value); } else if (e2.Key == "y") { y = int.Parse((string)e2.Value); } } location = new Point(x, y); } } base.Location = location; }
void DoAccept(ConfirmView v) { GameObject.Destroy(v.gameObject); isDisplayingConfirm = false; CardLevelSheet c = cardLevelSheets[mediumCardView]; Point p = selectedTileView.Location; Unit u = new Unit(c.Name, c.ID, c.Type, c.Subtype, c.Text, c.Text, c.Text, p); UnitView unitView = (UnitView)((GameObject)Instantiate(UnitPrefab)).GetComponent("UnitView"); unitView.MouseEnter = UnitViewEnter; unitView.MouseExit = UnitViewExit; unitView.MouseOver = UnitViewOver; unitView.SetPosition(mapView.GetTileViewAt(p).GetPosition()); unitView.SetColor(Color.white); unitViews[u] = unitView; units[unitView] = u; List <string> toRemove = new List <string>(); foreach (CardView cv in cards) { if (cv.Id == c.ID) { toRemove.Add(cv.Id); } } foreach (string s in toRemove) { foreach (CardView cv in cards) { if (cv.Id == s) { cards.Remove(cv); GameObject.Destroy(cv.gameObject); break; } } } mapView.Clear(); cardLevelSheets.Remove(mediumCardView); playerActions.Add(new SummonAction(c, u.Location)); }
void Awake() { cardLevelSheets = new Dictionary <CardView, CardLevelSheet>(); basicMatchUIViewObj = (GameObject)Instantiate(BasicMatchUIViewPrefab); basicMatchUIView = (BasicMatchUIView)(basicMatchUIViewObj.GetComponent("BasicMatchUIView")); basicMatchUIView.transform.SetParent(Canvas.transform, false); map = new Map(); units = new Dictionary <UnitView, Unit>(); resultsText = (UnityEngine.UI.Text)ResultsText.GetComponent("Text"); resultsImage = (UnityEngine.UI.Image)ResultsImage.GetComponent("Image"); tilemap = (tk2dTileMap)Tilemap.GetComponent("tk2dTileMap"); mapView = (MapView)Tilemap.GetComponent("MapView"); mapView.TileViewEnter = TileOnMouseEnter; mapView.TileViewExit = TileOnMouseExit; mapView.TileViewOver = TileOnMouseOver; mapView.Initialize(); GameManager.Instance.CurrentMatchOpponentPlayerId = "ERROR_NO_PLAYER"; // player1 = new Unit("Kaiju1", // "Set1.1", // "Kaiju", // "Lizard", // "This is the level one lizard Kaiju.", // "This is the level two lizard Kaiju.", // "This is the level three lizard Kaiju.", // new Point(Player1StartX, Player1StartY)); // Vector3 player1Location = mapView.GetTileViewAt(player1.Location).GetPosition(); // UnitView player1UnitView = (UnitView)((GameObject)Instantiate (Player1Prefab)).GetComponent("UnitView"); // player1UnitView.MouseEnter = UnitViewEnter; // player1UnitView.MouseExit = UnitViewExit; // player1UnitView.MouseOver = UnitViewOver; // player1UnitView.SetPosition(player1Location); // player1UnitView.SetColor(Color.white); // unitViews[player1] = player1UnitView; // units[player1UnitView] = player1; // currentPlayer = player1; // code for UnityEngine.UI // Vector3 player1LocationNew = GetScreenPosition(Player1StartX, Player1StartY); // TODO: make Vector2D // player1UnitView.SetPosition(player1LocationNew); // player1UnitView.transform.SetParent(Canvas.transform, false); // player2 = new Unit("Mecha1", // "Set1.2", // "Mecha", // "Gundam", // "This is the level one Gundam Mecha.", // "This is the level two Gundam Mecha.", // "This is the level three Gundam Mecha.", // new Point(Player2StartX, Player2StartY)); // Vector3 player2Location = mapView.GetTileViewAt(player2.Location).GetPosition(); // UnitView player2UnitView = (UnitView)((GameObject)Instantiate (Player2Prefab)).GetComponent("UnitView"); // player2UnitView.MouseEnter = UnitViewEnter; // player2UnitView.MouseExit = UnitViewExit; // player2UnitView.MouseOver = UnitViewOver; // player2UnitView.SetPosition(player2Location); // player2UnitView.SetColor(Color.white); // unitViews[player2] = player2UnitView; // units[player2UnitView] = player2; // code for UnityEngine.UI // player2UnitView.transform.SetParent(Canvas.transform, false); if (GameManager.Instance.CurrentPlayerId == "thomas") { basicMatchUIView.SetSprite(Resources.Load <Sprite> ("thomas_selfie")); } else { basicMatchUIView.SetSprite(Resources.Load <Sprite> ("spongebob_selfie")); } basicMatchUIView.SetPlayerNameText(GameManager.Instance.CurrentPlayerId); basicMatchUIView.SetTimeText("Time: 90"); basicMatchUIView.SetManaText("0/10"); basicMatchUIView.SetManaMeter(0); Action <bool, TurnBasedMatch, string> cb = (success, match, errors) => { if (success) { string matchId = match.MatchId; Debug.Log("GridManager:Start() starting match: " + matchId); GameManager.Instance.CurrentMatchId = matchId; string status = match.Status; Debug.Log("GridManager:Start() status: " + status); GameManager.Instance.CurrentMatchStatus = status; string pendingParticipantId = match.PendingParticipantId; Debug.Log("GridManager:Awake() pendingParticipantId: " + pendingParticipantId); GameManager.Instance.CurrentPendingParticipantId = pendingParticipantId; foreach (TurnBasedMatchParticipant p in match.Participants) { string participantId = p.Player.ParticipantId; Debug.Log("GridManager:Start() participantId: " + participantId); if (participantId == GameManager.Instance.CurrentPlayerId) { GameManager.Instance.CurrentMatchPlayerId = p.Id; } else { // TODO: refactor for more than 2 players GameManager.Instance.CurrentMatchOpponentPlayerId = p.Player.ParticipantId; } } isPlayerTurn = (GameManager.Instance.CurrentMatchPlayerId == GameManager.Instance.CurrentPendingParticipantId); if (isPlayerTurn) { Debug.Log("GridManager:Awake() it's my turn!"); } else { Debug.Log("GridManager:Awake() it's the other player's turn!"); } GameManager.Instance.Hand = match.Data.Data.GetCardPile("hand"); GameManager.Instance.DrawPile = match.Data.Data.GetCardPile("draw_pile"); GameManager.Instance.DiscardPile = match.Data.Data.GetCardPile("discard_pile"); GameManager.Instance.Units = match.Data.Data.GetUnits("units"); // todo: update displayed units based on GameManager.Instance.Units data // create new UnitViews for any newly added Units // update the position of previously existing Units // index Units locally by MatchId cards = new List <CardView>(); cards.Clear(); List <Vector2> cardLocations = new List <Vector2>(); int y = -260; cardLocations.Add(new Vector2(-250, y)); cardLocations.Add(new Vector2(-140, y)); cardLocations.Add(new Vector2(0, y)); cardLocations.Add(new Vector2(120, y)); cardLocations.Add(new Vector2(250, y)); for (int i = 0; i < 5; i++) { GameObject cardGameObject = (GameObject)Instantiate(CardPrefab); CardLevelSheet card1 = new CardLevelSheet(GameManager.Instance.Hand.Get(i)); CardView cardView = (CardView)(cardGameObject.GetComponent("CardView")); cardView.Id = card1.ID; cardView.transform.SetParent(Canvas.transform, false); cardView.BeginDragDel = CardBeginDrag; cardView.EndDragDel = CardEndDrag; cardView.DragDel = CardDrag; cardView.PointerClickDel = CardPointerClick; cardView.PointerEnterDel = CardPointerEnter; cardView.PointerExitDel = CardPointerExit; cardView.SetCost(card1.Cost); cardView.SetLevel(card1.Level); cardView.SetType(card1.Type); cardView.SetSubtype(card1.Subtype); cardView.SetName(card1.Name); cardView.SetText(card1.Text); cardView.SetImage(Resources.Load <Sprite> (card1.Art)); cardView.SetRarity(card1.Rarity); cardView.SetFaction(card1.Faction); RectTransform cardRT = (RectTransform)cardGameObject.GetComponent("RectTransform"); cardRT.anchoredPosition = cardLocations[i]; cards.Add(cardView); cardLevelSheets[cardView] = card1; } } else { Debug.Log("WARN!!! match info null"); } }; StartCoroutine(Platform.Instance.GetMatchInfo(GameManager.Instance.CurrentMatchId, cb)); StartCoroutine(CheckMatchStatusLoop()); }
public SummonAction(CardLevelSheet s, Point p) : base() { LevelSheet = s; Location = p; }
private void LoadCardData(List <string> files) { Dictionary <string, CardLevelSheet> cards = new Dictionary <string, CardLevelSheet>(); foreach (String s in files) { string path = "data/" + Sandbox + "/" + Version + "/" + s; TextAsset txt = (TextAsset)Resources.Load(path, typeof(TextAsset)); string content = txt.text; string d = JSON.Parse(content).ToString(); Dictionary <string, System.Object> dict = MiniJSON.Json.Deserialize(JSON.Parse(content).ToString()) as Dictionary <string, System.Object>; foreach (string cardId in dict.Keys) { CardLevelSheet card = new CardLevelSheet((Dictionary <string, System.Object>)dict[cardId]); cards.Add(card.ID, card); } } Dictionary <string, Card> cardContainers = new Dictionary <string, Card>(); foreach (string c in cards.Keys) { try { CardLevelSheet cSheet = cards[c]; CardLevelSheet level1 = cards[c]; CardLevelSheet level2 = null; CardLevelSheet level3 = null; if (cSheet.Level == "1") { foreach (string s2 in cards.Keys) { CardLevelSheet c2 = cards[s2]; if (level1.NextID == c2.ID) { level2 = c2; break; } } foreach (string s3 in cards.Keys) { CardLevelSheet c3 = cards[s3]; if (level2.NextID == c3.ID) { level3 = c3; break; } } cardContainers.Add(level1.ID, new Card(level1, level2, level3)); } } catch (Exception e) { Debug.Log(e.ToString()); } } GameManager.Instance.CardData = cards; GameManager.Instance.Cards = cardContainers; }
public MoveAction(CardLevelSheet s, Point p) : base() { }
public void PutOnBottom(CardLevelSheet c) { // todo }
public void PutOnTop(CardLevelSheet c) { cards.Push(c); }
public Card(CardLevelSheet l1, CardLevelSheet l2, CardLevelSheet l3) { cardLevelSheets.Add(1, l1); cardLevelSheets.Add(2, l2); cardLevelSheets.Add(3, l3); }