Search in sources :

Example 1 with Utils

use of com.demod.factorio.Utils in project Factorio-FBSR by demodude4u.

the class RenderUtils method getModules.

public static Optional<Multiset<String>> getModules(BlueprintEntity entity, DataTable table) {
    if (!entity.json().has("items")) {
        return Optional.empty();
    }
    Multiset<String> modules = LinkedHashMultiset.create();
    Object itemsJson = entity.json().get("items");
    if (itemsJson instanceof JSONObject) {
        Utils.forEach(entity.json().getJSONObject("items"), (String itemName, Integer count) -> {
            modules.add(itemName, count);
        });
    } else if (itemsJson instanceof JSONArray) {
        Utils.<JSONObject>forEach(entity.json().getJSONArray("items"), j -> {
            modules.add(j.getString("item"), j.getInt("count"));
        });
    }
    modules.entrySet().removeIf(e -> {
        Optional<ItemPrototype> item = table.getItem(e.getElement());
        return !item.isPresent() || !item.get().getType().equals("module");
    });
    return Optional.of(modules);
}
Also used : Color(java.awt.Color) Rectangle(java.awt.Rectangle) Point2D(java.awt.geom.Point2D) Multiset(com.google.common.collect.Multiset) Rectangle2D(java.awt.geom.Rectangle2D) DataTable(com.demod.factorio.DataTable) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) ImmutableList(com.google.common.collect.ImmutableList) Graphics2D(java.awt.Graphics2D) Map(java.util.Map) LinkedHashMultiset(com.google.common.collect.LinkedHashMultiset) Layer(com.demod.fbsr.Renderer.Layer) Stroke(java.awt.Stroke) TilePrototype(com.demod.factorio.prototype.TilePrototype) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) DecimalFormat(java.text.DecimalFormat) AffineTransform(java.awt.geom.AffineTransform) Collectors(java.util.stream.Collectors) Path2D(java.awt.geom.Path2D) ItemPrototype(com.demod.factorio.prototype.ItemPrototype) List(java.util.List) Utils(com.demod.factorio.Utils) FactorioData(com.demod.factorio.FactorioData) LuaValue(org.luaj.vm2.LuaValue) Optional(java.util.Optional) BasicStroke(java.awt.BasicStroke) EntityPrototype(com.demod.factorio.prototype.EntityPrototype) JSONArray(org.json.JSONArray) ItemPrototype(com.demod.factorio.prototype.ItemPrototype) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject)

Aggregations

DataTable (com.demod.factorio.DataTable)1 FactorioData (com.demod.factorio.FactorioData)1 Utils (com.demod.factorio.Utils)1 EntityPrototype (com.demod.factorio.prototype.EntityPrototype)1 ItemPrototype (com.demod.factorio.prototype.ItemPrototype)1 TilePrototype (com.demod.factorio.prototype.TilePrototype)1 Layer (com.demod.fbsr.Renderer.Layer)1 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedHashMultiset (com.google.common.collect.LinkedHashMultiset)1 Multiset (com.google.common.collect.Multiset)1 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 Stroke (java.awt.Stroke)1 AffineTransform (java.awt.geom.AffineTransform)1 Path2D (java.awt.geom.Path2D)1 Point2D (java.awt.geom.Point2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1