Example usage for com.badlogic.gdx.utils ObjectSet contains

List of usage examples for com.badlogic.gdx.utils ObjectSet contains

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils ObjectSet contains.

Prototype

public boolean contains(T key) 

Source Link

Usage

From source file:com.github.antag99.retinazer.FamilyConfig.java

License:Open Source License

@SafeVarargs
public final FamilyConfig with(Class<? extends Component>... componentTypes) {
    ObjectSet<Class<? extends Component>> newComponents = new ObjectSet<>();
    newComponents.addAll(components);//from  w  w w.  j  ava  2  s.c  o m
    for (Class<? extends Component> componentType : componentTypes) {
        if (newComponents.contains(componentType))
            throw new IllegalArgumentException(componentType.getName());
        if (excludedComponents.contains(componentType))
            throw new IllegalArgumentException(componentType.getName());
        newComponents.add(componentType);
    }
    this.components = newComponents;
    return this;
}

From source file:com.github.antag99.retinazer.FamilyConfig.java

License:Open Source License

@SafeVarargs
public final FamilyConfig exclude(Class<? extends Component>... componentTypes) {
    ObjectSet<Class<? extends Component>> newExcludedComponents = new ObjectSet<>();
    newExcludedComponents.addAll(excludedComponents);
    for (Class<? extends Component> componentType : componentTypes) {
        if (newExcludedComponents.contains(componentType))
            throw new IllegalArgumentException(componentType.getName());
        if (components.contains(componentType))
            throw new IllegalArgumentException(componentType.getName());
        newExcludedComponents.add(componentType);
    }//from  www .j a  v  a 2 s  . c o  m
    this.excludedComponents = newExcludedComponents;
    return this;
}

From source file:com.matthewmichelotti.collider.demos.comps.CElastic.java

License:Apache License

private boolean collideIteration(ObjectSet<Component> visitedSet) {
    visitedSet.add(this);
    boolean changed = false;
    for (Component c : overlaps) {
        if (visitedSet.contains(c))
            continue;
        changed |= elasticCollision(c);/*from ww w  .  j  av  a2 s  .  co m*/
    }
    for (Component c : overlaps) {
        if (c instanceof CElastic) {
            if (visitedSet.contains(c))
                continue;
            changed |= ((CElastic) c).collideIteration(visitedSet);
        }
    }
    return changed;
}

From source file:com.vlaaad.dice.game.actions.imp.ChainLightning.java

License:Open Source License

private IActionResult calcResult(Ability ability, Creature caster, Creature target, World world) {
    ObjectSet<Creature> affected = tmpSet;
    Array<Creature> chain = new Array<Creature>();
    chain.add(target);//  www.  j  av  a  2s  .  c  o m
    affected.add(target);

    // i == 1 because we already have initial target
    RandomController random = world.getController(RandomController.class);

    for (int i = 1; i < targets; i++) {
        Creature last = chain.peek();
        tmpArray2.clear();
        Array<Creature> neighbours = getNeighbourCreatures(world, last.getX(), last.getY(), tmpArray2);
        Iterator<Creature> it = neighbours.iterator();
        while (it.hasNext()) {
            Creature toCheck = it.next();
            if (affected.contains(toCheck))
                it.remove();
        }
        if (neighbours.size == 0) {
            break;
        } else if (neighbours.size == 1) {
            addToChain(affected, chain, neighbours.first());
        } else {
            Array<Creature> betterTargets = tmpArray3;
            betterTargets.clear();
            for (Creature toCheck : neighbours) {
                if (toCheck.get(Attribute.defenceFor(attackType)) < attackLevel) {
                    betterTargets.add(toCheck);
                }
            }
            if (betterTargets.size > 0) {
                addToChain(affected, chain, random.random(betterTargets));
            } else {
                addToChain(affected, chain, random.random(neighbours));
            }
        }
    }

    ObjectIntMap<Creature> expResults = new ObjectIntMap<Creature>();
    Array<Creature> killed = new Array<Creature>();

    for (Creature creature : chain) {
        if (creature.get(Attribute.defenceFor(attackType)) < attackLevel) { // killed
            if (creature.player != caster.player) {
                expResults.getAndIncrement(caster, 0, ExpHelper.expForKill(caster, creature));
            }
            killed.add(creature);
        } else { // survived
            expResults.put(creature, ExpHelper.expForDefence(caster, creature));
        }
    }

    tmpSet.clear();
    tmpArray2.clear();
    tmpArray3.clear();

    return new ChainLightningResult(caster, ability, chain, killed, expResults);
}

