Search in sources :

Example 1 with Layer

use of com.demod.fbsr.Renderer.Layer in project Factorio-FBSR by demodude4u.

the class RenderUtils method spriteRenderer.

public static EntityRenderer spriteRenderer(Layer layer, List<Sprite> sprites, BlueprintEntity entity, EntityPrototype prototype) {
    Point2D.Double pos = entity.getPosition();
    RenderUtils.shiftSprites(sprites, pos);
    Map<Boolean, List<Sprite>> groupedSprites = sprites.stream().collect(Collectors.partitioningBy(sprite -> sprite.shadow));
    // Rectangle2D.Double groundBounds =
    // Utils.parseRectangle(prototype.lua().get("collision_box"));
    Rectangle2D.Double groundBounds = Utils.parseRectangle(prototype.lua().get("selection_box"));
    groundBounds.x += pos.x;
    groundBounds.y += pos.y;
    return new EntityRenderer(layer, groundBounds) {

        @SuppressWarnings("unused")
        private void debugShowBounds(Rectangle2D.Double groundBounds, Graphics2D g) {
            long x = Math.round(groundBounds.getCenterX() * 2);
            long y = Math.round(groundBounds.getCenterY() * 2);
            long w = Math.round(groundBounds.width * 2);
            long h = Math.round(groundBounds.height * 2);
            // System.out.println("x=" + x + " y=" + y + " w=" + w + "
            // h=" + h);
            g.setColor(new Color(255, 255, 255, 64));
            g.draw(groundBounds);
            if (((w / 2) % 2) == (x % 2)) {
                g.setColor(new Color(255, 0, 0, 64));
                g.fill(groundBounds);
            }
            if (((h / 2) % 2) == (y % 2)) {
                g.setColor(new Color(0, 255, 0, 64));
                g.fill(groundBounds);
            }
        }

        @Override
        public void render(Graphics2D g) {
            for (Sprite sprite : groupedSprites.get(false)) {
                drawSprite(sprite, g);
            // debugShowBounds(groundBounds, g);
            }
        }

        @Override
        public void renderShadows(Graphics2D g) {
            for (Sprite sprite : groupedSprites.get(true)) {
                drawSprite(sprite, g);
            }
        }
    };
}
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) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Graphics2D(java.awt.Graphics2D) Point2D(java.awt.geom.Point2D) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 2 with Layer

use of com.demod.fbsr.Renderer.Layer in project Factorio-FBSR by demodude4u.

the class StraightRailRendering method createRenderers.

@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
    String railName = railNames[entity.getDirection().ordinal()];
    LuaValue pictureRailLua = prototype.lua().get("pictures").get(railName);
    for (Entry<String, Layer> entry : railLayers.entrySet()) {
        Sprite railLayerSprite = RenderUtils.getSpriteFromAnimation(pictureRailLua.get(entry.getKey()));
        register.accept(RenderUtils.spriteRenderer(entry.getValue(), railLayerSprite, entity, prototype));
    }
}
Also used : Sprite(com.demod.fbsr.Sprite) LuaValue(org.luaj.vm2.LuaValue) Layer(com.demod.fbsr.Renderer.Layer)

Example 3 with Layer

use of com.demod.fbsr.Renderer.Layer in project Factorio-FBSR by demodude4u.

the class CurvedRailRendering method createRenderers.

@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
    String railName = railNames[entity.getDirection().ordinal()];
    LuaValue pictureRailLua = prototype.lua().get("pictures").get(railName);
    for (Entry<String, Layer> entry : StraightRailRendering.railLayers.entrySet()) {
        Sprite railLayerSprite = RenderUtils.getSpriteFromAnimation(pictureRailLua.get(entry.getKey()));
        register.accept(RenderUtils.spriteRenderer(entry.getValue(), railLayerSprite, entity, prototype));
    }
}
Also used : Sprite(com.demod.fbsr.Sprite) LuaValue(org.luaj.vm2.LuaValue) Layer(com.demod.fbsr.Renderer.Layer)

Aggregations

Layer (com.demod.fbsr.Renderer.Layer)3 LuaValue (org.luaj.vm2.LuaValue)3 Sprite (com.demod.fbsr.Sprite)2 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 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