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);
}
}
};
}
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));
}
}
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));
}
}
Aggregations