From source file:com.vlaaad.dice.game.world.behaviours.processors.user.UserTurnProcessor.java

License:Open Source License

@Override
public IFuture<TurnResponse> process(final TurnParams params) {
    final Future<TurnResponse> future = new Future<TurnResponse>();
    final World world = params.creature.world;
    this.world = world;
    final Creature creature = params.creature;
    final UiController ui = world.getController(UiController.class);
    final ObjectSet<Grid2D.Coordinate> available = new ObjectSet<Grid2D.Coordinate>();
    available.addAll(params.availableCells);

    clickListener = new ClickListener() {
        @Override/*  w  w w  .j  ava 2  s .  com*/
        public void clicked(InputEvent event, float x, float y) {
            if (event.isCancelled())
                return;
            Vector2 c = world.getController(ViewController.class)
                    .stageToWorldCoordinates(new Vector2(event.getStageX(), event.getStageY()));
            final Grid2D.Coordinate coordinate = new Grid2D.Coordinate((int) c.x, (int) c.y);
            if (available.contains(coordinate)) {
                world.stage.removeListener(this);
                final ClickListener mainListener = this;
                confirm = new Image(Config.skin, "selection/turn-confirmation");
                back = new Tile("selection/turn-confirmation-background");
                confirm.setPosition(coordinate.x() * ViewController.CELL_SIZE,
                        coordinate.y() * ViewController.CELL_SIZE);
                back.setPosition(confirm.getX(), confirm.getY());
                world.getController(ViewController.class).notificationLayer.addActor(confirm);
                world.getController(ViewController.class).selectionLayer.addActor(back);
                confirmListener = new ClickListener() {
                    @Override
                    public void clicked(InputEvent event, float x, float y) {
                        if (event.isCancelled())
                            return;
                        Vector2 cell = world.getController(ViewController.class)
                                .stageToWorldCoordinates(new Vector2(event.getStageX(), event.getStageY()));
                        confirm.remove();
                        back.remove();
                        world.stage.removeListener(this);
                        if (coordinate.x() == (int) cell.x && coordinate.y() == (int) cell.y) {
                            UserTurnProcessor.this.cancel();
                            future.happen(new TurnResponse<Grid2D.Coordinate>(TurnResponse.TurnAction.MOVE,
                                    coordinate));
                        } else {
                            world.stage.addListener(mainListener);
                            mainListener.clicked(event, x, y);
                        }
                    }
                };
                world.stage.addListener(confirmListener);
            }
        }
    };
    world.stage.addListener(clickListener);

    Array<Ability> professionAbilities = creature.description.profession
            .getAvailableAbilities(creature.getCurrentLevel());
    boolean professionTutorial = false;
    if (professionAbilities.size > 0) {
        for (Ability ability : professionAbilities) {
            ProfessionAbilityIcon icon = ui.getProfessionIcon(ability);
            icon.addListener(createListener(ability, creature, clickListener, world, future));
        }
        if (!world.viewer.tutorialProvider.isProfessionAbilitiesTutorialCompleted()) {
            professionTutorial = true;
            Tutorial.whenAllTutorialsEnded(new Runnable() {
                @Override
                public void run() {
                    Tutorial.TutorialResources resources = Tutorial.resources()
                            .with("tutorial-provider", world.viewer.tutorialProvider).with("world", world)
                            .with("stage", world.stage);
                    new Tutorial(resources, DiceTutorial.professionAbilitiesTasks()).start();
                }
            });
        }
    }
    if (!professionTutorial && !world.viewer.tutorialProvider.isPlayPotionsTutorialCompleted()
            && world.viewer.hasPotions()) {
        Tutorial.whenAllTutorialsEnded(new Runnable() {
            @Override
            public void run() {
                Tutorial.TutorialResources resources = Tutorial.resources()
                        .with("tutorial-provider", world.viewer.tutorialProvider).with("world", world)
                        .with("stage", world.stage);
                new Tutorial(resources, DiceTutorial.playPotionsTasks()).start();
            }
        });
    }
    if (ui != null) {
        ui.potionsButton.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                new PotionsPlayWindow()
                        .show(new PotionsPlayWindow.Params(creature, world, new PotionsPlayWindow.Callback() {
                            @Override
                            public void usePotion(Ability potion, Potion.ActionType action) {
                                UserTurnProcessor.this.cancel();
                                future.happen(new TurnResponse<Tuple2<Ability, Potion.ActionType>>(
                                        TurnResponse.TurnAction.POTION, Tuple2.make(potion, action)));
                            }
                        }));
            }
        });
    }

    return future;
}

