Something went wrong. Try again.
A card game engine for Magic: The Gathering inspired by Card Forge
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192using Godot;using System;using Godot.Collections;
[GlobalClass]public partial class CardUI : Control{ public ColorRect color; public Label state; public Area2D dropDetector; public CardStateMachine cardStateMachine; public CardZone.ZoneType targetedZone; public CardZone.ZoneType currentZone; public Dictionary<String, String> data; public bool tapped;
[Signal] public delegate void ReparentRequestedEventHandler(CardUI whichCardUI); public override void _Ready() { color = GetNode<ColorRect>("Color"); state = GetNode<Label>("State"); dropDetector = GetNode<Area2D>("DropDetector"); cardStateMachine = GetNode<CardStateMachine>("CardStateMachine"); cardStateMachine.Init(this); Node topLayer = GetTree().GetFirstNodeInGroup("top_layer");
if (!IsInstanceIdValid(topLayer.GetInstanceId())) { GD.PrintErr(["Unable to find top layer node:", topLayer]); }
if (topLayer is Main mainNode) { this.ReparentRequested += mainNode.OnReparentRequested; } else { GD.PrintErr(["Top node is not type Main:", topLayer]); } }
public override void _Process(double delta) { base._Process(delta); }
public override void _Input(InputEvent @event) { base._Input(@event); cardStateMachine.OnInput(@event); }
public void OnGuiInput(InputEvent @event) { cardStateMachine.OnGuiInput(@event); }
public void OnMouseEntered() { cardStateMachine.OnMouseEntered(); }
public void OnMouseExited() { cardStateMachine.OnMouseExited(); }
public void OnDropDetectorEntered(Area2D area) { if (area is CardZone zone) { this.targetedZone = zone.type; } else { this.targetedZone = CardZone.ZoneType.None; } }
public void OnDropDetectorExited(Area2D area) { }
public bool CanBePlayed(CardZone.ZoneType zoneType) { return zoneType == CardZone.ZoneType.Battlefield; }}