Search in sources :

Example 1 with PathfinderPluginManager

use of me.wobblyyyy.pathfinder2.plugin.PathfinderPluginManager in project Pathfinder2 by Wobblyyyy.

the class ZoneProcessor method update.

/**
 * Based on the provided point, call the correct methods of each of
 * the zones.
 *
 * <ul>
 *     <li>
 *         If the robot has ENTERED the zone (previously, it was not in
 *         the zone, but now it is), the zone's {@link Zone#onEnter(Pathfinder)}
 *         method will be called.
 *     </li>
 *     <li>
 *         If the robot has EXITED the zone (previously, it was in the zone,
 *         but now it is not), the zone's {@link Zone#onExit(Pathfinder)}
 *         method will be called.
 *     </li>
 *     <li>
 *         If the robot is INSIDE the zone (this will be activated every
 *         time the {@code onEnter} method is called, as well as whenever
 *         the robot is inside the zone), the zone's
 *         {@link Zone#whileInside(Pathfinder)} method will be called.
 *     </li>
 * </ul>
 *
 * @param pathfinder the instance of Pathfinder.
 */
public void update(Pathfinder pathfinder) {
    if (zones.size() == 0)
        return;
    PathfinderPluginManager manager = pathfinder.getPluginManager();
    List<Zone> lastZones = currentZones;
    currentZones = getContainingZones(pathfinder.getPosition());
    List<Zone> enteredZones = getEnteredZones(lastZones, currentZones);
    List<Zone> exitedZones = getExitedZones(lastZones, currentZones);
    for (Zone zone : enteredZones) {
        zone.onEnter(pathfinder);
        manager.onEnterZone(pathfinder, zone);
    }
    for (Zone zone : currentZones) {
        zone.whileInside(pathfinder);
        manager.whileInsideZone(pathfinder, zone);
    }
    for (Zone zone : exitedZones) {
        zone.onExit(pathfinder);
        manager.onExitZone(pathfinder, zone);
    }
}
Also used : PathfinderPluginManager(me.wobblyyyy.pathfinder2.plugin.PathfinderPluginManager)

Aggregations

PathfinderPluginManager (me.wobblyyyy.pathfinder2.plugin.PathfinderPluginManager)1