From source file:com.vlaaad.dice.game.world.util.DistanceFiller.java

License:Open Source License

private static void addNeighbour(World world, int x, int y, ObjectSet<Coordinate> checked,
        ObjectSet<Coordinate> toCheck) {
    if (!world.inBounds(x, y) || !world.level.exists(LevelElementType.tile, x, y))
        return;/*from www .j  a v a  2s . com*/
    Coordinate coordinate = Coordinate.obtain(x, y);
    if (checked.contains(coordinate)) {
        coordinate.free();
        return;
    }
    toCheck.add(coordinate);

}

From source file:com.vlaaad.dice.services.GameServicesMultiplayer.java

License:Open Source License

@SuppressWarnings("unchecked")
public void loadInvitations(InvitationBuffer invitations) {
    ObjectSet<String> tmp = Pools.obtain(ObjectSet.class);
    tmp.addAll(invites);//from   w w w  .j  ava  2 s. c o m
    invites.clear();
    for (Invitation invitation : invitations) {
        invites.add(invitation.getInvitationId());
        if (!tmp.contains(invitation.getInvitationId())) {
            showInvitation(invitation);
        }
    }
    tmp.clear();
    Pools.free(tmp);
    Gdx.app.postRunnable(new Runnable() {
        @Override
        public void run() {
            invitesDispatcher.setState(invites.size);
        }
    });
}

From source file:com.vlaaad.dice.ui.windows.DieSettingsWindow.java

License:Open Source License

@Override
protected void doShow(final Params params) {
    Table content = new Table(Config.skin);
    content.setBackground("ui-store-window-background");
    content.defaults().pad(4);//from   www.jav a  2 s .  co m
    content.setTouchable(Touchable.enabled);

    final LocLabel infoLabel = new LocLabel(
            "ui-renames-left", Thesaurus.params().with("count", String.valueOf(params.die.renames))
                    .with("free-renames", "free-renames." + Thesaurus.Util.countForm(params.die.renames)),
            StoreWindow.INACTIVE);
    infoLabel.setWrap(true);
    infoLabel.setAlignment(Align.center);

    final StringSpin nameSpin = new StringSpin(4, 10, Config.thesaurus.localize(params.die.nameLocKey()));
    Container inner = new Container(nameSpin);
    inner.padTop(3);
    final Container nameContainer = new Container(inner);
    nameContainer.setBackground(Config.skin.getDrawable("ui/button/name-change-background"));
    final Button changeNameButton = new Button(Config.skin);
    final Thesaurus thesaurus = Config.assetManager.get("names.yml", Thesaurus.class);
    final Array<ThesaurusData> values = thesaurus.values();
    final Item coin = Config.items.get("coin");
    updateChangeNameButton(changeNameButton, params);
    changeNameButton.addListener(new ChangeListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            ObjectSet<ThesaurusData> existingNames = Pools.obtain(ObjectSet.class);
            for (Die die : params.userData.dice()) {
                existingNames.add(thesaurus.getData(die.name.toLowerCase()));
            }
            ThesaurusData newName = values.random();
            while (existingNames.contains(newName)) {
                newName = values.random();
            }
            existingNames.clear();
            Pools.free(existingNames);
            final ThesaurusData chosenName = newName;
            changeNameButton.setDisabled(true);
            nameSpin.setText(Config.thesaurus.localize(newName.key), new Runnable() {
                @Override
                public void run() {
                    params.die.name = chosenName.key;
                    if (params.die.renames > 0) {
                        params.die.renames -= 1;
                        infoLabel.setParams(Thesaurus.params().with("count", String.valueOf(params.die.renames))
                                .with("free-renames",
                                        "free-renames." + Thesaurus.Util.countForm(params.die.renames)));
                    } else {
                        params.userData.incrementItemCount(coin, -1);
                    }
                    updateChangeNameButton(changeNameButton, params);
                    fire(RefreshEvent.INSTANCE);
                }
            });
        }
    });

    content.add(new LocLabel("ui-select-die-name")).row();
    content.add(new Tile("ui-creature-info-line")).width(80).padTop(0).row();
    content.add(nameContainer).size(70, 21).row();
    content.add(changeNameButton).size(100, 21).padBottom(0).row();
    content.add(infoLabel).width(110).row();

    table.add(content);
}