Cleanup, main menu progress

This commit is contained in:
Anuken
2019-07-03 23:36:51 -04:00
90 changed files with 4123 additions and 16883 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 B

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 B

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 474 B

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 B

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 468 B

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 589 B

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 266 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 B

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 71 B

After

Width:  |  Height:  |  Size: 71 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 299 B

View File

@@ -1,8 +0,0 @@
{
duplicatePadding: true,
combineSubdirectories: true,
flattenPaths: true,
maxWidth: 1024,
maxHeight: 1024,
fast: true
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 B

View File

@@ -2,7 +2,7 @@
duplicatePadding: true, duplicatePadding: true,
combineSubdirectories: true, combineSubdirectories: true,
flattenPaths: true, flattenPaths: true,
maxWidth: 1024, maxWidth: 2048,
maxHeight: 1024, maxHeight: 2048,
fast: true fast: true
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 712 B

After

Width:  |  Height:  |  Size: 711 B

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.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 KiB

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 276 KiB

After

Width:  |  Height:  |  Size: 276 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 161 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 230 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 233 KiB

View File

@@ -9,15 +9,15 @@
}, },
TintedDrawable: { TintedDrawable: {
dialogDim: { dialogDim: {
name: white, name: whiteui,
color: { r: 0, g: 0, b: 0, a: 0.9 } color: { r: 0, g: 0, b: 0, a: 0.9 }
}, },
guideDim: { guideDim: {
name: white, name: whiteui,
color: { r: 0, g: 0, b: 0, a: 0.3 } color: { r: 0, g: 0, b: 0, a: 0.3 }
}, },
invis: { invis: {
name: white, name: whiteui,
color: { r: 0, g: 0, b: 0, a: 0 } color: { r: 0, g: 0, b: 0, a: 0 }
} }
loadDim: { loadDim: {
@@ -25,27 +25,27 @@
color: { r: 0, g: 0, b: 0, a: 0.8 } color: { r: 0, g: 0, b: 0, a: 0.8 }
}, },
chatfield: { chatfield: {
name: white, name: whiteui,
color: { r: 0, g: 0, b: 0, a: 0.2 } color: { r: 0, g: 0, b: 0, a: 0.2 }
}, },
dark: { dark: {
name: white, name: whiteui,
color: { hex: "#000000ff" } color: { hex: "#000000ff" }
}, },
none: { none: {
name: white, name: whiteui,
color: { r: 0, g: 0, b: 0, a: 0 } color: { r: 0, g: 0, b: 0, a: 0 }
}, },
flat: { flat: {
name: white, name: whiteui,
color: { r: 0.0, g: 0.0, b: 0.0, a: 0.6 } color: { r: 0.0, g: 0.0, b: 0.0, a: 0.6 }
}, },
flat-over: { flat-over: {
name: white, name: whiteui,
color: { hex: "#ffffff82" } color: { hex: "#ffffff82" }
}, },
flat-down: { flat-down: {
name: white, name: whiteui,
color: { hex: "#ffd37fff" } color: { hex: "#ffd37fff" }
} }
}, },
@@ -111,7 +111,7 @@
up: info-banner up: info-banner
}, },
clear-partial: { clear-partial: {
down: white, down: whiteui,
up: button-select, up: button-select,
over: flat-down, over: flat-down,
font: default-font, font: default-font,
@@ -209,7 +209,7 @@
over: flat-over over: flat-over
}, },
clear-full: { clear-full: {
down: white, down: whiteui,
up: button-select, up: button-select,
over: flat-down over: flat-down
}, },

View File

@@ -2,12 +2,9 @@ package io.anuke.mindustry;
import io.anuke.arc.*; import io.anuke.arc.*;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.Texture; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.SpriteBatch;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Log; import io.anuke.arc.util.*;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.core.*; import io.anuke.mindustry.core.*;
import io.anuke.mindustry.game.EventType.GameLoadEvent; import io.anuke.mindustry.game.EventType.GameLoadEvent;
import io.anuke.mindustry.io.BundleLoader; import io.anuke.mindustry.io.BundleLoader;
@@ -16,6 +13,7 @@ import static io.anuke.arc.Core.batch;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
public class Mindustry extends ApplicationCore{ public class Mindustry extends ApplicationCore{
private long lastTime;
@Override @Override
public void setup(){ public void setup(){
@@ -55,42 +53,42 @@ public class Mindustry extends ApplicationCore{
})); }));
} }
@Override
public void init(){
setup();
}
@Override @Override
public void update(){ public void update(){
long lastFrameTime = Time.nanos();
super.update(); super.update();
int fpsCap = Core.settings.getInt("fpscap", 125); int targetfps = Core.settings.getInt("fpscap", 120);
if(fpsCap <= 120){ if(targetfps > 0 && targetfps <= 120){
long target = (1000 * 1000000) / fpsCap; //target in nanos long target = (1000 * 1000000) / targetfps; //target in nanos
long elapsed = Time.timeSinceNanos(lastFrameTime); long elapsed = Time.timeSinceNanos(lastTime);
if(elapsed < target){ if(elapsed < target){
try{ try{
Thread.sleep((target - elapsed) / 1000000, (int)((target - elapsed) % 1000000)); Thread.sleep((target - elapsed) / 1000000, (int)((target - elapsed) % 1000000));
}catch(InterruptedException e){ }catch(InterruptedException ignored){
e.printStackTrace(); //ignore
} }
} }
} }
lastTime = Time.nanos();
}
@Override
public void init(){
setup();
} }
void drawLoading(){ void drawLoading(){
Core.graphics.clear(Color.BLACK); Core.graphics.clear(Color.BLACK);
Draw.proj().setOrtho(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight()); Draw.proj().setOrtho(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight());
Texture icon = new Texture("sprites/logotext.png"); //Texture icon = new Texture("sprites/logotext.png");
float width = Math.min(Core.graphics.getWidth() - 10f, icon.getWidth()); //float width = Math.min(Core.graphics.getWidth() - 10f, icon.getWidth());
Draw.rect(Draw.wrap(icon), Core.graphics.getWidth()/2f, Core.graphics.getHeight()/2f, width, (float)icon.getHeight() / icon.getWidth() * width); //Draw.rect(Draw.wrap(icon), Core.graphics.getWidth()/2f, Core.graphics.getHeight()/2f, width, (float)icon.getHeight() / icon.getWidth() * width);
Draw.flush(); //Draw.flush();
icon.dispose(); //icon.dispose();
} }
} }

View File

