public class BlockLinkChecker
extends java.lang.Object
BlockLinkChecker determines if two Block objects can connect. In particular,
BlockLinkChecker will report which sockets of the two Block objects can connect.
Interested Block objects may make a static call to canLink() to determine if it can link to another
Block object.
BlockLinkChecker uses a list of LinkRules to check the Connectors of each
Block. Rules may be added, inserted, and removed from the checker.
There is only one instance of the BlockLinkChecker.| Constructor and Description |
|---|
BlockLinkChecker() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addRule(Workspace workspace,
LinkRule rule)
Adds a rule to the end of this checker's list of rules.
|
static BlockLink |
canLink(Workspace workspace,
Block block1,
Block block2,
BlockConnector con1,
BlockConnector con2)
Returns a BlockLink instance if the two specified blocks can connect at the specified
block connectors at each block; null if no link is possible.
|
static BlockLink |
getLink(Workspace workspace,
RenderableBlock rblock1,
java.lang.Iterable<RenderableBlock> otherBlocks)
Checks to see if a
RenderableBlocks can connect to other RenderableBlocks. |
static BlockConnector |
getPlugEquivalent(Block b) |
static java.lang.Iterable<BlockConnector> |
getSocketEquivalents(Block b) |
static BlockLink |
getWeakLink(Workspace workspace,
RenderableBlock rblock1,
java.lang.Iterable<RenderableBlock> otherBlocks)
NOTE: ALWAYS prefer BlockLinkChecker.getLink over this method.
|
static boolean |
hasPlugEquivalent(Block b) |
static void |
insertRule(LinkRule rule,
int index)
Insert rule at the specified index in this checker's list of rules.
|
static void |
printRules()
Prints to the console all the rules this LinkChecker currently supports.
|
static void |
removeRule(LinkRule rule)
Removes the specified rule from the rule list
|
static void |
reset()
Clears all the rules within this.
|
public static void reset()
public static void addRule(Workspace workspace, LinkRule rule)
rule - the desired LinkRule to be addedpublic static void insertRule(LinkRule rule, int index)
rule - the desired rule to insertindex - the index to insert the rule inpublic static void removeRule(LinkRule rule)
rule - the desired LinkRule to removepublic static BlockLink canLink(Workspace workspace, Block block1, Block block2, BlockConnector con1, BlockConnector con2)
workspace - The workspace in useblock1 - Block instance to compareblock2 - Block instance to comparecon1 - the BlockConnector at block1 to compare against con2con2 - the BlockConnector at block2 to compare against con1public static BlockLink getLink(Workspace workspace, RenderableBlock rblock1, java.lang.Iterable<RenderableBlock> otherBlocks)
RenderableBlocks can connect to other RenderableBlocks.
This would mean that they have BlockConnectors that satisfy at least one of the LinkRules,
and that these sockets are in close proximity.workspace - The workspace in userblock1 - one of the blocks to checkotherBlocks - the other blocks to check againstBlockLink object that gives the two closest matching BlockConnectors in these blocks,
or null if no such matching exists.public static BlockLink getWeakLink(Workspace workspace, RenderableBlock rblock1, java.lang.Iterable<RenderableBlock> otherBlocks)
RenderableBlocks can connect
to other RenderableBlocks, implying that rblock1
has at least one BlockConnectors that satisfies at
least one of the LinkRules.
Does not require close proximity.workspace - The workspace in userblock1 - one of the blocks to checkotherBlocks - the other blocks to check againstBlockLink object that gives the two closest matching BlockConnectors in these blocks,
or null if no such matching exists.public static boolean hasPlugEquivalent(Block b)
public static BlockConnector getPlugEquivalent(Block b)
public static java.lang.Iterable<BlockConnector> getSocketEquivalents(Block b)
public static void printRules()