Skip to content

DropTarget

namespace Griff.Scenes;
public sealed class DropTarget : Component

A place to drop Draggable things: a slot in an inventory, a card’s place on the table, a hole a puzzle piece fits, a bin. Something dropped on it that it Accepts lands in its middle, until it holds Capacity things. It lights up with HoverTint while something it would take is held over it.

Its shape is its collider’s, or its sprite’s if it has no collider. What rests with its middle inside that shape is on it, however it got there: dropped, placed there in the editor, or moved by a script.

This is a component: its saved properties are on its component page.

public string? Accepts { get; set; }

The kinds of thing it takes (each a draggable’s Kind), separated by commas, e.g. “Red Gem, Blue Gem”. Empty takes anything.

public string? AllFullMessage { get; set; }

A message sent once every drop target with this same All Full Message is full (holds its Capacity, or something for a Capacity of 0), with this entity as its data: every piece in place, the puzzle solved. It’s sent again if they fill up again after one is emptied.

public int Capacity { get; set; }

How many things it holds at once; more are turned away. 0 holds any number: a bin, a discard pile.

public IReadOnlyList<Entity> Contents { get; }

What’s on it, in the order they arrived.

public string? DropMessage { get; set; }

A message sent with Game.Send when something lands on it, with this entity as its data.

public Color HoverTint { get; set; }

The color its sprite turns while something it would take is held over it. Transparent leaves it alone.

public bool IsFull { get; }

True when it holds its Capacity (or, with a Capacity of 0, anything at all).

public bool Snap { get; set; }

True if things dropped on it move to its middle. Off, they stay where they’re let go on it: a play area.

public bool Swap { get; set; }

True if dropping something on it while it’s full swaps them: what was on it goes where the dropped thing came from, as in an inventory. Only with a Capacity of 1.

public string? TakeMessage { get; set; }

A message sent with Game.Send when something is taken off it, with this entity as its data.

public bool AcceptsKind(string? kind)

True if it takes things of kind kind (a draggable’s Kind).

public event Action<Entity>? Received

Raised when something lands on it.

public event Action<Entity>? Taken

Raised when something is taken off it.