WIP animated gas

This commit is contained in:
Anuken
2021-11-26 21:35:58 -05:00
parent 616fa8748f
commit 77b3a83826
43 changed files with 194 additions and 18 deletions
@@ -20,6 +20,7 @@ import mindustry.world.blocks.*;
import mindustry.world.blocks.distribution.*;
import static mindustry.Vars.*;
import static mindustry.type.Liquid.*;
public class Conduit extends LiquidBlock implements Autotiler{
public final int timerFlow = timers++;
@@ -28,8 +29,13 @@ public class Conduit extends LiquidBlock implements Autotiler{
public @Load(value = "@-top-#", length = 5) TextureRegion[] topRegions;
public @Load(value = "@-bottom-#", length = 5, fallback = "conduit-bottom-#") TextureRegion[] botRegions;
public @Load(value = "@-liquid-r#", length = 4, fallback = "conduit-liquid-r#") TextureRegion[] liquidRotateRegions;
public @Load(value = "@-liquid", fallback = "conduit-liquid") TextureRegion liquidBaseRegion;
public @Load("@-cap") TextureRegion capRegion;
public @Load(value = "conduit-liquid-#", length = animationFrames) TextureRegion[] gasRegions;
public @Load(value = "conduit-liquid-r#1-#2", lengths = {4, animationFrames}) TextureRegion[][] rotateGasRegions;
public boolean leaks = true;
public @Nullable Block junctionReplacement, bridgeReplacement, rotBridgeReplacement;
@@ -106,7 +112,6 @@ public class Conduit extends LiquidBlock implements Autotiler{
@Override
public void draw(){
float rotation = rotdeg();
int r = this.rotation;
//draw extra conduits facing this one for tiling purposes
@@ -114,28 +119,40 @@ public class Conduit extends LiquidBlock implements Autotiler{
for(int i = 0; i < 4; i++){
if((blending & (1 << i)) != 0){
int dir = r - i;
float rot = i == 0 ? rotation : (dir)*90;
drawAt(x + Geometry.d4x(dir) * tilesize*0.75f, y + Geometry.d4y(dir) * tilesize*0.75f, 0, rot, i != 0 ? SliceMode.bottom : SliceMode.top);
drawAt(x + Geometry.d4x(dir) * tilesize*0.75f, y + Geometry.d4y(dir) * tilesize*0.75f, 0, i == 0 ? r : dir, i != 0 ? SliceMode.bottom : SliceMode.top);
}
}
Draw.z(Layer.block);
Draw.scl(xscl, yscl);
drawAt(x, y, blendbits, rotation, SliceMode.none);
drawAt(x, y, blendbits, r, SliceMode.none);
Draw.reset();
if(capped && capRegion.found()) Draw.rect(capRegion, x, y, rotdeg());
if(backCapped && capRegion.found()) Draw.rect(capRegion, x, y, rotdeg() + 180);
}
protected void drawAt(float x, float y, int bits, float rotation, SliceMode slice){
protected void drawAt(float x, float y, int bits, int rotation, SliceMode slice){
float angle = rotation * 90f;
Draw.color(botColor);
Draw.rect(sliced(botRegions[bits], slice), x, y, rotation);
Draw.rect(sliced(botRegions[bits], slice), x, y, angle);
Drawf.liquid(sliced(botRegions[bits], slice), x, y, smoothLiquid, liquids.current().color, rotation);
int offset = yscl == -1 ? 3 : 0;
//TODO move out of conduit
int frame = (int)(Time.time / animationScale * animationFrames) % animationFrames;
TextureRegion liquidr =
liquids.current().gas ?
(bits == 1 ? rotateGasRegions[(rotation + offset) % 4][frame] : gasRegions[frame]) :
(bits == 1 ? liquidRotateRegions[(rotation + offset) % 4] : liquidBaseRegion);
Draw.rect(sliced(topRegions[bits], slice), x, y, rotation);
//the drawing state machine sure was a great design choice with no downsides or hidden behavior!!!
float xscl = Draw.xscl, yscl = Draw.yscl;
Draw.scl(1f, 1f);
Drawf.liquid(sliced(liquidr, slice), x, y, smoothLiquid, liquids.current().color.write(Tmp.c1).a(1f));
Draw.scl(xscl, yscl);
Draw.rect(sliced(topRegions[bits], slice), x, y, angle);
}
@Override
@@ -1,12 +1,17 @@
package mindustry.world.blocks.liquid;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class LiquidBlock extends Block{
public @Load("@-liquid") TextureRegion liquidRegion;
public @Load("@-top") TextureRegion topRegion;
@@ -27,6 +32,39 @@ public class LiquidBlock extends Block{
return new TextureRegion[]{bottomRegion, topRegion};
}
public static void drawTiledGas(TextureRegion[] gasRegions, int size, float x, float y, float padding, Color color, float alpha){
TextureRegion region = gasRegions[(int)(Time.time / Liquid.animationScale * Liquid.animationFrames) % Liquid.animationFrames];
TextureRegion toDraw = Tmp.tr1;
float bounds = size/2f * tilesize - padding;
for(int sx = 0; sx < size; sx++){
for(int sy = 0; sy < size; sy++){
float relx = sx - (size-1)/2f, rely = sy - (size-1)/2f;
toDraw.set(region);
//truncate region if at border
float rightBorder = relx*tilesize + padding, topBorder = rely*tilesize + padding;
float squishX = rightBorder + tilesize/2f - bounds, squishY = topBorder + tilesize/2f - bounds;
float ox = 0f, oy = 0f;
//cut out the parts that don't fit inside the padding
if(squishX > 0){
toDraw.setWidth(toDraw.width - squishX * 4f);
ox = -squishX/2f;
}
if(squishY > 0){
toDraw.setY(toDraw.getY() + squishY * 4f);
oy = -squishY/2f;
}
Drawf.liquid(toDraw, x + rightBorder + ox, y + topBorder + oy, alpha, Tmp.c1.set(color).a(1f));
}
}
}
public class LiquidBuild extends Building{
@Override
public void draw(){
@@ -1,9 +1,18 @@
package mindustry.world.blocks.liquid;
import arc.graphics.g2d.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
import mindustry.type.*;
import static mindustry.Vars.*;
public class LiquidRouter extends LiquidBlock{
/** kept only for mod compatibility reasons; all vanilla blocks have this as true */
public boolean newDrawing = false;
public float liquidPadding = 0f;
public @Load(value = "conduit-liquid-#", length = Liquid.animationFrames) TextureRegion[] gasRegions;
public LiquidRouter(String name){
super(name);
@@ -12,6 +21,11 @@ public class LiquidRouter extends LiquidBlock{
canOverdrive = false;
}
@Override
public TextureRegion[] icons(){
return newDrawing ? new TextureRegion[]{bottomRegion, region} : super.icons();
}
public class LiquidRouterBuild extends LiquidBuild{
@Override
public void updateTile(){
@@ -20,6 +34,28 @@ public class LiquidRouter extends LiquidBlock{
}
}
@Override
public void draw(){
if(newDrawing){
Draw.rect(bottomRegion, x, y);
if(liquids.currentAmount() > 0.001f){
if(liquids.current().gas){
drawTiledGas(gasRegions, size, x, y, liquidPadding, liquids.current().color, liquids.currentAmount() / liquidCapacity);
}else{
Draw.color(liquids.current().color, liquids.currentAmount() / liquidCapacity);
Fill.square(x, y, size * tilesize/2f - liquidPadding);
Draw.color();
}
}
Draw.rect(region, x, y);
}else{
super.draw();
}
}
@Override
public boolean acceptLiquid(Building source, Liquid liquid){
return (liquids.current() == liquid || liquids.currentAmount() < 0.2f);