Editor map fix / Crafter renderer system

This commit is contained in:
Anuken 2020-06-13 10:33:19 -04:00
parent 27522ae494
commit 3b3a1dd496
27 changed files with 7415 additions and 7007 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 B

After

Width:  |  Height:  |  Size: 283 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 772 B

Before After
Before After

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 632 KiB

After

Width:  |  Height:  |  Size: 632 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 131 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 KiB

After

Width:  |  Height:  |  Size: 279 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 285 KiB

After

Width:  |  Height:  |  Size: 286 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 905 KiB

After

Width:  |  Height:  |  Size: 916 KiB

Before After
Before After

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 131 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 KiB

After

Width:  |  Height:  |  Size: 271 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 278 KiB

After

Width:  |  Height:  |  Size: 282 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 955 KiB

After

Width:  |  Height:  |  Size: 962 KiB

Before After
Before After

View file

@ -5,7 +5,6 @@ import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import mindustry.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
@ -28,6 +27,7 @@ import mindustry.world.blocks.sandbox.*;
import mindustry.world.blocks.storage.*;
import mindustry.world.blocks.units.*;
import mindustry.world.consumers.*;
import mindustry.world.draw.*;
import mindustry.world.meta.*;
public class Blocks implements ContentList{
@ -527,19 +527,11 @@ public class Blocks implements ContentList{
hasPower = hasLiquids = true;
craftEffect = Fx.formsmoke;
updateEffect = Fx.plasticburn;
drawer = new DrawGlow();
consumes.liquid(Liquids.oil, 0.25f);
consumes.power(3f);
consumes.item(Items.titanium, 2);
int topRegion = re("-top");
drawer = entity -> {
Draw.rect(region, entity.x(), entity.y());
Draw.alpha(Mathf.absin(entity.totalProgress, 3f, 0.9f) * entity.warmup);
Draw.rect(re(topRegion), entity.x(), entity.y());
Draw.reset();
};
}};
phaseWeaver = new GenericCrafter("phase-weaver"){{
@ -549,32 +541,11 @@ public class Blocks implements ContentList{
craftTime = 120f;
size = 2;
hasPower = true;
drawer = new DrawWeave();
consumes.items(new ItemStack(Items.thorium, 4), new ItemStack(Items.sand, 10));
consumes.power(5f);
itemCapacity = 20;
int bottomRegion = re("-bottom"), weaveRegion = re("-weave");
drawIcons = () -> new TextureRegion[]{Core.atlas.find(name + "-bottom"), Core.atlas.find(name), Core.atlas.find(name + "-weave")};
drawer = entity -> {
Draw.rect(re(bottomRegion), entity.x(), entity.y());
Draw.rect(re(weaveRegion), entity.x(), entity.y(), entity.totalProgress);
Draw.color(Pal.accent);
Draw.alpha(entity.warmup);
Lines.lineAngleCenter(
entity.x() + Mathf.sin(entity.totalProgress, 6f, Vars.tilesize / 3f * size),
entity.y(),
90,
size * Vars.tilesize / 2f);
Draw.reset();
Draw.rect(region, entity.x(), entity.y());
};
}};
surgeSmelter = new GenericSmelter("alloy-smelter"){{
@ -600,29 +571,11 @@ public class Blocks implements ContentList{
rotate = false;
solid = true;
outputsLiquid = true;
drawer = new DrawMixer();
consumes.power(1f);
consumes.item(Items.titanium);
consumes.liquid(Liquids.water, 0.2f);
int liquidRegion = re("-liquid"), topRegion = re("-top"), bottomRegion = re("-bottom");
drawIcons = () -> new TextureRegion[]{Core.atlas.find(name + "-bottom"), Core.atlas.find(name + "-top")};
drawer = entity -> {
float rotation = rotate ? entity.rotdeg() : 0;
Draw.rect(re(bottomRegion), entity.x(), entity.y(), rotation);
if(entity.liquids().total() > 0.001f){
Draw.color(outputLiquid.liquid.color);
Draw.alpha(entity.liquids().get(outputLiquid.liquid) / liquidCapacity);
Draw.rect(re(liquidRegion), entity.x(), entity.y(), rotation);
Draw.color();
}
Draw.rect(re(topRegion), entity.x(), entity.y(), rotation);
};
}};
blastMixer = new GenericCrafter("blast-mixer"){{
@ -704,27 +657,10 @@ public class Blocks implements ContentList{
hasLiquids = true;
hasPower = true;
craftEffect = Fx.none;
drawer = new DrawAnimation();
consumes.item(Items.sporePod, 1);
consumes.power(0.60f);
int[] frameRegions = new int[3];
for(int i = 0; i < 3; i++){
frameRegions[i] = re("-frame" + i);
}
int liquidRegion = re("-liquid");
int topRegion = re("-top");
drawIcons = () -> new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-top")};
drawer = entity -> {
Draw.rect(region, entity.x(), entity.y());
Draw.rect(re(frameRegions[(int)Mathf.absin(entity.totalProgress, 5f, 2.999f)]), entity.x(), entity.y());
Draw.color(Color.clear, entity.liquids().current().color, entity.liquids().total() / liquidCapacity);
Draw.rect(re(liquidRegion), entity.x(), entity.y());
Draw.color();
Draw.rect(re(topRegion), entity.x(), entity.y());
};
}};
pulverizer = new GenericCrafter("pulverizer"){{
@ -734,18 +670,10 @@ public class Blocks implements ContentList{
craftTime = 40f;
updateEffect = Fx.pulverizeSmall;
hasItems = hasPower = true;
drawer = new DrawRotator();
consumes.item(Items.scrap, 1);
consumes.power(0.50f);
int rotatorRegion = re("-rotator");
drawIcons = () -> new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-rotator")};
drawer = entity -> {
Draw.rect(region, entity.x(), entity.y());
Draw.rect(re(rotatorRegion), entity.x(), entity.y(), entity.totalProgress * 2f);
};
}};
coalCentrifuge = new GenericCrafter("coal-centrifuge"){{

View file

@ -152,7 +152,7 @@ public class MapRenderer implements Disposable{
region = !Core.atlas.isFound(wall.editorIcon()) ? Core.atlas.find("clear-editor") : wall.editorIcon();
offsetX = tilesize / 2f - region.getWidth() / 2f * Draw.scl;
offsetY = tilesize / 2f - region.getHeight() / 2f * Draw.scl;
}else if(wall == Blocks.air){
}else if(wall == Blocks.air && !tile.overlay().isAir()){
region = tile.overlay().editorVariantRegions()[Mathf.randomSeed(idxWall, 0, tile.overlay().editorVariantRegions().length - 1)];
}else{
region = Core.atlas.find("clear-editor");

View file

@ -28,6 +28,7 @@ import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.consumers.*;
import mindustry.world.draw.*;
import mindustry.world.meta.*;
import java.lang.reflect.*;
@ -143,6 +144,11 @@ public class ContentParser{
}
}
//try to load DrawBlock by instantiating it
if(type == DrawBlock.class && jsonData.isString()){
return Reflect.make("mindustry.world.draw." + Strings.capitalize(jsonData.asString()));
}
if(Content.class.isAssignableFrom(type)){
ContentType ctype = contentTypes.getThrow(type, () -> new IllegalArgumentException("No content type for class: " + type.getSimpleName()));
String prefix = currentMod != null ? currentMod.name + "-" : "";

View file

@ -173,7 +173,6 @@ public class Block extends UnlockableContent{
public boolean instantTransfer = false;
protected Prov<Tilec> entityType = null; //initialized later
//TODO move
public ObjectMap<Class<?>, Cons2> configurations = new ObjectMap<>();
//TODO move
@ -181,10 +180,6 @@ public class Block extends UnlockableContent{
protected TextureRegion[] variantRegions, editorVariantRegions;
public TextureRegion region, editorIcon;
//TODO remove completely
protected TextureRegion[] cacheRegions = {};
protected Seq<String> cacheRegionStrings = new Seq<>();
//TODO move
public static TextureRegion[][] cracks;
protected static final Seq<Tile> tempTiles = new Seq<>();
@ -200,7 +195,6 @@ public class Block extends UnlockableContent{
initEntity();
}
//TODO rename to draw() once class refactoring is done.
public void drawBase(Tile tile){
//delegates to entity unless it is null
if(tile.entity != null){
@ -574,19 +568,6 @@ public class Block extends UnlockableContent{
}
}
/** Adds a region by name to be loaded, with the final name "{name}-suffix". Returns an ID to looks this region up by in {@link #re(int)}.
* DO NOT USE. This will eventually be removed. */
protected int re(String suffix){
cacheRegionStrings.add(name + suffix);
return cacheRegionStrings.size - 1;
}
/** Returns an internally cached region by ID.
* DO NOT USE. This will eventually be removed*/
protected TextureRegion re(int id){
return cacheRegions[id];
}
@Override
public void displayInfo(Table table){
ContentDisplay.displayBlock(table, this);
@ -631,11 +612,6 @@ public class Block extends UnlockableContent{
public void load(){
region = Core.atlas.find(name);
cacheRegions = new TextureRegion[cacheRegionStrings.size];
for(int i = 0; i < cacheRegions.length; i++){
cacheRegions[i] = Core.atlas.find(cacheRegionStrings.get(i));
}
if(cracks == null || (cracks[0][0].getTexture() != null && cracks[0][0].getTexture().isDisposed())){
cracks = new TextureRegion[maxCrackSize][crackRegions];
for(int size = 1; size <= maxCrackSize; size++){

View file

@ -160,6 +160,11 @@ public class Floor extends Block{
}
}
@Override
public TextureRegion[] icons(){
return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")};
}
public boolean isDeep(){
return drownTime > 0;
}

View file

@ -1,6 +1,5 @@
package mindustry.world.blocks.production;
import arc.func.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.io.*;
@ -10,6 +9,7 @@ import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.consumers.*;
import mindustry.world.draw.*;
import mindustry.world.meta.*;
public class GenericCrafter extends Block{
@ -21,8 +21,10 @@ public class GenericCrafter extends Block{
public Effect updateEffect = Fx.none;
public float updateEffectChance = 0.04f;
public Cons<GenericCrafterEntity> drawer = null;
public Prov<TextureRegion[]> drawIcons = null;
public DrawBlock drawer = new DrawBlock();
//public Cons<GenericCrafterEntity> drawer = null;
//public Prov<TextureRegion[]> drawIcons = null;
public GenericCrafter(String name){
super(name);
@ -54,6 +56,13 @@ public class GenericCrafter extends Block{
}
}
@Override
public void load(){
super.load();
drawer.load(this);
}
@Override
public void init(){
outputsLiquid = outputLiquid != null;
@ -62,7 +71,7 @@ public class GenericCrafter extends Block{
@Override
public TextureRegion[] icons(){
return drawIcons == null ? super.icons() : drawIcons.get();
return drawer.icons(this);
}
@Override
@ -77,11 +86,7 @@ public class GenericCrafter extends Block{
@Override
public void draw(){
if(drawer == null){
super.draw();
}else{
drawer.get(this);
}
drawer.draw(this);
}
@Override

View file

@ -0,0 +1,46 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import mindustry.world.*;
import mindustry.world.blocks.production.GenericCrafter.*;
public class DrawAnimation extends DrawBlock{
public int frameCount = 3;
public float frameSpeed = 5f;
public boolean sine = true;
public TextureRegion[] frames;
public TextureRegion liquid, top;
@Override
public void draw(GenericCrafterEntity entity){
Draw.rect(entity.block.region, entity.x, entity.y);
Draw.rect(
sine ?
frames[(int)Mathf.absin(entity.totalProgress, frameSpeed, frameCount - 0.001f)] :
frames[(int)((entity.totalProgress / frameSpeed) % frameCount)],
entity.x, entity.y);
Draw.color(Color.clear, entity.liquids.current().color, entity.liquids.total() / entity.block.liquidCapacity);
Draw.rect(liquid, entity.x, entity.y);
Draw.color();
Draw.rect(top, entity.x, entity.y);
}
@Override
public void load(Block block){
frames = new TextureRegion[frameCount];
for(int i = 0; i < frameCount; i++){
frames[i] = Core.atlas.find(block.name + "-frame" + i);
}
liquid = Core.atlas.find(block.name + "-liquid");
top = Core.atlas.find(block.name + "-top");
}
@Override
public TextureRegion[] icons(Block block){
return new TextureRegion[]{block.region, top};
}
}

View file

@ -0,0 +1,25 @@
package mindustry.world.draw;
import arc.graphics.g2d.*;
import mindustry.world.*;
import mindustry.world.blocks.production.GenericCrafter.*;
/** An implementation of custom rendering behavior for a block.
* This is used mostly for mods. */
public class DrawBlock{
/** Draws the block. */
public void draw(GenericCrafterEntity entity){
Draw.rect(entity.block.region, entity.x, entity.y, entity.block.rotate ? entity.rotdeg() : 0);
}
/** Load any relevant texture regions. */
public void load(Block block){
}
/** @return the generated icons to be used for this block. */
public TextureRegion[] icons(Block block){
return new TextureRegion[]{block.region};
}
}

View file

@ -0,0 +1,25 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.g2d.*;
import arc.math.*;
import mindustry.world.*;
import mindustry.world.blocks.production.GenericCrafter.*;
public class DrawGlow extends DrawBlock{
public float glowAmount = 0.9f, glowScale = 3f;
public TextureRegion top;
@Override
public void draw(GenericCrafterEntity entity){
Draw.rect(entity.block.region, entity.x, entity.y);
Draw.alpha(Mathf.absin(entity.totalProgress, glowScale, glowAmount) * entity.warmup);
Draw.rect(top, entity.x, entity.y);
Draw.reset();
}
@Override
public void load(Block block){
top = Core.atlas.find(block.name + "-top");
}
}

View file

@ -0,0 +1,39 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.g2d.*;
import mindustry.world.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.production.GenericCrafter.*;
public class DrawMixer extends DrawBlock{
public TextureRegion liquid, top, bottom;
@Override
public void draw(GenericCrafterEntity entity){
float rotation = entity.block.rotate ? entity.rotdeg() : 0;
Draw.rect(bottom, entity.x, entity.y, rotation);
if(entity.liquids.total() > 0.001f){
Draw.color(((GenericCrafter)entity.block).outputLiquid.liquid.color);
Draw.alpha(entity.liquids.get(((GenericCrafter)entity.block).outputLiquid.liquid) / entity.block.liquidCapacity);
Draw.rect(liquid, entity.x, entity.y, rotation);
Draw.color();
}
Draw.rect(top, entity.x, entity.y, rotation);
}
@Override
public void load(Block block){
liquid = Core.atlas.find(block.name + "-liquid");
top = Core.atlas.find(block.name + "-top");
bottom = Core.atlas.find(block.name + "-bottom");
}
@Override
public TextureRegion[] icons(Block block){
return new TextureRegion[]{bottom, top};
}
}

View file

@ -0,0 +1,26 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.g2d.*;
import mindustry.world.*;
import mindustry.world.blocks.production.GenericCrafter.*;
public class DrawRotator extends DrawBlock{
public TextureRegion rotator;
@Override
public void draw(GenericCrafterEntity entity){
Draw.rect(entity.block.region, entity.x, entity.y);
Draw.rect(rotator, entity.x, entity.y, entity.totalProgress * 2f);
}
@Override
public void load(Block block){
rotator = Core.atlas.find(block.name + "-rotator");
}
@Override
public TextureRegion[] icons(Block block){
return new TextureRegion[]{block.region, rotator};
}
}

View file

@ -0,0 +1,43 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.g2d.*;
import arc.math.*;
import mindustry.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.blocks.production.GenericCrafter.*;
public class DrawWeave extends DrawBlock{
public TextureRegion weave, bottom;
@Override
public void draw(GenericCrafterEntity entity){
Draw.rect(bottom, entity.x(), entity.y());
Draw.rect(weave, entity.x(), entity.y(), entity.totalProgress);
Draw.color(Pal.accent);
Draw.alpha(entity.warmup);
Lines.lineAngleCenter(
entity.x() + Mathf.sin(entity.totalProgress, 6f, Vars.tilesize / 3f * entity.block.size),
entity.y(),
90,
entity.block.size * Vars.tilesize / 2f);
Draw.reset();
Draw.rect(entity.block.region, entity.x, entity.y);
}
@Override
public void load(Block block){
weave = Core.atlas.find(block.name + "-weave");
bottom = Core.atlas.find(block.name + "-bottom");
}
@Override
public TextureRegion[] icons(Block block){
return new TextureRegion[]{bottom, block.region, weave};
}
}

View file

@ -15,7 +15,9 @@ import mindustry.tools.ImagePacker.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.environment.*;
import mindustry.world.blocks.legacy.*;
import static mindustry.Vars.*;
@ -99,6 +101,8 @@ public class Generators{
Image colors = new Image(content.blocks().size, 1);
for(Block block : content.blocks()){
if(block.isAir() || block instanceof BuildBlock || block instanceof OreBlock || block instanceof LegacyBlock) continue;
block.load();
TextureRegion[] regions = block.getGeneratedIcons();