Something went wrong. Try again.
A card game engine for Magic: The Gathering inspired by Card Forge
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111using Godot;using System;
public partial class Main : Control{ private Node hand; private Node library; private Node exile; private Node graveyard; private Node command; private Node battlefield;
public override void _Ready() { base._Ready(); hand = GetNode<Node>("MainUI/Hand"); library = GetNode<Node>("MainUI/Library"); graveyard = GetNode<Node>("MainUI/Graveyard"); exile = GetNode<Node>("MainUI/Exile"); command = GetNode<Node>("MainUI/Command"); battlefield = GetNode<Node>("MainUI/Battlefield"); }
private void reparentZone(CardUI card, Node which) { if (which is Pile pile) { card.CallDeferred("reparent", [pile.zone.cardHolder]); card.SetGlobalPosition(pile.center); } }
private void reparentToZone(CardUI card, CardZone.ZoneType zoneType) { if (zoneType == CardZone.ZoneType.Command) { reparentZone(card, command); } else if (zoneType == CardZone.ZoneType.Exile) { reparentZone(card, exile); } else if (zoneType == CardZone.ZoneType.Graveyard) { reparentZone(card, graveyard); } else if (zoneType == CardZone.ZoneType.Library) { reparentZone(card, library); } }
public void OnReparentRequested(CardUI card) { if (card.currentZone == CardZone.ZoneType.None) { card.currentZone = CardZone.ZoneType.Hand; } if (card.targetedZone == CardZone.ZoneType.None) { card.targetedZone = card.currentZone; } switch (card.targetedZone) { case CardZone.ZoneType.Hand: if (hand is HBoxContainer container) { card.CallDeferred("reparent", [container]); }
break; case CardZone.ZoneType.Library: case CardZone.ZoneType.Command: case CardZone.ZoneType.Graveyard: case CardZone.ZoneType.Exile: reparentToZone(card, card.targetedZone); break; case CardZone.ZoneType.Battlefield: try { if (card.data["type"].Contains("land")) { Node lands = battlefield.GetNode<Node>("Cards/Lands"); card.CallDeferred("reparent", lands); } else { Node nonLands = battlefield.GetNode<Node>("Cards/NonLands"); card.CallDeferred("reparent", nonLands); } } catch { Node nonLands = battlefield.GetNode<Node>("Cards/NonLands"); card.CallDeferred("reparent", nonLands); }
break; }
card.currentZone = card.targetedZone; }
public void OnMoveCard(CardUI card, CardZone.ZoneType zone) { GD.Print($"Moving card {card} to zone {zone}"); }}