@@ -13,8 +13,7 @@ import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.game.ContentList; import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.graphics.*; import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.*; import io.anuke.mindustry.world.blocks.*;
import io.anuke.mindustry.world.blocks.defense.*; import io.anuke.mindustry.world.blocks.defense.*;
import io.anuke.mindustry.world.blocks.defense.turrets.*; import io.anuke.mindustry.world.blocks.defense.turrets.*;
@@ -310,11 +309,11 @@ public class Blocks implements ContentList{
saltRocks = new StaticWall("saltrocks"){{ saltRocks = new StaticWall("saltrocks"){{
}}; }};
sporePine = new StaticWall("spore-pine"){{ sporePine = new StaticTree("spore-pine"){{
variants = 0; variants = 0;
}}; }};
pine = new StaticWall("pine"){{ pine = new StaticTree("pine"){{
variants = 0; variants = 0;
}}; }};

View File

@@ -0,0 +1,18 @@
package io.anuke.mindustry.content;
import io.anuke.mindustry.entities.effect.Fire;
import io.anuke.mindustry.entities.effect.Puddle;
import io.anuke.mindustry.entities.type.Player;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.game.TypeID;
public class TypeIDs implements ContentList{
public static TypeID fire, puddle, player;
@Override
public void load(){
fire = new TypeID("fire", Fire::new);
puddle = new TypeID("puddle", Puddle::new);
player = new TypeID("player", Player::new);
}
}

View File

@@ -7,10 +7,6 @@ import io.anuke.arc.graphics.Pixmap;
import io.anuke.arc.util.Log; import io.anuke.arc.util.Log;
import io.anuke.mindustry.content.*; import io.anuke.mindustry.content.*;
import io.anuke.mindustry.entities.bullet.BulletType; import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.effect.Fire;
import io.anuke.mindustry.entities.effect.Puddle;
import io.anuke.mindustry.entities.traits.TypeTrait;
import io.anuke.mindustry.entities.type.Player;
import io.anuke.mindustry.game.*; import io.anuke.mindustry.game.*;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
@@ -43,6 +39,7 @@ public class ContentLoader{
new Loadouts(), new Loadouts(),
new TechTree(), new TechTree(),
new Zones(), new Zones(),
new TypeIDs(),
//these are not really content classes, but this makes initialization easier //these are not really content classes, but this makes initialization easier
new LegacyColorMapper(), new LegacyColorMapper(),
@@ -59,8 +56,6 @@ public class ContentLoader{
return; return;
} }
registerTypes();
for(ContentType type : ContentType.values()){ for(ContentType type : ContentType.values()){
contentMap[type.ordinal()] = new Array<>(); contentMap[type.ordinal()] = new Array<>();
contentNameMap[type.ordinal()] = new ObjectMap<>(); contentNameMap[type.ordinal()] = new ObjectMap<>();
@@ -232,14 +227,4 @@ public class ContentLoader{
public Array<UnitType> units(){ public Array<UnitType> units(){
return getBy(ContentType.unit); return getBy(ContentType.unit);
} }
/**
* Registers sync IDs for all types of sync entities.
* Do not register units here!
*/
private void registerTypes(){
TypeTrait.registerType(Player.class, Player::new);
TypeTrait.registerType(Fire.class, Fire::new);
TypeTrait.registerType(Puddle.class, Puddle::new);
}
} }

View File

@@ -2,7 +2,6 @@ package io.anuke.mindustry.core;
import io.anuke.arc.*; import io.anuke.arc.*;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.GL20;
import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureAtlas; import io.anuke.arc.graphics.g2d.TextureAtlas;
import io.anuke.arc.input.KeyCode; import io.anuke.arc.input.KeyCode;
@@ -23,7 +22,6 @@ import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import java.io.IOException; import java.io.IOException;
import java.nio.IntBuffer;
import static io.anuke.arc.Core.scene; import static io.anuke.arc.Core.scene;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
@@ -43,10 +41,6 @@ public class Control implements ApplicationListener{
private InputHandler input; private InputHandler input;
public Control(){ public Control(){
IntBuffer buf = BufferUtils.newIntBuffer(1);
Core.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_SIZE, buf);
int maxSize = buf.get(0);
saves = new Saves(); saves = new Saves();
data = new GlobalData(); data = new GlobalData();
@@ -55,7 +49,7 @@ public class Control implements ApplicationListener{
Effects.setShakeFalloff(10000f); Effects.setShakeFalloff(10000f);
content.initialize(Content::init); content.initialize(Content::init);
Core.atlas = new TextureAtlas(maxSize < 2048 ? "sprites/sprites_fallback.atlas" : "sprites/sprites.atlas"); Core.atlas = new TextureAtlas("sprites/sprites.atlas");
Draw.scl = 1f / Core.atlas.find("scale_marker").getWidth(); Draw.scl = 1f / Core.atlas.find("scale_marker").getWidth();
content.initialize(Content::load, true); content.initialize(Content::load, true);

View File

@@ -15,9 +15,9 @@ import io.anuke.mindustry.entities.Entities;
import io.anuke.mindustry.entities.EntityGroup; import io.anuke.mindustry.entities.EntityGroup;
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest; import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
import io.anuke.mindustry.entities.traits.SyncTrait; import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.traits.TypeTrait;
import io.anuke.mindustry.entities.type.Player; import io.anuke.mindustry.entities.type.Player;
import io.anuke.mindustry.entities.type.Unit; import io.anuke.mindustry.entities.type.Unit;
import io.anuke.mindustry.game.TypeID;
import io.anuke.mindustry.game.Version; import io.anuke.mindustry.game.Version;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.gen.RemoteReadClient; import io.anuke.mindustry.gen.RemoteReadClient;
@@ -25,6 +25,7 @@ import io.anuke.mindustry.net.Administration.TraceInfo;
import io.anuke.mindustry.net.*; import io.anuke.mindustry.net.*;
import io.anuke.mindustry.net.Net.SendMode; import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.Packets.*; import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.modules.ItemModule; import io.anuke.mindustry.world.modules.ItemModule;
@@ -240,7 +241,7 @@ public class NetClient implements ApplicationListener{
//entity must not be added yet, so create it //entity must not be added yet, so create it
if(entity == null){ if(entity == null){
entity = (SyncTrait)TypeTrait.getTypeByID(typeID).get(); //create entity from supplier entity = (SyncTrait)content.<TypeID>getByID(ContentType.typeid, typeID).constructor.get();
entity.resetID(id); entity.resetID(id);
if(!netClient.isEntityUsed(entity.getID())){ if(!netClient.isEntityUsed(entity.getID())){
add = true; add = true;

View File

@@ -474,7 +474,7 @@ public class NetServer implements ApplicationListener{
//write all entities now //write all entities now
dataStream.writeInt(entity.getID()); //write id dataStream.writeInt(entity.getID()); //write id
dataStream.writeByte(sync.getTypeID()); //write type ID dataStream.writeByte(sync.getTypeID().id); //write type ID
sync.write(dataStream); //write entity sync.write(dataStream); //write entity
sent++; sent++;

View File

@@ -189,11 +189,12 @@ public class Renderer implements ApplicationListener{
drawAllTeams(false); drawAllTeams(false);
blocks.skipLayer(Layer.turret); blocks.drawBlocks(Layer.turret);
blocks.drawBlocks(Layer.laser);
drawFlyerShadows(); drawFlyerShadows();
blocks.drawBlocks(Layer.power);
drawAllTeams(true); drawAllTeams(true);
draw(bulletGroup); draw(bulletGroup);
@@ -280,7 +281,6 @@ public class Renderer implements ApplicationListener{
draw(unitGroups[team.ordinal()], u -> u.isFlying() == flying && !u.isDead(), Unit::drawAll); draw(unitGroups[team.ordinal()], u -> u.isFlying() == flying && !u.isDead(), Unit::drawAll);
draw(playerGroup, p -> p.isFlying() == flying && p.getTeam() == team, Unit::drawAll); draw(playerGroup, p -> p.isFlying() == flying && p.getTeam() == team, Unit::drawAll);
blocks.drawTeamBlocks(Layer.turret, team);
draw(unitGroups[team.ordinal()], u -> u.isFlying() == flying && !u.isDead(), Unit::drawOver); draw(unitGroups[team.ordinal()], u -> u.isFlying() == flying && !u.isDead(), Unit::drawOver);
draw(playerGroup, p -> p.isFlying() == flying && p.getTeam() == team, Unit::drawOver); draw(playerGroup, p -> p.isFlying() == flying && p.getTeam() == team, Unit::drawOver);

View File

@@ -511,7 +511,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
int i = 0; int i = 0;
for(Team team : Team.all){ for(Team team : Team.all){
ImageButton button = new ImageButton("white", "clear-toggle-partial"); ImageButton button = new ImageButton("whiteui", "clear-toggle-partial");
button.margin(4f); button.margin(4f);
button.getImageCell().grow(); button.getImageCell().grow();
button.getStyle().imageUpColor = team.color; button.getStyle().imageUpColor = team.color;
@@ -636,7 +636,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
if(!Core.atlas.isFound(region)) continue; if(!Core.atlas.isFound(region)) continue;
ImageButton button = new ImageButton("white", "clear-toggle"); ImageButton button = new ImageButton("whiteui", "clear-toggle");
button.getStyle().imageUp = new TextureRegionDrawable(region); button.getStyle().imageUp = new TextureRegionDrawable(region);
button.clicked(() -> editor.drawBlock = block); button.clicked(() -> editor.drawBlock = block);
button.resizeImage(8 * 4f); button.resizeImage(8 * 4f);

View File

@@ -5,13 +5,15 @@ import io.anuke.arc.collection.IntMap;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry; import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Point2; import io.anuke.arc.math.geom.Point2;
import io.anuke.arc.util.*; import io.anuke.arc.util.Structs;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.content.*; import io.anuke.mindustry.content.*;
import io.anuke.mindustry.entities.*; import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.impl.TimedEntity; import io.anuke.mindustry.entities.impl.TimedEntity;
import io.anuke.mindustry.entities.traits.SaveTrait; import io.anuke.mindustry.entities.traits.SaveTrait;
import io.anuke.mindustry.entities.traits.SyncTrait; import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.type.TileEntity; import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.game.TypeID;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.*;
@@ -75,6 +77,11 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait{
} }
} }
@Override
public TypeID getTypeID(){
return TypeIDs.fire;
}
@Override @Override
public byte version(){ public byte version(){
return 0; return 0;

View File

@@ -16,6 +16,7 @@ import io.anuke.mindustry.content.*;
import io.anuke.mindustry.entities.*; import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.impl.SolidEntity; import io.anuke.mindustry.entities.impl.SolidEntity;
import io.anuke.mindustry.entities.traits.*; import io.anuke.mindustry.entities.traits.*;
import io.anuke.mindustry.game.TypeID;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.type.Liquid;
@@ -143,6 +144,11 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
return liquid.flammability * amount; return liquid.flammability * amount;
} }
@Override
public TypeID getTypeID(){
return TypeIDs.puddle;
}
@Override @Override
public byte version(){ public byte version(){
return 0; return 0;

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.entities.traits; package io.anuke.mindustry.entities.traits;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.*; import io.anuke.arc.math.*;
@@ -89,7 +90,7 @@ public interface MinerTrait extends Entity{
Draw.color(Color.LIGHT_GRAY, Color.WHITE, 1f - flashScl + Mathf.absin(Time.time(), 0.5f, flashScl)); Draw.color(Color.LIGHT_GRAY, Color.WHITE, 1f - flashScl + Mathf.absin(Time.time(), 0.5f, flashScl));
Shapes.laser("minelaser", "minelaser-end", px, py, ex, ey, 0.75f); Shapes.laser(Core.atlas.find("minelaser"), Core.atlas.find("minelaser-end"), px, py, ex, ey, 0.75f);
if(unit instanceof Player && ((Player)unit).isLocal){ if(unit instanceof Player && ((Player)unit).isLocal){
Lines.stroke(1f, Pal.accent); Lines.stroke(1f, Pal.accent);

View File

@@ -1,17 +1,18 @@
package io.anuke.mindustry.entities.traits; package io.anuke.mindustry.entities.traits;
import io.anuke.arc.collection.Array; import io.anuke.mindustry.game.TypeID;
import io.anuke.arc.collection.ObjectIntMap;
import io.anuke.arc.function.Supplier;
public interface TypeTrait{ public interface TypeTrait{
TypeID getTypeID();
/*
int[] lastRegisteredID = {0}; int[] lastRegisteredID = {0};
Array<Supplier<? extends TypeTrait>> registeredTypes = new Array<>(); Array<Supplier<? extends TypeTrait>> registeredTypes = new Array<>();
ObjectIntMap<Class<? extends TypeTrait>> typeToID = new ObjectIntMap<>(); ObjectIntMap<Class<? extends TypeTrait>> typeToID = new ObjectIntMap<>();
/** /**
* Register and return a type ID. The supplier should return a fresh instace of that type. * Register and return a type ID. The supplier should return a fresh instace of that type.
*/
static <T extends TypeTrait> void registerType(Class<T> type, Supplier<T> supplier){ static <T extends TypeTrait> void registerType(Class<T> type, Supplier<T> supplier){
if(typeToID.get(type, -1) != -1){ if(typeToID.get(type, -1) != -1){
return; //already registered return; //already registered
@@ -23,7 +24,7 @@ public interface TypeTrait{
lastRegisteredID[0]++; lastRegisteredID[0]++;
} }
/**Gets a syncable type by ID.*/ /**Gets a syncable type by ID.
static Supplier<? extends TypeTrait> getTypeByID(int id){ static Supplier<? extends TypeTrait> getTypeByID(int id){
if(id == -1){ if(id == -1){
throw new IllegalArgumentException("Attempt to retrieve invalid entity type ID! Did you forget to set it in ContentLoader.registerTypes()?"); throw new IllegalArgumentException("Attempt to retrieve invalid entity type ID! Did you forget to set it in ContentLoader.registerTypes()?");
@@ -34,11 +35,11 @@ public interface TypeTrait{
/** /**
* Returns the type ID of this entity used for intstantiation. Should be < BYTE_MAX. * Returns the type ID of this entity used for intstantiation. Should be < BYTE_MAX.
* Do not override! * Do not override!
*/
default int getTypeID(){ default int getTypeID(){
int id = typeToID.get(getClass(), -1); int id = typeToID.get(getClass(), -1);
if(id == -1) if(id == -1)
throw new RuntimeException("Class of type '" + getClass() + "' is not registered! Did you forget to register it in ContentLoader#registerTypes()?"); throw new RuntimeException("Class of type '" + getClass() + "' is not registered! Did you forget to register it in ContentLoader#registerTypes()?");
return id; return id;
} }*/
} }

View File

@@ -19,6 +19,7 @@ import io.anuke.mindustry.entities.traits.ShooterTrait;
import io.anuke.mindustry.entities.traits.TargetTrait; import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.entities.units.*; import io.anuke.mindustry.entities.units.*;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.TypeID;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
@@ -80,6 +81,11 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
return type.drag; return type.drag;
} }
@Override
public TypeID getTypeID(){
return type.typeID;
}
public Tile getSpawner(){ public Tile getSpawner(){
return world.tile(spawner); return world.tile(spawner);
} }

View File

@@ -41,7 +41,7 @@ public abstract class FlyingUnit extends BaseUnit{
if(target == null){ if(target == null){
setState(patrol); setState(patrol);
} }
}; }
if(target != null){ if(target != null){
attack(type.attackLength); attack(type.attackLength);

View File

@@ -12,11 +12,11 @@ import io.anuke.arc.math.geom.*;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.arc.util.pooling.Pools; import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.Fx; import io.anuke.mindustry.content.*;
import io.anuke.mindustry.content.Mechs;
import io.anuke.mindustry.entities.*; import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.traits.*; import io.anuke.mindustry.entities.traits.*;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.TypeID;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Pal; import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.input.Binding; import io.anuke.mindustry.input.Binding;
@@ -115,6 +115,11 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
heal(); heal();
} }
@Override
public TypeID getTypeID(){
return TypeIDs.player;
}
@Override @Override
public void move(float x, float y){ public void move(float x, float y){
if(!mech.flying){ if(!mech.flying){

View File

@@ -0,0 +1,19 @@
package io.anuke.mindustry.game;
import io.anuke.arc.function.Supplier;
import io.anuke.mindustry.entities.traits.TypeTrait;
import io.anuke.mindustry.type.ContentType;
public class TypeID extends MappableContent{
public final Supplier<? extends TypeTrait> constructor;
public TypeID(String name, Supplier<? extends TypeTrait> constructor){
super(name);
this.constructor = constructor;
}
@Override
public ContentType getContentType(){
return ContentType.typeid;
}
}

View File

@@ -1,22 +1,16 @@
package io.anuke.mindustry.graphics; package io.anuke.mindustry.graphics;
import io.anuke.arc.Core; import io.anuke.arc.*;
import io.anuke.arc.Events; import io.anuke.arc.collection.*;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.Sort;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.Texture.TextureFilter; import io.anuke.arc.graphics.Texture.TextureFilter;
import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.graphics.glutils.FrameBuffer; import io.anuke.arc.graphics.glutils.FrameBuffer;
import io.anuke.arc.util.Disposable; import io.anuke.arc.util.*;
import io.anuke.arc.util.Tmp;
import io.anuke.mindustry.content.Blocks; import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.game.EventType.TileChangeEvent; import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Tile;
import static io.anuke.arc.Core.camera; import static io.anuke.arc.Core.camera;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;

View File

@@ -10,7 +10,5 @@ public enum Layer{
/** "High" blocks, like turrets. */ /** "High" blocks, like turrets. */
turret, turret,
/** Power lasers. */ /** Power lasers. */
power, power
/** Extra lasers, like healing turrets. */
laser
} }

View File

@@ -1,27 +1,36 @@
package io.anuke.mindustry.graphics; package io.anuke.mindustry.graphics;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.graphics.*; import io.anuke.arc.collection.Array;
import io.anuke.arc.function.PositionConsumer;
import io.anuke.arc.graphics.Camera;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.graphics.glutils.FrameBuffer; import io.anuke.arc.graphics.glutils.FrameBuffer;
import io.anuke.arc.math.Matrix3; import io.anuke.arc.math.*;
import io.anuke.arc.scene.ui.layout.Unit;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.arc.util.noise.RidgedPerlin;
import io.anuke.arc.util.noise.Simplex; import io.anuke.arc.util.noise.Simplex;
import io.anuke.mindustry.content.Blocks; import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.Floor; import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
public class MenuRenderer implements Disposable{ public class MenuRenderer implements Disposable{
private static final int width = 100, height = 50; private static final int width = 100, height = 50;
private static final float darkness = 0.1f; private static final float darkness = 0.3f;
private int cacheFloor, cacheWall; private int cacheFloor, cacheWall;
private Camera camera = new Camera(); private Camera camera = new Camera();
private Matrix3 mat = new Matrix3(); private Matrix3 mat = new Matrix3();
private FrameBuffer shadows; private FrameBuffer shadows;
private CacheBatch batch; private CacheBatch batch;
private float time = 0f;
private float flyerRot = 45f;
private int flyers = Mathf.chance(0.2) ? Mathf.random(30) : Mathf.random(12);
public MenuRenderer(){ public MenuRenderer(){
Time.mark(); Time.mark();
@@ -32,34 +41,109 @@ public class MenuRenderer implements Disposable{
private void generate(){ private void generate(){
Tile[][] tiles = world.createTiles(width, height); Tile[][] tiles = world.createTiles(width, height);
Array<Block> ores = content.blocks().select(b -> b instanceof OreBlock);
shadows = new FrameBuffer(width, height); shadows = new FrameBuffer(width, height);
Simplex s1 = new Simplex(0); int offset = Mathf.random(100000);
Simplex s2 = new Simplex(1); Simplex s1 = new Simplex(offset);
Simplex s3 = new Simplex(2); Simplex s2 = new Simplex(offset + 1);
Simplex s3 = new Simplex(offset + 2);
RidgedPerlin rid = new RidgedPerlin(1 + offset, 1);
Block[] selected = Structs.select(
new Block[]{Blocks.moss, Blocks.sporePine},
new Block[]{Blocks.sand, Blocks.sandRocks},
new Block[]{Blocks.shale, Blocks.shaleRocks},
new Block[]{Blocks.ice, Blocks.icerocks}
);
Block[] selected2 = Structs.select(
new Block[]{Blocks.moss, Blocks.sporerocks},
new Block[]{Blocks.ignarock, Blocks.duneRocks},
new Block[]{Blocks.stone, Blocks.rocks},
new Block[]{Blocks.stone, Blocks.rocks},
new Block[]{Blocks.salt, Blocks.saltRocks}
);
Block ore1 = ores.random();
ores.remove(ore1);
Block ore2 = ores.random();
double tr1 = Mathf.random(0.65f, 0.85f);
double tr2 = Mathf.random(0.65f, 0.85f);
boolean doheat = Mathf.chance(0.25);
boolean tendrils = Mathf.chance(0.25);
boolean tech = Mathf.chance(0.25);
int secSize = 10;
Block floord = selected[0], walld = selected[1];
Block floord2 = selected2[0], walld2 = selected2[1];
for(int x = 0; x < width; x++){ for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){ for(int y = 0; y < height; y++){
Block floor = Blocks.shale; Block floor = floord;
Block ore = Blocks.air; Block ore = Blocks.air;
Block wall = Blocks.air; Block wall = Blocks.air;
if(s1.octaveNoise2D(3, 0.5, 1/20.0, x, y) > 0.5){ if(s1.octaveNoise2D(3, 0.5, 1/20.0, x, y) > 0.5){
wall = Blocks.shaleRocks; wall = walld;
} }
if(s3.octaveNoise2D(3, 0.5, 1/20.0, x, y) > 0.5){ if(s3.octaveNoise2D(3, 0.5, 1/20.0, x, y) > 0.5){
floor = Blocks.stone; floor = floord2;
if(wall != Blocks.air){ if(wall != Blocks.air){
wall = Blocks.rocks; wall = walld2;
} }
} }
if(s2.octaveNoise2D(3, 0.3, 1/30.0, x, y) > 0.5){ if(s2.octaveNoise2D(3, 0.3, 1/30.0, x, y) > tr1){
ore = Blocks.oreCopper; ore = ore1;
} }
if(s2.octaveNoise2D(2, 0.2, 1/15.0, x, y+99999) > 0.7){ if(s2.octaveNoise2D(2, 0.2, 1/15.0, x, y+99999) > tr2){
ore = Blocks.oreLead; ore = ore2;
}
if(doheat){
double heat = s3.octaveNoise2D(4, 0.6, 1 / 50.0, x, y + 9999);
double base = 0.65;
if(heat > base){
ore = Blocks.air;
wall = Blocks.air;
floor = Blocks.ignarock;
if(heat > base + 0.1){
floor = Blocks.hotrock;
if(heat > base + 0.15){
floor = Blocks.magmarock;
}
}
}
}
if(tech){
int mx = x % secSize, my = y % secSize;
int sclx = x / secSize, scly = y / secSize;
if(s1.octaveNoise2D(2, 1f / 10f, 0.5f, sclx, scly) > 0.4f && (mx == 0 || my == 0 || mx == secSize - 1 || my == secSize - 1)){
floor = Blocks.darkPanel3;
if(Mathf.dst(mx, my, secSize/2, secSize/2) > secSize/2f + 1){
floor = Blocks.darkPanel4;
}
if(wall != Blocks.air && Mathf.chance(0.7)){
wall = Blocks.darkMetal;
}
}
}
if(tendrils){
if(rid.getValue(x, y, 1f / 17f) > 0f){
floor = Mathf.chance(0.2) ? Blocks.sporeMoss : Blocks.moss;
if(wall != Blocks.air){
wall = Blocks.sporerocks;
}
}
} }
Tile tile; Tile tile;
@@ -130,7 +214,8 @@ public class MenuRenderer implements Disposable{
} }
public void render(){ public void render(){
float scaling = 4f; time += Time.delta();
float scaling = Math.max(Unit.dp.scl(4f), Math.max(Core.graphics.getWidth() / ((width - 1f) * tilesize), Core.graphics.getHeight() / ((height - 1f) * tilesize)));
camera.position.set(width * tilesize / 2f, height * tilesize / 2f); camera.position.set(width * tilesize / 2f, height * tilesize / 2f);
camera.resize(Core.graphics.getWidth() / scaling, camera.resize(Core.graphics.getWidth() / scaling,
Core.graphics.getHeight() / scaling); Core.graphics.getHeight() / scaling);
@@ -150,12 +235,56 @@ public class MenuRenderer implements Disposable{
batch.drawCache(cacheWall); batch.drawCache(cacheWall);
batch.endDraw(); batch.endDraw();
drawFlyers();
Draw.proj(mat); Draw.proj(mat);
Draw.color(0f, 0f, 0f, darkness); Draw.color(0f, 0f, 0f, darkness);
Fill.crect(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight()); Fill.crect(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight());
Draw.color(); Draw.color();
} }
private void drawFlyers(){
Draw.color(0f, 0f, 0f, 0.4f);
flyers((x, y) -> {
Draw.rect("wraith", x - 12f, y - 13f, flyerRot - 90);
});
flyers((x, y) -> {
Draw.rect("circle-shadow", x, y, 18f, 18f);
});
Draw.color();
flyers((x, y) -> {
float engineOffset = 5.5f, engineSize = 2f, rotation = flyerRot;
Draw.color(Pal.engine);
Fill.circle(x + Angles.trnsx(rotation + 180, engineOffset), y + Angles.trnsy(rotation + 180, engineOffset),
engineSize + Mathf.absin(Time.time(), 2f, engineSize / 4f));
Draw.color(Color.WHITE);
Fill.circle(x + Angles.trnsx(rotation + 180, engineOffset - 1f), y + Angles.trnsy(rotation + 180, engineOffset - 1f),
(engineSize + Mathf.absin(Time.time(), 2f, engineSize / 4f)) / 2f);
Draw.color();
Draw.rect("wraith", x, y, flyerRot - 90);
});
}
private void flyers(PositionConsumer cons){
float tw = width * tilesize * 2;
float th = height * tilesize * 2;
float range = 500f;
float offset = -300f;
for(int i = 0; i < flyers; i++){
Tmp.v1.trns(flyerRot, time * 3f);
cons.accept((Mathf.randomSeedRange(i, range) + Tmp.v1.x + Mathf.absin(time + Mathf.randomSeedRange(i + 2, 500), 10f, 3f) + offset) % tw,
(Mathf.randomSeedRange(i + 1, range) + Tmp.v1.y + Mathf.absin(time + Mathf.randomSeedRange(i + 3, 500), 10f, 3f) + offset) % th);
}
}
@Override @Override
public void dispose(){ public void dispose(){
batch.dispose(); batch.dispose();

View File

@@ -7,24 +7,22 @@ import io.anuke.arc.util.Tmp;
public class Shapes{ public class Shapes{
public static void laser(String line, String edge, float x, float y, float x2, float y2, float scale){ public static void laser(TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float scale){
laser(line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), scale); laser(line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), scale);
} }
public static void laser(String line, String edge, float x, float y, float x2, float y2){ public static void laser(TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2){
laser(line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), 1f); laser(line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), 1f);
} }
public static void laser(String line, String edge, float x, float y, float x2, float y2, float rotation, float scale){ public static void laser(TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float rotation, float scale){
TextureRegion region = Core.atlas.find(edge);
Tmp.v1.trns(rotation, 8f * scale * Draw.scl); Tmp.v1.trns(rotation, 8f * scale * Draw.scl);
Draw.rect(Core.atlas.find(edge), x, y, region.getWidth() * scale * Draw.scl, region.getHeight() * scale * Draw.scl, rotation + 180); Draw.rect(edge, x, y, edge.getWidth() * scale * Draw.scl, edge.getHeight() * scale * Draw.scl, rotation + 180);
Draw.rect(Core.atlas.find(edge), x2, y2, region.getWidth() * scale * Draw.scl, region.getHeight() * scale * Draw.scl, rotation); Draw.rect(edge, x2, y2, edge.getWidth() * scale * Draw.scl, edge.getHeight() * scale * Draw.scl, rotation);
Lines.stroke(12f * scale); Lines.stroke(12f * scale);
Lines.line(Core.atlas.find(line), x + Tmp.v1.x, y + Tmp.v1.y, x2 - Tmp.v1.x, y2 - Tmp.v1.y, CapStyle.none, 0f); Lines.line(line, x + Tmp.v1.x, y + Tmp.v1.y, x2 - Tmp.v1.x, y2 - Tmp.v1.y, CapStyle.none, 0f);
Lines.stroke(1f); Lines.stroke(1f);
} }

View File

@@ -6,6 +6,7 @@ import io.anuke.arc.util.io.CounterInputStream;
import io.anuke.arc.util.io.FastDeflaterOutputStream; import io.anuke.arc.util.io.FastDeflaterOutputStream;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.io.versions.Save1; import io.anuke.mindustry.io.versions.Save1;
import io.anuke.mindustry.io.versions.Save2;
import io.anuke.mindustry.world.WorldContext; import io.anuke.mindustry.world.WorldContext;
import java.io.*; import java.io.*;
@@ -18,7 +19,7 @@ public class SaveIO{
/** Format header. This is the string 'MSAV' in ASCII. */ /** Format header. This is the string 'MSAV' in ASCII. */
public static final byte[] header = {77, 83, 65, 86}; public static final byte[] header = {77, 83, 65, 86};
public static final IntMap<SaveVersion> versions = new IntMap<>(); public static final IntMap<SaveVersion> versions = new IntMap<>();
public static final Array<SaveVersion> versionArray = Array.with(new Save1()); public static final Array<SaveVersion> versionArray = Array.with(new Save1(), new Save2());
static{ static{
for(SaveVersion version : versionArray){ for(SaveVersion version : versionArray){

View File

@@ -6,7 +6,8 @@ import io.anuke.arc.util.Time;
import io.anuke.arc.util.io.CounterInputStream; import io.anuke.arc.util.io.CounterInputStream;
import io.anuke.mindustry.entities.Entities; import io.anuke.mindustry.entities.Entities;
import io.anuke.mindustry.entities.EntityGroup; import io.anuke.mindustry.entities.EntityGroup;
import io.anuke.mindustry.entities.traits.*; import io.anuke.mindustry.entities.traits.Entity;
import io.anuke.mindustry.entities.traits.SaveTrait;
import io.anuke.mindustry.game.*; import io.anuke.mindustry.game.*;
import io.anuke.mindustry.gen.BrokenBlock; import io.anuke.mindustry.gen.BrokenBlock;
import io.anuke.mindustry.maps.Map; import io.anuke.mindustry.maps.Map;
@@ -20,6 +21,9 @@ import static io.anuke.mindustry.Vars.*;
public abstract class SaveVersion extends SaveFileReader{ public abstract class SaveVersion extends SaveFileReader{
public final int version; public final int version;
//HACK stores the last read build of the save file, valid after read meta call
protected int lastReadBuild;
public SaveVersion(int version){ public SaveVersion(int version){
this.version = version; this.version = version;
} }
@@ -78,6 +82,7 @@ public abstract class SaveVersion extends SaveFileReader{
state.stats = JsonIO.read(Stats.class, map.get("stats", "{}")); state.stats = JsonIO.read(Stats.class, map.get("stats", "{}"));
state.rules = JsonIO.read(Rules.class, map.get("rules", "{}")); state.rules = JsonIO.read(Rules.class, map.get("rules", "{}"));
if(state.rules.spawns.isEmpty()) state.rules.spawns = defaultWaves.get(); if(state.rules.spawns.isEmpty()) state.rules.spawns = defaultWaves.get();
lastReadBuild = map.getInt("build", -1);
Map worldmap = world.maps.byName(map.get("mapname", "\\\\\\")); Map worldmap = world.maps.byName(map.get("mapname", "\\\\\\"));
world.setMap(worldmap == null ? new Map(StringMap.of( world.setMap(worldmap == null ? new Map(StringMap.of(
@@ -222,7 +227,7 @@ public abstract class SaveVersion extends SaveFileReader{
SaveTrait save = (SaveTrait)entity; SaveTrait save = (SaveTrait)entity;
//each entity is a separate chunk. //each entity is a separate chunk.
writeChunk(stream, true, out -> { writeChunk(stream, true, out -> {
out.writeByte(save.getTypeID()); out.writeByte(save.getTypeID().id);
out.writeByte(save.version()); out.writeByte(save.version());
save.writeSave(out); save.writeSave(out);
}); });
@@ -241,9 +246,7 @@ public abstract class SaveVersion extends SaveFileReader{
readChunk(stream, true, in -> { readChunk(stream, true, in -> {
byte typeid = in.readByte(); byte typeid = in.readByte();
byte version = in.readByte(); byte version = in.readByte();
SaveTrait trait = (SaveTrait)content.<TypeID>getByID(ContentType.typeid, typeid).constructor.get();
Log.info(typeid);
SaveTrait trait = (SaveTrait)TypeTrait.getTypeByID(typeid).get();
trait.readSave(in, version); trait.readSave(in, version);
}); });
} }

View File

@@ -0,0 +1,129 @@
package io.anuke.mindustry.io.versions;
import io.anuke.arc.function.Supplier;
import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.effect.*;
import io.anuke.mindustry.entities.type.Player;
import io.anuke.mindustry.entities.type.base.*;
/*
Latest data: [build 81]
0 = Player
1 = Fire
2 = Puddle
3 = Draug
4 = Spirit
5 = Phantom
6 = Dagger
7 = Crawler
8 = Titan
9 = Fortress
10 = Eruptor
11 = Wraith
12 = Ghoul
13 = Revenant
Before removal of lightining/bullet: [build 80]
0 = Player
1 = Fire
2 = Puddle
3 = Bullet
4 = Lightning
5 = Draug
6 = Spirit
7 = Phantom
8 = Dagger
9 = Crawler
10 = Titan
11 = Fortress
12 = Eruptor
13 = Wraith
14 = Ghoul
15 = Revenant
Before addition of new units: [build 79 and below]
0 = Player
1 = Fire
2 = Puddle
3 = Bullet
4 = Lightning
5 = Spirit
6 = Dagger
7 = Crawler
8 = Titan
9 = Fortress
10 = Eruptor
11 = Wraith
12 = Ghoul
13 = Phantom
14 = Revenant
*/
public class LegacyTypeTable{
private static final Supplier[] build81Table = {
Player::new,
Fire::new,
Puddle::new,
Draug::new,
Spirit::new,
Phantom::new,
Dagger::new,
Crawler::new,
Titan::new,
Fortress::new,
Eruptor::new,
Wraith::new,
Ghoul::new,
Revenant::new
};
private static final Supplier[] build80Table = {
Player::new,
Fire::new,
Puddle::new,
Bullet::new, //TODO reading these may crash
Lightning::new,
Draug::new,
Spirit::new,
Phantom::new,
Dagger::new,
Crawler::new,
Titan::new,
Fortress::new,
Eruptor::new,
Wraith::new,
Ghoul::new,
Revenant::new
};
private static final Supplier[] build79Table = {
Player::new,
Fire::new,
Puddle::new,
Bullet::new, //TODO reading these may crash
Lightning::new,
Spirit::new,
Dagger::new,
Crawler::new,
Titan::new,
Fortress::new,
Eruptor::new,
Wraith::new,
Ghoul::new,
Phantom::new,
Revenant::new
};
public static Supplier[] getTable(int build){
if(build == -1 || build == 81){
//return most recent one since that's probably is; not guaranteed
return build81Table;
}else if(build == 80){
return build80Table;
}else{
return build79Table;
}
}
}

View File

@@ -1,10 +1,34 @@
package io.anuke.mindustry.io.versions; package io.anuke.mindustry.io.versions;
import io.anuke.arc.function.Supplier;
import io.anuke.mindustry.entities.traits.SaveTrait;
import io.anuke.mindustry.io.SaveVersion; import io.anuke.mindustry.io.SaveVersion;
import java.io.DataInput;
import java.io.IOException;
public class Save1 extends SaveVersion{ public class Save1 extends SaveVersion{
public Save1(){ public Save1(){
super(1); super(1);
} }
@Override
public void readEntities(DataInput stream) throws IOException{
Supplier[] table = LegacyTypeTable.getTable(lastReadBuild);
byte groups = stream.readByte();
for(int i = 0; i < groups; i++){
int amount = stream.readInt();
for(int j = 0; j < amount; j++){
readChunk(stream, true, in -> {
byte typeid = in.readByte();
byte version = in.readByte();
SaveTrait trait = (SaveTrait)table[typeid].get();
trait.readSave(in, version);
});
}
}
}
} }

View File

@@ -0,0 +1,9 @@
package io.anuke.mindustry.io.versions;
import io.anuke.mindustry.io.SaveVersion;
public class Save2 extends SaveVersion{
public Save2(){
super(2);
}
}

View File

@@ -12,5 +12,6 @@ public enum ContentType{
weather, weather,
effect, effect,
zone, zone,
loadout loadout,
typeid
} }

View File

@@ -6,14 +6,14 @@ import io.anuke.arc.function.Supplier;
import io.anuke.arc.graphics.g2d.TextureRegion; import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.scene.ui.layout.Table; import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.mindustry.content.Items; import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.entities.traits.TypeTrait;
import io.anuke.mindustry.entities.type.BaseUnit; import io.anuke.mindustry.entities.type.BaseUnit;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.*;
import io.anuke.mindustry.game.UnlockableContent;
import io.anuke.mindustry.ui.ContentDisplay; import io.anuke.mindustry.ui.ContentDisplay;
public class UnitType extends UnlockableContent{ public class UnitType extends UnlockableContent{
protected final Supplier<? extends BaseUnit> constructor; public final TypeID typeID;
public final Supplier<? extends BaseUnit> constructor;
public float health = 60; public float health = 60;
public float hitsize = 7f; public float hitsize = 7f;
public float hitsizeTile = 4f; public float hitsizeTile = 4f;
@@ -42,8 +42,7 @@ public class UnitType extends UnlockableContent{
super(name); super(name);
this.constructor = mainConstructor; this.constructor = mainConstructor;
this.description = Core.bundle.getOrNull("unit." + name + ".description"); this.description = Core.bundle.getOrNull("unit." + name + ".description");
this.typeID = new TypeID(name, mainConstructor);
TypeTrait.registerType(type, mainConstructor);
} }
@Override @Override

View File

@@ -25,7 +25,7 @@ public class ContentDisplay{
table.row(); table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(8).padLeft(0).padRight(0).fillX(); table.addImage("whiteui").height(3).color(Color.LIGHT_GRAY).pad(8).padLeft(0).padRight(0).fillX();
table.row(); table.row();
@@ -33,7 +33,7 @@ public class ContentDisplay{
table.add(block.description).padLeft(5).padRight(5).width(400f).wrap().fillX(); table.add(block.description).padLeft(5).padRight(5).width(400f).wrap().fillX();
table.row(); table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(8).padLeft(0).padRight(0).fillX(); table.addImage("whiteui").height(3).color(Color.LIGHT_GRAY).pad(8).padLeft(0).padRight(0).fillX();
table.row(); table.row();
} }
@@ -73,7 +73,7 @@ public class ContentDisplay{
table.row(); table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX(); table.addImage("whiteui").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row(); table.row();
@@ -81,7 +81,7 @@ public class ContentDisplay{
table.add(item.description).padLeft(5).padRight(5).width(400f).wrap().fillX(); table.add(item.description).padLeft(5).padRight(5).width(400f).wrap().fillX();
table.row(); table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX(); table.addImage("whiteui").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row(); table.row();
} }
@@ -104,7 +104,7 @@ public class ContentDisplay{
table.row(); table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX(); table.addImage("whiteui").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row(); table.row();
@@ -112,7 +112,7 @@ public class ContentDisplay{
table.add(liquid.description).padLeft(5).padRight(5).width(400f).wrap().fillX(); table.add(liquid.description).padLeft(5).padRight(5).width(400f).wrap().fillX();
table.row(); table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX(); table.addImage("whiteui").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row(); table.row();
} }
@@ -139,7 +139,7 @@ public class ContentDisplay{
table.row(); table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX(); table.addImage("whiteui").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row(); table.row();
@@ -147,7 +147,7 @@ public class ContentDisplay{
table.add(mech.description).padLeft(5).padRight(5).width(400f).wrap().fillX(); table.add(mech.description).padLeft(5).padRight(5).width(400f).wrap().fillX();
table.row(); table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX(); table.addImage("whiteui").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row(); table.row();
} }
@@ -186,7 +186,7 @@ public class ContentDisplay{
table.row(); table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX(); table.addImage("whiteui").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row(); table.row();
@@ -194,7 +194,7 @@ public class ContentDisplay{
table.add(unit.description).padLeft(5).padRight(5).width(400f).wrap().fillX(); table.add(unit.description).padLeft(5).padRight(5).width(400f).wrap().fillX();
table.row(); table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX(); table.addImage("whiteui").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row(); table.row();
} }

View File

@@ -46,9 +46,9 @@ public class AboutDialog extends FloatingDialog{
Table table = new Table("underline"); Table table = new Table("underline");
table.margin(0); table.margin(0);
table.table(img -> { table.table(img -> {
img.addImage("white").height(h - 5).width(40f).color(link.color); img.addImage("whiteui").height(h - 5).width(40f).color(link.color);
img.row(); img.row();
img.addImage("white").height(5).width(40f).color(link.color.cpy().mul(0.8f, 0.8f, 0.8f, 1f)); img.addImage("whiteui").height(5).width(40f).color(link.color.cpy().mul(0.8f, 0.8f, 0.8f, 1f));
}).expandY(); }).expandY();
table.table(i -> { table.table(i -> {

View File

@@ -25,7 +25,7 @@ public class ColorPickDialog extends Dialog{
for(int i = 0; i < playerColors.length; i++){ for(int i = 0; i < playerColors.length; i++){
Color color = playerColors[i]; Color color = playerColors[i];
ImageButton button = table.addImageButton("white", "clear-toggle", 34, () -> { ImageButton button = table.addImageButton("whiteui", "clear-toggle", 34, () -> {
cons.accept(color); cons.accept(color);
hide(); hide();
}).size(48).get(); }).size(48).get();

View File

@@ -15,7 +15,7 @@ public class ControlsDialog extends KeybindDialog{
setFillParent(true); setFillParent(true);
title.setAlignment(Align.center); title.setAlignment(Align.center);
titleTable.row(); titleTable.row();
titleTable.add(new Image("white")) titleTable.add(new Image("whiteui"))
.growX().height(3f).pad(4f).get().setColor(Pal.accent); .growX().height(3f).pad(4f).get().setColor(Pal.accent);
} }

View File

@@ -40,7 +40,7 @@ public class DatabaseDialog extends FloatingDialog{
table.add("$content." + type.name() + ".name").growX().left().color(Pal.accent); table.add("$content." + type.name() + ".name").growX().left().color(Pal.accent);
table.row(); table.row();
table.addImage("white").growX().pad(5).padLeft(0).padRight(0).height(3).color(Pal.accent); table.addImage("whiteui").growX().pad(5).padLeft(0).padRight(0).height(3).color(Pal.accent);
table.row(); table.row();
table.table(list -> { table.table(list -> {
list.left(); list.left();

View File

@@ -22,9 +22,9 @@ public class DiscordDialog extends Dialog{
t.background("button").margin(0); t.background("button").margin(0);
t.table(img -> { t.table(img -> {
img.addImage("white").height(h - 5).width(40f).color(color); img.addImage("whiteui").height(h - 5).width(40f).color(color);
img.row(); img.row();
img.addImage("white").height(5).width(40f).color(color.cpy().mul(0.8f, 0.8f, 0.8f, 1f)); img.addImage("whiteui").height(5).width(40f).color(color.cpy().mul(0.8f, 0.8f, 0.8f, 1f));
}).expandY(); }).expandY();
t.table(i -> { t.table(i -> {

View File

@@ -23,7 +23,7 @@ public class FloatingDialog extends Dialog{
setFillParent(true); setFillParent(true);
this.title.setAlignment(Align.center); this.title.setAlignment(Align.center);
titleTable.row(); titleTable.row();
titleTable.addImage("white", Pal.accent) titleTable.addImage("whiteui", Pal.accent)
.growX().height(3f).pad(4f); .growX().height(3f).pad(4f);
hidden(() -> { hidden(() -> {

View File

@@ -30,7 +30,7 @@ public class HostDialog extends FloatingDialog{
ui.listfrag.rebuild(); ui.listfrag.rebuild();
}).grow().pad(8).get().setMaxLength(40); }).grow().pad(8).get().setMaxLength(40);
ImageButton button = t.addImageButton("white", "clear-full", 40, () -> { ImageButton button = t.addImageButton("whiteui", "clear-full", 40, () -> {
new ColorPickDialog().show(color -> { new ColorPickDialog().show(color -> {
player.color.set(color); player.color.set(color);
Core.settings.put("color-0", Color.rgba8888(color)); Core.settings.put("color-0", Color.rgba8888(color));

View File

@@ -223,7 +223,7 @@ public class JoinDialog extends FloatingDialog{
Core.settings.save(); Core.settings.save();
}).grow().pad(8).get().setMaxLength(maxNameLength); }).grow().pad(8).get().setMaxLength(maxNameLength);
ImageButton button = t.addImageButton("white", "clear-full", 40, () -> { ImageButton button = t.addImageButton("whiteui", "clear-full", 40, () -> {
new ColorPickDialog().show(color -> { new ColorPickDialog().show(color -> {
player.color.set(color); player.color.set(color);
Core.settings.put("color-0", Color.rgba8888(color)); Core.settings.put("color-0", Color.rgba8888(color));

View File

@@ -106,7 +106,7 @@ public class MapsDialog extends FloatingDialog{
button.margin(9); button.margin(9);
button.add(map.name()).width(mapsize - 18f).center().get().setEllipsis(true); button.add(map.name()).width(mapsize - 18f).center().get().setEllipsis(true);
button.row(); button.row();
button.addImage("white").growX().pad(4).color(Color.GRAY); button.addImage("whiteui").growX().pad(4).color(Color.GRAY);
button.row(); button.row();
button.stack(new Image(map.texture).setScaling(Scaling.fit), new BorderImage(map.texture).setScaling(Scaling.fit)).size(mapsize - 20f); button.stack(new Image(map.texture).setScaling(Scaling.fit), new BorderImage(map.texture).setScaling(Scaling.fit)).size(mapsize - 20f);
button.row(); button.row();

View File

@@ -48,7 +48,7 @@ public class SettingsMenuDialog extends SettingsDialog{
setFillParent(true); setFillParent(true);
title.setAlignment(Align.center); title.setAlignment(Align.center);
titleTable.row(); titleTable.row();
titleTable.add(new Image("white")).growX().height(3f).pad(4f).get().setColor(Pal.accent); titleTable.add(new Image("whiteui")).growX().height(3f).pad(4f).get().setColor(Pal.accent);
cont.clearChildren(); cont.clearChildren();
cont.remove(); cont.remove();

View File

@@ -101,7 +101,7 @@ public class ZoneInfoDialog extends FloatingDialog{
}else{ }else{
cont.add(zone.localizedName()).color(Pal.accent).growX().center(); cont.add(zone.localizedName()).color(Pal.accent).growX().center();
cont.row(); cont.row();
cont.addImage("white").color(Pal.accent).height(3).pad(6).growX(); cont.addImage("whiteui").color(Pal.accent).height(3).pad(6).growX();
cont.row(); cont.row();
cont.addButton(zone.canConfigure() ? "$configure" : Core.bundle.format("configure.locked", zone.configureWave), () -> loadout.show(zone, rebuildItems)).fillX().pad(3).disabled(b -> !zone.canConfigure()); cont.addButton(zone.canConfigure() ? "$configure" : Core.bundle.format("configure.locked", zone.configureWave), () -> loadout.show(zone, rebuildItems)).fillX().pad(3).disabled(b -> !zone.canConfigure());
cont.row(); cont.row();

View File

@@ -528,7 +528,7 @@ public class HudFragment extends Fragment{
} }
public void showLaunch(){ public void showLaunch(){
Image image = new Image("white"); Image image = new Image("whiteui");
image.getColor().a = 0f; image.getColor().a = 0f;
image.setFillParent(true); image.setFillParent(true);
image.actions(Actions.fadeIn(40f / 60f)); image.actions(Actions.fadeIn(40f / 60f));

View File

@@ -18,11 +18,11 @@ public class LoadingFragment extends Fragment{
t.touchable(Touchable.enabled); t.touchable(Touchable.enabled);
t.add().height(70f).row(); t.add().height(70f).row();
t.addImage("white").growX().height(3f).pad(4f).growX().get().setColor(Pal.accent); t.addImage("whiteui").growX().height(3f).pad(4f).growX().get().setColor(Pal.accent);
t.row(); t.row();
t.add("$loading").name("namelabel").pad(10f); t.add("$loading").name("namelabel").pad(10f);
t.row(); t.row();
t.addImage("white").growX().height(3f).pad(4f).growX().get().setColor(Pal.accent); t.addImage("whiteui").growX().height(3f).pad(4f).growX().get().setColor(Pal.accent);
t.row(); t.row();
button = t.addButton("$cancel", () -> { button = t.addButton("$cancel", () -> {

View File

@@ -62,11 +62,11 @@ public class MenuFragment extends Fragment{
parent.fill((x, y, w, h) -> { parent.fill((x, y, w, h) -> {
float logoscl = (int)Unit.dp.scl(1); float logoscl = (int)Unit.dp.scl(1);
float logow = Math.min(Math.min(logo.getWidth() * logoscl, 768), Core.graphics.getWidth() - 10); float logow = Math.min(logo.getWidth() * logoscl, Core.graphics.getWidth() - Unit.dp.scl(20));
float logoh = logow * (float)logo.getHeight() / logo.getWidth(); float logoh = logow * (float)logo.getHeight() / logo.getWidth();
Draw.color(); Draw.color();
Draw.rect(Draw.wrap(logo), (int)(Core.graphics.getWidth() / 2), (int)(Core.graphics.getHeight() - 10 - logoh) + logoh / 2, logow, logoh); Draw.rect(Draw.wrap(logo), (int)(Core.graphics.getWidth() / 2), (int)(Core.graphics.getHeight() - 10 - logoh) + logoh / 2 - (Core.graphics.isPortrait() ? Unit.dp.scl(30f) : 0f), logow, logoh);
}).touchable(Touchable.disabled); }).touchable(Touchable.disabled);
} }

View File

@@ -0,0 +1,44 @@
package io.anuke.mindustry.world;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.util.Tmp;
import io.anuke.mindustry.world.blocks.StaticWall;
import static io.anuke.mindustry.Vars.tilesize;
public class StaticTree extends StaticWall{
public StaticTree(String name){
super(name);
}
@Override
public void draw(Tile tile){
TextureRegion r = Tmp.tr1;
r.set(region);
int crop = (region.getWidth() - tilesize*4) / 2;
float ox = 0;
float oy = 0;
for(int i = 0; i < 4; i++){
if(tile.getNearby(i) != null && tile.getNearby(i).block() instanceof StaticWall){
if(i == 0){
r.setWidth(r.getWidth() - crop);
ox -= crop /2f;
}else if(i == 1){
r.setY(r.getY() + crop);
oy -= crop /2f;
}else if(i == 2){
r.setX(r.getX() + crop);
ox += crop /2f;
}else{
r.setHeight(r.getHeight() - crop);
oy += crop /2f;
}
}
}
Draw.rect(r, tile.drawx() + ox * Draw.scl, tile.drawy() + oy * Draw.scl);
}
}

View File

@@ -28,7 +28,7 @@ public class ItemSelection{
for(Item item : items){ for(Item item : items){
if(!data.isUnlocked(item) && world.isZone()) continue; if(!data.isUnlocked(item) && world.isZone()) continue;
ImageButton button = cont.addImageButton("white", "clear-toggle", 24, () -> control.input().frag.config.hideConfig()).group(group).get(); ImageButton button = cont.addImageButton("whiteui", "clear-toggle", 24, () -> control.input().frag.config.hideConfig()).group(group).get();
button.changed(() -> consumer.accept(button.isChecked() ? item : null)); button.changed(() -> consumer.accept(button.isChecked() ? item : null));
button.getStyle().imageUp = new TextureRegionDrawable(item.icon(Icon.medium)); button.getStyle().imageUp = new TextureRegionDrawable(item.icon(Icon.medium));
button.update(() -> button.setChecked(holder.get() == item)); button.update(() -> button.setChecked(holder.get() == item));

View File

@@ -2,7 +2,7 @@ package io.anuke.mindustry.world.blocks.defense;
import io.anuke.arc.graphics.Blending; import io.anuke.arc.graphics.Blending;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.*; import io.anuke.arc.math.geom.*;
import io.anuke.arc.util.Time; import io.anuke.arc.util.Time;
@@ -35,7 +35,7 @@ public class DeflectorWall extends Wall{
Draw.color(Color.WHITE); Draw.color(Color.WHITE);
Draw.alpha(entity.hit * 0.5f); Draw.alpha(entity.hit * 0.5f);
Draw.blend(Blending.additive); Draw.blend(Blending.additive);
Draw.rect("blank", tile.drawx(), tile.drawy(), tilesize * size, tilesize * size); Fill.rect(tile.drawx(), tile.drawy(), tilesize * size, tilesize * size);
Draw.blend(); Draw.blend();
Draw.reset(); Draw.reset();

View File

@@ -2,25 +2,20 @@ package io.anuke.mindustry.world.blocks.defense;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.collection.IntSet; import io.anuke.arc.collection.IntSet;
import io.anuke.arc.graphics.Blending;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time; import io.anuke.arc.util.*;
import io.anuke.arc.util.Tmp;
import io.anuke.mindustry.content.Fx; import io.anuke.mindustry.content.Fx;
import io.anuke.mindustry.entities.Effects; import io.anuke.mindustry.entities.Effects;
import io.anuke.mindustry.entities.type.TileEntity; import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.graphics.Pal; import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.meta.*;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit;
import java.io.*; import java.io.*;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.world;
public class MendProjector extends Block{ public class MendProjector extends Block{
private static Color color = Color.valueOf("84f491"); private static Color color = Color.valueOf("84f491");
@@ -130,13 +125,13 @@ public class MendProjector extends Block{
Draw.color(color, phase, entity.phaseHeat); Draw.color(color, phase, entity.phaseHeat);
Draw.alpha(entity.heat * Mathf.absin(Time.time(), 10f, 1f) * 0.5f); Draw.alpha(entity.heat * Mathf.absin(Time.time(), 10f, 1f) * 0.5f);
Draw.blend(Blending.additive); //Draw.blend(Blending.additive);
Draw.rect(topRegion, tile.drawx(), tile.drawy()); Draw.rect(topRegion, tile.drawx(), tile.drawy());
Draw.blend(); //Draw.blend();
Draw.alpha(1f); Draw.alpha(1f);
Lines.stroke((2f * f + 0.2f) * entity.heat); Lines.stroke((2f * f + 0.2f) * entity.heat);
Lines.circle(tile.drawx(), tile.drawy(), ((1f - f) * 8f) * size / 2f); Lines.square(tile.drawx(), tile.drawy(), ((1f - f) * 8f) * size / 2f);
Draw.reset(); Draw.reset();
} }

View File

@@ -2,22 +2,18 @@ package io.anuke.mindustry.world.blocks.defense;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.collection.IntSet; import io.anuke.arc.collection.IntSet;
import io.anuke.arc.graphics.Blending;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time; import io.anuke.arc.util.Time;
import io.anuke.mindustry.entities.type.TileEntity; import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.graphics.Pal; import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.meta.*;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit;
import java.io.*; import java.io.*;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.world;
public class OverdriveProjector extends Block{ public class OverdriveProjector extends Block{
private static Color color = Color.valueOf("feb380"); private static Color color = Color.valueOf("feb380");
@@ -130,12 +126,12 @@ public class OverdriveProjector extends Block{
Draw.color(color, phase, entity.phaseHeat); Draw.color(color, phase, entity.phaseHeat);
Draw.alpha(entity.heat * Mathf.absin(Time.time(), 10f, 1f) * 0.5f); Draw.alpha(entity.heat * Mathf.absin(Time.time(), 10f, 1f) * 0.5f);
Draw.blend(Blending.additive); //Draw.blend(Blending.additive);
Draw.rect(topRegion, tile.drawx(), tile.drawy()); Draw.rect(topRegion, tile.drawx(), tile.drawy());
Draw.blend(); //Draw.blend();
Draw.alpha(1f); Draw.alpha(1f);
Lines.stroke((2f * f + 0.2f) * entity.heat); Lines.stroke((2f * f + 0.2f) * entity.heat);
Lines.circle(tile.drawx(), tile.drawy(), (1f - f) * 9f); Lines.square(tile.drawx(), tile.drawy(), (1f - f) * 8f);
Draw.reset(); Draw.reset();
} }

View File

@@ -2,7 +2,7 @@ package io.anuke.mindustry.world.blocks.distribution;
import io.anuke.annotations.Annotations.*; import io.anuke.annotations.Annotations.*;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.scene.ui.layout.Table; import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.mindustry.entities.type.*; import io.anuke.mindustry.entities.type.*;
@@ -54,7 +54,7 @@ public class Sorter extends Block{
if(entity.sortItem == null) return; if(entity.sortItem == null) return;
Draw.color(entity.sortItem.color); Draw.color(entity.sortItem.color);
Draw.rect("blank", tile.worldx(), tile.worldy(), 4f, 4f); Draw.rect("center", tile.worldx(), tile.worldy());
Draw.color(); Draw.color();
} }

View File

@@ -36,7 +36,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
protected Effects.Effect generateEffect = Fx.generatespark; protected Effects.Effect generateEffect = Fx.generatespark;
protected Effects.Effect explodeEffect = Fx.generatespark; protected Effects.Effect explodeEffect = Fx.generatespark;
protected Color heatColor = Color.valueOf("ff9b59"); protected Color heatColor = Color.valueOf("ff9b59");
protected TextureRegion topRegion; protected TextureRegion topRegion, liquidRegion;
protected boolean randomlyExplode = false; protected boolean randomlyExplode = false;
public ItemLiquidGenerator(boolean hasItems, boolean hasLiquids, String name){ public ItemLiquidGenerator(boolean hasItems, boolean hasLiquids, String name){
@@ -59,6 +59,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
if(hasItems){ if(hasItems){
topRegion = Core.atlas.find(name + "-top"); topRegion = Core.atlas.find(name + "-top");
} }
liquidRegion = Core.atlas.find(name + "-liquid");
} }
@Override @Override
@@ -151,15 +152,11 @@ public class ItemLiquidGenerator extends PowerGenerator{
if(hasLiquids){ if(hasLiquids){
Draw.color(entity.liquids.current().color); Draw.color(entity.liquids.current().color);
Draw.alpha(entity.liquids.currentAmount() / liquidCapacity); Draw.alpha(entity.liquids.currentAmount() / liquidCapacity);
drawLiquidCenter(tile); Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
Draw.color(); Draw.color();
} }
} }
public void drawLiquidCenter(Tile tile){
Draw.rect("blank", tile.drawx(), tile.drawy(), 2, 2);
}
protected float getItemEfficiency(Item item){ protected float getItemEfficiency(Item item){
return 0.0f; return 0.0f;
} }

View File

@@ -2,8 +2,7 @@ package io.anuke.mindustry.world.blocks.power;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Vector2; import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Time; import io.anuke.arc.util.Time;
@@ -155,7 +154,7 @@ public class NuclearReactor extends PowerGenerator{
NuclearReactorEntity entity = tile.entity(); NuclearReactorEntity entity = tile.entity();
Draw.color(coolColor, hotColor, entity.heat); Draw.color(coolColor, hotColor, entity.heat);
Draw.rect("white", tile.drawx(), tile.drawy(), size * tilesize, size * tilesize); Fill.rect(tile.drawx(), tile.drawy(), size * tilesize, size * tilesize);
Draw.color(entity.liquids.current().color); Draw.color(entity.liquids.current().color);
Draw.alpha(entity.liquids.currentAmount() / liquidCapacity); Draw.alpha(entity.liquids.currentAmount() / liquidCapacity);

View File

@@ -4,8 +4,7 @@ import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote; import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.math.Angles; import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Intersector; import io.anuke.arc.math.geom.Intersector;
@@ -29,7 +28,7 @@ public class PowerNode extends PowerBlock{
private static int lastPlaced = -1; private static int lastPlaced = -1;
protected Vector2 t1 = new Vector2(); protected Vector2 t1 = new Vector2();
protected Vector2 t2 = new Vector2(); protected TextureRegion laser, laserEnd;
protected float laserRange = 6; protected float laserRange = 6;
protected int maxNodes = 3; protected int maxNodes = 3;
@@ -86,6 +85,14 @@ public class PowerNode extends PowerBlock{
} }
} }
@Override
public void load(){
super.load();
laser = Core.atlas.find("laser");
laserEnd = Core.atlas.find("laser-end");
}
@Override @Override
public void setBars(){ public void setBars(){
super.setBars(); super.setBars();
@@ -204,7 +211,7 @@ public class PowerNode extends PowerBlock{
for(int i = 0; i < entity.power.links.size; i++){ for(int i = 0; i < entity.power.links.size; i++){
Tile link = world.tile(entity.power.links.get(i)); Tile link = world.tile(entity.power.links.get(i));
if(linkValid(tile, link)){ if(link != null && (link.pos() < tile.pos() || !(link.block() instanceof PowerNode) || !Core.camera.bounds(Tmp.r1).contains(link.drawx(), link.drawy()))){
drawLaser(tile, link); drawLaser(tile, link);
} }
} }
@@ -237,26 +244,21 @@ public class PowerNode extends PowerBlock{
} }
protected void drawLaser(Tile tile, Tile target){ protected void drawLaser(Tile tile, Tile target){
float x1 = tile.drawx(), y1 = tile.drawy(), float x1 = tile.drawx(), y1 = tile.drawy(),
x2 = target.drawx(), y2 = target.drawy(); x2 = target.drawx(), y2 = target.drawy();
float angle1 = Angles.angle(x1, y1, x2, y2); float angle1 = Angles.angle(x1, y1, x2, y2);
float angle2 = angle1 + 180f;
t1.trns(angle1, tile.block().size * tilesize / 2f - 1.5f); t1.trns(angle1, tile.block().size * tilesize / 2f - 1.5f);
t2.trns(angle2, target.block().size * tilesize / 2f - 1.5f);
x1 += t1.x; x1 += t1.x;
y1 += t1.y; y1 += t1.y;
x2 += t2.x; x2 -= t1.x;
y2 += t2.y; y2 -= t1.y;
Draw.color(Pal.powerLight, Color.WHITE, Mathf.absin(Time.time(), 8f, 0.3f) + 0.2f); Draw.color(Pal.powerLight, Color.WHITE, Mathf.absin(Time.time(), 8f, 0.3f) + 0.2f);
//Lines.stroke(2f); Shapes.laser(laser, laserEnd, x1, y1, x2, y2, 0.6f);
//Lines.line(x1, y1, x2, y2); Draw.color();
Shapes.laser("laser", "laser-end", x1, y1, x2, y2, 0.6f);
} }
} }

View File

@@ -5,8 +5,7 @@ import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.ObjectIntMap; import io.anuke.arc.collection.ObjectIntMap;
import io.anuke.arc.graphics.Blending; import io.anuke.arc.graphics.Blending;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Strings; import io.anuke.arc.util.Strings;
import io.anuke.arc.util.Time; import io.anuke.arc.util.Time;
@@ -116,7 +115,7 @@ public class Drill extends Block{
if(entity.dominantItem != null && drawMineItem){ if(entity.dominantItem != null && drawMineItem){
Draw.color(entity.dominantItem.color); Draw.color(entity.dominantItem.color);
Draw.rect("blank", tile.drawx(), tile.drawy(), 2f, 2f); Fill.square(tile.drawx(), tile.drawy(), 1f);
Draw.color(); Draw.color();
} }
} }

View File

@@ -1,17 +1,14 @@
package io.anuke.mindustry.world.blocks.storage; package io.anuke.mindustry.world.blocks.storage;
import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.*;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.scene.ui.layout.Table; import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.mindustry.entities.type.Player; import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.ItemSelection; import io.anuke.mindustry.world.blocks.ItemSelection;
import java.io.*; import java.io.*;
@@ -81,7 +78,7 @@ public class Unloader extends Block{
SortedUnloaderEntity entity = tile.entity(); SortedUnloaderEntity entity = tile.entity();
Draw.color(entity.sortItem == null ? Color.CLEAR : entity.sortItem.color); Draw.color(entity.sortItem == null ? Color.CLEAR : entity.sortItem.color);
Draw.rect("blank", tile.worldx(), tile.worldy(), 2f, 2f); Fill.square(tile.worldx(), tile.worldy(), 1f);
Draw.color(); Draw.color();
} }

View File

@@ -25,6 +25,7 @@ public class RepairPoint extends Block{
protected float repairSpeed = 0.3f; protected float repairSpeed = 0.3f;
protected float powerUse; protected float powerUse;
protected TextureRegion baseRegion; protected TextureRegion baseRegion;
protected TextureRegion laser, laserEnd;
public RepairPoint(String name){ public RepairPoint(String name){
super(name); super(name);
@@ -32,7 +33,7 @@ public class RepairPoint extends Block{
solid = true; solid = true;
flags = EnumSet.of(BlockFlag.repair); flags = EnumSet.of(BlockFlag.repair);
layer = Layer.turret; layer = Layer.turret;
layer2 = Layer.laser; layer2 = Layer.power;
hasPower = true; hasPower = true;
outlineIcon = true; outlineIcon = true;
} }
@@ -42,6 +43,8 @@ public class RepairPoint extends Block{
super.load(); super.load();
baseRegion = Core.atlas.find(name + "-base"); baseRegion = Core.atlas.find(name + "-base");
laser = Core.atlas.find("laser");
laserEnd = Core.atlas.find("laser-end");
} }
@Override @Override
@@ -79,9 +82,9 @@ public class RepairPoint extends Block{
float len = 5f; float len = 5f;
Draw.color(Color.valueOf("e8ffd7")); Draw.color(Color.valueOf("e8ffd7"));
Shapes.laser("laser", "laser-end", Shapes.laser(laser, laserEnd,
tile.drawx() + Angles.trnsx(ang, len), tile.drawy() + Angles.trnsy(ang, len), tile.drawx() + Angles.trnsx(ang, len), tile.drawy() + Angles.trnsy(ang, len),
entity.target.x, entity.target.y, entity.strength); entity.target.x, entity.target.y, entity.strength);
Draw.color(); Draw.color();
} }
} }

View File

@@ -300,32 +300,24 @@ task pack(dependsOn: classes){
workingDir = "../core/assets-raw/sprites_out/ui/icons" workingDir = "../core/assets-raw/sprites_out/ui/icons"
} }
//antialias everything except UI elements (...for some reason) copy{
from "../core/assets-raw/sprites_out/ui/icons"
into "../core/assets-raw/sprites_out/ui/"
}
delete{
delete "../core/assets-raw/sprites_out/ui/icons"
}
//antialias everything except UI elements
fileTree(dir: '../core/assets-raw/sprites_out/', include: "**/*.png").visit{ file -> fileTree(dir: '../core/assets-raw/sprites_out/', include: "**/*.png").visit{ file ->
if(file.isDirectory() || (file.toString().replace("\\", "/").contains("/ui/") && !file.toString().replace("\\", "/").contains("/icons/"))) return if(file.isDirectory() || (file.toString().replace("\\", "/").contains("/ui/"))) return
antialias(file.file) antialias(file.file)
} }
//pack normal sprites //pack normal sprites
TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites.atlas") TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites.atlas")
//delete old pack defintions
delete{
delete fileTree(dir: '../core/assets-raw/sprites_out/', include: '**/pack.json')
}
if(false){
//rename pack definitions, generate fallback 1024x sprites
copy{
from '../core/assets-raw/sprites_out/'
into '../core/assets-raw/sprites_out/'
include "**/*.json"
rename 'pack_fallback.json', "pack.json"
}
TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites_fallback.atlas")
}
} }
} }