Example usage for com.badlogic.gdx.utils ObjectIntMap putAll

List of usage examples for com.badlogic.gdx.utils ObjectIntMap putAll

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils ObjectIntMap putAll.

Prototype

public void putAll(ObjectIntMap<K> map) 

Source Link

Usage

From source file:com.vlaaad.dice.ui.components.CraftingPane.java

License:Open Source License

private boolean inputMatches(ObjectIntMap<Item> in, ObjectIntMap<Item> req) {
    ObjectIntMap<Item> cost = tmp2;
    cost.clear();//from   ww w  . j  av a 2s . c  o m
    cost.putAll(req);
    ObjectIntMap<Item> resources = tmp3;
    resources.clear();
    resources.putAll(in);
    for (Item item : resources.keys()) {
        int required = cost.get(item, 0);
        int existed = resources.get(item, 0);
        if (required > existed)
            return false;
        if (required == 0)
            continue;
        cost.remove(item, 0);
        resources.getAndIncrement(item, 0, -required);
    }
    if (cost.size == 0)
        return true;
    for (Item unsatisfied : cost.keys()) {
        if (unsatisfied.type != Item.Type.anyIngredient)
            return false;
        int required = cost.get(unsatisfied, 0);
        for (Item item : resources.keys()) {
            int withdrawCount = Math.min(resources.get(item, 0), required);
            if (withdrawCount == 0)
                continue;
            required -= withdrawCount;
            resources.getAndIncrement(item, 0, -withdrawCount);
            cost.getAndIncrement(unsatisfied, 0, -withdrawCount);
            if (required == 0)
                break;
        }
    }
    for (Item unsatisfied : cost.keys()) {
        if (cost.get(unsatisfied, 0) != 0)
            return false;
    }
    return true;
}