1
0
mirror of https://github.com/demodude4u/Factorio-FBSR.git synced 2024-11-24 08:12:21 +02:00

Belt rendering for 0.17

This commit is contained in:
Weston Rye (Demod) 2019-02-28 23:14:51 -05:00
parent c42466fc82
commit f7b9dea20e
3 changed files with 48 additions and 74 deletions

View File

@ -23,6 +23,7 @@ import com.demod.fbsr.Renderer;
import com.demod.fbsr.Renderer.Layer;
import com.demod.fbsr.Sprite;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.WorldMap.BeltBend;
public class SplitterRendering extends EntityRendererFactory {
@ -37,18 +38,7 @@ public class SplitterRendering extends EntityRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
EntityPrototype prototype) {
int[] beltSpriteMapping = TransportBeltRendering.transportBeltSpriteMapping[entity.getDirection()
.cardinal()][1];
Sprite belt1Sprite = RenderUtils.getSpriteFromAnimation(prototype.lua().get("belt_horizontal"));
belt1Sprite.source.y = belt1Sprite.source.height * beltSpriteMapping[0];
if (beltSpriteMapping[1] == 1) {
belt1Sprite.source.x += belt1Sprite.source.width;
belt1Sprite.source.width *= -1;
}
if (beltSpriteMapping[2] == 1) {
belt1Sprite.source.y += belt1Sprite.source.height;
belt1Sprite.source.height *= -1;
}
Sprite belt1Sprite = TransportBeltRendering.getBeltSprite(prototype, entity.getDirection(), BeltBend.NONE);
Sprite belt2Sprite = new Sprite(belt1Sprite);
Point2D.Double beltShift = entity.getDirection().left().offset(new Point2D.Double(), 0.5);

View File

@ -19,14 +19,22 @@ import com.demod.fbsr.WorldMap.BeltBend;
public class TransportBeltRendering extends EntityRendererFactory {
public static final int[][][] transportBeltSpriteMapping = //
new int[/* Cardinal */][/* Bend */][/* SXY */] { //
{ { 8, 1, 0 }, { 1, 0, 0 }, { 8, 0, 0 } }, // North
{ { 9, 0, 0 }, { 0, 0, 0 }, { 11, 0, 0 } }, // East
{ { 10, 1, 0 }, { 1, 0, 1 }, { 10, 0, 0 } }, // South
{ { 11, 1, 0 }, { 0, 1, 0 }, { 9, 1, 0 } }, // West
public static final String[][] transportBeltIndexName = //
new String[/* Cardinal */][/* Bend */] { //
{ "west_to_north_index", "north_index", "east_to_north_index" }, // North
{ "north_to_east_index", "east_index", "south_to_east_index" }, // East
{ "east_to_south_index", "south_index", "west_to_south_index" }, // South
{ "south_to_west_index", "west_index", "north_to_west_index" }, // West
};
// public static final int[][][] transportBeltSpriteMapping = //
// new int[/* Cardinal */][/* Bend */][/* SXY */] { //
// { { 8, 1, 0 }, { 1, 0, 0 }, { 8, 0, 0 } }, // North
// { { 9, 0, 0 }, { 0, 0, 0 }, { 11, 0, 0 } }, // East
// { { 10, 1, 0 }, { 1, 0, 1 }, { 10, 0, 0 } }, // South
// { { 11, 1, 0 }, { 0, 1, 0 }, { 9, 1, 0 } }, // West
// };
// XXX I'm not using horizontal or vertical frames
public static final int[][] transportBeltConnectorFrameMappingIndex = //
new int[/* Cardinal */][/* Bend */] { //
@ -36,26 +44,20 @@ public class TransportBeltRendering extends EntityRendererFactory {
{ 4, 0, 6 }, // West
};
public static Sprite getBeltSprite(EntityPrototype prototype, Direction direction, BeltBend bend) {
LuaValue anim = prototype.lua().get("belt_animation_set");
Sprite sprite = RenderUtils.getSpriteFromAnimation(anim.get("animation_set"));
int spriteIndex = anim.get(transportBeltIndexName[direction.cardinal()][bend.ordinal()]).toint();
sprite.source.y = sprite.source.height * (spriteIndex - 1);
return sprite;
}
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
EntityPrototype prototype) {
BeltBend bend = map.getBeltBend(entity.getPosition()).get();
int[] spriteMapping = transportBeltSpriteMapping[entity.getDirection().cardinal()][bend.ordinal()];
LuaValue anim = prototype.lua().get("animations");
Sprite sprite = RenderUtils.getSpriteFromAnimation(anim);
int frameCount = anim.get("frame_count").toint();
int lineLength = anim.get("line_length").optint(frameCount);
int offsetMultiplier = frameCount / lineLength;
sprite.source.y = sprite.source.height * spriteMapping[0] * offsetMultiplier;
if (spriteMapping[1] == 1) {
sprite.source.x += sprite.source.width;
sprite.source.width *= -1;
}
if (spriteMapping[2] == 1) {
sprite.source.y += sprite.source.height;
sprite.source.height *= -1;
}
Sprite sprite = getBeltSprite(prototype, entity.getDirection(), bend);
register.accept(RenderUtils.spriteRenderer(sprite, entity, prototype));

View File

@ -3,8 +3,6 @@ package com.demod.fbsr.entity;
import java.awt.geom.Point2D;
import java.util.function.Consumer;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
@ -15,54 +13,38 @@ import com.demod.fbsr.Renderer;
import com.demod.fbsr.Renderer.Layer;
import com.demod.fbsr.Sprite;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.WorldMap.BeltBend;
public class UndergroundBeltRendering extends EntityRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
EntityPrototype prototype) {
// LuaUtils.debugPrintTable("", prototype.lua());
// System.exit(1);
boolean input = entity.json().getString("type").equals("input");
Direction structDir = input ? entity.getDirection() : entity.getDirection().back();
int[] beltSpriteMapping = TransportBeltRendering.transportBeltSpriteMapping[entity.getDirection()
.cardinal()][1];
LuaValue beltAnim = prototype.lua().get("belt_horizontal");
Sprite beltSprite = RenderUtils.getSpriteFromAnimation(beltAnim);
int frameCount = beltAnim.get("frame_count").toint();
int lineLength = beltAnim.get("line_length").optint(frameCount);
int offsetMultiplier = frameCount / lineLength;
beltSprite.source.y = beltSprite.source.height * beltSpriteMapping[0] * offsetMultiplier;
if (beltSpriteMapping[1] == 1) {
beltSprite.source.x += beltSprite.source.width;
beltSprite.source.width *= -1;
}
if (beltSpriteMapping[2] == 1) {
beltSprite.source.y += beltSprite.source.height;
beltSprite.source.height *= -1;
}
switch (structDir) {
case NORTH:
beltSprite.source.height /= 2;
beltSprite.source.y += beltSprite.source.height;
beltSprite.bounds.height /= 2;
beltSprite.bounds.y += beltSprite.bounds.height;
break;
case WEST:
beltSprite.source.width /= 2;
beltSprite.source.x += beltSprite.source.width;
beltSprite.bounds.width /= 2;
beltSprite.bounds.x += beltSprite.bounds.width;
break;
case EAST:
beltSprite.source.width /= 2;
beltSprite.bounds.width /= 2;
break;
default:
break;
}
Sprite beltSprite = TransportBeltRendering.getBeltSprite(prototype, entity.getDirection(), BeltBend.NONE);
// switch (structDir) {
// case NORTH:
// beltSprite.source.height /= 2;
// beltSprite.source.y += beltSprite.source.height;
// beltSprite.bounds.height /= 2;
// beltSprite.bounds.y += beltSprite.bounds.height;
// break;
// case WEST:
// beltSprite.source.width /= 2;
// beltSprite.source.x += beltSprite.source.width;
// beltSprite.bounds.width /= 2;
// beltSprite.bounds.x += beltSprite.bounds.width;
// break;
// case EAST:
// beltSprite.source.width /= 2;
// beltSprite.bounds.width /= 2;
// break;
// default:
// break;
// }
Sprite sprite = RenderUtils.getSpriteFromAnimation(
prototype.lua().get("structure").get(input ? "direction_in" : "direction_out").get("sheet"));