Refactored almost every class, somehow didn't break game yet

This commit is contained in:
Anuken
2018-01-27 23:42:42 -05:00
parent 78c8dc4902
commit 35b6b41f24
110 changed files with 1648 additions and 1463 deletions

View File

@@ -1,113 +1,26 @@
package io.anuke.mindustry;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.I18NBundle;
import io.anuke.mindustry.core.*;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.io.PlatformFunction;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.BlockLoader;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.mindustry.io.BundleLoader;
import io.anuke.mindustry.io.BlockLoader;
import io.anuke.ucore.modules.ModuleCore;
import static io.anuke.mindustry.Vars.*;
import java.util.Locale;
public class Mindustry extends ModuleCore {
public static boolean hasDiscord = true;
public static Array<String> args = new Array<>();
public static PlatformFunction platforms = new PlatformFunction(){};
public static boolean externalBundle = false;
@Override
public void init(){
if(args.contains("-debug", false)) debug = true;
Settings.defaults("locale", "default");
Settings.load("io.anuke.moment");
loadBundle();
BundleLoader.load();
BlockLoader.load();
UCore.log("Total blocks loaded: " + Block.getAllBlocks().size);
module(logic = new Logic());
module(world = new World());
module(control = new Control());
module(logic = new Logic());
module(renderer = new Renderer());
module(ui = new UI());
module(netServer = new NetServer());
module(netClient = new NetClient());
}
@Override
public void dispose() {
state.set(State.menu);
platforms.onGameExit();
Net.dispose();
super.dispose();
}
public Locale getLocale(){
String loc = Settings.getString("locale");
if(loc.equals("default")){
return Locale.getDefault();
}else{
Locale lastLocale;
if (loc.contains("_")) {
String[] split = loc.split("_");
lastLocale = new Locale(split[0], split[1]);
} else {
lastLocale = new Locale(loc);
}
return lastLocale;
}
}
public void loadBundle(){
I18NBundle.setExceptionOnMissingKey(false);
if(externalBundle){
try {
FileHandle handle = Gdx.files.local("bundle");
Locale locale = Locale.ENGLISH;
Core.bundle = I18NBundle.createBundle(handle, locale);
}catch (Exception e){
UCore.error(e);
platforms.showError("Failed to find bundle!\nMake sure you have bundle.properties in the same directory\nas the jar file.\n\nIf the problem persists, try running it through the command prompt:\n" +
"Hold left-shift, then right click and select 'open command prompt here'.\nThen, type in 'java -jar mindustry.jar' without quotes.");
Gdx.app.exit();
}
}else{
FileHandle handle = Gdx.files.internal("bundles/bundle");
Locale locale = getLocale();
UCore.log("Got locale: " + locale);
Core.bundle = I18NBundle.createBundle(handle, locale);
}
}
@Override
public void postInit(){
control.reset();
}
@Override
public void render(){
super.render();
if(!GameState.is(State.paused) || Net.active()){
Timers.update();
}
Inputs.update();
module(netCommon = new NetCommon());
}
}

View File

@@ -73,9 +73,6 @@ public class Vars{
//only if smoothCamera
public static boolean snapCamera = true;
//turret and enemy shootInternal speed inverse multiplier
public static final float multiplier = android ? 3 : 2;
public static final int tilesize = 8;
//server port
@@ -89,6 +86,7 @@ public class Vars{
public static Renderer renderer;
public static UI ui;
public static World world;
public static NetCommon netCommon;
public static NetServer netServer;
public static NetClient netClient;

View File

@@ -1,11 +1,12 @@
package io.anuke.mindustry.ai;
import com.badlogic.gdx.ai.pfa.Heuristic;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.function.Predicate;
import static io.anuke.mindustry.Vars.tilesize;
public class Heuristics {
/**How many times more it costs to go through a destructible block than an empty block.*/
static final float solidMultiplier = 5f;
@@ -23,11 +24,11 @@ public class Heuristics {
//If either one of the tiles is a breakable solid block (that is, it's player-made),
//increase the cost by the tilesize times the solid block multiplier
//Also add the block health, so blocks with more health cost more to traverse
if(node.breakable() && node.block().solid) cost += Vars.tilesize* solidMultiplier + node.block().health;
if(other.breakable() && other.block().solid) cost += Vars.tilesize* solidMultiplier + other.block().health;
if(node.breakable() && node.block().solid) cost += tilesize* solidMultiplier + node.block().health;
if(other.breakable() && other.block().solid) cost += tilesize* solidMultiplier + other.block().health;
//if this block has solid blocks near it, increase the cost, as we don't want enemies hugging walls
if(node.occluded) cost += Vars.tilesize*occludedMultiplier;
if(node.occluded) cost += tilesize*occludedMultiplier;
return cost;
}
@@ -50,11 +51,11 @@ public class Heuristics {
//If either one of the tiles is a breakable solid block (that is, it's player-made),
//increase the cost by the tilesize times the solid block multiplier
//Also add the block health, so blocks with more health cost more to traverse
if(node.breakable() && node.block().solid) cost += Vars.tilesize* solidMultiplier + node.block().health;
if(other.breakable() && other.block().solid) cost += Vars.tilesize* solidMultiplier + other.block().health;
if(node.breakable() && node.block().solid) cost += tilesize* solidMultiplier + node.block().health;
if(other.breakable() && other.block().solid) cost += tilesize* solidMultiplier + other.block().health;
//if this block has solid blocks near it, increase the cost, as we don't want enemies hugging walls
if(node.occluded) cost += Vars.tilesize*occludedMultiplier;
if(node.occluded) cost += tilesize*occludedMultiplier;
if(other.getLinked() != null) other = other.getLinked();
if(node.getLinked() != null) node = node.getLinked();

View File

@@ -4,7 +4,6 @@ import com.badlogic.gdx.ai.pfa.PathFinderRequest;
import com.badlogic.gdx.ai.pfa.PathSmoother;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.world.Tile;
@@ -14,6 +13,8 @@ import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.*;
public class Pathfind{
/**Maximum time taken per frame on pathfinding for a single path.*/
private static final long maxTime = 1000000 * 5;
@@ -39,11 +40,11 @@ public class Pathfind{
enemy.node = -1;
}
if(enemy.node < 0 || Vars.control.getSpawnPoints().get(enemy.lane).pathTiles == null){
if(enemy.node < 0 || world.getSpawns().get(enemy.lane).pathTiles == null){
return vector.set(enemy.x, enemy.y);
}
Tile[] path = Vars.control.getSpawnPoints().get(enemy.lane).pathTiles;
Tile[] path = world.getSpawns().get(enemy.lane).pathTiles;
if(enemy.node >= path.length){
enemy.node = -1;
@@ -60,7 +61,7 @@ public class Pathfind{
Tile target = path[enemy.node];
//a bridge has been broken, re-path
if(!Vars.world.passable(target.x, target.y)){
if(!world.passable(target.x, target.y)){
remakePath();
return vector.set(enemy.x, enemy.y);
}
@@ -108,8 +109,8 @@ public class Pathfind{
/**Re-calculate paths for all enemies. Runs when a path changes while moving.*/
private void remakePath(){
for(int i = 0; i < Vars.control.enemyGroup.amount(); i ++){
Enemy enemy = Vars.control.enemyGroup.all().get(i);
for(int i = 0; i < enemyGroup.amount(); i ++){
Enemy enemy = enemyGroup.all().get(i);
enemy.node = -1;
}
@@ -121,7 +122,7 @@ public class Pathfind{
public void update(){
//go through each spawnpoint, and if it's not found a path yet, update it
for(SpawnPoint point : Vars.control.getSpawnPoints()){
for(SpawnPoint point : world.getSpawns()){
if(point.request == null || point.finder == null){
resetPathFor(point);
}
@@ -145,18 +146,18 @@ public class Pathfind{
//1300-1500ms, usually 1400 unoptimized on Caldera
/**Benchmark pathfinding speed. Debugging stuff.*/
public void benchmark(){
SpawnPoint point = Vars.control.getSpawnPoints().first();
SpawnPoint point = world.getSpawns().first();
int amount = 100;
//warmup
for(int i = 0; i < 100; i ++){
point.finder.searchNodePath(point.start, Vars.world.getCore(), Vars.control.getDifficulty().heuristic, point.path);
point.finder.searchNodePath(point.start, world.getCore(), state.difficulty.heuristic, point.path);
point.path.clear();
}
Timers.mark();
for(int i = 0; i < amount; i ++){
point.finder.searchNodePath(point.start, Vars.world.getCore(), Vars.control.getDifficulty().heuristic, point.path);
point.finder.searchNodePath(point.start, world.getCore(), state.difficulty.heuristic, point.path);
point.path.clear();
}
UCore.log("Time elapsed: " + Timers.elapsed() + "ms\nAverage MS per path: " + Timers.elapsed()/amount);
@@ -164,7 +165,7 @@ public class Pathfind{
/**Reset and clear the paths.*/
public void resetPaths(){
for(SpawnPoint point : Vars.control.getSpawnPoints()){
for(SpawnPoint point : world.getSpawns()){
resetPathFor(point);
}
}
@@ -176,21 +177,21 @@ public class Pathfind{
point.pathTiles = null;
point.request = new PathFinderRequest<>(point.start, Vars.world.getCore(), Vars.control.getDifficulty().heuristic, point.path);
point.request = new PathFinderRequest<>(point.start, world.getCore(), state.difficulty.heuristic, point.path);
point.request.statusChanged = true; //IMPORTANT!
}
/**For an enemy that was just loaded from a save, find the node in the path it should be following.*/
void findNode(Enemy enemy){
if(enemy.lane >= Vars.control.getSpawnPoints().size || enemy.lane < 0){
if(enemy.lane >= world.getSpawns().size || enemy.lane < 0){
enemy.lane = 0;
}
if(Vars.control.getSpawnPoints().get(enemy.lane).pathTiles == null){
if(world.getSpawns().get(enemy.lane).pathTiles == null){
return;
}
Tile[] path = Vars.control.getSpawnPoints().get(enemy.lane).pathTiles;
Tile[] path = world.getSpawns().get(enemy.lane).pathTiles;
int closest = findClosest(path, enemy.x, enemy.y);

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.ai.utils.Ray;
import com.badlogic.gdx.ai.utils.RaycastCollisionDetector;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
@@ -17,7 +17,7 @@ public class Raycaster implements RaycastCollisionDetector<Vector2>{
public boolean collides(Ray<Vector2> ray){
found = false;
Geometry.iterateLine(0f, ray.start.x, ray.start.y, ray.end.x, ray.end.y, Vars.tilesize, (x, y)->{
Geometry.iterateLine(0f, ray.start.x, ray.start.y, ray.end.x, ray.end.y, tilesize, (x, y)->{
if(solid(x, y)){
found = true;
return;
@@ -71,7 +71,7 @@ public class Raycaster implements RaycastCollisionDetector<Vector2>{
}
private boolean solid(float x, float y){
Tile tile = Vars.world.tile(Mathf.scl2(x, Vars.tilesize), Mathf.scl2(y, Vars.tilesize));
Tile tile = world.tile(Mathf.scl2(x, tilesize), Mathf.scl2(y, tilesize));
if(tile == null || tile.solid()) return true;

View File

@@ -2,7 +2,7 @@ package io.anuke.mindustry.ai;
import com.badlogic.gdx.ai.pfa.Connection;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.world.Tile;
/**Tilegraph that ignores player-made tiles.*/
@@ -31,6 +31,6 @@ public class TileGraph implements OptimizedGraph<Tile> {
@Override
public int getNodeCount(){
return Vars.world.width() * Vars.world.height();
return world.width() * world.height();
}
}

View File

@@ -2,20 +2,17 @@ package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.game.DefaultKeybinds;
import io.anuke.mindustry.game.EventType.GameOver;
import io.anuke.mindustry.game.EventType.PlayEvent;
import io.anuke.mindustry.game.EventType.ResetEvent;
import io.anuke.mindustry.game.EventType.WaveEvent;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.Tutorial;
import io.anuke.mindustry.game.UpgradeInventory;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.input.AndroidInput;
import io.anuke.mindustry.input.DesktopInput;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.io.Platform;
import io.anuke.mindustry.io.Saves;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.resource.Weapon;
@@ -35,9 +32,9 @@ import static io.anuke.mindustry.Vars.*;
/**Control module.
* Handles all input, saving, keybinds and keybinds.
* Should <i>not</i> handle any game-critical state.
* This class is not created in the headless server.
*/
* This class is not created in the headless server.*/
public class Control extends Module{
private UpgradeInventory upgrades = new UpgradeInventory();
private Tutorial tutorial = new Tutorial();
private boolean hiscore = false;
@@ -56,7 +53,7 @@ public class Control extends Module{
public Control(){
saves = new Saves();
Inputs.useControllers(!Vars.gwt);
Inputs.useControllers(!gwt);
Gdx.input.setCatchBackKey(true);
@@ -105,37 +102,43 @@ public class Control extends Module{
DefaultKeybinds.load();
for(int i = 0; i < Vars.saveSlots; i ++){
Settings.defaults("save-" + i + "-autosave", !Vars.gwt);
for(int i = 0; i < saveSlots; i ++){
Settings.defaults("save-" + i + "-autosave", !gwt);
Settings.defaults("save-" + i + "-name", "untitled");
Settings.defaults("save-" + i + "-data", "empty");
}
Settings.defaultList(
"ip", "localhost",
"port", Vars.port+"",
"name", Vars.android || Vars.gwt ? "player" : UCore.getProperty("user.name"),
"port", port+"",
"name", android || gwt ? "player" : UCore.getProperty("user.name"),
"servers", ""
);
KeyBinds.load();
for(Map map : Vars.world.maps().list()){
for(Map map : world.maps().list()){
Settings.defaults("hiscore" + map.name, 0);
}
player = new Player();
player.name = Settings.getString("name");
player.isAndroid = Vars.android;
player.isAndroid = android;
player.isLocal = true;
saves.load();
Events.on(StateChangeEvent.class, (from, to) -> {
if((from == State.playing && to == State.menu) || (from == State.menu && to != State.menu)){
Timers.runTask(5f, Platform.instance::updateRPC);
}
});
Events.on(PlayEvent.class, () -> {
renderer.clearTiles();
player.x = world.getCore().worldx();
player.y = world.getCore().worldy() - Vars.tilesize*2;
player.y = world.getCore().worldy() - tilesize*2;
Core.camera.position.set(player.x, player.y, 0);
@@ -168,10 +171,10 @@ public class Control extends Module{
hiscore = true;
}
Mindustry.platforms.updateRPC();
Platform.instance.updateRPC();
});
Events.on(GameOver.class, () -> {
Events.on(GameOverEvent.class, () -> {
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);
Sounds.play("corexplode");
for(int i = 0; i < 16; i ++){
@@ -183,6 +186,10 @@ public class Control extends Module{
});
}
public UpgradeInventory upgrades() {
return upgrades;
}
public Saves getSaves(){
return saves;
}
@@ -220,9 +227,15 @@ public class Control extends Module{
this.respawntime = respawntime;
}
public Tutorial getTutorial(){
public Tutorial tutorial(){
return tutorial;
}
@Override
public void dispose(){
Platform.instance.onGameExit();
Net.dispose();
}
@Override
public void pause(){
@@ -245,11 +258,12 @@ public class Control extends Module{
Entities.collisions().setCollider(tilesize, world::solid);
Mindustry.platforms.updateRPC();
Platform.instance.updateRPC();
}
@Override
public void update(){
Inputs.update();
if(Gdx.input != proxy){
Gdx.input = proxy;
@@ -267,10 +281,10 @@ public class Control extends Module{
float xa = Inputs.getAxis("cursor_x");
float ya = Inputs.getAxis("cursor_y");
if(Math.abs(xa) > Vars.controllerMin || Math.abs(ya) > Vars.controllerMin) {
if(Math.abs(xa) > controllerMin || Math.abs(ya) > controllerMin) {
float scl = Settings.getInt("sensitivity")/100f * Unit.dp.scl(1f);
controlx += xa*Vars.baseControllerSpeed*scl;
controly -= ya*Vars.baseControllerSpeed*scl;
controlx += xa*baseControllerSpeed*scl;
controly -= ya*baseControllerSpeed*scl;
controlling = true;
Inputs.getProcessor().touchDragged(Gdx.input.getX(), Gdx.input.getY(), 0);

View File

@@ -1,7 +1,7 @@
package io.anuke.mindustry.core;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.EventType.StateChange;
import io.anuke.mindustry.game.EventType.StateChangeEvent;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.game.Inventory;
import io.anuke.ucore.core.Events;
@@ -11,19 +11,19 @@ public class GameState{
public final Inventory inventory = new Inventory();
int wave = 1;
int lastUpdated = -1;
float wavetime;
float extrawavetime;
int enemies = 0;
boolean gameOver = false;
GameMode mode = GameMode.waves;
Difficulty difficulty = Difficulty.normal;
boolean friendlyFire;
public int wave = 1;
public int lastUpdated = -1;
public float wavetime;
public float extrawavetime;
public int enemies = 0;
public boolean gameOver = false;
public GameMode mode = GameMode.waves;
public Difficulty difficulty = Difficulty.normal;
public boolean friendlyFire;
public void set(State astate){
//TODO update RPC handler
Events.fire(StateChange.class, state, astate);
Events.fire(StateChangeEvent.class, state, astate);
state = astate;
}

View File

@@ -4,10 +4,12 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.game.EventType.GameOver;
import io.anuke.mindustry.game.EnemySpawn;
import io.anuke.mindustry.game.EventType.GameOverEvent;
import io.anuke.mindustry.game.EventType.PlayEvent;
import io.anuke.mindustry.game.EventType.ResetEvent;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.game.WaveCreator;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.Tile;
@@ -100,12 +102,17 @@ public class Logic extends Module {
state.extrawavetime = maxwavespace;
}
public void updateLogic(){
@Override
public void update(){
if(!state.is(State.paused) || Net.active()){
Timers.update();
}
if(!state.is(State.menu)){
if(world.getCore().block() != ProductionBlocks.core && !state.gameOver){
state.gameOver = true;
Events.fire(GameOver.class);
Events.fire(GameOverEvent.class);
}
if(!state.is(State.paused) || Net.active()){

View File

@@ -5,8 +5,6 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.IntSet;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
@@ -15,15 +13,13 @@ import io.anuke.mindustry.entities.SyncEntity;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.io.Platform;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.NetworkIO;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Recipes;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Effects;
@@ -38,7 +34,7 @@ import java.io.DataInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.ui;
import static io.anuke.mindustry.Vars.*;
public class NetClient extends Module {
public static final Color[] colorArray = {Color.ORANGE, Color.SCARLET, Color.LIME, Color.PURPLE,
@@ -54,7 +50,7 @@ public class NetClient extends Module {
public NetClient(){
Net.handle(Connect.class, packet -> {
Net.handleClient(Connect.class, packet -> {
Net.setClientLoaded(false);
recieved.clear();
dead.clear();
@@ -62,62 +58,61 @@ public class NetClient extends Module {
gotData = false;
kicked = false;
Vars.ui.loadfrag.hide();
Vars.ui.loadfrag.show("$text.connecting.data");
ui.loadfrag.hide();
ui.loadfrag.show("$text.connecting.data");
Entities.clear();
ConnectPacket c = new ConnectPacket();
c.name = Vars.player.name;
c.android = Vars.android;
c.name = player.name;
c.android = android;
Net.send(c, SendMode.tcp);
Timers.runTask(dataTimeout, () -> {
if (!gotData) {
Gdx.app.error("Mindustry", "Failed to load data!");
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
Net.disconnect();
}
});
});
Net.handle(Disconnect.class, packet -> {
Net.handleClient(Disconnect.class, packet -> {
if (kicked) return;
Timers.runFor(3f, Vars.ui.loadfrag::hide);
Timers.runFor(3f, ui.loadfrag::hide);
state.set(State.menu);
Vars.ui.showError("$text.disconnect");
ui.showError("$text.disconnect");
connecting = false;
Mindustry.platforms.updateRPC();
Platform.instance.updateRPC();
});
Net.handle(WorldData.class, data -> {
Net.handleClient(WorldData.class, data -> {
UCore.log("Recieved world data: " + data.stream.available() + " bytes.");
NetworkIO.loadWorld(data.stream);
Vars.player.set(Vars.control.core.worldx(), Vars.control.core.worldy() - Vars.tilesize * 2);
UCore.log(Vars.control.core);
player.set(world.getSpawnX(), world.getSpawnY());
gotData = true;
finishConnecting();
});
Net.handle(CustomMapPacket.class, packet -> {
Net.handleClient(CustomMapPacket.class, packet -> {
UCore.log("Recieved custom map: " + packet.stream.available() + " bytes.");
//custom map is always sent before world data
Pixmap pixmap = NetworkIO.loadMap(packet.stream);
Vars.world.maps().setNetworkMap(pixmap);
world.maps().setNetworkMap(pixmap);
MapAckPacket ack = new MapAckPacket();
Net.send(ack, SendMode.tcp);
});
Net.handle(SyncPacket.class, packet -> {
Net.handleClient(SyncPacket.class, packet -> {
if (!gotData) return;
ByteBuffer data = ByteBuffer.wrap(packet.data);
@@ -131,8 +126,8 @@ public class NetClient extends Module {
SyncEntity entity = (SyncEntity) group.getByID(id);
if (entity == null || id == Vars.player.id) {
if (id != Vars.player.id) {
if (entity == null || id == player.id) {
if (id != player.id) {
UCore.log("Requesting entity " + id, "group " + group.getType());
EntityRequestPacket req = new EntityRequestPacket();
req.id = id;
@@ -145,37 +140,22 @@ public class NetClient extends Module {
}
});
Net.handle(ShootPacket.class, packet -> {
Player player = Vars.control.playerGroup.getByID(packet.playerid);
Net.handleClient(StateSyncPacket.class, packet -> {
Weapon weapon = (Weapon) Upgrade.getByID(packet.weaponid);
weapon.shoot(player, packet.x, packet.y, packet.rotation);
});
System.arraycopy(packet.items, 0, state.inventory.getItems(), 0, packet.items.length);
Net.handle(PlacePacket.class, packet -> {
Recipe recipe = Recipes.getByResult(Block.getByID(packet.block));
if (recipe != null) Vars.control.removeItems(recipe.requirements);
Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
});
Net.handle(BreakPacket.class, packet -> {
Vars.control.input.breakBlockInternal(packet.x, packet.y, false);
});
Net.handle(StateSyncPacket.class, packet -> {
System.arraycopy(packet.items, 0, Vars.control.items, 0, packet.items.length);
Vars.control.setWaveData(packet.enemies, packet.wave, packet.countdown);
state.enemies = packet.enemies;
state.wavetime = packet.countdown;
state.wave = packet.wave;
Timers.resetTime(packet.time + (float) (TimeUtils.timeSinceMillis(packet.timestamp) / 1000.0 * 60.0));
Vars.ui.hudfrag.updateItems();
ui.hudfrag.updateItems();
});
Net.handle(EnemySpawnPacket.class, spawn -> {
Net.handleClient(EnemySpawnPacket.class, spawn -> {
//duplicates.
if (Vars.control.enemyGroup.getByID(spawn.id) != null ||
if (enemyGroup.getByID(spawn.id) != null ||
recieved.contains(spawn.id) || dead.contains(spawn.id)) return;
recieved.add(spawn.id);
@@ -191,34 +171,34 @@ public class NetClient extends Module {
Effects.effect(Fx.spawn, enemy);
});
Net.handle(EnemyDeathPacket.class, spawn -> {
Enemy enemy = Vars.control.enemyGroup.getByID(spawn.id);
Net.handleClient(EnemyDeathPacket.class, spawn -> {
Enemy enemy = enemyGroup.getByID(spawn.id);
if (enemy != null) enemy.onDeath();
dead.add(spawn.id);
});
Net.handle(BulletPacket.class, packet -> {
Net.handleClient(BulletPacket.class, packet -> {
//TODO shoot effects for enemies, clientside as well as serverside
BulletType type = (BulletType) BaseBulletType.getByID(packet.type);
Entity owner = Vars.control.enemyGroup.getByID(packet.owner);
Entity owner = enemyGroup.getByID(packet.owner);
new Bullet(type, owner, packet.x, packet.y, packet.angle).add();
});
Net.handle(BlockDestroyPacket.class, packet -> {
Tile tile = Vars.world.tile(packet.position % Vars.world.width(), packet.position / Vars.world.width());
Net.handleClient(BlockDestroyPacket.class, packet -> {
Tile tile = world.tile(packet.position % world.width(), packet.position / world.width());
if (tile != null && tile.entity != null) {
if (tile.entity != null) tile.entity.onDeath(true);
tile.entity.onDeath(true);
}
});
Net.handle(BlockUpdatePacket.class, packet -> {
Tile tile = Vars.world.tile(packet.position % Vars.world.width(), packet.position / Vars.world.width());
Net.handleClient(BlockUpdatePacket.class, packet -> {
Tile tile = world.tile(packet.position % world.width(), packet.position / world.width());
if (tile != null && tile.entity != null) {
tile.entity.health = packet.health;
}
});
Net.handle(BlockSyncPacket.class, packet -> {
Net.handleClient(BlockSyncPacket.class, packet -> {
if (!gotData) return;
DataInputStream stream = new DataInputStream(packet.stream);
@@ -232,7 +212,7 @@ public class NetClient extends Module {
int pos = stream.readInt();
//TODO what if there's no entity? new code
Tile tile = Vars.world.tile(pos % Vars.world.width(), pos / Vars.world.width());
Tile tile = world.tile(pos % world.width(), pos / world.width());
byte times = stream.readByte();
@@ -255,19 +235,19 @@ public class NetClient extends Module {
});
Net.handle(DisconnectPacket.class, packet -> {
Player player = Vars.control.playerGroup.getByID(packet.playerid);
Net.handleClient(DisconnectPacket.class, packet -> {
Player player = playerGroup.getByID(packet.playerid);
if (player != null) {
player.remove();
}
Mindustry.platforms.updateRPC();
Platform.instance.updateRPC();
});
Net.handle(PlayerSpawnPacket.class, packet -> {
Net.handleClient(PlayerSpawnPacket.class, packet -> {
//duplicates.
if (Vars.control.enemyGroup.getByID(packet.id) != null ||
if (enemyGroup.getByID(packet.id) != null ||
recieved.contains(packet.id)) return;
recieved.add(packet.id);
@@ -284,58 +264,30 @@ public class NetClient extends Module {
player.interpolator.target.set(player.x, player.y);
player.add();
Mindustry.platforms.updateRPC();
Platform.instance.updateRPC();
});
Net.handle(ChatPacket.class, packet -> Vars.ui.chatfrag.addMessage(packet.text, Vars.netClient.colorizeName(packet.id, packet.name)));
Net.handle(KickPacket.class, packet -> {
Net.handleClient(KickPacket.class, packet -> {
kicked = true;
Net.disconnect();
state.set(State.menu);
Vars.ui.showError("$text.server.kicked." + packet.reason.name());
Vars.ui.loadfrag.hide();
ui.showError("$text.server.kicked." + packet.reason.name());
ui.loadfrag.hide();
});
Net.handle(WeaponSwitchPacket.class, packet -> {
Player player = Vars.control.playerGroup.getByID(packet.playerid);
if (player == null) return;
player.weaponLeft = (Weapon) Upgrade.getByID(packet.left);
player.weaponRight = (Weapon) Upgrade.getByID(packet.right);
});
Net.handle(BlockTapPacket.class, packet -> {
Tile tile = Vars.world.tile(packet.position);
if (tile != null) tile.block().tapped(tile);
});
Net.handle(BlockConfigPacket.class, packet -> {
Tile tile = Vars.world.tile(packet.position);
if (tile != null) tile.block().configure(tile, packet.data);
});
Net.handle(GameOverPacket.class, packet -> {
Net.handleClient(GameOverPacket.class, packet -> {
kicked = true;
ui.restart.show();
});
Net.handle(FriendlyFireChangePacket.class, packet -> Vars.control.setFriendlyFire(packet.enabled));
Net.handle(PlayerDeathPacket.class, packet -> {
Player player = Vars.control.playerGroup.getByID(packet.id);
if(player == null) return;
player.doRespawn();
});
Net.handleClient(FriendlyFireChangePacket.class, packet -> state.friendlyFire = packet.enabled);
}
@Override
public void update(){
if(!Net.client() || !Net.active()) return;
if(!Net.client()) return;
if(!GameState.is(State.menu) && Net.active()){
if(!state.is(State.menu) && Net.active()){
if(gotData) sync();
}else if(!connecting){
Net.disconnect();
@@ -347,8 +299,8 @@ public class NetClient extends Module {
state.set(State.playing);
Net.setClientLoaded(true);
connecting = false;
Vars.ui.loadfrag.hide();
Vars.ui.join.hide();
ui.loadfrag.hide();
ui.join.hide();
}
public void beginConnecting(){
@@ -364,81 +316,11 @@ public class NetClient extends Module {
return name == null ? null : "[#" + colorArray[id % colorArray.length].toString().toUpperCase() + "]" + name;
}
public void handlePlayerDeath(){
PlayerDeathPacket packet = new PlayerDeathPacket();
packet.id = Vars.player.id;
Net.send(packet, SendMode.tcp);
}
public void handleBlockConfig(Tile tile, byte data){
BlockConfigPacket packet = new BlockConfigPacket();
packet.data = data;
packet.position = tile.packedPosition();
Net.send(packet, SendMode.tcp);
}
public void handleBlockTap(Tile tile){
BlockTapPacket packet = new BlockTapPacket();
packet.position = tile.packedPosition();
Net.send(packet, SendMode.tcp);
}
public void handleWeaponSwitch(){
WeaponSwitchPacket packet = new WeaponSwitchPacket();
packet.left = Vars.player.weaponLeft.id;
packet.right = Vars.player.weaponRight.id;
packet.playerid = Vars.player.id;
Net.send(packet, SendMode.tcp);
}
public void handleUpgrade(Weapon weapon){
UpgradePacket packet = new UpgradePacket();
packet.id = weapon.id;
Net.send(packet, SendMode.tcp);
}
public void handleSendMessage(String message){
ChatPacket packet = new ChatPacket();
packet.text = message;
packet.name = Vars.player.name;
packet.id = Vars.player.id;
Net.send(packet, SendMode.tcp);
Vars.ui.chatfrag.addMessage(packet.text, colorizeName(Vars.player.id, Vars.player.name));
}
public void handleShoot(Weapon weapon, float x, float y, float angle){
ShootPacket packet = new ShootPacket();
packet.weaponid = weapon.id;
packet.x = x;
packet.y = y;
packet.rotation = angle;
packet.playerid = Vars.player.id;
Net.send(packet, SendMode.udp);
}
public void handlePlace(int x, int y, Block block, int rotation){
PlacePacket packet = new PlacePacket();
packet.x = (short)x;
packet.y = (short)y;
packet.rotation = (byte)rotation;
packet.playerid = Vars.player.id;
packet.block = block.id;
Net.send(packet, SendMode.tcp);
}
public void handleBreak(int x, int y){
BreakPacket packet = new BreakPacket();
packet.x = (short)x;
packet.y = (short)y;
Net.send(packet, SendMode.tcp);
}
void sync(){
if(Timers.get("syncPlayer", playerSyncTime)){
byte[] bytes = new byte[Vars.player.getWriteSize()];
byte[] bytes = new byte[player.getWriteSize()];
ByteBuffer buffer = ByteBuffer.wrap(bytes);
Vars.player.write(buffer);
player.write(buffer);
PositionPacket packet = new PositionPacket();
packet.data = bytes;

View File

@@ -0,0 +1,85 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Recipes;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.modules.Module;
import static io.anuke.mindustry.Vars.*;
public class NetCommon extends Module {
public static final Color[] colorArray = {Color.ORANGE, Color.SCARLET, Color.LIME, Color.PURPLE,
Color.GOLD, Color.PINK, Color.SKY, Color.GOLD, Color.VIOLET,
Color.GREEN, Color.CORAL, Color.CYAN, Color.CHARTREUSE};
public NetCommon(){
Net.handleServer(ShootPacket.class, (id, packet) -> {
Player player = playerGroup.getByID(packet.playerid);
Weapon weapon = (Weapon) Upgrade.getByID(packet.weaponid);
weapon.shoot(player, packet.x, packet.y, packet.rotation);
});
Net.handleServer(PlacePacket.class, (id, packet) -> {
control.input().placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
Recipe recipe = Recipes.getByResult(Block.getByID(packet.block));
if (recipe != null) state.inventory.removeItems(recipe.requirements);
});
Net.handleServer(BreakPacket.class, (id, packet) -> {
control.input().breakBlockInternal(packet.x, packet.y, false);
});
Net.handleServer(ChatPacket.class, (id, packet) -> {
ui.chatfrag.addMessage(packet.text, colorizeName(packet.id, packet.name));
});
Net.handleServer(WeaponSwitchPacket.class, (id, packet) -> {
Player player = playerGroup.getByID(packet.playerid);
if (player == null) return;
player.weaponLeft = (Weapon) Upgrade.getByID(packet.left);
player.weaponRight = (Weapon) Upgrade.getByID(packet.right);
});
Net.handleServer(BlockTapPacket.class, (id, packet) -> {
Tile tile = world.tile(packet.position);
tile.block().tapped(tile);
});
Net.handleServer(BlockConfigPacket.class, (id, packet) -> {
Tile tile = world.tile(packet.position);
if (tile != null) tile.block().configure(tile, packet.data);
});
Net.handleServer(PlayerDeathPacket.class, (id, packet) -> {
Player player = playerGroup.getByID(packet.id);
if(player == null) return;
player.doRespawn();
});
}
public void sendMessage(String message){
ChatPacket packet = new ChatPacket();
packet.name = null;
packet.text = message;
Net.send(packet, SendMode.tcp);
ui.chatfrag.addMessage(message, null);
}
public String colorizeName(int id, String name){
return name == null ? null : "[#" + colorArray[id % colorArray.length].toString().toUpperCase() + "]" + name;
}
}

View File

@@ -2,26 +2,23 @@ package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.*;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.SyncEntity;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.net.NetConnection;
import io.anuke.mindustry.net.NetworkIO;
import io.anuke.mindustry.io.Platform;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.NetConnection;
import io.anuke.mindustry.net.NetworkIO;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.resource.*;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.UpgradeRecipes;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.modules.Module;
import io.anuke.ucore.util.Bundles;
@@ -33,6 +30,8 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.*;
public class NetServer extends Module{
/**Maps connection IDs to players.*/
IntMap<Player> connections = new IntMap<>();
@@ -57,14 +56,14 @@ public class NetServer extends Module{
player.clientid = id;
player.name = packet.name;
player.isAndroid = packet.android;
player.set(Vars.control.core.worldx(), Vars.control.core.worldy() - Vars.tilesize * 2);
player.set(world.getSpawnX(), world.getSpawnY());
player.interpolator.last.set(player.x, player.y);
player.interpolator.target.set(player.x, player.y);
connections.put(id, player);
if(Vars.world.getMap().custom){
if(world.getMap().custom){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
NetworkIO.writeMap(Vars.world.getMap().pixmap, stream);
NetworkIO.writeMap(world.getMap().pixmap, stream);
CustomMapPacket data = new CustomMapPacket();
data.stream = new ByteArrayInputStream(stream.toByteArray());
Net.sendStream(id, data);
@@ -75,7 +74,7 @@ public class NetServer extends Module{
Net.handleServerReceived(id, new MapAckPacket());
}
Mindustry.platforms.updateRPC();
Platform.instance.updateRPC();
});
Net.handleServer(MapAckPacket.class, (id, packet) -> {
@@ -96,7 +95,7 @@ public class NetServer extends Module{
if (player == null) return;
player.add();
sendMessage("[accent]" + Bundles.format("text.server.connected", player.name));
netCommon.sendMessage("[accent]" + Bundles.format("text.server.connected", player.name));
});
Net.handleServer(Disconnect.class, (id, packet) -> {
@@ -107,7 +106,7 @@ public class NetServer extends Module{
return;
}
sendMessage("[accent]" + Bundles.format("text.server.disconnected", player.name));
netCommon.sendMessage("[accent]" + Bundles.format("text.server.disconnected", player.name));
player.remove();
DisconnectPacket dc = new DisconnectPacket();
@@ -115,7 +114,7 @@ public class NetServer extends Module{
Net.send(dc, SendMode.tcp);
Mindustry.platforms.updateRPC();
Platform.instance.updateRPC();
});
Net.handleServer(PositionPacket.class, (id, packet) -> {
@@ -124,44 +123,25 @@ public class NetServer extends Module{
});
Net.handleServer(ShootPacket.class, (id, packet) -> {
Player player = connections.get(id);
Weapon weapon = (Weapon) Upgrade.getByID(packet.weaponid);
weapon.shoot(player, packet.x, packet.y, packet.rotation);
packet.playerid = player.id;
packet.playerid = connections.get(id).id;
Net.sendExcept(id, packet, SendMode.udp);
});
Net.handleServer(PlacePacket.class, (id, packet) -> {
Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
packet.playerid = connections.get(id).id;
Recipe recipe = Recipes.getByResult(Block.getByID(packet.block));
if (recipe != null) Vars.control.removeItems(recipe.requirements);
Net.sendExcept(id, packet, SendMode.tcp);
});
Net.handleServer(BreakPacket.class, (id, packet) -> {
Vars.control.input.breakBlockInternal(packet.x, packet.y, false);
packet.playerid = connections.get(id).id;
Net.sendExcept(id, packet, SendMode.tcp);
});
Net.handleServer(ChatPacket.class, (id, packet) -> {
Player player = connections.get(id);
if (player == null) {
Gdx.app.error("Mindustry", "Could not find player for chat: " + id);
return; //GHOSTS AAAA
}
packet.name = player.name;
packet.id = player.id;
Net.sendExcept(player.clientid, packet, SendMode.tcp);
Vars.ui.chatfrag.addMessage(packet.text, Vars.netClient.colorizeName(packet.id, packet.name));
});
Net.handleServer(UpgradePacket.class, (id, packet) -> {
@@ -172,41 +152,27 @@ public class NetServer extends Module{
if (!weapons.containsKey(player.name)) weapons.put(player.name, new ByteArray());
if (!weapons.get(player.name).contains(weapon.id)) weapons.get(player.name).add(weapon.id);
Vars.control.removeItems(UpgradeRecipes.get(weapon));
state.inventory.removeItems(UpgradeRecipes.get(weapon));
});
Net.handleServer(WeaponSwitchPacket.class, (id, packet) -> {
Player player = connections.get(id);
if (player == null) return;
packet.playerid = player.id;
player.weaponLeft = (Weapon) Upgrade.getByID(packet.left);
player.weaponRight = (Weapon) Upgrade.getByID(packet.right);
packet.playerid = connections.get(id).id;
Net.sendExcept(player.clientid, packet, SendMode.tcp);
});
Net.handleServer(BlockTapPacket.class, (id, packet) -> {
Tile tile = Vars.world.tile(packet.position);
tile.block().tapped(tile);
Net.sendExcept(id, packet, SendMode.tcp);
});
Net.handleServer(BlockConfigPacket.class, (id, packet) -> {
Tile tile = Vars.world.tile(packet.position);
if (tile != null) tile.block().configure(tile, packet.data);
Net.sendExcept(id, packet, SendMode.tcp);
});
Net.handleServer(EntityRequestPacket.class, (cid, packet) -> {
int id = packet.id;
int dest = cid;
if (Vars.control.playerGroup.getByID(id) != null) {
Player player = Vars.control.playerGroup.getByID(id);
if (playerGroup.getByID(id) != null) {
Player player = playerGroup.getByID(id);
PlayerSpawnPacket p = new PlayerSpawnPacket();
p.x = player.x;
p.y = player.y;
@@ -218,8 +184,8 @@ public class NetServer extends Module{
Net.sendTo(dest, p, SendMode.tcp);
log("Replying to entity request (" + id + "): player, " + id);
} else if (Vars.control.enemyGroup.getByID(id) != null) {
Enemy enemy = Vars.control.enemyGroup.getByID(id);
} else if (enemyGroup.getByID(id) != null) {
Enemy enemy = enemyGroup.getByID(id);
EnemySpawnPacket e = new EnemySpawnPacket();
e.x = enemy.x;
e.y = enemy.y;
@@ -236,83 +202,26 @@ public class NetServer extends Module{
});
Net.handleServer(PlayerDeathPacket.class, (id, packet) -> {
Player player = connections.get(id);
if(player == null) return;
packet.id = player.id;
player.doRespawn();
packet.id = connections.get(id).id;
Net.sendExcept(id, packet, SendMode.tcp);
});
}
public void sendMessage(String message){
ChatPacket packet = new ChatPacket();
packet.name = null;
packet.text = message;
Net.send(packet, SendMode.tcp);
Vars.ui.chatfrag.addMessage(message, null);
}
public void handleFriendlyFireChange(boolean enabled){
FriendlyFireChangePacket packet = new FriendlyFireChangePacket();
packet.enabled = enabled;
sendMessage(enabled ? "[accent]Friendly fire enabled." : "[accent]Friendly fire disabled.");
Net.send(packet, SendMode.tcp);
}
public void handleGameOver(){
Net.send(new GameOverPacket(), SendMode.tcp);
Timers.runTask(30f, () -> state.set(State.menu));
}
public void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){
BulletPacket packet = new BulletPacket();
packet.x = x;
packet.y = y;
packet.angle = angle;
packet.damage = damage;
packet.owner = owner.id;
packet.type = type.id;
Net.send(packet, SendMode.udp);
}
public void handleEnemyDeath(Enemy enemy){
EnemyDeathPacket packet = new EnemyDeathPacket();
packet.id = enemy.id;
Net.send(packet, SendMode.tcp);
}
public void handleBlockDestroyed(TileEntity entity){
BlockDestroyPacket packet = new BlockDestroyPacket();
packet.position = entity.tile.packedPosition();
Net.send(packet, SendMode.tcp);
}
public void handleBlockDamaged(TileEntity entity){
BlockUpdatePacket packet = new BlockUpdatePacket();
packet.health = (int)entity.health;
packet.position = entity.tile.packedPosition();
Net.send(packet, SendMode.udp);
}
public void update(){
if(!Net.server()) return;
if(!GameState.is(State.menu) && Net.active()){
sync();
}else if(!closing){
if(!closing && Net.active() && state.is(State.menu)){
closing = true;
weapons.clear();
Vars.ui.loadfrag.show("$text.server.closing");
ui.loadfrag.show("$text.server.closing");
Timers.runTask(5f, () -> {
Net.closeServer();
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
closing = false;
});
}
if(!state.is(State.menu) && Net.server()){
sync();
}
}
void sync(){
@@ -383,10 +292,10 @@ public class NetServer extends Module{
if(Timers.get("serverItemSync", itemSyncTime)){
StateSyncPacket packet = new StateSyncPacket();
packet.items = Vars.control.items;
packet.countdown = Vars.control.getWaveCountdown();
packet.enemies = Vars.control.getEnemiesRemaining();
packet.wave = Vars.control.getWave();
packet.items = state.inventory.getItems();
packet.countdown = state.wavetime;
packet.enemies = state.enemies;
packet.wave = state.wave;
packet.time = Timers.time();
packet.timestamp = TimeUtils.millis();
@@ -401,8 +310,8 @@ public class NetServer extends Module{
int id = connections.get(i).id;
Player player = this.connections.get(id);
if(player == null) continue;
int x = Mathf.scl2(player.x, Vars.tilesize);
int y = Mathf.scl2(player.y, Vars.tilesize);
int x = Mathf.scl2(player.x, tilesize);
int y = Mathf.scl2(player.y, tilesize);
int w = 16;
int h = 12;
sendBlockSync(id, x, y, w, h);
@@ -423,7 +332,7 @@ public class NetServer extends Module{
for (int rx = -viewx / 2; rx <= viewx / 2; rx++) {
for (int ry = -viewy / 2; ry <= viewy / 2; ry++) {
Tile tile = Vars.world.tile(x + rx, y + ry);
Tile tile = world.tile(x + rx, y + ry);
if (tile == null || tile.entity == null) continue;

View File

@@ -10,16 +10,15 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.FloatArray;
import com.badlogic.gdx.utils.Pools;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.graphics.BlockRenderer;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.input.PlaceMode;
import io.anuke.mindustry.ui.fragments.ToolFragment;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
@@ -96,25 +95,25 @@ public class Renderer extends RendererModule{
if(Mathf.in(camera.zoom, targetzoom, 0.005f)){
camera.zoom = 1f;
Graphics.setCameraScale(targetscale);
control.input.resetCursor();
control.input().resetCursor();
}
}else{
camera.zoom = Mathf.lerp(camera.zoom, 1f, 0.2f * Timers.delta());
}
if(GameState.is(State.menu)){
if(state.is(State.menu)){
clearScreen();
}else{
boolean smoothcam = Settings.getBool("smoothcam");
if(control.core == null || control.core.block() == ProductionBlocks.core){
if(world.getCore() == null || world.getCore().block() == ProductionBlocks.core){
if(!smoothcam){
setCamera(player.x, player.y);
}else{
smoothCamera(player.x, player.y, android ? 0.3f : 0.14f);
}
}else{
smoothCamera(control.core.worldx(), control.core.worldy(), 0.4f);
smoothCamera(world.getCore().worldx(), world.getCore().worldy(), 0.4f);
}
if(Settings.getBool("pixelate"))
@@ -135,7 +134,7 @@ public class Renderer extends RendererModule{
float lastx = camera.position.x, lasty = camera.position.y;
if(Vars.snapCamera && smoothcam && Settings.getBool("pixelate")){
if(snapCamera && smoothcam && Settings.getBool("pixelate")){
camera.position.set((int) camera.position.x, (int) camera.position.y, 0);
}
@@ -151,7 +150,7 @@ public class Renderer extends RendererModule{
camera.position.set(lastx - deltax, lasty - deltay, 0);
if(Vars.debug) record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't
if(debug) record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't
}
}
@@ -177,22 +176,22 @@ public class Renderer extends RendererModule{
blocks.drawBlocks(false);
Graphics.shader(Shaders.outline, false);
Entities.draw(control.enemyGroup);
Entities.draw(enemyGroup);
Graphics.shader();
Entities.draw(control.playerGroup, p -> !p.isAndroid);
Entities.draw(playerGroup, p -> !p.isAndroid);
Entities.draw(Entities.defaultGroup());
blocks.drawBlocks(true);
Entities.draw(control.playerGroup, p -> p.isAndroid);
Entities.draw(control.bulletGroup);
Entities.draw(playerGroup, p -> p.isAndroid);
Entities.draw(bulletGroup);
drawShield();
drawOverlay();
if(Settings.getBool("indicators") && Vars.showUI){
if(Settings.getBool("indicators") && showUI){
drawEnemyMarkers();
}
@@ -207,7 +206,7 @@ public class Renderer extends RendererModule{
@Override
public void resize(int width, int height){
super.resize(width, height);
control.input.resetCursor();
control.input().resetCursor();
camera.position.set(player.x, player.y, 0);
}
@@ -219,7 +218,7 @@ public class Renderer extends RendererModule{
GlyphLayout layout = Pools.obtain(GlyphLayout.class);
Draw.tscl(0.25f/2);
for(Player player : Vars.control.playerGroup.all()){
for(Player player : playerGroup.all()){
if(!player.isLocal){
layout.setText(Core.font, player.name);
Draw.color(0f, 0f, 0f, 0.3f);
@@ -231,13 +230,13 @@ public class Renderer extends RendererModule{
}
}
Pools.free(layout);
Draw.tscl(Vars.fontscale);
Draw.tscl(fontscale);
}
void drawEnemyMarkers(){
Graphics.surface(indicatorSurface);
Draw.color(Color.RED);
for(Enemy enemy : control.enemyGroup.all()){
for(Enemy enemy : enemyGroup.all()){
if(Tmp.r1.setSize(camera.viewportWidth, camera.viewportHeight).setCenter(camera.position.x, camera.position.y).overlaps(enemy.hitbox.getRect(enemy.x, enemy.y))){
continue;
@@ -254,11 +253,11 @@ public class Renderer extends RendererModule{
}
void drawShield(){
if(control.shieldGroup.amount() == 0 && shieldDraws.size == 0) return;
if(shieldGroup.amount() == 0 && shieldDraws.size == 0) return;
Graphics.surface(Vars.renderer.shieldSurface, false);
Graphics.surface(renderer.shieldSurface, false);
Draw.color(Color.ROYAL);
Entities.draw(control.shieldGroup);
Entities.draw(shieldGroup);
for(Callable c : shieldDraws){
c.run();
}
@@ -319,10 +318,10 @@ public class Renderer extends RendererModule{
void drawOverlay(){
//draw tutorial placement point
if(Vars.world.getMap().name.equals("tutorial") && Vars.control.tutorial.showBlock()){
int x = control.core.x + Vars.control.tutorial.getPlacePoint().x;
int y = control.core.y + Vars.control.tutorial.getPlacePoint().y;
int rot = Vars.control.tutorial.getPlaceRotation();
if(world.getMap().name.equals("tutorial") && control.tutorial().showBlock()){
int x = world.getCore().x + control.tutorial().getPlacePoint().x;
int y = world.getCore().y + control.tutorial().getPlacePoint().y;
int rot = control.tutorial().getPlaceRotation();
Lines.stroke(1f);
Draw.color(Color.YELLOW);
@@ -337,19 +336,19 @@ public class Renderer extends RendererModule{
}
//draw config selected block
if(Vars.ui.configfrag.isShown()){
if(ui.configfrag.isShown()){
Tile tile = ui.configfrag.getSelectedTile();
Draw.color(Colors.get("accent"));
Lines.stroke(1f);
Lines.square(tile.drawx(), tile.drawy(),
tile.block().width * Vars.tilesize / 2f + 1f);
tile.block().width * tilesize / 2f + 1f);
Draw.reset();
}
int tilex = control.input.getBlockX();
int tiley = control.input.getBlockY();
int tilex = control.input().getBlockX();
int tiley = control.input().getBlockY();
if(Vars.android){
if(android){
Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(0));
tilex = Mathf.scl2(vec.x, tilesize);
tiley = Mathf.scl2(vec.y, tilesize);
@@ -358,27 +357,27 @@ public class Renderer extends RendererModule{
InputHandler input = control.input();
//draw placement box
if((input.recipe != null && Vars.control.hasItems(input.recipe.requirements) && (!ui.hasMouse() || android)
&& control.input.drawPlace())){
if((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || android)
&& control.input().drawPlace())){
input.placeMode.draw(control.input.getBlockX(), control.input.getBlockY(), control.input.getBlockEndX(), control.input.getBlockEndY());
input.placeMode.draw(control.input().getBlockX(), control.input().getBlockY(), control.input().getBlockEndX(), control.input().getBlockEndY());
Lines.stroke(1f);
Draw.color(Color.SCARLET);
for(SpawnPoint spawn : control.getSpawnPoints()){
for(SpawnPoint spawn : world.getSpawns()){
Lines.dashCircle(spawn.start.worldx(), spawn.start.worldy(), enemyspawnspace);
}
if(input.breakMode == PlaceMode.holdDelete)
input.breakMode.draw(tilex, tiley, 0, 0);
}else if(input.breakMode.delete && control.input.drawPlace() && input.recipe == null){
input.breakMode.draw(control.input.getBlockX(), control.input.getBlockY(),
control.input.getBlockEndX(), control.input.getBlockEndY());
}else if(input.breakMode.delete && control.input().drawPlace() && input.recipe == null){
input.breakMode.draw(control.input().getBlockX(), control.input().getBlockY(),
control.input().getBlockEndX(), control.input().getBlockEndY());
}
if(Vars.ui.toolfrag.confirming){
ToolFragment t = Vars.ui.toolfrag;
if(ui.toolfrag.confirming){
ToolFragment t = ui.toolfrag;
PlaceMode.areaDelete.draw(t.px, t.py, t.px2, t.py2);
}
@@ -394,27 +393,27 @@ public class Renderer extends RendererModule{
target = tile.getLinked();
if(target.entity != null)
drawHealth(target.drawx(), target.drawy() - 3f - target.block().height / 2f * Vars.tilesize, target.entity.health, target.entity.tile.block().health);
drawHealth(target.drawx(), target.drawy() - 3f - target.block().height / 2f * tilesize, target.entity.health, target.entity.tile.block().health);
target.block().drawSelect(target);
}
}
if((!Vars.debug || Vars.showUI) && Settings.getBool("healthbars")){
if((!debug || showUI) && Settings.getBool("healthbars")){
//draw entity health bars
for(Enemy entity : control.enemyGroup.all()){
for(Enemy entity : enemyGroup.all()){
drawHealth(entity);
}
for(Player player : Vars.control.playerGroup.all()){
for(Player player : playerGroup.all()){
if(!player.isDead() && !player.isAndroid) drawHealth(player);
}
}
}
void drawHealth(DestructibleEntity dest){
if(dest instanceof Player && Vars.snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate")){
if(dest instanceof Player && snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate")){
drawHealth((int) dest.x, (int) dest.y - 7f, dest.health, dest.maxhealth);
}else{
drawHealth(dest.x, dest.y - 7f, dest.health, dest.maxhealth);

View File

@@ -5,12 +5,15 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.Align;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.io.Platform;
import io.anuke.mindustry.mapeditor.MapEditorDialog;
import io.anuke.mindustry.ui.dialogs.*;
import io.anuke.mindustry.ui.fragments.*;
import io.anuke.ucore.core.*;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.function.Listenable;
import io.anuke.ucore.graphics.Draw;
@@ -185,7 +188,7 @@ public class UI extends SceneModule{
content().margin(30).add(text).padRight(6f);
TextField field = content().addField(def, t->{}).size(170f, 50f).get();
field.setTextFieldFilter((f, c) -> field.getText().length() < 12 && filter.acceptChar(f, c));
Mindustry.platforms.addDialog(field);
Platform.instance.addDialog(field);
buttons().defaults().size(120, 54).pad(4);
buttons().addButton("$text.ok", () -> {
confirmed.accept(field.getText());

View File

@@ -4,7 +4,6 @@ import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.game.SpawnPoint;
@@ -24,8 +23,7 @@ import io.anuke.ucore.modules.Module;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
import static io.anuke.mindustry.Vars.*;
public class World extends Module{
private int seed;
@@ -46,7 +44,7 @@ public class World extends Module{
@Override
public void update(){
if(!(Net.active() && Net.client()))
if(!(Net.client()))
pathfind.update();
}
@@ -76,7 +74,7 @@ public class World extends Module{
}
public float getSpawnY(){
return core.worldy() - Vars.tilesize/2;
return core.worldy() - tilesize/2;
}
public boolean solid(int x, int y){
@@ -208,7 +206,7 @@ public class World extends Module{
if(!map.name.equals("tutorial")){
setDefaultBlocks();
}else{
Vars.control.getTutorial().setDefaultBlocks(core.x, core.y);
control.tutorial().setDefaultBlocks(core.x, core.y);
}
pathfind.resetPaths();

View File

@@ -1,13 +1,12 @@
package io.anuke.mindustry.entities;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.BulletEntity;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.*;
public class Bullet extends BulletEntity{
public boolean absorbed = false;
@@ -36,7 +35,7 @@ public class Bullet extends BulletEntity{
int tilex = Mathf.scl2(x, tilesize);
int tiley = Mathf.scl2(y, tilesize);
Tile tile = Vars.world.tile(tilex, tiley);
Tile tile = world.tile(tilex, tiley);
TileEntity targetEntity = null;
if(tile != null){
@@ -61,7 +60,7 @@ public class Bullet extends BulletEntity{
super.update();
}
@Override
public boolean collides(SolidEntity other){
if(owner instanceof TileEntity && other instanceof Player)
@@ -82,7 +81,7 @@ public class Bullet extends BulletEntity{
@Override
public Bullet add(){
return super.add(Vars.bulletGroup);
return super.add(bulletGroup);
}
}

View File

@@ -1,13 +1,16 @@
package io.anuke.mindustry.entities;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.resource.Mech;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.core.*;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Angles;
@@ -46,7 +49,7 @@ public class Player extends SyncEntity{
@Override
public void damage(int amount){
if(!Vars.debug && !isAndroid)
if(!debug && !isAndroid)
super.damage(amount);
}
@@ -54,7 +57,7 @@ public class Player extends SyncEntity{
public boolean collides(SolidEntity other){
if(other instanceof Bullet){
Bullet b = (Bullet)other;
if(!Vars.logic.friendlyFire && b.owner instanceof Player){
if(!state.friendlyFire && b.owner instanceof Player){
return false;
}
}
@@ -67,7 +70,7 @@ public class Player extends SyncEntity{
if(isLocal){
remove();
if(Net.active()){
Vars.netClient.handlePlayerDeath();
NetEvents.handlePlayerDeath();
}
Effects.effect(Fx.explosion, this);
@@ -77,7 +80,7 @@ public class Player extends SyncEntity{
//TODO respawning doesn't work properly for multiplayer at all
if(isLocal) {
Vars.control.setRespawnTime(respawnduration);
control.setRespawnTime(respawnduration);
ui.hudfrag.fadeRespawn(true);
}
}
@@ -91,7 +94,7 @@ public class Player extends SyncEntity{
set(-9999, -9999);
Timers.run(respawnduration, () -> {
heal();
set(logic.getSpawnX(), logic.getSpawnY());
set(world.getSpawnX(), world.getSpawnY());
});
}
@@ -101,8 +104,8 @@ public class Player extends SyncEntity{
angle = Mathf.lerpAngDelta(angle, targetAngle, 0.2f);
}
if((Vars.debug && (!Vars.showPlayer || !Vars.showUI)) || (isAndroid && isLocal) ) return;
boolean snap = Vars.snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate") && isLocal;
if((debug && (!showPlayer || !showUI)) || (isAndroid && isLocal) ) return;
boolean snap = snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate") && isLocal;
String part = isAndroid ? "ship" : "mech";
@@ -128,7 +131,7 @@ public class Player extends SyncEntity{
@Override
public void update(){
if(!isLocal || isAndroid || Vars.ui.chatfrag.chatOpen()){
if(!isLocal || isAndroid || ui.chatfrag.chatOpen()){
if(!isDead() && !isLocal) interpolate();
return;
}
@@ -174,7 +177,7 @@ public class Player extends SyncEntity{
vector.limit(speed);
if(!Vars.noclip){
if(!noclip){
move(vector.x*Timers.delta(), vector.y*Timers.delta());
}else{
x += vector.x*Timers.delta();
@@ -189,13 +192,13 @@ public class Player extends SyncEntity{
this.angle = Mathf.lerpAngDelta(this.angle, angle, 0.1f);
}
x = Mathf.clamp(x, 0, Vars.world.width() * Vars.tilesize);
y = Mathf.clamp(y, 0, Vars.world.height() * Vars.tilesize);
x = Mathf.clamp(x, 0, world.width() * tilesize);
y = Mathf.clamp(y, 0, world.height() * tilesize);
}
@Override
public Player add(){
return add(Vars.control.playerGroup);
return add(playerGroup);
}
@Override

View File

@@ -1,13 +1,12 @@
package io.anuke.mindustry.entities;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.mindustry.world.blocks.types.Wall;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
@@ -19,6 +18,9 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.tileGroup;
import static io.anuke.mindustry.Vars.world;
public class TileEntity extends Entity{
private static final boolean friendlyFire = false;
@@ -64,14 +66,11 @@ public class TileEntity extends Entity{
}
public void onDeath(boolean force){
if(Net.active() && Net.server()){
Vars.netServer.handleBlockDestroyed(this);
if(Net.server()){
NetEvents.handleBlockDestroyed(this);
}
if(!Net.active() || Net.server() || force){
if(tile.block() == ProductionBlocks.core){
Vars.control.coreDestroyed();
}
if(!dead) {
dead = true;
@@ -79,7 +78,7 @@ public class TileEntity extends Entity{
block.onDestroyed(tile);
Vars.world.removeBlock(tile);
world.removeBlock(tile);
remove();
}
}
@@ -96,8 +95,8 @@ public class TileEntity extends Entity{
health -= amount;
if(health <= 0) onDeath();
if(Net.active() && Net.server()){
Vars.netServer.handleBlockDamaged(this);
if(Net.server()){
NetEvents.handleBlockDamaged(this);
}
}
@@ -150,6 +149,6 @@ public class TileEntity extends Entity{
@Override
public TileEntity add(){
return add(Vars.control.tileGroup);
return add(tileGroup);
}
}

View File

@@ -2,7 +2,6 @@ package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
@@ -16,6 +15,8 @@ import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Physics;
import static io.anuke.mindustry.Vars.*;
public class DamageArea{
private static Rectangle rect = new Rectangle();
@@ -59,14 +60,14 @@ public class DamageArea{
}
};
Entities.getNearby(Vars.control.enemyGroup, rect, cons);
if(Vars.control.isFriendlyFire()) Entities.getNearby(Vars.control.playerGroup, rect, cons);
Entities.getNearby(enemyGroup, rect, cons);
if(state.friendlyFire) Entities.getNearby(playerGroup, rect, cons);
}
public static void damageEntities(float x, float y, float radius, int damage){
damage(true, x, y, radius, damage);
for(Player player : Vars.control.playerGroup.all()){
for(Player player : playerGroup.all()){
if(player.isAndroid) continue;
int amount = calculateDamage(x, y, player.x, player.y, radius, damage);
player.damage(amount);
@@ -84,12 +85,12 @@ public class DamageArea{
};
if(enemies){
Entities.getNearby(Vars.control.enemyGroup, x, y, radius*2, cons);
Entities.getNearby(enemyGroup, x, y, radius*2, cons);
}else{
int trad = (int)(radius / Vars.tilesize);
int trad = (int)(radius / tilesize);
for(int dx = -trad; dx <= trad; dx ++){
for(int dy= -trad; dy <= trad; dy ++){
Tile tile = Vars.world.tile(Mathf.scl2(x, Vars.tilesize) + dx, Mathf.scl2(y, Vars.tilesize) + dy);
Tile tile = world.tile(Mathf.scl2(x, tilesize) + dx, Mathf.scl2(y, tilesize) + dy);
if(tile != null && tile.entity != null && Vector2.dst(dx, dy, 0, 0) <= trad){
int amount = calculateDamage(x, y, tile.worldx(), tile.worldy(), radius, damage);
tile.entity.damage(amount);
@@ -97,7 +98,7 @@ public class DamageArea{
}
}
Entities.getNearby(Vars.control.playerGroup, x, y, radius*2, cons);
Entities.getNearby(playerGroup, x, y, radius*2, cons);
}
}

View File

@@ -4,7 +4,7 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
@@ -29,15 +29,15 @@ public class EMP extends TimedEntity{
lifetime = 30f;
int worldx = Mathf.scl2(x, Vars.tilesize);
int worldy = Mathf.scl2(y, Vars.tilesize);
int worldx = Mathf.scl2(x, tilesize);
int worldy = Mathf.scl2(y, tilesize);
array.clear();
for(int dx = -radius; dx <= radius; dx ++){
for(int dy = -radius; dy <= radius; dy ++){
if(Vector2.dst(dx, dy, 0, 0) < radius){
Tile tile = Vars.world.tile(worldx + dx, worldy + dy);
Tile tile = world.tile(worldx + dx, worldy + dy);
if(tile != null && tile.block().destructible){
array.add(tile);
@@ -80,12 +80,12 @@ public class EMP extends TimedEntity{
}
for(int i = 0; i < 14 - targets.size; i ++){
Angles.translation(Mathf.randomSeed(i + id*77)*360f, radius * Vars.tilesize);
Angles.translation(Mathf.randomSeed(i + id*77)*360f, radius * tilesize);
drawLine(x + Angles.x(), y + Angles.y());
}
Lines.stroke(fract()*2f);
Lines.poly(x, y, 34, radius * Vars.tilesize);
Lines.poly(x, y, 34, radius * tilesize);
Draw.reset();
}

View File

@@ -1,18 +1,19 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.math.Interpolation;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.defense.ShieldBlock;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.BulletEntity;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.bulletGroup;
import static io.anuke.mindustry.Vars.shieldGroup;
public class Shield extends Entity{
public boolean active;
public boolean hitPlayers = false;
@@ -52,7 +53,7 @@ public class Shield extends Entity{
ShieldBlock block = (ShieldBlock)tile.block();
Entities.getNearby(Vars.control.bulletGroup, x, y, block.shieldRadius * 2*uptime + 10, entity->{
Entities.getNearby(bulletGroup, x, y, block.shieldRadius * 2*uptime + 10, entity->{
BulletEntity bullet = (BulletEntity)entity;
if((bullet.owner instanceof Enemy || hitPlayers)){
@@ -85,7 +86,7 @@ public class Shield extends Entity{
@Override
public Shield add(){
return super.add(Vars.control.shieldGroup);
return super.add(shieldGroup);
}
@Override

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.ucore.graphics.Draw;
@@ -44,7 +44,7 @@ public class TeslaOrb extends Entity{
break;
}
Array<SolidEntity> enemies = Entities.getNearby(Vars.control.enemyGroup, curx, cury, range*2f);
Array<SolidEntity> enemies = Entities.getNearby(enemyGroup, curx, cury, range*2f);
for(SolidEntity entity : enemies){
if(entity.distanceTo(curx, cury) < range && !hit.contains((Enemy)entity)){

View File

@@ -1,11 +1,11 @@
package io.anuke.mindustry.entities.enemies;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.SyncEntity;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.util.Angles;
@@ -14,6 +14,8 @@ import io.anuke.ucore.util.Timer;
import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.enemyGroup;
public class Enemy extends SyncEntity {
public final EnemyType type;
@@ -88,7 +90,7 @@ public class Enemy extends SyncEntity {
@Override
public Enemy add(){
return add(Vars.enemyGroup);
return add(enemyGroup);
}
@Override
@@ -130,14 +132,14 @@ public class Enemy extends SyncEntity {
public void shoot(BulletType bullet, float rotation){
if(!(Net.active() && Net.client())) {
if(!(Net.client())) {
Angles.translation(angle + rotation, type.length);
Bullet out = new Bullet(bullet, this, x + Angles.x(), y + Angles.y(), this.angle + rotation).add();
out.damage = (int) ((bullet.damage * (1 + (tier - 1) * 1f)) * Vars.multiplier);
out.damage = (int) ((bullet.damage * (1 + (tier - 1) * 1f)));
type.onShoot(this, bullet, rotation);
if(Net.active() && Net.server()){
Vars.netServer.handleBullet(bullet, this, x + Angles.x(), y + Angles.y(), this.angle + rotation, (short)out.damage);
if(Net.server()){
NetEvents.handleBullet(bullet, this, x + Angles.x(), y + Angles.y(), this.angle + rotation, (short)out.damage);
}
}
}

View File

@@ -3,20 +3,20 @@ package io.anuke.mindustry.entities.enemies;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings;
import io.anuke.ucore.util.Tmp;
@@ -220,7 +220,7 @@ public class EnemyType {
public void updateShooting(Enemy enemy){
float reload = this.reload / Math.max(enemy.tier / 1.5f, 1f);
if(enemy.timer.get(timerReload, reload * multiplier)){
if(enemy.timer.get(timerReload, reload)){
shoot(enemy);
}
}
@@ -233,8 +233,8 @@ public class EnemyType {
public void onShoot(Enemy enemy, BulletType type, float rotation){}
public void onDeath(Enemy enemy){
if(Net.active() && Net.server()){
netServer.handleEnemyDeath(enemy);
if(Net.server()){
NetEvents.handleEnemyDeath(enemy);
}
Effects.effect(Fx.explosion, enemy);
@@ -249,7 +249,7 @@ public class EnemyType {
if(enemy.spawner != null){
enemy.spawner.spawned --;
}else{
Vars.control.enemyDeath(); //TODO
state.enemies --;
}
}
}

View File

@@ -1,8 +1,7 @@
package io.anuke.mindustry.entities.enemies.types;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.TileEntity;
@@ -31,7 +30,7 @@ public class BlastType extends EnemyType {
if(enemy.target instanceof TileEntity){
TileEntity e = (TileEntity)enemy.target;
range = (e.tile.block().width * Vars.tilesize) /2f + 8f;
range = (e.tile.block().width * tilesize) /2f + 8f;
offset.set(e.tile.block().getPlaceOffset());
}

View File

@@ -1,6 +1,6 @@
package io.anuke.mindustry.entities.enemies.types;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
@@ -30,8 +30,8 @@ public class FortressType extends EnemyType {
@Override
public void move(Enemy enemy){
if(enemy.distanceTo(Vars.world.getCore().worldx(),
Vars.world.getCore().worldy()) <= 90f){
if(enemy.distanceTo(world.getCore().worldx(),
world.getCore().worldy()) <= 90f){
if(Timers.get(this, "spawn", spawnTime) && enemy.spawned < maxSpawn){
Angles.translation(enemy.angle, 20f);

View File

@@ -1,21 +1,23 @@
package io.anuke.mindustry.entities.enemies.types;
import com.badlogic.gdx.math.MathUtils;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.ucore.core.*;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.graphics.Shapes;
import io.anuke.ucore.util.Angles;
import static io.anuke.mindustry.Vars.enemyGroup;
public class HealerType extends EnemyType {
public HealerType() {
@@ -46,7 +48,7 @@ public class HealerType extends EnemyType {
@Override
public void updateTargeting(Enemy enemy, boolean nearCore){
if(enemy.timer.get(timerTarget, 15)){
enemy.target = Entities.getClosest(Vars.control.enemyGroup,
enemy.target = Entities.getClosest(enemyGroup,
enemy.x, enemy.y, range, e -> e instanceof Enemy && e != enemy && ((Enemy)e).healthfrac() < 1f);
}

View File

@@ -1,16 +1,16 @@
package io.anuke.mindustry.entities.enemies.types;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.mindustry.entities.enemies.EnemyTypes;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.control;
public class TargetType extends EnemyType {
public TargetType(){
@@ -42,7 +42,7 @@ public class TargetType extends EnemyType {
Draw.color(Color.YELLOW);
if(Vars.control.getTutorial().showTarget()){
if(control.tutorial().showTarget()){
Lines.spikes(enemy.x, enemy.y, 11f + Mathf.sin(Timers.time(), 7f, 1f), 4f, 8, Timers.time());
}

View File

@@ -1,9 +1,10 @@
package io.anuke.mindustry.game;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.state;
public class EnemySpawn{
/**The enemy type spawned*/
public final EnemyType type;
@@ -34,7 +35,7 @@ public class EnemySpawn{
if(wave < after || wave > before || (wave - after) % spacing != 0){
return 0;
}
float scaling = this.scaling * Vars.control.getDifficulty().enemyScaling;
float scaling = this.scaling * state.difficulty.enemyScaling;
return Math.min(amount-1 + Math.max((int)((wave / spacing) / scaling), 1) + (tier(wave, lane)-1) * tierscaleback, max);
}

View File

@@ -1,6 +1,13 @@
package io.anuke.mindustry.game;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.function.Event;
public class EventType {
@@ -17,11 +24,67 @@ public class EventType {
void handle();
}
public interface GameOver extends Event{
public interface GameOverEvent extends Event{
void handle();
}
public interface StateChange extends Event{
public interface StateChangeEvent extends Event{
void handle(State from, State to);
}
public interface FriendlyFireChange extends Event{
void handle(boolean on);
}
public interface BulletEvent extends Event{
void handle(BulletType type, Entity owner, float x, float y, float angle, short damage);
}
public interface EnemyDeathEvent extends Event{
void handle(Enemy enemy);
}
public interface BlockDestroyEvent extends Event{
void handle(TileEntity entity);
}
public interface BlockDamageEvent extends Event{
void handle(TileEntity entity);
}
public interface PlayerDeathEvent extends Event{
void handle();
}
public interface BlockConfigEvent extends Event{
void handle(Tile tile, byte data);
}
public interface BlockTapEvent extends Event{
void handle(Tile tile);
}
public interface WeaponSwitchEvent extends Event{
void handle();
}
public interface UpgradeEvent extends Event{
void handle(Weapon weapon);
}
public interface MessageSendEvent extends Event{
void handle(String message);
}
public interface ShootEvent extends Event{
void handle(Weapon weapon, float x, float y, float angle);
}
public interface PlaceEvent extends Event{
void handle(int x, int y, Block block, int rotation);
}
public interface BreakEvent extends Event{
void handle(int x, int y);
}
}

View File

@@ -5,8 +5,6 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.world.Block;
@@ -15,9 +13,9 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.types.StaticBlock;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.graphics.CacheBatch;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Mathf;
@@ -89,7 +87,7 @@ public class BlockRenderer{
if(!(block instanceof StaticBlock)){
if(block == Blocks.air){
if(!GameState.is(State.paused)) tile.floor().update(tile);
if(!state.is(State.paused)) tile.floor().update(tile);
}else{
if(!expanded){
@@ -190,11 +188,11 @@ public class BlockRenderer{
Draw.reset();
if(Vars.showPaths && Vars.debug){
if(showPaths && debug){
drawPaths();
}
if(Vars.debug && Vars.debugChunks){
if(debug && debugChunks){
Draw.color(Color.YELLOW);
Lines.stroke(1f);
for(int x = -crangex; x <= crangex; x++){
@@ -213,7 +211,7 @@ public class BlockRenderer{
void drawPaths(){
Draw.color(Color.RED);
for(SpawnPoint point : control.getSpawnPoints()){
for(SpawnPoint point : world.getSpawns()){
if(point.pathTiles != null){
for(int i = 1; i < point.pathTiles.length; i ++){
Lines.line(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(),
@@ -280,6 +278,6 @@ public class BlockRenderer{
private void createBatch(){
if(cbatch != null)
cbatch.dispose();
cbatch = new CacheBatch(Vars.world.width() * Vars.world.height() * 4);
cbatch = new CacheBatch(world.width() * world.height() * 4);
}
}

View File

@@ -2,15 +2,17 @@ package io.anuke.mindustry.graphics;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Colors;
import io.anuke.mindustry.Vars;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.graphics.Shapes;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.respawnduration;
import static io.anuke.mindustry.Vars.tilesize;
public class Fx{
public static Color lightRed = Hue.mix(Color.WHITE, Color.FIREBRICK, 0.1f);
public static Color lightOrange = Color.valueOf("f68021");
@@ -249,31 +251,31 @@ public class Fx{
place = new Effect(16, e -> {
Lines.stroke(3f - e.ifract() * 2f);
Lines.square(e.x, e.y, Vars.tilesize / 2f + e.ifract() * 3f);
Lines.square(e.x, e.y, tilesize / 2f + e.ifract() * 3f);
Draw.reset();
}),
dooropen = new Effect(10, e -> {
Lines.stroke(e.fract() * 1.6f);
Lines.square(e.x, e.y, Vars.tilesize / 2f + e.ifract() * 2f);
Lines.square(e.x, e.y, tilesize / 2f + e.ifract() * 2f);
Draw.reset();
}),
doorclose= new Effect(10, e -> {
Lines.stroke(e.fract() * 1.6f);
Lines.square(e.x, e.y, Vars.tilesize / 2f + e.fract() * 2f);
Lines.square(e.x, e.y, tilesize / 2f + e.fract() * 2f);
Draw.reset();
}),
dooropenlarge = new Effect(10, e -> {
Lines.stroke(e.fract() * 1.6f);
Lines.square(e.x, e.y, Vars.tilesize + e.ifract() * 2f);
Lines.square(e.x, e.y, tilesize + e.ifract() * 2f);
Draw.reset();
}),
doorcloselarge = new Effect(10, e -> {
Lines.stroke(e.fract() * 1.6f);
Lines.square(e.x, e.y, Vars.tilesize + e.fract() * 2f);
Lines.square(e.x, e.y, tilesize + e.fract() * 2f);
Draw.reset();
}),
@@ -502,7 +504,7 @@ public class Fx{
Draw.reset();
}),
respawn = new Effect(Vars.respawnduration, e -> {
respawn = new Effect(respawnduration, e -> {
Draw.tcolor(Color.SCARLET);
Draw.tscl(0.25f);
Draw.text("Respawning in " + (int)((e.lifetime-e.time)/60), e.x, e.y);

View File

@@ -3,10 +3,9 @@ package io.anuke.mindustry.input;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Graphics;
@@ -73,7 +72,7 @@ public class AndroidInput extends InputHandler{
warmup = 0;
if(!GameState.is(State.menu)){
if(!state.is(State.menu)){
Tile cursor = world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
if(cursor != null && !ui.hasMouse(screenX, screenY)){
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
@@ -85,7 +84,7 @@ public class AndroidInput extends InputHandler{
if(linked != null) {
linked.block().tapped(linked);
if(Net.active()) netClient.handleBlockTap(linked);
if(Net.active()) NetEvents.handleBlockTap(linked);
}
}
}
@@ -125,8 +124,8 @@ public class AndroidInput extends InputHandler{
float xa = Inputs.getAxis("move_x");
float ya = Inputs.getAxis("move_y");
if(Math.abs(xa) < Vars.controllerMin) xa = 0;
if(Math.abs(ya) < Vars.controllerMin) ya = 0;
if(Math.abs(xa) < controllerMin) xa = 0;
if(Math.abs(ya) < controllerMin) ya = 0;
player.x += xa * 4f;
player.y += ya * 4f;
@@ -173,15 +172,15 @@ public class AndroidInput extends InputHandler{
public boolean tryPlaceBlock(int x, int y, boolean sound){
if(recipe != null &&
validPlace(x, y, recipe.result) && cursorNear() &&
Vars.control.hasItems(recipe.requirements)){
state.inventory.hasItems(recipe.requirements)){
placeBlock(x, y, recipe.result, rotation, true, sound);
for(ItemStack stack : recipe.requirements){
Vars.control.removeItem(stack);
state.inventory.removeItem(stack);
}
if(!Vars.control.hasItems(recipe.requirements)){
if(!state.inventory.hasItems(recipe.requirements)){
Cursors.restoreCursor();
}
return true;

View File

@@ -2,11 +2,9 @@ package io.anuke.mindustry.input;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Inputs;
@@ -60,7 +58,7 @@ public class DesktopInput extends InputHandler{
boolean controller = KeyBinds.getSection("default").device.type == DeviceType.controller;
if(Inputs.getAxisActive("zoom") && (Inputs.keyDown("zoom_hold") || controller)
&& !GameState.is(State.menu) && !ui.hasDialog()){
&& !state.is(State.menu) && !ui.hasDialog()){
if((!zoomed || !controller)) {
renderer.scaleCamera((int) Inputs.getAxis("zoom"));
}
@@ -89,11 +87,11 @@ public class DesktopInput extends InputHandler{
breakMode = PlaceMode.hold;
}
for(int i = 1; i <= 6 && i <= control.getWeapons().size; i ++){
for(int i = 1; i <= 6 && i <= control.upgrades().getWeapons().size; i ++){
if(Inputs.keyTap("weapon_" + i)){
player.weaponLeft = player.weaponRight = control.getWeapons().get(i - 1);
if(Net.active()) Vars.netClient.handleWeaponSwitch();
Vars.ui.hudfrag.updateWeapons();
player.weaponLeft = player.weaponRight = control.upgrades().getWeapons().get(i - 1);
if(Net.active()) NetEvents.handleWeaponSwitch();
ui.hudfrag.updateWeapons();
}
}
@@ -109,7 +107,7 @@ public class DesktopInput extends InputHandler{
if(linked != null) {
linked.block().tapped(linked);
if(Net.active()) netClient.handleBlockTap(linked);
if(Net.active()) NetEvents.handleBlockTap(linked);
}
}
@@ -151,16 +149,6 @@ public class DesktopInput extends InputHandler{
recipe.result.height % 2 == 0) ?
Mathf.scl(Graphics.mouseWorld().y, tilesize) : Mathf.scl2(Graphics.mouseWorld().y, tilesize);
}
public int currentWeapon(){
int i = 0;
for(Weapon weapon : control.getWeapons()){
if(weapon == weapon)
return i;
i ++;
}
return 0;
}
@Override
public boolean keyDown(int keycode) {

View File

@@ -3,7 +3,6 @@ package io.anuke.mindustry.input;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.input.GestureDetector.GestureAdapter;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.scene.ui.layout.Unit;
@@ -45,9 +44,10 @@ public class GestureHandler extends GestureAdapter{
@Override
public boolean pan(float x, float y, float deltaX, float deltaY){
if(Vars.control.showCursor() && !Inputs.keyDown("select")) return false;
if(control.showCursor() && !Inputs.keyDown("select")) return false;
if(!Vars.control.showCursor() && !(control.input().recipe != null && Vars.control.hasItems(control.input().recipe.requirements) && control.input().placeMode.lockCamera) &&
if(!control.showCursor() && !(control.input().recipe != null
&& state.inventory.hasItems(control.input().recipe.requirements) && control.input().placeMode.lockCamera) &&
!(control.input().recipe == null && control.input().breakMode.lockCamera)){
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
player.x -= dx;

View File

@@ -5,15 +5,15 @@ import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Recipes;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
@@ -27,7 +27,6 @@ import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.player;
public abstract class InputHandler extends InputAdapter{
public float breaktime = 0;
@@ -43,15 +42,15 @@ public abstract class InputHandler extends InputAdapter{
public abstract float getCursorY();
public abstract float getCursorEndX();
public abstract float getCursorEndY();
public int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, Vars.tilesize, round2()); }
public int getBlockY(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).y, Vars.tilesize, round2()); }
public int getBlockEndX(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).x, Vars.tilesize, round2()); }
public int getBlockEndY(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).y, Vars.tilesize, round2()); }
public int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, tilesize, round2()); }
public int getBlockY(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).y, tilesize, round2()); }
public int getBlockEndX(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).x, tilesize, round2()); }
public int getBlockEndY(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).y, tilesize, round2()); }
public void resetCursor(){}
public boolean drawPlace(){ return true; }
public boolean onConfigurable(){
Tile tile = Vars.world.tile(getBlockX(), getBlockY());
Tile tile = world.tile(getBlockX(), getBlockY());
return tile != null && (tile.block().isConfigurable(tile) || (tile.isLinked() && tile.getLinked().block().isConfigurable(tile)));
}
@@ -62,15 +61,15 @@ public abstract class InputHandler extends InputAdapter{
public boolean tryPlaceBlock(int x, int y, boolean sound){
if(recipe != null &&
validPlace(x, y, recipe.result) && !ui.hasMouse() && cursorNear() &&
Vars.control.hasItems(recipe.requirements)){
state.inventory.hasItems(recipe.requirements)){
placeBlock(x, y, recipe.result, rotation, true, sound);
for(ItemStack stack : recipe.requirements){
Vars.control.removeItem(stack);
state.inventory.removeItem(stack);
}
if(!Vars.control.hasItems(recipe.requirements)){
if(!state.inventory.hasItems(recipe.requirements)){
Cursors.restoreCursor();
}
return true;
@@ -92,17 +91,17 @@ public abstract class InputHandler extends InputAdapter{
public boolean validPlace(int x, int y, Block type){
for(SpawnPoint spawn : control.getSpawnPoints()){
for(SpawnPoint spawn : world.getSpawns()){
if(Vector2.dst(x * tilesize, y * tilesize, spawn.start.worldx(), spawn.start.worldy()) < enemyspawnspace){
return false;
}
}
Tmp.r2.setSize(type.width * Vars.tilesize, type.height * Vars.tilesize);
Tmp.r2.setSize(type.width * tilesize, type.height * tilesize);
Vector2 offset = type.getPlaceOffset();
Tmp.r2.setCenter(offset.x + x * Vars.tilesize, offset.y + y * Vars.tilesize);
Tmp.r2.setCenter(offset.x + x * tilesize, offset.y + y * tilesize);
for(SolidEntity e : Entities.getNearby(control.enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
for(SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
Rectangle rect = e.hitbox.getRect(e.x, e.y);
if(Tmp.r2.overlaps(rect)){
@@ -111,7 +110,7 @@ public abstract class InputHandler extends InputAdapter{
}
if(type.solid || type.solidifes) {
for (Player player : Vars.control.playerGroup.all()) {
for (Player player : playerGroup.all()) {
if (!player.isAndroid && Tmp.r2.overlaps(player.hitbox.getRect(player.x, player.y))) {
return false;
}
@@ -122,18 +121,18 @@ public abstract class InputHandler extends InputAdapter{
if(tile == null) return false;
if(!type.isMultiblock() && Vars.control.getTutorial().active() &&
Vars.control.getTutorial().showBlock()){
if(!type.isMultiblock() && control.tutorial().active() &&
control.tutorial().showBlock()){
GridPoint2 point = Vars.control.getTutorial().getPlacePoint();
int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock();
GridPoint2 point = control.tutorial().getPlacePoint();
int rotation = control.tutorial().getPlaceRotation();
Block block = control.tutorial().getPlaceBlock();
if(type != block || point.x != x - world.getCore().x || point.y != y - world.getCore().y
|| (rotation != -1 && rotation != this.rotation)){
return false;
}
}else if(Vars.control.getTutorial().active()){
}else if(control.tutorial().active()){
return false;
}
@@ -166,12 +165,12 @@ public abstract class InputHandler extends InputAdapter{
return false;
}
if(Vars.control.getTutorial().active()){
if(control.tutorial().active()){
if(Vars.control.getTutorial().showBlock()){
GridPoint2 point = Vars.control.getTutorial().getPlacePoint();
int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock();
if(control.tutorial().showBlock()){
GridPoint2 point = control.tutorial().getPlacePoint();
int rotation = control.tutorial().getPlaceRotation();
Block block = control.tutorial().getPlaceBlock();
if(block != Blocks.air || point.x != x - world.getCore().x || point.y != y - world.getCore().y
|| (rotation != -1 && rotation != this.rotation)){
@@ -190,7 +189,7 @@ public abstract class InputHandler extends InputAdapter{
placeBlockInternal(x, y, result, rotation, effects, sound);
if(Net.active() && result != ProductionBlocks.core){
Vars.netClient.handlePlace(x, y, result, rotation);
NetEvents.handlePlace(x, y, result, rotation);
}
}
@@ -217,11 +216,11 @@ public abstract class InputHandler extends InputAdapter{
toplace.setLinked((byte)(dx + offsetx), (byte)(dy + offsety));
}
if(effects) Effects.effect(Fx.place, worldx * Vars.tilesize, worldy * Vars.tilesize);
if(effects) Effects.effect(Fx.place, worldx * tilesize, worldy * tilesize);
}
}
}else{
if(effects) Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize);
if(effects) Effects.effect(Fx.place, x * tilesize, y * tilesize);
}
if(effects && sound) Sounds.play("place");
@@ -233,7 +232,7 @@ public abstract class InputHandler extends InputAdapter{
breakBlockInternal(x, y, sound);
if(Net.active()){
Vars.netClient.handleBreak(x, y);
NetEvents.handleBreak(x, y);
}
}
@@ -254,12 +253,12 @@ public abstract class InputHandler extends InputAdapter{
if(result != null){
for(ItemStack stack : result.requirements){
Vars.control.addItem(stack.item, (int)(stack.amount * Vars.breakDropAmount));
state.inventory.addItem(stack.item, (int)(stack.amount * breakDropAmount));
}
}
if(tile.block().drops != null){
Vars.control.addItem(tile.block().drops.item, tile.block().drops.amount);
state.inventory.addItem(tile.block().drops.item, tile.block().drops.amount);
}
//Effects.shake(3f, 1f, player);

View File

@@ -4,12 +4,11 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.ui.fragments.ToolFragment;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Bundles;
@@ -27,8 +26,8 @@ public enum PlaceMode{
}
public void draw(int tilex, int tiley, int endx, int endy){
float x = tilex * Vars.tilesize;
float y = tiley * Vars.tilesize;
float x = tilex * tilesize;
float y = tiley * tilesize;
boolean valid = control.input().validPlace(tilex, tiley, control.input().recipe.result) && (android || control.input().cursorNear());
@@ -152,7 +151,7 @@ public enum PlaceMode{
Lines.stroke(1f);
for(int cx = tilex; cx <= endx; cx ++){
for(int cy = tiley; cy <= endy; cy ++){
Tile tile = Vars.world.tile(cx, cy);
Tile tile = world.tile(cx, cy);
if(tile != null && tile.getLinked() != null)
tile = tile.getLinked();
if(tile != null && control.input().validBreak(tile.x, tile.y)){
@@ -176,8 +175,8 @@ public enum PlaceMode{
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
if(Vars.android){
ToolFragment t = Vars.ui.toolfrag;
if(android){
ToolFragment t = ui.toolfrag;
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
t.confirming = true;
t.px = tilex;
@@ -242,11 +241,11 @@ public enum PlaceMode{
}
public void draw(int tilex, int tiley, int endx, int endy){
if(Vars.android && !Gdx.input.isTouched(0) && !Vars.control.showCursor()){
if(android && !Gdx.input.isTouched(0) && !control.showCursor()){
return;
}
float t = Vars.tilesize;
float t = tilesize;
Block block = control.input().recipe.result;
Vector2 offset = block.getPlaceOffset();
@@ -290,7 +289,7 @@ public enum PlaceMode{
py = ty + cy * Mathf.sign(ey - ty);
if(!control.input().validPlace(px, py, control.input().recipe.result)
|| !control.hasItems(control.input().recipe.requirements, amount)){
|| !state.inventory.hasItems(control.input().recipe.requirements, amount)){
Lines.crect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
}
amount ++;

View File

@@ -1,8 +1,10 @@
package io.anuke.mindustry.world;
package io.anuke.mindustry.io;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectIntMap;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.*;
import io.anuke.ucore.UCore;
public class BlockLoader {
static final ObjectIntMap<String> defaultMap = map(
@@ -120,6 +122,8 @@ public class BlockLoader {
Block block = Block.getByName(string);
blockmap.put(defaultMap.get(string, -1), block);
}
UCore.log("Total blocks loaded: " + Block.getAllBlocks().size);
}
public static Block getByOldID(int id){

View File

@@ -0,0 +1,62 @@
package io.anuke.mindustry.io;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.I18NBundle;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Settings;
import java.util.Locale;
public class BundleLoader {
private static boolean externalBundle = false;
public static void load(){
Settings.defaults("locale", "default");
Settings.load("io.anuke.moment");
loadBundle();
}
private static Locale getLocale(){
String loc = Settings.getString("locale");
if(loc.equals("default")){
return Locale.getDefault();
}else{
Locale lastLocale;
if (loc.contains("_")) {
String[] split = loc.split("_");
lastLocale = new Locale(split[0], split[1]);
} else {
lastLocale = new Locale(loc);
}
return lastLocale;
}
}
private static void loadBundle(){
I18NBundle.setExceptionOnMissingKey(false);
if(externalBundle){
try {
FileHandle handle = Gdx.files.local("bundle");
Locale locale = Locale.ENGLISH;
Core.bundle = I18NBundle.createBundle(handle, locale);
}catch (Exception e){
UCore.error(e);
Platform.instance.showError("Failed to find bundle!\nMake sure you have bundle.properties in the same directory\nas the jar file.\n\nIf the problem persists, try running it through the command prompt:\n" +
"Hold left-shift, then right click and select 'open command prompt here'.\nThen, type in 'java -jar mindustry.jar' without quotes.");
Gdx.app.exit();
}
}else{
FileHandle handle = Gdx.files.internal("bundles/bundle");
Locale locale = getLocale();
UCore.log("Got locale: " + locale);
Core.bundle = I18NBundle.createBundle(handle, locale);
}
}
}

View File

@@ -8,12 +8,13 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.*;
import com.badlogic.gdx.utils.Json.Serializer;
import com.badlogic.gdx.utils.JsonWriter.OutputType;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Map;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.graphics.Pixmaps;
import static io.anuke.mindustry.Vars.*;
public class Maps implements Disposable{
private IntMap<Map> maps = new IntMap<>();
private ObjectMap<String, Map> mapNames = new ObjectMap<>();
@@ -60,10 +61,10 @@ public class Maps implements Disposable{
throw new RuntimeException("Failed to load maps!");
}
if(!Vars.gwt) {
if (!loadMapFile(Vars.customMapDirectory.child("maps.json"))) {
if(!gwt) {
if (!loadMapFile(customMapDirectory.child("maps.json"))) {
try {
Vars.customMapDirectory.child("maps.json").writeString("{}", false);
customMapDirectory.child("maps.json").writeString("{}", false);
} catch (Exception e) {
throw new RuntimeException("Failed to create custom map directory!");
}
@@ -80,7 +81,7 @@ public class Maps implements Disposable{
out.add(m);
}
}
saveMaps(out, Vars.customMapDirectory.child("maps.json"));
saveMaps(out, customMapDirectory.child("maps.json"));
}
public void saveAndReload(Map map, Pixmap out){
@@ -107,7 +108,7 @@ public class Maps implements Disposable{
}
saveCustomMap(map);
Vars.ui.levels.reload();
ui.levels.reload();
}
public void saveMaps(Array<Map> array, FileHandle file){
@@ -136,8 +137,8 @@ public class Maps implements Disposable{
mapNames.remove(toSave.name);
maps.put(toSave.id, toSave);
mapNames.put(toSave.name, toSave);
Pixmaps.write(toSave.pixmap, Vars.customMapDirectory.child(toSave.name + ".png"));
saveMaps(out, Vars.customMapDirectory.child("maps.json"));
Pixmaps.write(toSave.pixmap, customMapDirectory.child(toSave.name + ".png"));
saveMaps(out, customMapDirectory.child("maps.json"));
}
private boolean loadMapFile(FileHandle file){
@@ -154,7 +155,7 @@ public class Maps implements Disposable{
}
return true;
}catch(Exception e){
if(!Vars.android) UCore.error(e);
if(!android) UCore.error(e);
Gdx.app.error("Mindustry-Maps", "Failed loading map file: " + file);
return false;
}

View File

@@ -5,7 +5,9 @@ import io.anuke.ucore.scene.ui.TextField;
import java.util.Date;
import java.util.Locale;
public abstract class PlatformFunction{
public abstract class Platform {
public static Platform instance = new Platform() {};
public String format(Date date){return "invalid";}
public String format(int number){return "invalid";}
public void showError(String text){}
@@ -16,6 +18,7 @@ public abstract class PlatformFunction{
public void updateRPC(){}
public void onGameExit(){}
public void openDonations(){}
public boolean hasDiscord(){return true;}
public void requestWritePerms(){}
public String getLocaleName(Locale locale){
return locale.toString();

View File

@@ -4,7 +4,6 @@ import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Base64Coder;
import com.badlogic.gdx.utils.IntMap;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.io.versions.Save12;
import io.anuke.mindustry.io.versions.Save13;
import io.anuke.mindustry.io.versions.Save14;
@@ -13,13 +12,16 @@ import io.anuke.ucore.core.Settings;
import java.io.*;
import static io.anuke.mindustry.Vars.gwt;
import static io.anuke.mindustry.Vars.saveDirectory;
public class SaveIO{
public static final IntMap<SaveFileVersion> versions = new IntMap<>();
public static final Array<SaveFileVersion> versionArray = Array.with(
new Save12(),
new Save13(),
new Save14(),
new Save15()
new Save12(),
new Save13(),
new Save14(),
new Save15()
);
static{
@@ -29,7 +31,7 @@ public class SaveIO{
}
public static void saveToSlot(int slot){
if(Vars.gwt){
if(gwt){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
write(stream);
Settings.putString("save-"+slot+"-data", new String(Base64Coder.encode(stream.toByteArray())));
@@ -48,7 +50,7 @@ public class SaveIO{
}
public static void loadFromSlot(int slot){
if(Vars.gwt){
if(gwt){
String string = Settings.getString("save-"+slot+"-data");
ByteArrayInputStream stream = new ByteArrayInputStream(Base64Coder.decode(string));
load(stream);
@@ -58,7 +60,7 @@ public class SaveIO{
}
public static DataInputStream getSlotStream(int slot){
if(Vars.gwt){
if(gwt){
String string = Settings.getString("save-"+slot+"-data");
byte[] bytes = Base64Coder.decode(string);
return new DataInputStream(new ByteArrayInputStream(bytes));
@@ -108,7 +110,7 @@ public class SaveIO{
}
public static FileHandle fileFor(int slot){
return Vars.saveDirectory.child(slot + ".mins");
return saveDirectory.child(slot + ".mins");
}
public static void write(FileHandle file){

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.io;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.world.Map;
@@ -16,9 +15,9 @@ public class SaveMeta {
public SaveMeta(int version, long date, int mode, int map, int wave){
this.version = version;
this.date = Mindustry.platforms.format(new Date(date));
this.date = Platform.instance.format(new Date(date));
this.mode = GameMode.values()[mode];
this.map = Vars.world.maps().getMap(map);
this.map = world.maps().getMap(map);
this.wave = wave;
}
}

View File

@@ -3,8 +3,6 @@ package io.anuke.mindustry.io;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.async.AsyncExecutor;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.world.Map;
@@ -13,6 +11,9 @@ import io.anuke.ucore.core.Timers;
import java.io.IOException;
import static io.anuke.mindustry.Vars.saveSlots;
import static io.anuke.mindustry.Vars.state;
public class Saves {
private int nextSlot;
private Array<SaveSlot> saves = new Array<>();
@@ -24,7 +25,7 @@ public class Saves {
public void load(){
saves.clear();
for(int i = 0; i < Vars.saveSlots; i ++){
for(int i = 0; i < saveSlots; i ++){
if(SaveIO.isSaveValid(i)){
SaveSlot slot = new SaveSlot(i);
saves.add(slot);
@@ -39,11 +40,11 @@ public class Saves {
}
public void update(){
if(GameState.is(State.menu)){
if(state.is(State.menu)){
current = null;
}
if(!GameState.is(State.menu) && !Vars.control.isGameOver() && current != null && current.isAutosave()){
if(!state.is(State.menu) && !state.gameOver && current != null && current.isAutosave()){
time += Timers.delta();
if(time > Settings.getInt("saveinterval")*60) {
saving = true;
@@ -70,7 +71,7 @@ public class Saves {
}
public boolean canAddSave(){
return nextSlot < Vars.saveSlots;
return nextSlot < saveSlots;
}
public void addSave(String name){

View File

@@ -5,12 +5,12 @@ import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.io.BlockLoader;
import io.anuke.mindustry.io.SaveFileVersion;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.BlockLoader;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.core.Core;
@@ -21,7 +21,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.android;
import static io.anuke.mindustry.Vars.*;
public class Save12 extends SaveFileVersion {
@@ -48,36 +48,36 @@ public class Save12 extends SaveFileVersion {
Vars.player.x = playerx;
Vars.player.y = playery;
Vars.player.health = playerhealth;
Vars.control.setMode(GameMode.values()[mode]);
state.mode = GameMode.values()[mode];
Core.camera.position.set(playerx, playery, 0);
//weapons
Vars.control.getWeapons().clear();
Vars.control.getWeapons().add(Weapon.blaster);
control.upgrades().getWeapons().clear();
control.upgrades().getWeapons().add(Weapon.blaster);
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
int weapons = stream.readByte();
for(int i = 0; i < weapons; i ++){
Vars.control.addWeapon((Weapon)Upgrade.getByID(stream.readByte()));
control.upgrades().addWeapon((Weapon)Upgrade.getByID(stream.readByte()));
}
Vars.ui.hudfrag.updateWeapons();
ui.hudfrag.updateWeapons();
//inventory
int totalItems = stream.readByte();
Arrays.fill(Vars.control.getItems(), 0);
Arrays.fill(state.inventory.getItems(), 0);
for(int i = 0; i < totalItems; i ++){
Item item = Item.getByID(stream.readByte());
int amount = stream.readInt();
Vars.control.getItems()[item.id] = amount;
state.inventory.getItems()[item.id] = amount;
}
Vars.ui.hudfrag.updateItems();
ui.hudfrag.updateItems();
//enemies
@@ -102,14 +102,16 @@ public class Save12 extends SaveFileVersion {
enemy.x = x;
enemy.y = y;
enemy.tier = tier;
enemy.add(Vars.control.enemyGroup);
enemy.add(enemyGroup);
enemiesToUpdate.add(enemy);
}catch (Exception e){
throw new RuntimeException(e);
}
}
Vars.control.setWaveData(enemies, wave, wavetime);
state.enemies = enemies;
state.wave = wave;
state.wavetime = wavetime;
if(!android)
Vars.player.add();
@@ -119,20 +121,20 @@ public class Save12 extends SaveFileVersion {
int seed = stream.readInt();
int tiles = stream.readInt();
Vars.world.loadMap(Vars.world.maps().getMap(mapid), seed);
Vars.renderer.clearTiles();
world.loadMap(world.maps().getMap(mapid), seed);
renderer.clearTiles();
for(Enemy enemy : enemiesToUpdate){
enemy.node = -2;
}
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
//remove breakables like rocks
if(tile.breakable()){
Vars.world.tile(x, y).setBlock(Blocks.air);
world.tile(x, y).setBlock(Blocks.air);
}
}
}
@@ -143,7 +145,7 @@ public class Save12 extends SaveFileVersion {
boolean hasEntity = stream.readBoolean();
int blockid = stream.readInt();
Tile tile = Vars.world.tile(pos % Vars.world.width(), pos / Vars.world.width());
Tile tile = world.tile(pos % world.width(), pos / world.width());
tile.setBlock(BlockLoader.getByOldID(blockid));
tile.link = link;
@@ -174,31 +176,31 @@ public class Save12 extends SaveFileVersion {
stream.writeLong(TimeUtils.millis()); //last saved
//--GENERAL STATE--
stream.writeByte(Vars.control.getMode().ordinal()); //gamemode
stream.writeByte(Vars.world.getMap().id); //map ID
stream.writeByte(state.mode.ordinal()); //gamemode
stream.writeByte(world.getMap().id); //map ID
stream.writeInt(Vars.control.getWave()); //wave
stream.writeFloat(Vars.control.getWaveCountdown()); //wave countdown
stream.writeInt(state.wave); //wave
stream.writeFloat(state.wavetime); //wave countdown
stream.writeFloat(Vars.player.x); //player x/y
stream.writeFloat(Vars.player.y);
stream.writeInt(Vars.player.health); //player health
stream.writeByte(Vars.control.getWeapons().size - 1); //amount of weapons
stream.writeByte(control.upgrades().getWeapons().size - 1); //amount of weapons
//start at 1, because the first weapon is always the starter - ignore that
for(int i = 1; i < Vars.control.getWeapons().size; i ++){
stream.writeByte(Vars.control.getWeapons().get(i).id); //weapon ordinal
for(int i = 1; i < control.upgrades().getWeapons().size; i ++){
stream.writeByte(control.upgrades().getWeapons().get(i).id); //weapon ordinal
}
//--INVENTORY--
int l = Vars.control.getItems().length;
int l = state.inventory.getItems().length;
int itemsize = 0;
for(int i = 0; i < l; i ++){
if(Vars.control.getItems()[i] > 0){
if(state.inventory.getItems()[i] > 0){
itemsize ++;
}
}
@@ -206,15 +208,15 @@ public class Save12 extends SaveFileVersion {
stream.writeByte(itemsize); //amount of items
for(int i = 0; i < l; i ++){
if(Vars.control.getItems()[i] > 0){
if(state.inventory.getItems()[i] > 0){
stream.writeByte(i); //item ID
stream.writeInt(Vars.control.getItems()[i]); //item amount
stream.writeInt(state.inventory.getItems()[i]); //item amount
}
}
//--ENEMIES--
Array<Enemy> enemies = Vars.control.enemyGroup.all();
Array<Enemy> enemies = enemyGroup.all();
stream.writeInt(enemies.size); //enemy amount
@@ -231,13 +233,13 @@ public class Save12 extends SaveFileVersion {
//--MAP DATA--
//seed
stream.writeInt(Vars.world.getSeed());
stream.writeInt(world.getSeed());
int totalblocks = 0;
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
if(tile.breakable()){
totalblocks ++;
@@ -248,13 +250,13 @@ public class Save12 extends SaveFileVersion {
//tile amount
stream.writeInt(totalblocks);
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
if(tile.breakable()){
stream.writeInt(x + y*Vars.world.width()); //tile pos
stream.writeInt(x + y*world.width()); //tile pos
stream.writeByte(tile.link);
stream.writeBoolean(tile.entity != null); //whether it has a tile entity
stream.writeInt(tile.block().id); //block ID

View File

@@ -6,11 +6,14 @@ import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.io.BlockLoader;
import io.anuke.mindustry.io.SaveFileVersion;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.WorldGenerator;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.types.BlockPart;
import io.anuke.mindustry.world.blocks.types.Rock;
@@ -22,7 +25,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.android;
import static io.anuke.mindustry.Vars.*;
public class Save13 extends SaveFileVersion {
@@ -49,36 +52,36 @@ public class Save13 extends SaveFileVersion {
Vars.player.x = playerx;
Vars.player.y = playery;
Vars.player.health = playerhealth;
Vars.control.setMode(GameMode.values()[mode]);
state.mode = GameMode.values()[mode];
Core.camera.position.set(playerx, playery, 0);
//weapons
Vars.control.getWeapons().clear();
Vars.control.getWeapons().add(Weapon.blaster);
control.upgrades().getWeapons().clear();
control.upgrades().getWeapons().add(Weapon.blaster);
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
int weapons = stream.readByte();
for(int i = 0; i < weapons; i ++){
Vars.control.addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
}
Vars.ui.hudfrag.updateWeapons();
ui.hudfrag.updateWeapons();
//inventory
int totalItems = stream.readByte();
Arrays.fill(Vars.control.getItems(), 0);
Arrays.fill(state.inventory.getItems(), 0);
for(int i = 0; i < totalItems; i ++){
Item item = Item.getByID(stream.readByte());
int amount = stream.readInt();
Vars.control.getItems()[item.id] = amount;
state.inventory.getItems()[item.id] = amount;
}
Vars.ui.hudfrag.updateItems();
ui.hudfrag.updateItems();
//enemies
@@ -103,14 +106,16 @@ public class Save13 extends SaveFileVersion {
enemy.x = x;
enemy.y = y;
enemy.tier = tier;
enemy.add(Vars.control.enemyGroup);
enemy.add(enemyGroup);
enemiesToUpdate.add(enemy);
}catch (Exception e){
throw new RuntimeException(e);
}
}
Vars.control.setWaveData(enemies, wave, wavetime);
state.enemies = enemies;
state.wave = wave;
state.wavetime = wavetime;
if(!android)
Vars.player.add();
@@ -119,8 +124,8 @@ public class Save13 extends SaveFileVersion {
int seed = stream.readInt();
Vars.world.loadMap(Vars.world.maps().getMap(mapid), seed);
Vars.renderer.clearTiles();
world.loadMap(world.maps().getMap(mapid), seed);
renderer.clearTiles();
for(Enemy enemy : enemiesToUpdate){
enemy.node = -2;
@@ -128,20 +133,20 @@ public class Save13 extends SaveFileVersion {
int rocks = stream.readInt();
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
//remove breakables like rocks
if(tile.breakable()){
Vars.world.tile(x, y).setBlock(Blocks.air);
world.tile(x, y).setBlock(Blocks.air);
}
}
}
for(int i = 0; i < rocks; i ++){
int pos = stream.readInt();
Tile tile = Vars.world.tile(pos % Vars.world.width(), pos / Vars.world.width());
Tile tile = world.tile(pos % world.width(), pos / world.width());
Block result = WorldGenerator.rocks.get(tile.floor());
if(result != null) tile.setBlock(result);
}
@@ -152,7 +157,7 @@ public class Save13 extends SaveFileVersion {
int pos = stream.readInt();
int blockid = stream.readInt();
Tile tile = Vars.world.tile(pos % Vars.world.width(), pos / Vars.world.width());
Tile tile = world.tile(pos % world.width(), pos / world.width());
tile.setBlock(BlockLoader.getByOldID(blockid));
if(blockid == Blocks.blockpart.id){
@@ -185,31 +190,31 @@ public class Save13 extends SaveFileVersion {
stream.writeLong(TimeUtils.millis()); //last saved
//--GENERAL STATE--
stream.writeByte(Vars.control.getMode().ordinal()); //gamemode
stream.writeByte(Vars.world.getMap().id); //map ID
stream.writeByte(state.mode.ordinal()); //gamemode
stream.writeByte(world.getMap().id); //map ID
stream.writeInt(Vars.control.getWave()); //wave
stream.writeFloat(Vars.control.getWaveCountdown()); //wave countdown
stream.writeInt(state.wave); //wave
stream.writeFloat(state.wavetime); //wave countdown
stream.writeFloat(Vars.player.x); //player x/y
stream.writeFloat(Vars.player.y);
stream.writeInt(Vars.player.health); //player health
stream.writeByte(Vars.control.getWeapons().size - 1); //amount of weapons
stream.writeByte(control.upgrades().getWeapons().size - 1); //amount of weapons
//start at 1, because the first weapon is always the starter - ignore that
for(int i = 1; i < Vars.control.getWeapons().size; i ++){
stream.writeByte(Vars.control.getWeapons().get(i).id); //weapon ordinal
for(int i = 1; i < control.upgrades().getWeapons().size; i ++){
stream.writeByte(control.upgrades().getWeapons().get(i).id); //weapon ordinal
}
//--INVENTORY--
int l = Vars.control.getItems().length;
int l = state.inventory.getItems().length;
int itemsize = 0;
for(int i = 0; i < l; i ++){
if(Vars.control.getItems()[i] > 0){
if(state.inventory.getItems()[i] > 0){
itemsize ++;
}
}
@@ -217,14 +222,14 @@ public class Save13 extends SaveFileVersion {
stream.writeByte(itemsize); //amount of items
for(int i = 0; i < l; i ++){
if(Vars.control.getItems()[i] > 0){
if(state.inventory.getItems()[i] > 0){
stream.writeByte(i); //item ID
stream.writeInt(Vars.control.getItems()[i]); //item amount
stream.writeInt(state.inventory.getItems()[i]); //item amount
}
}
//--ENEMIES--
Array<Enemy> enemies = Vars.control.enemyGroup.all();
Array<Enemy> enemies = enemyGroup.all();
stream.writeInt(enemies.size); //enemy amount
@@ -241,14 +246,14 @@ public class Save13 extends SaveFileVersion {
//--MAP DATA--
//seed
stream.writeInt(Vars.world.getSeed());
stream.writeInt(world.getSeed());
int totalblocks = 0;
int totalrocks = 0;
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
if(tile.breakable()){
if(tile.block() instanceof Rock){
@@ -264,9 +269,9 @@ public class Save13 extends SaveFileVersion {
stream.writeInt(totalrocks);
//write all rocks
for(int x = 0; x < Vars.world.width(); x ++) {
for (int y = 0; y < Vars.world.height(); y++) {
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.block() instanceof Rock) {
stream.writeInt(tile.packedPosition());
@@ -277,13 +282,13 @@ public class Save13 extends SaveFileVersion {
//write all blocks
stream.writeInt(totalblocks);
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
if(tile.breakable() && !(tile.block() instanceof Rock)){
stream.writeInt(x + y*Vars.world.width()); //tile pos
stream.writeInt(x + y*world.width()); //tile pos
stream.writeInt(tile.block().id); //block ID
if(tile.block() instanceof BlockPart) stream.writeByte(tile.link);

View File

@@ -25,7 +25,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.android;
import static io.anuke.mindustry.Vars.*;
public class Save14 extends SaveFileVersion{
@@ -66,36 +66,36 @@ public class Save14 extends SaveFileVersion{
Vars.player.x = playerx;
Vars.player.y = playery;
Vars.player.health = playerhealth;
Vars.control.setMode(GameMode.values()[mode]);
state.mode = GameMode.values()[mode];
Core.camera.position.set(playerx, playery, 0);
//weapons
Vars.control.getWeapons().clear();
Vars.control.getWeapons().add(Weapon.blaster);
control.upgrades().getWeapons().clear();
control.upgrades().getWeapons().add(Weapon.blaster);
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
int weapons = stream.readByte();
for(int i = 0; i < weapons; i ++){
Vars.control.addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
}
Vars.ui.hudfrag.updateWeapons();
ui.hudfrag.updateWeapons();
//inventory
int totalItems = stream.readByte();
Arrays.fill(Vars.control.getItems(), 0);
Arrays.fill(state.inventory.getItems(), 0);
for(int i = 0; i < totalItems; i ++){
Item item = Item.getByID(stream.readByte());
int amount = stream.readInt();
Vars.control.getItems()[item.id] = amount;
state.inventory.getItems()[item.id] = amount;
}
Vars.ui.hudfrag.updateItems();
ui.hudfrag.updateItems();
//enemies
@@ -120,14 +120,16 @@ public class Save14 extends SaveFileVersion{
enemy.x = x;
enemy.y = y;
enemy.tier = tier;
enemy.add(Vars.control.enemyGroup);
enemy.add(enemyGroup);
enemiesToUpdate.add(enemy);
}catch (Exception e){
throw new RuntimeException(e);
}
}
Vars.control.setWaveData(enemies, wave, wavetime);
state.enemies = enemies;
state.wave = wave;
state.wavetime = wavetime;
if(!android)
Vars.player.add();
@@ -136,8 +138,8 @@ public class Save14 extends SaveFileVersion{
int seed = stream.readInt();
Vars.world.loadMap(Vars.world.maps().getMap(mapid), seed);
Vars.renderer.clearTiles();
world.loadMap(world.maps().getMap(mapid), seed);
renderer.clearTiles();
for(Enemy enemy : enemiesToUpdate){
enemy.node = -2;
@@ -145,20 +147,20 @@ public class Save14 extends SaveFileVersion{
int rocks = stream.readInt();
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
//remove breakables like rocks
if(tile.breakable()){
Vars.world.tile(x, y).setBlock(Blocks.air);
world.tile(x, y).setBlock(Blocks.air);
}
}
}
for(int i = 0; i < rocks; i ++){
int pos = stream.readInt();
Tile tile = Vars.world.tile(pos % Vars.world.width(), pos / Vars.world.width());
Tile tile = world.tile(pos % world.width(), pos / world.width());
if(tile == null) continue;
Block result = WorldGenerator.rocks.get(tile.floor());
if(result != null) tile.setBlock(result);
@@ -170,7 +172,7 @@ public class Save14 extends SaveFileVersion{
int pos = stream.readInt();
int blockid = stream.readInt();
Tile tile = Vars.world.tile(pos % Vars.world.width(), pos / Vars.world.width());
Tile tile = world.tile(pos % world.width(), pos / world.width());
tile.setBlock(map.get(blockid));
if(blockid == Blocks.blockpart.id){
@@ -203,11 +205,11 @@ public class Save14 extends SaveFileVersion{
stream.writeLong(TimeUtils.millis()); //last saved
//--GENERAL STATE--
stream.writeByte(Vars.control.getMode().ordinal()); //gamemode
stream.writeByte(Vars.world.getMap().id); //map ID
stream.writeByte(state.mode.ordinal()); //gamemode
stream.writeByte(world.getMap().id); //map ID
stream.writeInt(Vars.control.getWave()); //wave
stream.writeFloat(Vars.control.getWaveCountdown()); //wave countdown
stream.writeInt(state.wave); //wave
stream.writeFloat(state.wavetime); //wave countdown
//--BLOCK HEADER--
@@ -224,20 +226,20 @@ public class Save14 extends SaveFileVersion{
stream.writeInt(Vars.player.health); //player health
stream.writeByte(Vars.control.getWeapons().size - 1); //amount of weapons
stream.writeByte(control.upgrades().getWeapons().size - 1); //amount of weapons
//start at 1, because the first weapon is always the starter - ignore that
for(int i = 1; i < Vars.control.getWeapons().size; i ++){
stream.writeByte(Vars.control.getWeapons().get(i).id); //weapon ordinal
for(int i = 1; i < control.upgrades().getWeapons().size; i ++){
stream.writeByte(control.upgrades().getWeapons().get(i).id); //weapon ordinal
}
//--INVENTORY--
int l = Vars.control.getItems().length;
int l = state.inventory.getItems().length;
int itemsize = 0;
for(int i = 0; i < l; i ++){
if(Vars.control.getItems()[i] > 0){
if(state.inventory.getItems()[i] > 0){
itemsize ++;
}
}
@@ -245,15 +247,15 @@ public class Save14 extends SaveFileVersion{
stream.writeByte(itemsize); //amount of items
for(int i = 0; i < l; i ++){
if(Vars.control.getItems()[i] > 0){
if(state.inventory.getItems()[i] > 0){
stream.writeByte(i); //item ID
stream.writeInt(Vars.control.getItems()[i]); //item amount
stream.writeInt(state.inventory.getItems()[i]); //item amount
}
}
//--ENEMIES--
Array<Enemy> enemies = Vars.control.enemyGroup.all();
Array<Enemy> enemies = enemyGroup.all();
stream.writeInt(enemies.size); //enemy amount
@@ -270,14 +272,14 @@ public class Save14 extends SaveFileVersion{
//--MAP DATA--
//seed
stream.writeInt(Vars.world.getSeed());
stream.writeInt(world.getSeed());
int totalblocks = 0;
int totalrocks = 0;
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
if(tile.breakable()){
if(tile.block() instanceof Rock){
@@ -293,9 +295,9 @@ public class Save14 extends SaveFileVersion{
stream.writeInt(totalrocks);
//write all rocks
for(int x = 0; x < Vars.world.width(); x ++) {
for (int y = 0; y < Vars.world.height(); y++) {
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.block() instanceof Rock) {
stream.writeInt(tile.packedPosition());
@@ -306,13 +308,13 @@ public class Save14 extends SaveFileVersion{
//write all blocks
stream.writeInt(totalblocks);
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
if(tile.breakable() && !(tile.block() instanceof Rock)){
stream.writeInt(x + y*Vars.world.width()); //tile pos
stream.writeInt(x + y*world.width()); //tile pos
stream.writeInt(tile.block().id); //block ID
if(tile.block() instanceof BlockPart) stream.writeByte(tile.link);

View File

@@ -3,7 +3,6 @@ package io.anuke.mindustry.io.versions;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.mindustry.game.Difficulty;
@@ -26,7 +25,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.android;
import static io.anuke.mindustry.Vars.*;
public class Save15 extends SaveFileVersion {
@@ -47,7 +46,7 @@ public class Save15 extends SaveFileVersion {
float wavetime = stream.readFloat();
byte difficulty = stream.readByte();
Vars.control.setDifficulty(Difficulty.values()[difficulty]);
state.difficulty = Difficulty.values()[difficulty];
//block header
@@ -67,39 +66,39 @@ public class Save15 extends SaveFileVersion {
int playerhealth = stream.readInt();
Vars.player.x = playerx;
Vars.player.y = playery;
Vars.player.health = playerhealth;
Vars.control.setMode(GameMode.values()[mode]);
player.x = playerx;
player.y = playery;
player.health = playerhealth;
state.mode = GameMode.values()[mode];
Core.camera.position.set(playerx, playery, 0);
//weapons
Vars.control.getWeapons().clear();
Vars.control.getWeapons().add(Weapon.blaster);
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
control.upgrades().getWeapons().clear();
control.upgrades().getWeapons().add(Weapon.blaster);
player.weaponLeft = player.weaponRight = Weapon.blaster;
int weapons = stream.readByte();
for(int i = 0; i < weapons; i ++){
Vars.control.addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
}
Vars.ui.hudfrag.updateWeapons();
ui.hudfrag.updateWeapons();
//inventory
int totalItems = stream.readByte();
Arrays.fill(Vars.control.getItems(), 0);
Arrays.fill(state.inventory.getItems(), 0);
for(int i = 0; i < totalItems; i ++){
Item item = Item.getByID(stream.readByte());
int amount = stream.readInt();
Vars.control.getItems()[item.id] = amount;
state.inventory.getItems()[item.id] = amount;
}
Vars.ui.hudfrag.updateItems();
ui.hudfrag.updateItems();
//enemies
@@ -124,24 +123,26 @@ public class Save15 extends SaveFileVersion {
enemy.x = x;
enemy.y = y;
enemy.tier = tier;
enemy.add(Vars.control.enemyGroup);
enemy.add(enemyGroup);
enemiesToUpdate.add(enemy);
}catch (Exception e){
throw new RuntimeException(e);
}
}
Vars.control.setWaveData(enemies, wave, wavetime);
state.enemies = enemies;
state.wave = wave;
state.wavetime = wavetime;
if(!android)
Vars.player.add();
player.add();
//map
int seed = stream.readInt();
Vars.world.loadMap(Vars.world.maps().getMap(mapid), seed);
Vars.renderer.clearTiles();
world.loadMap(world.maps().getMap(mapid), seed);
renderer.clearTiles();
for(Enemy enemy : enemiesToUpdate){
enemy.node = -2;
@@ -149,20 +150,20 @@ public class Save15 extends SaveFileVersion {
int rocks = stream.readInt();
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
//remove breakables like rocks
if(tile.breakable()){
Vars.world.tile(x, y).setBlock(Blocks.air);
world.tile(x, y).setBlock(Blocks.air);
}
}
}
for(int i = 0; i < rocks; i ++){
int pos = stream.readInt();
Tile tile = Vars.world.tile(pos % Vars.world.width(), pos / Vars.world.width());
Tile tile = world.tile(pos % world.width(), pos / world.width());
if(tile == null) continue;
Block result = WorldGenerator.rocks.get(tile.floor());
if(result != null) tile.setBlock(result);
@@ -174,7 +175,7 @@ public class Save15 extends SaveFileVersion {
int pos = stream.readInt();
int blockid = stream.readInt();
Tile tile = Vars.world.tile(pos % Vars.world.width(), pos / Vars.world.width());
Tile tile = world.tile(pos % world.width(), pos / world.width());
tile.setBlock(map.get(blockid));
if(blockid == Blocks.blockpart.id){
@@ -207,12 +208,12 @@ public class Save15 extends SaveFileVersion {
stream.writeLong(TimeUtils.millis()); //last saved
//--GENERAL STATE--
stream.writeByte(Vars.control.getMode().ordinal()); //gamemode
stream.writeByte(Vars.world.getMap().id); //map ID
stream.writeByte(state.mode.ordinal()); //gamemode
stream.writeByte(world.getMap().id); //map ID
stream.writeInt(Vars.control.getWave()); //wave
stream.writeFloat(Vars.control.getWaveCountdown()); //wave countdown
stream.writeByte(Vars.control.getDifficulty().ordinal());
stream.writeInt(state.wave); //wave
stream.writeFloat(state.wavetime); //wave countdown
stream.writeByte(state.difficulty.ordinal());
//--BLOCK HEADER--
@@ -224,25 +225,25 @@ public class Save15 extends SaveFileVersion {
stream.writeShort(block.id);
}
stream.writeFloat(Vars.player.x); //player x/y
stream.writeFloat(Vars.player.y);
stream.writeFloat(player.x); //player x/y
stream.writeFloat(player.y);
stream.writeInt(Vars.player.health); //player health
stream.writeInt(player.health); //player health
stream.writeByte(Vars.control.getWeapons().size - 1); //amount of weapons
stream.writeByte(control.upgrades().getWeapons().size - 1); //amount of weapons
//start at 1, because the first weapon is always the starter - ignore that
for(int i = 1; i < Vars.control.getWeapons().size; i ++){
stream.writeByte(Vars.control.getWeapons().get(i).id); //weapon ordinal
for(int i = 1; i < control.upgrades().getWeapons().size; i ++){
stream.writeByte(control.upgrades().getWeapons().get(i).id); //weapon ordinal
}
//--INVENTORY--
int l = Vars.control.getItems().length;
int l = state.inventory.getItems().length;
int itemsize = 0;
for(int i = 0; i < l; i ++){
if(Vars.control.getItems()[i] > 0){
if(state.inventory.getItems()[i] > 0){
itemsize ++;
}
}
@@ -250,15 +251,15 @@ public class Save15 extends SaveFileVersion {
stream.writeByte(itemsize); //amount of items
for(int i = 0; i < l; i ++){
if(Vars.control.getItems()[i] > 0){
if(state.inventory.getItems()[i] > 0){
stream.writeByte(i); //item ID
stream.writeInt(Vars.control.getItems()[i]); //item amount
stream.writeInt(state.inventory.getItems()[i]); //item amount
}
}
//--ENEMIES--
Array<Enemy> enemies = Vars.control.enemyGroup.all();
Array<Enemy> enemies = enemyGroup.all();
stream.writeInt(enemies.size); //enemy amount
@@ -275,14 +276,14 @@ public class Save15 extends SaveFileVersion {
//--MAP DATA--
//seed
stream.writeInt(Vars.world.getSeed());
stream.writeInt(world.getSeed());
int totalblocks = 0;
int totalrocks = 0;
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
if(tile.breakable()){
if(tile.block() instanceof Rock){
@@ -298,9 +299,9 @@ public class Save15 extends SaveFileVersion {
stream.writeInt(totalrocks);
//write all rocks
for(int x = 0; x < Vars.world.width(); x ++) {
for (int y = 0; y < Vars.world.height(); y++) {
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.block() instanceof Rock) {
stream.writeInt(tile.packedPosition());
@@ -311,13 +312,13 @@ public class Save15 extends SaveFileVersion {
//write all blocks
stream.writeInt(totalblocks);
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
if(tile.breakable() && !(tile.block() instanceof Rock)){
stream.writeInt(x + y*Vars.world.width()); //tile pos
stream.writeInt(x + y*world.width()); //tile pos
stream.writeInt(tile.block().id); //block ID
if(tile.block() instanceof BlockPart) stream.writeByte(tile.link);

View File

@@ -3,7 +3,7 @@ package io.anuke.mindustry.mapeditor;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.utils.IntSet;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.ColorMapper;
import io.anuke.mindustry.world.ColorMapper.BlockPair;
@@ -17,7 +17,7 @@ public enum EditorTool{
if(pair == null) return;
Block block = pair.dominant();
editor.setDrawBlock(block);
Vars.ui.editor.updateSelectedBlock();
ui.editor.updateSelectedBlock();
}
},
pencil{

View File

@@ -4,8 +4,7 @@ import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.io.Platform;
import io.anuke.mindustry.ui.dialogs.FileChooser;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.ColorMapper;
@@ -15,8 +14,8 @@ import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.SpecialBlocks;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Pixmaps;
import io.anuke.ucore.scene.builders.build;
import io.anuke.ucore.scene.builders.imagebutton;
@@ -29,6 +28,8 @@ import io.anuke.ucore.util.Strings;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.*;
public class MapEditorDialog extends Dialog{
private MapEditor editor;
private MapView view;
@@ -43,14 +44,14 @@ public class MapEditorDialog extends Dialog{
public MapEditorDialog(){
super("$text.mapeditor", "dialog");
if(Vars.gwt) return;
if(gwt) return;
editor = new MapEditor();
dialog = new MapGenerateDialog(editor);
view = new MapView(editor);
openFile = new FileChooser("$text.loadimage", FileChooser.pngFilter, true, file -> {
Vars.ui.loadfrag.show();
ui.loadfrag.show();
Timers.run(3f, () -> {
try{
Pixmap pixmap = new Pixmap(file);
@@ -58,13 +59,13 @@ public class MapEditorDialog extends Dialog{
editor.setPixmap(pixmap);
view.clearStack();
}else{
Vars.ui.showError(Bundles.format("text.editor.badsize", Arrays.toString(MapEditor.validMapSizes)));
ui.showError(Bundles.format("text.editor.badsize", Arrays.toString(MapEditor.validMapSizes)));
}
}catch (Exception e){
Vars.ui.showError(Bundles.format("text.editor.errorimageload", Strings.parseException(e, false)));
ui.showError(Bundles.format("text.editor.errorimageload", Strings.parseException(e, false)));
UCore.error(e);
}
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
});
});
@@ -73,21 +74,21 @@ public class MapEditorDialog extends Dialog{
file = file.parent().child(file.nameWithoutExtension() + ".png");
}
FileHandle result = file;
Vars.ui.loadfrag.show();
ui.loadfrag.show();
Timers.run(3f, () -> {
try{
Pixmaps.write(editor.pixmap(), result);
}catch (Exception e){
Vars.ui.showError(Bundles.format("text.editor.errorimagesave", Strings.parseException(e, false)));
if(!Vars.android) UCore.error(e);
ui.showError(Bundles.format("text.editor.errorimagesave", Strings.parseException(e, false)));
if(!android) UCore.error(e);
}
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
});
});
loadDialog = new MapLoadDialog(map -> {
saveDialog.setFieldText(map.name);
Vars.ui.loadfrag.show();
ui.loadfrag.show();
Timers.run(3f, () -> {
Map copy = new Map();
@@ -96,7 +97,7 @@ public class MapEditorDialog extends Dialog{
copy.pixmap = Pixmaps.copy(map.pixmap);
copy.texture = new Texture(copy.pixmap);
editor.beginEdit(copy);
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
view.clearStack();
});
});
@@ -104,28 +105,28 @@ public class MapEditorDialog extends Dialog{
resizeDialog = new MapResizeDialog(editor, (x, y) -> {
Pixmap pix = editor.pixmap();
if(!(pix.getWidth() == x && pix.getHeight() == y)){
Vars.ui.loadfrag.show();
ui.loadfrag.show();
Timers.run(10f, ()->{
editor.resize(x, y);
view.clearStack();
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
});
}
});
saveDialog = new MapSaveDialog(name -> {
Vars.ui.loadfrag.show();
ui.loadfrag.show();
if(verifyMap()){
saved = true;
editor.getMap().name = name;
Timers.run(10f, () -> {
Vars.world.maps().saveAndReload(editor.getMap(), editor.pixmap());
world.maps().saveAndReload(editor.getMap(), editor.pixmap());
loadDialog.rebuild();
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
view.clearStack();
});
}else{
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
}
});
@@ -145,11 +146,11 @@ public class MapEditorDialog extends Dialog{
view.clearStack();
Timers.runTask(3f, () -> {
Mindustry.platforms.updateRPC();
Platform.instance.updateRPC();
});
});
hidden(() -> Mindustry.platforms.updateRPC());
hidden(() -> Platform.instance.updateRPC());
}
public MapView getView() {
@@ -220,7 +221,7 @@ public class MapEditorDialog extends Dialog{
new imagebutton("icon-back", isize, () -> {
if(!saved){
Vars.ui.showConfirm("$text.confirm", "$text.editor.unsaved",
ui.showConfirm("$text.confirm", "$text.editor.unsaved",
MapEditorDialog.this::hide);
}else{
hide();
@@ -317,15 +318,15 @@ public class MapEditorDialog extends Dialog{
}
if(playerSpawns == 0){
Vars.ui.showError("$text.editor.noplayerspawn");
ui.showError("$text.editor.noplayerspawn");
return false;
}else if(playerSpawns > 1){
Vars.ui.showError("$text.editor.manyplayerspawns");
ui.showError("$text.editor.manyplayerspawns");
return false;
}
if(enemySpawns > MapEditor.maxSpawnpoints){
Vars.ui.showError(Bundles.format("text.editor.manyenemyspawns", MapEditor.maxSpawnpoints));
ui.showError(Bundles.format("text.editor.manyenemyspawns", MapEditor.maxSpawnpoints));
return false;
}

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Scaling;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.mapeditor.MapFilter.GenPref;
import io.anuke.mindustry.ui.BorderImage;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
@@ -71,14 +71,14 @@ public class MapGenerateDialog extends FloatingDialog{
});
buttons().addButton("$text.update", this::apply);
buttons().addButton("$text.apply", () ->{
Vars.ui.loadfrag.show();
ui.loadfrag.show();
Timers.run(3f, () ->{
Pixmap copy = Pixmaps.copy(editor.pixmap());
editor.applyFilter();
Vars.ui.editor.getView().push(copy, Pixmaps.copy(editor.pixmap()));
Vars.ui.loadfrag.hide();
Vars.ui.editor.resetSaved();
ui.editor.getView().push(copy, Pixmaps.copy(editor.pixmap()));
ui.loadfrag.hide();
ui.editor.resetSaved();
hide();
});
});

View File

@@ -1,6 +1,6 @@
package io.anuke.mindustry.mapeditor;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.ui.BorderImage;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.mindustry.world.Map;
@@ -11,7 +11,7 @@ import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.ui.layout.Table;
public class MapLoadDialog extends FloatingDialog{
private Map selected = Vars.world.maps().getMap(0);
private Map selected = world.maps().getMap(0);
public MapLoadDialog(Consumer<Map> loader) {
super("$text.editor.loadmap");
@@ -35,7 +35,7 @@ public class MapLoadDialog extends FloatingDialog{
public void rebuild(){
content().clear();
selected = Vars.world.maps().getMap(0);
selected = world.maps().getMap(0);
ButtonGroup<TextButton> group = new ButtonGroup<>();
@@ -50,7 +50,7 @@ public class MapLoadDialog extends FloatingDialog{
ScrollPane pane = new ScrollPane(table, "horizontal");
pane.setFadeScrollBars(false);
for (Map map : Vars.world.maps().list()) {
for (Map map : world.maps().list()) {
if (!map.visible) continue;
TextButton button = new TextButton(map.localized(), "toggle");

View File

@@ -1,7 +1,7 @@
package io.anuke.mindustry.mapeditor;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.io.Platform;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.mindustry.world.Map;
import io.anuke.ucore.function.Consumer;
@@ -15,12 +15,12 @@ public class MapSaveDialog extends FloatingDialog{
super("$text.editor.savemap");
field = new TextField();
Mindustry.platforms.addDialog(field);
Platform.instance.addDialog(field);
shown(() -> {
content().clear();
content().label(() ->{
Map map = Vars.world.maps().getMap(field.getText());
Map map = world.maps().getMap(field.getText());
if(map != null){
if(map.custom){
return "$text.editor.overwrite";
@@ -58,7 +58,7 @@ public class MapSaveDialog extends FloatingDialog{
if(field.getText().isEmpty()){
return true;
}
Map map = Vars.world.maps().getMap(field.getText());
Map map = world.maps().getMap(field.getText());
return map != null && !map.custom;
}
}

View File

@@ -11,7 +11,7 @@ import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.ui.GridImage;
import io.anuke.mindustry.world.ColorMapper;
import io.anuke.ucore.core.Core;
@@ -116,7 +116,7 @@ public class MapView extends Element implements GestureListener{
if(tool.edit){
updated = true;
Vars.ui.editor.resetSaved();
ui.editor.resetSaved();
}
op = new DrawOperation(editor.pixmap());
@@ -132,7 +132,7 @@ public class MapView extends Element implements GestureListener{
GridPoint2 p = project(x, y);
if(tool == EditorTool.line){
Vars.ui.editor.resetSaved();
ui.editor.resetSaved();
Array<GridPoint2> points = br.line(startx, starty, p.x, p.y);
for(GridPoint2 point : points){
editor.draw(point.x, point.y);
@@ -155,7 +155,7 @@ public class MapView extends Element implements GestureListener{
GridPoint2 p = project(x, y);
if(drawing && tool == EditorTool.pencil){
Vars.ui.editor.resetSaved();
ui.editor.resetSaved();
Array<GridPoint2> points = br.line(lastx, lasty, p.x, p.y);
for(GridPoint2 point : points){
editor.draw(point.x, point.y);
@@ -256,8 +256,8 @@ public class MapView extends Element implements GestureListener{
private boolean active(){
return Core.scene.getKeyboardFocus() != null
&& Core.scene.getKeyboardFocus().isDescendantOf(Vars.ui.editor)
&& Vars.ui.editor.isShown() && tool == EditorTool.zoom &&
&& Core.scene.getKeyboardFocus().isDescendantOf(ui.editor)
&& ui.editor.isShown() && tool == EditorTool.zoom &&
Core.scene.hit(Graphics.mouse().x, Graphics.mouse().y, true) == this;
}

View File

@@ -4,14 +4,12 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.net.Packet.ImportantPacket;
import io.anuke.mindustry.net.Packets.KickReason;
import io.anuke.mindustry.net.Streamable.StreamBegin;
import io.anuke.mindustry.net.Streamable.StreamBuilder;
import io.anuke.mindustry.net.Streamable.StreamChunk;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.function.BiConsumer;
import io.anuke.ucore.function.Consumer;
@@ -23,6 +21,7 @@ public class Net{
private static boolean server;
private static boolean active;
private static boolean clientLoaded;
private static ObjectMap<Class<?>, Consumer> listeners = new ObjectMap<>();
private static ObjectMap<Class<?>, Consumer> clientListeners = new ObjectMap<>();
private static ObjectMap<Class<?>, BiConsumer<Integer, Object>> serverListeners = new ObjectMap<>();
private static ClientProvider clientProvider;
@@ -40,8 +39,6 @@ public class Net{
clientProvider.connect(ip, port);
active = true;
server = false;
Timers.runTask(60f, Mindustry.platforms::updateRPC);
}
/**Host a server at an address*/
@@ -49,8 +46,6 @@ public class Net{
serverProvider.host(port);
active = true;
server = true;
Timers.runTask(60f, Mindustry.platforms::updateRPC);
}
/**Closes the server.*/
@@ -115,9 +110,14 @@ public class Net{
public static void setServerProvider(ServerProvider provider){
Net.serverProvider = provider;
}
/**Registers a client listener for when an object is recieved.*/
/**Registers a common listener for when an object is recieved. Fired on both client and serve.r*/
public static <T> void handle(Class<T> type, Consumer<T> listener){
listeners.put(type, listener);
}
/**Registers a client listener for when an object is recieved.*/
public static <T> void handleClient(Class<T> type, Consumer<T> listener){
clientListeners.put(type, listener);
}
@@ -142,9 +142,11 @@ public class Net{
streams.remove(builder.id);
handleClientReceived(builder.build());
}
}else if(clientListeners.get(object.getClass()) != null){
}else if(clientListeners.get(object.getClass()) != null ||
listeners.get(object.getClass()) != null){
if(clientLoaded || object instanceof ImportantPacket){
clientListeners.get(object.getClass()).accept(object);
if(clientListeners.get(object.getClass()) != null) clientListeners.get(object.getClass()).accept(object);
if(listeners.get(object.getClass()) != null) listeners.get(object.getClass()).accept(object);
}else{
UCore.log("Recieved " + object, "but ignoring data, as client is not loaded.");
}
@@ -155,8 +157,9 @@ public class Net{
/**Call to handle a packet being recieved for the server.*/
public static void handleServerReceived(int connection, Object object){
if(serverListeners.get(object.getClass()) != null){
serverListeners.get(object.getClass()).accept(connection, object);
if(serverListeners.get(object.getClass()) != null || listeners.get(object.getClass()) != null){
if(serverListeners.get(object.getClass()) != null) serverListeners.get(object.getClass()).accept(connection, object);
if(listeners.get(object.getClass()) != null) listeners.get(object.getClass()).accept(object);
}else{
Gdx.app.error("Mindustry::Net", "Unhandled packet type: '" + object.getClass() + "'!");
}
@@ -184,12 +187,12 @@ public class Net{
/**Whether this is a server or not.*/
public static boolean server(){
return server;
return server && active;
}
/**Whether this is a client or not.*/
public static boolean client(){
return !server;
return !server && active;
}
public static void dispose(){

View File

@@ -0,0 +1,135 @@
package io.anuke.mindustry.net;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entity;
import static io.anuke.mindustry.Vars.*;
public class NetEvents {
public static void handleFriendlyFireChange(boolean enabled){
FriendlyFireChangePacket packet = new FriendlyFireChangePacket();
packet.enabled = enabled;
netCommon.sendMessage(enabled ? "[accent]Friendly fire enabled." : "[accent]Friendly fire disabled.");
Net.send(packet, SendMode.tcp);
}
public static void handleGameOver(){
Net.send(new GameOverPacket(), SendMode.tcp);
state.gameOver = true;
Timers.runTask(30f, () -> state.set(State.menu));
}
public static void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){
BulletPacket packet = new BulletPacket();
packet.x = x;
packet.y = y;
packet.angle = angle;
packet.damage = damage;
packet.owner = owner.id;
packet.type = type.id;
Net.send(packet, SendMode.udp);
}
public static void handleEnemyDeath(Enemy enemy){
EnemyDeathPacket packet = new EnemyDeathPacket();
packet.id = enemy.id;
state.gameOver = true;
Net.send(packet, SendMode.tcp);
}
public static void handleBlockDestroyed(TileEntity entity){
BlockDestroyPacket packet = new BlockDestroyPacket();
packet.position = entity.tile.packedPosition();
Net.send(packet, SendMode.tcp);
}
public static void handleBlockDamaged(TileEntity entity){
BlockUpdatePacket packet = new BlockUpdatePacket();
packet.health = (int)entity.health;
packet.position = entity.tile.packedPosition();
Net.send(packet, SendMode.udp);
}
public static void handlePlayerDeath(){
PlayerDeathPacket packet = new PlayerDeathPacket();
packet.id = Vars.player.id;
Net.send(packet, SendMode.tcp);
}
public static void handleBlockConfig(Tile tile, byte data){
BlockConfigPacket packet = new BlockConfigPacket();
packet.data = data;
packet.position = tile.packedPosition();
Net.send(packet, SendMode.tcp);
}
public static void handleBlockTap(Tile tile){
BlockTapPacket packet = new BlockTapPacket();
packet.position = tile.packedPosition();
Net.send(packet, SendMode.tcp);
}
public static void handleWeaponSwitch(){
WeaponSwitchPacket packet = new WeaponSwitchPacket();
packet.left = Vars.player.weaponLeft.id;
packet.right = Vars.player.weaponRight.id;
packet.playerid = Vars.player.id;
Net.send(packet, SendMode.tcp);
}
public static void handleUpgrade(Weapon weapon){
UpgradePacket packet = new UpgradePacket();
packet.id = weapon.id;
Net.send(packet, SendMode.tcp);
}
public static void handleSendMessage(String message){
ChatPacket packet = new ChatPacket();
packet.text = message;
packet.name = Vars.player.name;
packet.id = Vars.player.id;
Net.send(packet, SendMode.tcp);
ui.chatfrag.addMessage(packet.text, netCommon.colorizeName(Vars.player.id, Vars.player.name));
}
public static void handleShoot(Weapon weapon, float x, float y, float angle){
ShootPacket packet = new ShootPacket();
packet.weaponid = weapon.id;
packet.x = x;
packet.y = y;
packet.rotation = angle;
packet.playerid = Vars.player.id;
Net.send(packet, SendMode.udp);
}
public static void handlePlace(int x, int y, Block block, int rotation){
PlacePacket packet = new PlacePacket();
packet.x = (short)x;
packet.y = (short)y;
packet.rotation = (byte)rotation;
packet.playerid = Vars.player.id;
packet.block = block.id;
Net.send(packet, SendMode.tcp);
}
public static void handleBreak(int x, int y){
BreakPacket packet = new BreakPacket();
packet.x = (short)x;
packet.y = (short)y;
Net.send(packet, SendMode.tcp);
}
}

View File

@@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.utils.ByteArray;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
@@ -20,6 +19,8 @@ import io.anuke.ucore.entities.Entities;
import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class NetworkIO {
public static void writeMap(Pixmap map, OutputStream os){
@@ -97,20 +98,20 @@ public class NetworkIO {
stream.writeLong(TimeUtils.millis()); //timestamp
//--GENERAL STATE--
stream.writeByte(Vars.control.getMode().ordinal()); //gamemode
stream.writeByte(Vars.world.getMap().custom ? -1 : Vars.world.getMap().id); //map ID
stream.writeByte(state.mode.ordinal()); //gamemode
stream.writeByte(world.getMap().custom ? -1 : world.getMap().id); //map ID
stream.writeInt(Vars.control.getWave()); //wave
stream.writeFloat(Vars.control.getWaveCountdown()); //wave countdown
stream.writeInt(Vars.control.enemyGroup.amount()); //enemy amount
stream.writeInt(state.wave); //wave
stream.writeFloat(state.wavetime); //wave countdown
stream.writeInt(state.enemies); //enemy amount
stream.writeBoolean(Vars.control.isFriendlyFire()); //friendly fire state
stream.writeBoolean(state.friendlyFire); //friendly fire state
stream.writeInt(playerID); //player remap ID
//--INVENTORY--
for(int i = 0; i < Vars.control.getItems().length; i ++){ //items
stream.writeInt(Vars.control.getItems()[i]);
for(int i = 0; i < state.inventory.getItems().length; i ++){ //items
stream.writeInt(state.inventory.getItems()[i]);
}
stream.writeByte(upgrades.size); //upgrade data
@@ -122,14 +123,14 @@ public class NetworkIO {
//--MAP DATA--
//seed
stream.writeInt(Vars.world.getSeed());
stream.writeInt(world.getSeed());
int totalblocks = 0;
int totalrocks = 0;
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
if(tile.breakable()){
if(tile.block() instanceof Rock){
@@ -145,9 +146,9 @@ public class NetworkIO {
stream.writeInt(totalrocks);
//write all rocks
for(int x = 0; x < Vars.world.width(); x ++) {
for (int y = 0; y < Vars.world.height(); y++) {
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.block() instanceof Rock) {
stream.writeInt(tile.packedPosition());
@@ -158,13 +159,13 @@ public class NetworkIO {
//tile amount
stream.writeInt(totalblocks);
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
if(tile.breakable() && !(tile.block() instanceof Rock)){
stream.writeInt(x + y*Vars.world.width()); //tile pos
stream.writeInt(x + y*world.width()); //tile pos
//TODO will break if block number gets over BYTE_MAX
stream.writeByte(tile.block().id); //block ID
@@ -227,51 +228,53 @@ public class NetworkIO {
int enemies = stream.readInt();
boolean friendlyfire = stream.readBoolean();
Vars.control.setWaveData(enemies, wave, wavetime);
Vars.control.setMode(GameMode.values()[mode]);
Vars.control.setFriendlyFire(friendlyfire);
state.enemies = enemies;
state.wave = wave;
state.wavetime = wavetime;
state.mode = GameMode.values()[mode];
state.friendlyFire = friendlyfire;
int pid = stream.readInt();
//inventory
for(int i = 0; i < Vars.control.getItems().length; i ++){
Vars.control.getItems()[i] = stream.readInt();
for(int i = 0; i < state.inventory.getItems().length; i ++){
state.inventory.getItems()[i] = stream.readInt();
}
Vars.ui.hudfrag.updateItems();
ui.hudfrag.updateItems();
Vars.control.getWeapons().clear();
Vars.control.getWeapons().add(Weapon.blaster);
control.upgrades().getWeapons().clear();
control.upgrades().getWeapons().add(Weapon.blaster);
byte weapons = stream.readByte();
for(int i = 0; i < weapons; i ++){
Vars.control.getWeapons().add((Weapon) Upgrade.getByID(stream.readByte()));
control.upgrades().getWeapons().add((Weapon) Upgrade.getByID(stream.readByte()));
}
Vars.player.weaponLeft = Vars.player.weaponRight = Vars.control.getWeapons().peek();
Vars.ui.hudfrag.updateWeapons();
player.weaponLeft = player.weaponRight = control.upgrades().getWeapons().peek();
ui.hudfrag.updateWeapons();
Entities.clear();
Vars.player.id = pid;
Vars.player.add();
player.id = pid;
player.add();
//map
int seed = stream.readInt();
Vars.world.loadMap(Vars.world.maps().getMap(mapid), seed);
Vars.renderer.clearTiles();
world.loadMap(world.maps().getMap(mapid), seed);
renderer.clearTiles();
Vars.player.set(Vars.world.getCore().worldx(), Vars.world.getCore().worldy());
player.set(world.getCore().worldx(), world.getCore().worldy());
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
Tile tile = Vars.world.tile(x, y);
for(int x = 0; x < world.width(); x ++){
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
//remove breakables like rocks
if(tile.breakable()){
Vars.world.tile(x, y).setBlock(Blocks.air);
world.tile(x, y).setBlock(Blocks.air);
}
}
}
@@ -280,7 +283,7 @@ public class NetworkIO {
for(int i = 0; i < rocks; i ++){
int pos = stream.readInt();
Tile tile = Vars.world.tile(pos % Vars.world.width(), pos / Vars.world.width());
Tile tile = world.tile(pos % world.width(), pos / world.width());
Block result = WorldGenerator.rocks.get(tile.floor());
if(result != null) tile.setBlock(result);
}
@@ -291,7 +294,7 @@ public class NetworkIO {
int pos = stream.readInt();
byte blockid = stream.readByte();
Tile tile = Vars.world.tile(pos % Vars.world.width(), pos / Vars.world.width());
Tile tile = world.tile(pos % world.width(), pos / world.width());
tile.setBlock(Block.getByID(blockid));
if(tile.block() == Blocks.blockpart){

View File

@@ -6,6 +6,7 @@ import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.core.Timers;
@@ -112,7 +113,7 @@ public class Weapon extends Upgrade{
shootInternal(p, x, y, angle);
if(Net.active() && p == Vars.player){
Vars.netClient.handleShoot(this, x, y, angle);
NetEvents.handleShoot(this, x, y, angle);
}
}

View File

@@ -1,9 +1,10 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.Gdx;
import io.anuke.mindustry.Vars;
import io.anuke.ucore.scene.ui.Dialog;
import static io.anuke.mindustry.Vars.discordURL;
public class DiscordDialog extends Dialog {
public DiscordDialog(){
@@ -11,9 +12,9 @@ public class DiscordDialog extends Dialog {
content().margin(12f);
content().add("$text.discord");
content().row();
content().add("[orange]"+ Vars.discordURL);
content().add("[orange]"+ discordURL);
buttons().defaults().size(200f, 50);
buttons().addButton("$text.openlink", () -> Gdx.net.openURI(Vars.discordURL));
buttons().addButton("$text.openlink", () -> Gdx.net.openURI(discordURL));
buttons().addButton("$text.back", this::hide);
}
}

View File

@@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pools;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.io.Platform;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.function.Consumer;
@@ -49,7 +49,7 @@ public class FileChooser extends FloatingDialog {
filefield = new TextField();
filefield.setOnlyFontChars(false);
if(!open) Mindustry.platforms.addDialog(filefield);
if(!open) Platform.instance.addDialog(filefield);
filefield.setDisabled(open);
ok = new TextButton(open ? "$text.load" : "$text.save");
@@ -251,7 +251,7 @@ public class FileChooser extends FloatingDialog {
@Override
public Dialog show(){
Mindustry.platforms.requestWritePerms();
Platform.instance.requestWritePerms();
Timers.runTask(2f, () -> {
content().clear();
setupWidgets();
@@ -316,8 +316,8 @@ public class FileChooser extends FloatingDialog {
}
}
public static interface FileHandleFilter{
public boolean accept(FileHandle file);
public interface FileHandleFilter{
boolean accept(FileHandle file);
}
public static Predicate<FileHandle> pngFilter = file -> file.extension().equalsIgnoreCase("png");

View File

@@ -9,6 +9,8 @@ import io.anuke.ucore.util.Strings;
import java.io.IOException;
import static io.anuke.mindustry.Vars.ui;
//TODO add port specification
public class HostDialog extends FloatingDialog{
float w = 300;
@@ -25,21 +27,21 @@ public class HostDialog extends FloatingDialog{
Vars.player.name = text;
Settings.put("name", text);
Settings.save();
Vars.ui.listfrag.rebuild();
ui.listfrag.rebuild();
}).grow().pad(8);
}).width(w).height(70f).pad(4);
content().row();
content().addButton("$text.host", () -> {
Vars.ui.loadfrag.show("$text.hosting");
ui.loadfrag.show("$text.hosting");
Timers.runTask(5f, () -> {
try{
Net.host(Vars.port);
}catch (IOException e){
Vars.ui.showError(Bundles.format("text.server.error", Strings.parseException(e, false)));
ui.showError(Bundles.format("text.server.error", Strings.parseException(e, false)));
}
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
hide();
});
}).width(w).height(70f);
@@ -49,12 +51,12 @@ public class HostDialog extends FloatingDialog{
showTextInput("$text.hostserver", "$text.server.port", Vars.port + "", new DigitsOnlyFilter(), text -> {
int result = Strings.parseInt(text);
if(result == Integer.MIN_VALUE || result >= 65535){
Vars.ui.showError("$text.server.invalidport");
ui.showError("$text.server.invalidport");
}else{
try{
Net.host(result);
}catch (IOException e){
Vars.ui.showError(Bundles.format("text.server.error", Strings.parseException(e, false)));
ui.showError(Bundles.format("text.server.error", Strings.parseException(e, false)));
}
}
});

View File

@@ -1,8 +1,8 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.io.Platform;
import io.anuke.mindustry.net.Host;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.UCore;
@@ -16,6 +16,8 @@ import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.ui;
public class JoinDialog extends FloatingDialog {
Array<Server> servers = new Array<>();
Dialog add;
@@ -35,7 +37,7 @@ public class JoinDialog extends FloatingDialog {
add = new FloatingDialog("$text.joingame.title");
add.content().add("$text.joingame.ip").padRight(5f).left();
Mindustry.platforms.addDialog(add.content().addField(Settings.getString("ip"), text ->{
Platform.instance.addDialog(add.content().addField(Settings.getString("ip"), text ->{
Settings.putString("ip", text);
Settings.save();
}).size(340f, 54f).get(), 100);
@@ -100,7 +102,7 @@ public class JoinDialog extends FloatingDialog {
}).margin(3f).padTop(6f).top().right();
inner.addImageButton("icon-trash-16", "empty", 16*2, () -> {
Vars.ui.showConfirm("$text.confirm", "$text.server.delete", () -> {
ui.showConfirm("$text.confirm", "$text.server.delete", () -> {
servers.removeValue(server, true);
saveServers();
setupRemote();
@@ -207,7 +209,7 @@ public class JoinDialog extends FloatingDialog {
}
void connect(String ip, int port){
Vars.ui.loadfrag.show("$text.connecting");
ui.loadfrag.show("$text.connecting");
Timers.runTask(2f, () -> {
try{
@@ -233,8 +235,8 @@ public class JoinDialog extends FloatingDialog {
}else{
error = Strings.parseException(e, false);
}
Vars.ui.showError(Bundles.format("text.connectfail", error));
Vars.ui.loadfrag.hide();
ui.showError(Bundles.format("text.connectfail", error));
ui.loadfrag.hide();
UCore.error(e);
}

View File

@@ -1,7 +1,7 @@
package io.anuke.mindustry.ui.dialogs;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.io.Platform;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.scene.ui.ButtonGroup;
@@ -30,17 +30,17 @@ public class LanguageDialog extends FloatingDialog{
ButtonGroup<TextButton> group = new ButtonGroup<>();
for(Locale loc : locales){
TextButton button = new TextButton(Mindustry.platforms.getLocaleName(loc), "toggle");
button.setChecked(Vars.ui.getLocale().equals(loc));
TextButton button = new TextButton(Platform.instance.getLocaleName(loc), "toggle");
button.setChecked(ui.getLocale().equals(loc));
button.clicked(() -> {
if(Vars.ui.getLocale().equals(loc)) return;
if(ui.getLocale().equals(loc)) return;
Settings.putString("locale", loc.toString());
Settings.save();
UCore.log("Setting locale: " + loc.toString());
Vars.ui.showInfo("$text.language.restart");
ui.showInfo("$text.language.restart");
});
langs.add(button).group(group).update(t -> {
t.setChecked(loc.equals(Vars.ui.getLocale()));
t.setChecked(loc.equals(ui.getLocale()));
}).size(400f, 60f).row();
}

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.world.Map;
@@ -19,8 +18,10 @@ import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.*;
public class LevelDialog extends FloatingDialog{
private Map selectedMap = Vars.world.maps().getMap(0);
private Map selectedMap = world.maps().getMap(0);
private TextureRegion region = new TextureRegion();
private ScrollPane pane;
@@ -50,7 +51,7 @@ public class LevelDialog extends FloatingDialog{
for(GameMode mode : GameMode.values()){
TextButton b = Elements.newButton("$mode."+mode.name()+".name", "toggle", ()->{
Vars.control.setMode(mode);
state.mode = mode;
});
group.add(b);
selmode.add(b).size(130f, 54f);
@@ -69,27 +70,27 @@ public class LevelDialog extends FloatingDialog{
sdif.defaults().height(s+4);
sdif.addImageButton("icon-arrow-left", 10*3, () -> {
Vars.control.setDifficulty(ds[Mathf.mod(Vars.control.getDifficulty().ordinal() - 1, ds.length)]);
state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() - 1, ds.length)]);
}).width(s);
sdif.addButton("", () -> {
}).update(t -> {
t.setText(Vars.control.getDifficulty().toString());
t.setText(state.difficulty.toString());
t.setTouchable(Touchable.disabled);
}).width(180f);
sdif.addImageButton("icon-arrow-right", 10*3, () -> {
Vars.control.setDifficulty(ds[Mathf.mod(Vars.control.getDifficulty().ordinal() + 1, ds.length)]);
state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() + 1, ds.length)]);
}).width(s);
content().add(sdif);
content().row();
int i = 0;
for(Map map : Vars.world.maps().list()){
for(Map map : world.maps().list()){
if(!map.visible && !Vars.debug) continue;
if(!map.visible && !debug) continue;
if(i % maxwidth == 0){
maps.row();
@@ -122,8 +123,8 @@ public class LevelDialog extends FloatingDialog{
image.row();
delete[0] = image.addButton("Delete", () -> {
Timers.run(1f, () -> {
Vars.ui.showConfirm("$text.level.delete.title", Bundles.format("text.level.delete", Bundles.get("map."+map.name+".name", map.name)), () -> {
Vars.world.maps().removeMap(map);
ui.showConfirm("$text.level.delete.title", Bundles.format("text.level.delete", Bundles.get("map."+map.name+".name", map.name)), () -> {
world.maps().removeMap(map);
reload();
Core.scene.setScrollFocus(pane);
});
@@ -142,7 +143,7 @@ public class LevelDialog extends FloatingDialog{
selectedMap = map;
hide();
Vars.control.playMap(selectedMap);
control.playMap(selectedMap);
}
});
image.getImageCell().size(images);

View File

@@ -1,8 +1,6 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.io.Saves.SaveSlot;
@@ -17,6 +15,8 @@ import io.anuke.ucore.util.Strings;
import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
public class LoadDialog extends FloatingDialog{
ScrollPane pane;
Table slots;
@@ -49,7 +49,7 @@ public class LoadDialog extends FloatingDialog{
Timers.runTask(2f, () -> Core.scene.setScrollFocus(pane));
Array<SaveSlot> array = Vars.control.getSaves().getSaveSlots();
Array<SaveSlot> array = control.getSaves().getSaveSlots();
for(SaveSlot slot : array){
@@ -68,27 +68,27 @@ public class LoadDialog extends FloatingDialog{
}).checked(slot.isAutosave()).right();
t.addImageButton("icon-trash", "empty", 14*3, () -> {
Vars.ui.showConfirm("$text.confirm", "$text.save.delete.confirm", () -> {
ui.showConfirm("$text.confirm", "$text.save.delete.confirm", () -> {
slot.delete();
setup();
});
}).size(14*3).right();
t.addImageButton("icon-pencil-small", "empty", 14*3, () -> {
Vars.ui.showTextInput("$text.save.rename", "$text.save.rename.text", slot.getName(), text -> {
ui.showTextInput("$text.save.rename", "$text.save.rename.text", slot.getName(), text -> {
slot.setName(text);
setup();
});
}).size(14*3).right();
if(!Vars.gwt) {
if(!gwt) {
t.addImageButton("icon-save", "empty", 14 * 3, () -> {
new FileChooser("$text.save.export", false, file -> {
try {
slot.exportFile(file);
setup();
} catch (IOException e) {
Vars.ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
}
}).show();
}).size(14 * 3).right();
@@ -123,7 +123,7 @@ public class LoadDialog extends FloatingDialog{
}
public void addSetup(){
if(Vars.control.getSaves().getSaveSlots().size == 0) {
if(control.getSaves().getSaveSlots().size == 0) {
slots.row();
slots.addButton("$text.save.none", "clear", () -> {
@@ -132,19 +132,19 @@ public class LoadDialog extends FloatingDialog{
slots.row();
if(Vars.gwt) return;
if(gwt) return;
slots.addImageTextButton("$text.save.import", "icon-add", "clear", 14*3, () -> {
new FileChooser("$text.save.import", f -> f.extension().equals("mins"), true, file -> {
if(SaveIO.isSaveValid(file)){
try{
Vars.control.getSaves().importSave(file);
control.getSaves().importSave(file);
setup();
}catch (IOException e){
Vars.ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e, false)));
ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e, false)));
}
}else{
Vars.ui.showError("$text.save.import.invalid");
ui.showError("$text.save.import.invalid");
}
}).show();
}).fillX().margin(10f).minWidth(300f).height(70f).pad(4f).padRight(-4);
@@ -153,21 +153,21 @@ public class LoadDialog extends FloatingDialog{
public void modifyButton(TextButton button, SaveSlot slot){
button.clicked(() -> {
if(!button.childrenPressed()){
Vars.ui.loadfrag.show();
ui.loadfrag.show();
Timers.runTask(3f, () -> {
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
hide();
try{
slot.load();
state.set(State.playing);
Vars.ui.paused.hide();
ui.paused.hide();
}catch(Exception e){
UCore.error(e);
Vars.ui.paused.hide();
ui.paused.hide();
state.set(State.menu);
Vars.control.reset();
Vars.ui.showError("$text.save.corrupted");
logic.reset();
ui.showError("$text.save.corrupted");
}
});
}

View File

@@ -1,8 +1,6 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.ui.PressGroup;
@@ -13,7 +11,7 @@ import io.anuke.ucore.scene.builders.imagebutton;
import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.util.Bundles;
import static io.anuke.mindustry.Vars.ui;
import static io.anuke.mindustry.Vars.*;
public class PausedDialog extends FloatingDialog{
private SaveDialog save = new SaveDialog();
@@ -27,22 +25,22 @@ public class PausedDialog extends FloatingDialog{
void setup(){
update(() -> {
if(GameState.is(State.menu) && isShown()){
if(state.is(State.menu) && isShown()){
hide();
}
});
shown(() -> {
wasPaused = GameState.is(State.paused);
wasPaused = state.is(State.paused);
if(!Net.active()) state.set(State.paused);
});
if(!Vars.android){
if(!android){
content().defaults().width(220).height(50);
content().addButton("$text.back", () -> {
hide();
if((!wasPaused || Net.active()) && !GameState.is(State.menu))
if((!wasPaused || Net.active()) && !state.is(State.menu))
state.set(State.playing);
});
@@ -52,7 +50,7 @@ public class PausedDialog extends FloatingDialog{
content().row();
content().addButton("$text.savegame", () -> {
save.show();
}).disabled(b -> Vars.world.getMap().id == -1);
}).disabled(b -> world.getMap().id == -1);
content().row();
content().addButton("$text.loadgame", () -> {
@@ -61,7 +59,7 @@ public class PausedDialog extends FloatingDialog{
content().row();
if(!Vars.gwt) {
if(!gwt) {
content().addButton("$text.hostserver", () -> {
ui.host.show();
}).disabled(b -> Net.active());
@@ -71,7 +69,7 @@ public class PausedDialog extends FloatingDialog{
content().addButton("$text.quit", () -> {
ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
if(Net.active() && Net.client()) Vars.netClient.disconnectQuietly();
if(Net.client()) netClient.disconnectQuietly();
runExitSave();
hide();
});
@@ -87,7 +85,7 @@ public class PausedDialog extends FloatingDialog{
new imagebutton("icon-play-2", isize, () -> {
hide();
if(!wasPaused && !GameState.is(State.menu))
if(!wasPaused && !state.is(State.menu))
state.set(State.playing);
}).text("$text.back").padTop(4f);
@@ -95,7 +93,7 @@ public class PausedDialog extends FloatingDialog{
imagebutton sa = new imagebutton("icon-save", isize, save::show);
sa.text("$text.save").padTop(4f);
sa.cell.disabled(b -> Vars.world.getMap().id == -1);
sa.cell.disabled(b -> world.getMap().id == -1);
content().row();
@@ -110,8 +108,8 @@ public class PausedDialog extends FloatingDialog{
ho.cell.disabled(b -> Net.active());
new imagebutton("icon-quit", isize, () -> {
Vars.ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
if(Net.active() && Net.client()) Vars.netClient.disconnectQuietly();
ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
if(Net.client()) netClient.disconnectQuietly();
runExitSave();
hide();
});
@@ -128,22 +126,22 @@ public class PausedDialog extends FloatingDialog{
}
private void runExitSave(){
if(Vars.control.getSaves().getCurrent() == null ||
!Vars.control.getSaves().getCurrent().isAutosave()){
if(control.getSaves().getCurrent() == null ||
!control.getSaves().getCurrent().isAutosave()){
state.set(State.menu);
Vars.control.getTutorial().reset();
control.tutorial().reset();
return;
}
Vars.ui.loadfrag.show("$text.saveload");
ui.loadfrag.show("$text.saveload");
Timers.runTask(5f, () -> {
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
try{
Vars.control.getSaves().getCurrent().save();
control.getSaves().getCurrent().save();
}catch(Throwable e){
e = (e.getCause() == null ? e : e.getCause());
Vars.ui.showError("[orange]"+ Bundles.get("text.savefail")+"\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
ui.showError("[orange]"+ Bundles.get("text.savefail")+"\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
}
state.set(State.menu);
});

View File

@@ -1,10 +1,9 @@
package io.anuke.mindustry.ui.dialogs;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.ucore.scene.ui.Dialog;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.*;
public class RestartDialog extends Dialog {
@@ -18,14 +17,14 @@ public class RestartDialog extends Dialog {
content().row();
}
content().add("$text.lasted").pad(12).get();
content().add("[accent]" + control.getWave());
content().add("[accent]" + state.wave);
pack();
});
getButtonTable().addButton("$text.menu", ()-> {
hide();
state.set(State.menu);
control.reset();
logic.reset();
}).size(130f, 60f);
}
}

View File

@@ -1,35 +1,35 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.io.Saves.SaveSlot;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.util.Bundles;
import static io.anuke.mindustry.Vars.*;
public class SaveDialog extends LoadDialog{
public SaveDialog() {
super("$text.savegame");
update(() -> {
if(GameState.is(State.menu) && isShown()){
if(state.is(State.menu) && isShown()){
hide();
}
});
}
public void addSetup(){
if(!Vars.control.getSaves().canAddSave()){
if(!control.getSaves().canAddSave()){
return;
}
slots.row();
slots.addImageTextButton("$text.save.new", "icon-add", "clear", 14*3, () ->
Vars.ui.showTextInput("$text.save", "$text.save.newslot", "", text -> {
Vars.control.getSaves().addSave(text);
ui.showTextInput("$text.save", "$text.save.newslot", "", text -> {
control.getSaves().addSave(text);
setup();
})
).fillX().margin(10f).minWidth(300f).height(70f).pad(4f).padRight(-4);
@@ -40,23 +40,23 @@ public class SaveDialog extends LoadDialog{
button.clicked(() -> {
if(button.childrenPressed()) return;
Vars.ui.showConfirm("$text.overwrite", "$text.save.overwrite", () -> save(slot));
ui.showConfirm("$text.overwrite", "$text.save.overwrite", () -> save(slot));
});
}
void save(SaveSlot slot){
Vars.ui.loadfrag.show("$text.saveload");
ui.loadfrag.show("$text.saveload");
Timers.runTask(5f, () -> {
hide();
Vars.ui.loadfrag.hide();
ui.loadfrag.hide();
try{
slot.save();
}catch(Throwable e){
e = (e.getCause() == null ? e : e.getCause());
Vars.ui.showError("[orange]"+Bundles.get("text.savefail")+"\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
ui.showError("[orange]"+Bundles.get("text.savefail")+"\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
}
});
}

View File

@@ -5,7 +5,6 @@ import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.utils.Align;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.core.Core;
@@ -18,7 +17,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.renderer;
import static io.anuke.mindustry.Vars.*;
public class SettingsMenuDialog extends SettingsDialog{
public SettingsTable graphics;
@@ -33,20 +32,20 @@ public class SettingsMenuDialog extends SettingsDialog{
setStyle(Core.skin.get("dialog", WindowStyle.class));
hidden(()->{
if(!GameState.is(State.menu)){
if(!state.is(State.menu)){
if(!wasPaused || Net.active())
state.set(State.playing);
}
});
shown(()->{
if(!GameState.is(State.menu)){
wasPaused = GameState.is(State.paused);
if(!state.is(State.menu)){
wasPaused = state.is(State.paused);
if(menu.getScene() != null){
wasPaused = ((PausedDialog)menu).wasPaused;
}
if(!Net.active()) state.set(State.paused);
Vars.ui.paused.hide();
ui.paused.hide();
}
});
@@ -83,10 +82,10 @@ public class SettingsMenuDialog extends SettingsDialog{
menu.addButton("$text.settings.sound", () -> visible(2));
if(!Vars.android) {
menu.row();
menu.addButton("$text.settings.controls", Vars.ui.controls::show);
menu.addButton("$text.settings.controls", ui.controls::show);
}
menu.row();
menu.addButton("$text.settings.language", Vars.ui.language::show);
menu.addButton("$text.settings.language", ui.language::show);
prefs.clearChildren();
prefs.add(menu);

View File

@@ -1,12 +1,13 @@
package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.ui.layout.Unit;
import static io.anuke.mindustry.Vars.state;
public class BackgroundFragment implements Fragment {
@Override
@@ -29,6 +30,6 @@ public class BackgroundFragment implements Fragment {
Draw.color();
Core.batch.draw(logo, w/2 - logow/2, h - logoh + 15, logow, logoh);
}).visible(() -> GameState.is(State.menu)).grow();
}).visible(() -> state.is(State.menu)).grow();
}
}

View File

@@ -5,8 +5,6 @@ import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.resource.*;
@@ -23,8 +21,7 @@ import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.fontscale;
import static io.anuke.mindustry.Vars.*;
public class BlocksFragment implements Fragment{
private Table desctable, itemtable, blocks, weapons;
@@ -39,12 +36,12 @@ public class BlocksFragment implements Fragment{
abottom();
aright();
visible(() -> !GameState.is(State.menu) && shown);
visible(() -> !state.is(State.menu) && shown);
blocks = new table(){{
itemtable = new Table("button");
itemtable.setVisible(() -> input.recipe == null && !Vars.control.getMode().infiniteResources);
itemtable.setVisible(() -> input.recipe == null && !state.mode.infiniteResources);
desctable = new Table("button");
desctable.setVisible(() -> input.recipe != null);
@@ -121,8 +118,8 @@ public class BlocksFragment implements Fragment{
image.getImageCell().size(size);
image.update(() -> {
boolean canPlace = !control.getTutorial().active() || control.getTutorial().canPlace();
boolean has = (control.hasItems(r.requirements)) && canPlace;
boolean canPlace = !control.tutorial().active() || control.tutorial().canPlace();
boolean has = (state.inventory.hasItems(r.requirements)) && canPlace;
image.setChecked(input.recipe == r);
image.setTouchable(canPlace ? Touchable.enabled : Touchable.disabled);
image.getImage().setColor(has ? Color.WHITE : Hue.lightness(0.33f));
@@ -152,11 +149,11 @@ public class BlocksFragment implements Fragment{
row();
if(!Vars.android) {
if(!android) {
weapons = new table("button").margin(0).fillX().end().get();
}
visible(() -> !GameState.is(State.menu) && shown);
visible(() -> !state.is(State.menu) && shown);
}}.end().get();
}}.end();
@@ -165,21 +162,21 @@ public class BlocksFragment implements Fragment{
}
public void updateWeapons(){
if(Vars.android) return;
if(android) return;
weapons.clearChildren();
weapons.left();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
for(int i = 0; i < Vars.control.getWeapons().size; i ++){
Weapon weapon = Vars.control.getWeapons().get(i);
for(int i = 0; i < control.upgrades().getWeapons().size; i ++){
Weapon weapon = control.upgrades().getWeapons().get(i);
weapons.addImageButton(weapon.name, "toggle", 8*3, () -> {
Vars.player.weaponLeft = Vars.player.weaponRight = weapon;
player.weaponLeft = player.weaponRight = weapon;
}).left().size(40f, 45f).padRight(-1).group(group);
}
int idx = Vars.control.getWeapons().indexOf(Vars.player.weaponLeft, true);
int idx = control.upgrades().getWeapons().indexOf(player.weaponLeft, true);
if(idx != -1)
group.getButtons().get(idx).setChecked(true);
@@ -197,7 +194,7 @@ public class BlocksFragment implements Fragment{
}
void updateRecipe(){
Recipe recipe = Vars.control.input().recipe;
Recipe recipe = control.input().recipe;
desctable.clear();
desctable.setTouchable(Touchable.enabled);
@@ -228,7 +225,7 @@ public class BlocksFragment implements Fragment{
Label desclabel = new Label(recipe.result.fullDescription);
desclabel.setWrap(true);
boolean wasPaused = GameState.is(State.paused);
boolean wasPaused = state.is(State.paused);
state.set(State.paused);
FloatingDialog d = new FloatingDialog("$text.blocks.blockinfo");
@@ -286,7 +283,7 @@ public class BlocksFragment implements Fragment{
Label reqlabel = new Label("");
reqlabel.update(()->{
int current = control.getAmount(stack.item);
int current = state.inventory.getAmount(stack.item);
String text = Mathf.clamp(current, 0, stack.amount) + "/" + stack.amount;
reqlabel.setColor(current < stack.amount ? Colors.get("missingitems") : Color.WHITE);
@@ -311,12 +308,12 @@ public class BlocksFragment implements Fragment{
itemtable.clear();
itemtable.left();
if(control.getMode().infiniteResources){
if(state.mode.infiniteResources){
return;
}
for(int i = 0; i < control.getItems().length; i ++){
int amount = control.getItems()[i];
for(int i = 0; i < state.inventory.getItems().length; i ++){
int amount = state.inventory.getItems()[i];
if(amount == 0) continue;
String formatted = amount > 99999999 ? "inf" : format(amount);
Image image = new Image(Draw.hasRegion("icon-" + Item.getByID(i).name) ?

View File

@@ -6,11 +6,11 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.io.Platform;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Timers;
@@ -21,6 +21,7 @@ import io.anuke.ucore.scene.ui.TextField;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.scene.ui.layout.Unit;
import static io.anuke.mindustry.Vars.state;
import static io.anuke.ucore.core.Core.scene;
import static io.anuke.ucore.core.Core.skin;
@@ -45,7 +46,7 @@ public class ChatFragment extends Table implements Fragment{
setFillParent(true);
font = Core.skin.getFont("default-font");
setVisible(() -> !GameState.is(State.menu) && Net.active());
setVisible(() -> !state.is(State.menu) && Net.active());
//TODO put it in input?
update(() -> {
@@ -57,7 +58,7 @@ public class ChatFragment extends Table implements Fragment{
toggle();
}
if(GameState.is(State.menu) && messages.size > 0){
if(state.is(State.menu) && messages.size > 0){
messages.clear();
}
});
@@ -81,7 +82,7 @@ public class ChatFragment extends Table implements Fragment{
chatfield.getStyle().fontColor = Color.WHITE;
chatfield.getStyle().font = skin.getFont("default-font-chat");
chatfield.setStyle(chatfield.getStyle());
Mindustry.platforms.addDialog(chatfield, maxLength);
Platform.instance.addDialog(chatfield, maxLength);
bottom().left().marginBottom(offsety).marginLeft(offsetx*2).add(fieldlabel).padBottom(4f);
@@ -105,10 +106,6 @@ public class ChatFragment extends Table implements Fragment{
if(chatOpen)
batch.draw(skin.getRegion("white"), offsetx, chatfield.getY(), chatfield.getWidth() + 15f, chatfield.getHeight()-1);
//font.getData().down = Unit.dp.scl(-21.5f);
//font.getData().lineHeight = 22f;
//chatfield.getStyle().font.getData().setScale(Vars.fontscale);
super.draw(batch, alpha);
float spacing = chatspace;
@@ -151,7 +148,7 @@ public class ChatFragment extends Table implements Fragment{
if(message.replaceAll(" ", "").isEmpty()) return;
Vars.netClient.handleSendMessage(message);
NetEvents.handleSendMessage(message);
}
public void toggle(){

View File

@@ -3,8 +3,6 @@ package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Interpolation;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.core.Core;
@@ -28,7 +26,7 @@ public class HudFragment implements Fragment{
private Table wavetable;
private boolean shown = true;
private BlocksFragment blockfrag = new BlocksFragment();
public void build(){
//menu at top left
@@ -66,17 +64,17 @@ public class HudFragment implements Fragment{
}).get();
new imagebutton("icon-pause", isize, () -> {
if (Net.active() && Vars.android) {
if (Net.active() && android) {
ui.listfrag.visible = !ui.listfrag.visible;
} else {
state.set(GameState.is(State.paused) ? State.playing : State.paused);
state.set(state.is(State.paused) ? State.playing : State.paused);
}
}).update(i -> {
if (Net.active() && Vars.android) {
if (Net.active() && android) {
i.getStyle().imageUp = Core.skin.getDrawable("icon-players");
} else {
i.setDisabled(Net.active());
i.getStyle().imageUp = Core.skin.getDrawable(GameState.is(State.paused) ? "icon-play" : "icon-pause");
i.getStyle().imageUp = Core.skin.getDrawable(state.is(State.paused) ? "icon-play" : "icon-pause");
}
}).get();
@@ -92,10 +90,10 @@ public class HudFragment implements Fragment{
row();
visible(() -> !GameState.is(State.menu));
visible(() -> !state.is(State.menu));
Label fps = new Label(() -> (Settings.getBool("fps") ? (Gdx.graphics.getFramesPerSecond() + " FPS") +
(Net.active() && !Vars.gwt && !Net.server() ? " / Ping: " + Net.getPing() : "") : ""));
(Net.client() && !gwt ? " / Ping: " + Net.getPing() : "") : ""));
row();
add(fps).size(-1);
@@ -110,46 +108,46 @@ public class HudFragment implements Fragment{
}).visible(() -> Net.active() && android).top().left().size(58f).get();
}}.end();
//tutorial ui table
new table(){{
control.getTutorial().buildUI(this);
visible(()->control.getTutorial().active());
control.tutorial().buildUI(this);
visible(() -> control.tutorial().active());
}}.end();
//paused table
new table(){{
visible(()->GameState.is(State.paused) && !Net.active());
visible(() -> state.is(State.paused) && !Net.active());
atop();
new table("pane"){{
new label("[orange]< "+ Bundles.get("text.paused") + " >").scale(0.75f).pad(6);
}}.end();
}}.end();
//respawn background table
new table("white"){{
respawntable = get();
respawntable.setColor(Color.CLEAR);
update(t -> {
if(GameState.is(State.menu)){
if(state.is(State.menu)){
respawntable.setColor(Color.CLEAR);
}
});
}}.end();
//respawn table
new table(){{
new table("pane"){{
new label(()->"[orange]"+Bundles.get("text.respawn")+" " + (int)(control.getRespawnTime()/60)).scale(0.75f).pad(10);
visible(()->control.getRespawnTime() > 0 && !GameState.is(State.menu));
visible(()->control.getRespawnTime() > 0 && !state.is(State.menu));
}}.end();
}}.end();
//profiling table
if(debug){
new table(){{
@@ -158,11 +156,11 @@ public class HudFragment implements Fragment{
row();
new label(() -> "[blue]requests: " + renderer.getBlocks().getRequests()).left();
row();
new label(() -> "[purple]tiles: " + Vars.control.tileGroup.amount()).left();
new label(() -> "[purple]tiles: " + tileGroup.amount()).left();
row();
new label(() -> "[purple]enemies: " + Vars.control.enemyGroup.amount()).left();
new label(() -> "[purple]enemies: " + enemyGroup.amount()).left();
row();
new label(() -> "[orange]noclip: " + Vars.noclip).left();
new label(() -> "[orange]noclip: " + noclip).left();
row();
new label(() -> "[purple]time: " + (int)(Timers.time() / 10f) % 50).left();
row();
@@ -172,17 +170,17 @@ public class HudFragment implements Fragment{
new table(){{
abottom();
visible(() -> !GameState.is(State.menu) && Vars.control.getSaves().isSaving());
visible(() -> !state.is(State.menu) && control.getSaves().isSaving());
new label("$text.saveload");
}}.end();
if(Vars.debugNet) {
if(debugNet) {
new table() {{
new label(() -> "players: " + Vars.control.playerGroup.amount());
new label(() -> "players: " + playerGroup.amount());
row();
new label(() -> "" + Vars.control.playerGroup.all());
new label(() -> "" + playerGroup.all());
}}.end();
}
@@ -190,44 +188,44 @@ public class HudFragment implements Fragment{
}
private String getEnemiesRemaining() {
if(control.getEnemiesRemaining() == 1) {
return Bundles.format("text.enemies.single", control.getEnemiesRemaining());
} else return Bundles.format("text.enemies", control.getEnemiesRemaining());
if(state.enemies == 1) {
return Bundles.format("text.enemies.single", state.enemies);
} else return Bundles.format("text.enemies", state.enemies);
}
private void addWaveTable(){
float uheight = 66f;
wavetable = new table("button"){{
aleft();
new table(){{
aleft();
new label(() -> Bundles.format("text.wave", control.getWave())).scale(fontscale*1.5f).left().padLeft(-6);
new label(() -> Bundles.format("text.wave", state.wave)).scale(fontscale*1.5f).left().padLeft(-6);
row();
new label(()-> control.getEnemiesRemaining() > 0 ?
new label(()-> state.enemies > 0 ?
getEnemiesRemaining() :
(control.getTutorial().active() || Vars.control.getMode().toggleWaves) ? "$text.waiting"
: Bundles.format("text.wave.waiting", (int) (control.getWaveCountdown() / 60f)))
(control.tutorial().active() || state.mode.toggleWaves) ? "$text.waiting"
: Bundles.format("text.wave.waiting", (int) (state.wavetime / 60f)))
.minWidth(126).padLeft(-6).padRight(-12).left();
margin(10f);
get().marginLeft(6);
}}.left().end();
playButton(uheight);
}}.height(uheight).fillX().expandX().end().get();
wavetable.getParent().getParent().swapActor(wavetable.getParent(), menu.getParent());
}
private void playButton(float uheight){
new imagebutton("icon-play", 30f, () -> {
Vars.control.runWave();
logic.runWave();
}).height(uheight).fillX().right().padTop(-8f).padBottom(-12f).padRight(-36).width(40f).update(l->{
boolean vis = Vars.control.getEnemiesRemaining() <= 0 && (Net.server() || !Net.active());
boolean paused = GameState.is(State.paused) || !vis;
boolean vis = state.enemies <= 0 && (Net.server() || !Net.active());
boolean paused = state.is(State.paused) || !vis;
l.setVisible(vis);
l.getStyle().imageUp = Core.skin.getDrawable(vis ? "icon-play" : "clear");

View File

@@ -1,10 +1,9 @@
package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.Gdx;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.io.Platform;
import io.anuke.mindustry.ui.MenuButton;
import io.anuke.mindustry.ui.PressGroup;
import io.anuke.ucore.scene.builders.imagebutton;
@@ -28,7 +27,7 @@ public class MenuFragment implements Fragment{
add(new MenuButton("$text.play", group, ui.levels::show));
row();
if(Mindustry.platforms.canJoinGame()) {
if(Platform.instance.canJoinGame()) {
add(new MenuButton("$text.joingame", group, ui.join::show));
row();
}
@@ -53,7 +52,7 @@ public class MenuFragment implements Fragment{
get().margin(16);
}}.end();
visible(()-> GameState.is(State.menu));
visible(() -> state.is(State.menu));
}}.end();
}else{
new table(){{
@@ -77,9 +76,9 @@ public class MenuFragment implements Fragment{
new imagebutton("icon-info", isize, ui.about::show).text("$text.about.button").padTop(4f);
new imagebutton("icon-donate", isize, Mindustry.platforms::openDonations).text("$text.donate").padTop(4f);
new imagebutton("icon-donate", isize, Platform.instance::openDonations).text("$text.donate").padTop(4f);
visible(()->GameState.is(State.menu));
visible(() -> state.is(State.menu));
}}.end();
}}.end();
}
@@ -87,12 +86,12 @@ public class MenuFragment implements Fragment{
//extra icons in top right
new table(){{
atop().aright();
if(Mindustry.hasDiscord){
if(Platform.instance.hasDiscord()){
new imagebutton("icon-discord", 30f, ui.discord::show).margin(14);
}
if(!Vars.android) {
new imagebutton("icon-info", 30f, ui.about::show).margin(14);
}
}}.end().visible(()->GameState.is(State.menu));
}}.end().visible(()->state.is(State.menu));
}
}

View File

@@ -3,8 +3,6 @@ package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.Align;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.input.PlaceMode;
@@ -22,7 +20,7 @@ import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.*;
public class PlacementFragment implements Fragment{
boolean shown = false, placing = false;
@@ -30,7 +28,7 @@ public class PlacementFragment implements Fragment{
Label modelabel;
public void build(){
if(!Vars.android) return;
if(!android) return;
InputHandler input = control.input();
@@ -38,7 +36,7 @@ public class PlacementFragment implements Fragment{
float translation = Unit.dp.scl(54f);
new table(){{
visible(() -> !GameState.is(State.menu));
visible(() -> !state.is(State.menu));
abottom();
aleft();

View File

@@ -1,20 +1,21 @@
package io.anuke.mindustry.ui.fragments;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.net.Packets.KickReason;
import io.anuke.mindustry.ui.BorderImage;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.builders.label;
import io.anuke.ucore.scene.builders.table;
import io.anuke.ucore.scene.ui.ScrollPane;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
import static io.anuke.mindustry.Vars.*;
public class PlayerListFragment implements Fragment{
public boolean visible = false;
Table content = new Table();
@@ -25,8 +26,8 @@ public class PlayerListFragment implements Fragment{
new table(){{
new table("pane"){{
margin(14f);
new label(() -> Bundles.format(Vars.control.playerGroup.amount() == 1 ? "text.players.single" :
"text.players", Vars.control.playerGroup.amount()));
new label(() -> Bundles.format(playerGroup.amount() == 1 ? "text.players.single" :
"text.players", playerGroup.amount()));
row();
content.marginRight(13f).marginLeft(13f);
ScrollPane pane = new ScrollPane(content, "clear");
@@ -37,21 +38,22 @@ public class PlayerListFragment implements Fragment{
new table("pane"){{
margin(12f);
get().addCheck("$text.server.friendlyfire", b -> {
Vars.control.setFriendlyFire(b);
}).growX().update(i -> i.setChecked(Vars.control.isFriendlyFire())).disabled(b -> Net.client());
state.friendlyFire = b;
NetEvents.handleFriendlyFireChange(b);
}).growX().update(i -> i.setChecked(state.friendlyFire)).disabled(b -> Net.client());
}}.pad(10f).growX().end();
}}.end();
update(t -> {
if(!Vars.android){
if(!android){
visible = Inputs.keyDown("player_list");
}
if(!(Net.active() && !GameState.is(State.menu))){
if(!(Net.active() && !state.is(State.menu))){
visible = false;
}
if(Vars.control.playerGroup.amount() != last){
if(playerGroup.amount() != last){
rebuild();
last = Vars.control.playerGroup.amount();
last = playerGroup.amount();
}
});
@@ -66,7 +68,7 @@ public class PlayerListFragment implements Fragment{
float h = 60f;
for(Player player : Vars.control.playerGroup.all()){
for(Player player : playerGroup.all()){
Table button = new Table("button");
button.left();
button.margin(5).marginBottom(10);

View File

@@ -3,8 +3,7 @@ package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.input.PlaceMode;
@@ -51,13 +50,13 @@ public class ToolFragment implements Fragment{
Core.scene.add(tools);
tools.setVisible(() ->
!GameState.is(State.menu) && android && ((input.recipe != null && control.hasItems(input.recipe.requirements) &&
!state.is(State.menu) && android && ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) &&
input.placeMode == PlaceMode.cursor) || confirming)
);
tools.update(() -> {
if(confirming){
Vector2 v = Graphics.screen((px + px2)/2f * Vars.tilesize, Math.min(py, py2) * Vars.tilesize - Vars.tilesize*1.5f);
Vector2 v = Graphics.screen((px + px2)/2f * tilesize, Math.min(py, py2) * tilesize - tilesize*1.5f);
tools.setPosition(v.x, v.y, Align.top);
}else{

View File

@@ -4,21 +4,24 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.state;
import static io.anuke.mindustry.Vars.tilesize;
public class Block{
private static int lastid;
private static Array<Block> blocks = new Array<>();
@@ -111,7 +114,7 @@ public class Block{
public void configure(Tile tile, byte data){}
public void setConfigure(Tile tile, byte data){
Vars.netClient.handleBlockConfig(tile, data);
NetEvents.handleBlockConfig(tile, data);
}
public boolean isConfigurable(Tile tile){
@@ -244,7 +247,7 @@ public class Block{
}
//update the tile entity through the draw method, only if it's an entity without updating
if(destructible && !update && !GameState.is(State.paused)){
if(destructible && !update && !state.is(State.paused)){
tile.entity.update();
}
}
@@ -260,7 +263,7 @@ public class Block{
/**Offset for placing and drawing multiblocks.*/
public Vector2 getPlaceOffset(){
return Tmp.v3.set(((width + 1) % 2) * Vars.tilesize/2, ((height + 1) % 2) * Vars.tilesize/2);
return Tmp.v3.set(((width + 1) % 2) * tilesize/2, ((height + 1) % 2) * tilesize/2);
}
public boolean isMultiblock(){

View File

@@ -2,13 +2,13 @@ package io.anuke.mindustry.world;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.util.Bits;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class Tile{
@@ -37,7 +37,7 @@ public class Tile{
}
public int packedPosition(){
return x + y * Vars.world.width();
return x + y * world.width();
}
private void iSetFloor(Block floor){
@@ -77,7 +77,7 @@ public class Tile{
float dst = Vector2.dst(dx, dy, 0, 0);
if(dst > rad || (dx == 0 && dy == 0)) continue;
Tile other = Vars.world.tile(x + dx, y + dy);
Tile other = world.tile(x + dx, y + dy);
if(other != null && other.entity != null){
other.entity.damage((int)(amount * Mathf.lerp(1f-dst/rad, 1f, falloff)));
}
@@ -86,7 +86,7 @@ public class Tile{
}
public int id(){
return x + y * Vars.world.width();
return x + y * world.width();
}
public float worldx(){
@@ -211,7 +211,7 @@ public class Tile{
int offsety = -(block.height-1)/2;
for(int dx = 0; dx < block.width; dx ++){
for(int dy = 0; dy < block.height; dy ++){
Tile other = Vars.world.tile(x + dx + offsetx, y + dy + offsety);
Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
tmpArray.add(other);
}
}
@@ -226,23 +226,23 @@ public class Tile{
}else{
byte dx = Bits.getLeftByte(link);
byte dy = Bits.getRightByte(link);
return Vars.world.tile(x - (dx - 8), y - (dy - 8));
return world.tile(x - (dx - 8), y - (dy - 8));
}
}
public Tile[] getNearby(){
return Vars.world.getNearby(x, y);
return world.getNearby(x, y);
}
public Tile[] getNearby(Tile[] copy){
return Vars.world.getNearby(x, y, copy);
return world.getNearby(x, y, copy);
}
public void updateOcclusion(){
occluded = false;
for(int dx = -1; dx <= 1; dx ++){
for(int dy = -1; dy <= 1; dy ++){
Tile tile = Vars.world.tile(x + dx, y + dy);
Tile tile = world.tile(x + dx, y + dy);
if(tile != null && tile.solid()){
occluded = true;
break;

View File

@@ -16,6 +16,9 @@ import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.noise.Noise;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class WorldGenerator {
public static final ObjectMap<Block, Block> rocks = new ObjectMap(){{
put(Blocks.stone, Blocks.rock);
@@ -26,7 +29,7 @@ public class WorldGenerator {
/**Returns the core (starting) block. Should fill spawns with the correct spawnpoints.*/
public static Tile generate(Pixmap pixmap, Tile[][] tiles, Array<SpawnPoint> spawns){
Noise.setSeed(Vars.world.getSeed());
Noise.setSeed(world.getSeed());
Tile core = null;
@@ -45,7 +48,7 @@ public class WorldGenerator {
if(block == SpecialBlocks.playerSpawn){
block = Blocks.air;
core = Vars.world.tile(x, y);
core = world.tile(x, y);
}else if(block == SpecialBlocks.enemySpawn){
block = Blocks.air;
spawns.add(new SpawnPoint(tiles[x][y]));
@@ -55,7 +58,7 @@ public class WorldGenerator {
block = rocks.get(floor);
}
if(Vars.world.getMap().oreGen && (floor == Blocks.stone || floor == Blocks.grass || floor == Blocks.blackstone ||
if(world.getMap().oreGen && (floor == Blocks.stone || floor == Blocks.grass || floor == Blocks.blackstone ||
floor == Blocks.snow || floor == Blocks.sand)){
if(Noise.nnoise(x, y, 8, 1) > 0.21){
floor = Blocks.iron;
@@ -75,7 +78,7 @@ public class WorldGenerator {
}
if(color == Hue.rgb(Color.PURPLE)){
if(!Vars.android) new Enemy(EnemyTypes.target).set(x * Vars.tilesize, y * Vars.tilesize).add();
if(!Vars.android) new Enemy(EnemyTypes.target).set(x * tilesize, y * tilesize).add();
floor = Blocks.stone;
}

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.world.blocks;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.effect.TeslaOrb;
import io.anuke.mindustry.graphics.Fx;
@@ -138,8 +137,7 @@ public class WeaponBlocks{
TurretEntity entity = tile.entity();
Angles.translation(entity.rotation, 4);
new TeslaOrb(tile.worldx() + Angles.x(), tile.worldy() + Angles.y(),
range, (int)(9*Vars.multiplier)).add();
new TeslaOrb(tile.worldx() + Angles.x(), tile.worldy() + Angles.y(), range, 9).add();
}
},

View File

@@ -3,7 +3,7 @@ package io.anuke.mindustry.world.blocks.types;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw;
@@ -31,7 +31,7 @@ public class Floor extends Block{
if(dx == 0 && dy == 0) continue;
Tile other = Vars.world.tile(tile.x+dx, tile.y+dy);
Tile other = world.tile(tile.x+dx, tile.y+dy);
if(other == null) continue;

View File

@@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks.types;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
@@ -12,6 +11,9 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.renderer;
import static io.anuke.mindustry.Vars.tilesize;
public abstract class PowerBlock extends Block implements PowerAcceptor{
public float powerCapacity = 10f;
public float voltage = 0.001f;
@@ -32,12 +34,12 @@ public abstract class PowerBlock extends Block implements PowerAcceptor{
public void drawSelect(Tile tile){
PowerEntity entity = tile.entity();
float fract = (float)entity.power / powerCapacity;
float fract = entity.power / powerCapacity;
if(fract > 0)
fract = Mathf.clamp(fract + 0.2f, 0.24f, 1f);
Vars.renderer.drawBar(Color.YELLOW, tile.drawx(),
tile.drawy() + Vars.tilesize * height/2f + 2, fract);
renderer.drawBar(Color.YELLOW, tile.drawx(),
tile.drawy() + tilesize * height/2f + 2, fract);
}
/**Tries adding all the power with no remainder, returns success.*/

View File

@@ -1,10 +1,12 @@
package io.anuke.mindustry.world.blocks.types.defense;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import static io.anuke.mindustry.Vars.debug;
import static io.anuke.mindustry.Vars.state;
public class CoreBlock extends Block {
public CoreBlock(String name) {
@@ -19,12 +21,12 @@ public class CoreBlock extends Block {
@Override
public int handleDamage(Tile tile, int amount){
return Vars.debug ? 0 : amount;
return debug ? 0 : amount;
}
@Override
public void handleItem(Item item, Tile tile, Tile source){
Vars.control.addItem(item, 1);
state.inventory.addItem(item, 1);
}
@Override

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.world.blocks.types.defense;
import com.badlogic.gdx.math.Rectangle;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.world.Block;
@@ -18,8 +17,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.player;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.*;
public class Door extends Wall{
protected Effect openfx = Fx.dooropen;
@@ -67,10 +65,10 @@ public class Door extends Wall{
boolean anyEntities(Tile tile){
int x = tile.x, y = tile.y;
Block type = tile.block();
Tmp.r2.setSize(type.width * Vars.tilesize, type.height * Vars.tilesize);
Tmp.r2.setSize(type.width * tilesize, type.height * tilesize);
Tmp.r2.setCenter(tile.drawx(), tile.drawy());
for(SolidEntity e : Entities.getNearby(Vars.control.enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
for(SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
Rectangle rect = e.hitbox.getRect(e.x, e.y);
if(Tmp.r2.overlaps(rect)){

View File

@@ -2,7 +2,7 @@ package io.anuke.mindustry.world.blocks.types.defense;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Tile;
@@ -48,7 +48,7 @@ public class PowerTurret extends Turret implements PowerAcceptor{
if(fract > 0)
fract = Mathf.clamp(fract, 0.24f, 1f);
Vars.renderer.drawBar(Color.YELLOW, tile.drawx(), tile.drawy() + 6, fract);
renderer.drawBar(Color.YELLOW, tile.drawx(), tile.drawy() + 6, fract);
}
@Override

View File

@@ -3,7 +3,6 @@ package io.anuke.mindustry.world.blocks.types.defense;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Layer;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
@@ -14,6 +13,8 @@ import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.world;
public class RepairTurret extends PowerTurret{
protected float repairFrac = 1f / 135f;
@@ -45,7 +46,7 @@ public class RepairTurret extends PowerTurret{
}
if(entity.timer.get(timerTarget, targetInterval)){
entity.blockTarget = Vars.world.findTileTarget(tile.worldx(), tile.worldy(), tile, range, true);
entity.blockTarget = world.findTileTarget(tile.worldx(), tile.worldy(), tile, range, true);
}
if(entity.blockTarget != null){

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.world.blocks.types.defense;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.effect.Shield;
@@ -14,6 +13,8 @@ import io.anuke.ucore.entities.BulletEntity;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.renderer;
public class ShieldBlock extends PowerBlock{
public float shieldRadius = 40f;
public float powerDrain = 0.005f;
@@ -75,7 +76,7 @@ public class ShieldBlock extends PowerBlock{
bullet.remove();
Effects.effect(bullet.damage > 5 ? Fx.shieldhit : Fx.laserhit, bullet);
Vars.renderer.addShieldHit(bullet.x, bullet.y);
renderer.addShieldHit(bullet.x, bullet.y);
entity.power -= bullet.getDamage() * powerPerDamage;
}

View File

@@ -2,14 +2,16 @@ package io.anuke.mindustry.world.blocks.types.defense;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.PowerBlock;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.renderer;
public class ShieldedWallBlock extends PowerBlock{
static final float hitTime = 18f;
static final Color hitColor = Color.SKY.cpy().mul(1.2f);
@@ -54,12 +56,12 @@ public class ShieldedWallBlock extends PowerBlock{
ShieldedWallEntity entity = tile.entity();
if(entity.power > powerPerDamage){
Vars.renderer.addShield(() -> Draw.rect("blank", tile.worldx(), tile.worldy(), Vars.tilesize, Vars.tilesize));
renderer.addShield(() -> Draw.rect("blank", tile.worldx(), tile.worldy(), tilesize, tilesize));
}
Draw.color(hitColor);
Draw.alpha(entity.hit / hitTime * 0.9f);
Draw.rect("blank", tile.worldx(), tile.worldy(), Vars.tilesize, Vars.tilesize);
Draw.rect("blank", tile.worldx(), tile.worldy(), tilesize, tilesize);
Draw.reset();
entity.hit -= Timers.delta();

View File

@@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks.types.defense;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.TileEntity;
@@ -26,6 +25,8 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
public class Turret extends Block{
static final int targetInterval = 15;
static boolean drawDebug = false;
@@ -90,7 +91,7 @@ public class Turret extends Block{
Draw.rect(name(), tile.drawx(), tile.drawy(), entity.rotation - 90);
if(Vars.debug && drawDebug){
if(debug && drawDebug){
drawTargeting(tile);
}
}
@@ -107,14 +108,14 @@ public class Turret extends Block{
if(fract > 0)
fract = Mathf.clamp(fract, 0.24f, 1f);
Vars.renderer.drawBar(Color.GREEN, tile.drawx(), 2 + tile.drawy() + height/2f*Vars.tilesize, fract);
renderer.drawBar(Color.GREEN, tile.drawx(), 2 + tile.drawy() + height/2f * tilesize, fract);
}
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Draw.color(Color.PURPLE);
Lines.stroke(1f);
Lines.dashCircle(x*Vars.tilesize, y*Vars.tilesize, range);
Lines.dashCircle(x * tilesize, y * tilesize, range);
}
@Override
@@ -134,10 +135,10 @@ public class Turret extends Block{
if(entity.target != null && entity.target.isDead())
entity.target = null;
if(hasAmmo(tile) || (Vars.debug && Vars.infiniteAmmo)){
if(hasAmmo(tile) || (debug && infiniteAmmo)){
if(entity.timer.get(timerTarget, targetInterval)){
entity.target = (Enemy)Entities.getClosest(Vars.control.enemyGroup,
entity.target = (Enemy)Entities.getClosest(enemyGroup,
tile.worldx(), tile.worldy(), range, e-> e instanceof Enemy && !((Enemy)e).isDead());
}
@@ -151,8 +152,7 @@ public class Turret extends Block{
}
entity.rotation = Mathf.slerp(entity.rotation, targetRot,
rotatespeed*Timers.delta());
float reload = Vars.multiplier*this.reload;
if(Angles.angleDist(entity.rotation, targetRot) < shootCone && entity.timer.get(timerReload, reload)){
if(shootsound != null && entity.timer.get(timerSound, soundReload)) Effects.sound(shootsound, entity);
shoot(tile);
@@ -214,17 +214,15 @@ public class Turret extends Block{
protected void shoot(Tile tile){
TurretEntity entity = tile.entity();
Angles.translation(entity.rotation, width * Vars.tilesize / 2f);
Angles.translation(entity.rotation, width * tilesize / 2f);
for(int i = 0; i < shots; i ++){
if(Mathf.zero(shotDelayScale)){
bullet(tile, entity.rotation + Mathf.range(inaccuracy));
}else{
Timers.run(i * shotDelayScale, ()->{
Angles.translation(entity.rotation, width * Vars.tilesize / 2f);
Angles.translation(entity.rotation, width * tilesize / 2f);
bullet(tile, entity.rotation + Mathf.range(inaccuracy));
});
}
@@ -243,7 +241,6 @@ public class Turret extends Block{
protected void bullet(Tile tile, float angle){
Bullet out = new Bullet(bullet, tile.entity, tile.drawx() + Angles.x(), tile.drawy() + Angles.y(), angle).add();
out.damage = (int)(bullet.damage*Vars.multiplier);
}
public static class TurretEntity extends TileEntity{

View File

@@ -4,7 +4,7 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
import io.anuke.mindustry.world.blocks.types.production.Generator;
@@ -29,7 +29,7 @@ public class PowerBooster extends Generator{
super.drawSelect(tile);
Draw.color(Color.YELLOW);
Lines.dashCircle(tile.worldx(), tile.worldy(), powerRange * Vars.tilesize);
Lines.dashCircle(tile.worldx(), tile.worldy(), powerRange * tilesize);
Draw.reset();
}
@@ -37,7 +37,7 @@ public class PowerBooster extends Generator{
public void drawPlace(int x, int y, int rotation, boolean valid){
Draw.color(Color.PURPLE);
Lines.stroke(1f);
Lines.dashCircle(x * Vars.tilesize, y * Vars.tilesize, powerRange * Vars.tilesize);
Lines.dashCircle(x * tilesize, y * tilesize, powerRange * tilesize);
Draw.reset();
}
@@ -82,7 +82,7 @@ public class PowerBooster extends Generator{
}
if(Vector2.dst(x, y, 0, 0) < powerRange){
Tile dest = Vars.world.tile(tile.x + x, tile.y + y);
Tile dest = world.tile(tile.x + x, tile.y + y);
if(dest != null && dest.block() instanceof PowerAcceptor && ((PowerAcceptor) dest.block()).acceptsPower(dest)){
if(i == 1){
PowerAcceptor block = (PowerAcceptor) dest.block();

View File

@@ -3,7 +3,7 @@ package io.anuke.mindustry.world.blocks.types.distribution;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
@@ -62,7 +62,7 @@ public class Router extends Block{
float fract = (float)tile.entity.totalItems()/capacity;
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 6, fract);
renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 6, fract);
}
}

View File

@@ -4,24 +4,24 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.world.Layer;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
import io.anuke.mindustry.world.blocks.types.PowerBlock;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.graphics.Shapes;
import io.anuke.ucore.util.*;
import static io.anuke.mindustry.Vars.state;
public class Generator extends PowerBlock{
public static final int powerTime = 2;
public static boolean drawRangeOverlay = false;
@@ -66,14 +66,14 @@ public class Generator extends PowerBlock{
for(int i = 0; i < laserDirections; i++){
int dir = Mathf.mod(i + rotation - laserDirections / 2, 4);
float lx = Geometry.d4[dir].x, ly = Geometry.d4[dir].y;
float dx = lx * laserRange * Vars.tilesize;
float dy = ly * laserRange * Vars.tilesize;
float dx = lx * laserRange * tilesize;
float dy = ly * laserRange * tilesize;
Lines.dashLine(
tile.worldx() + lx * Vars.tilesize / 2,
tile.worldy() + ly * Vars.tilesize / 2,
tile.worldx() + dx - lx * Vars.tilesize,
tile.worldy() + dy - ly * Vars.tilesize, 9);
tile.worldx() + lx * tilesize / 2,
tile.worldy() + ly * tilesize / 2,
tile.worldx() + dx - lx * tilesize,
tile.worldy() + dy - ly * tilesize, 9);
}
Draw.reset();
@@ -90,13 +90,13 @@ public class Generator extends PowerBlock{
for(int i = 0; i < laserDirections; i++){
int dir = Mathf.mod(i + rotation - laserDirections / 2, 4);
float lx = Geometry.d4[dir].x, ly = Geometry.d4[dir].y;
float dx = lx * laserRange * Vars.tilesize;
float dy = ly * laserRange * Vars.tilesize;
float dx = lx * laserRange * tilesize;
float dy = ly * laserRange * tilesize;
Lines.dashLine(
x * Vars.tilesize + lx * Vars.tilesize / 2,
y * Vars.tilesize + ly * Vars.tilesize / 2,
x * Vars.tilesize + dx - lx * Vars.tilesize,
y * Vars.tilesize + dy - ly * Vars.tilesize, 9);
x * tilesize + lx * tilesize / 2,
y * tilesize + ly * tilesize / 2,
x * tilesize + dx - lx * tilesize,
y * tilesize + dy - ly * tilesize, 9);
}
Draw.reset();
@@ -177,15 +177,16 @@ public class Generator extends PowerBlock{
if(target != null){
boolean interfering = isInterfering(target, rotation);
Tmp.v1.set(Angles.translation(rotation * 90, target.block().width * Vars.tilesize / 2 + 2f + (interfering ? Vector2.dst(tile.worldx(), tile.worldy(), target.worldx(), target.worldy()) / 2f - Vars.tilesize / 2f * target.block().width - 1 : 0)));
Tmp.v1.set(Angles.translation(rotation * 90, target.block().width * tilesize / 2 + 2f + (interfering ? Vector2.dst(tile.worldx(), tile.worldy(), target.worldx(), target.worldy()) / 2f - tilesize / 2f * target.block().width - 1 : 0)));
Angles.translation(rotation * 90, width * Vars.tilesize / 2 + 2f);
Angles.translation(rotation * 90, width * tilesize / 2 + 2f);
if(!interfering){
Draw.tint(Hue.mix(Color.GRAY, Color.WHITE, 0.904f + Mathf.sin(Timers.time(), 1.7f, 0.06f)));
}else{
Draw.tint(Hue.mix(Color.SCARLET, Color.WHITE, 0.902f + Mathf.sin(Timers.time(), 1.7f, 0.08f)));
if(GameState.is(State.playing) && Mathf.chance(Timers.delta() * 0.033)){
if(state.is(State.playing) && Mathf.chance(Timers.delta() * 0.033)){
Effects.effect(Fx.laserspark, target.worldx() - Tmp.v1.x, target.worldy() - Tmp.v1.y);
}
}
@@ -200,8 +201,8 @@ public class Generator extends PowerBlock{
target.worldy() - Tmp.v1.y + Mathf.range(r), 0.7f);
}else{
Draw.rect("laserfull",
tile.worldx() + Geometry.d4[relative].x * width * Vars.tilesize / 2f,
tile.worldy() + Geometry.d4[relative].y * width * Vars.tilesize / 2f);
tile.worldx() + Geometry.d4[relative].x * width * tilesize / 2f,
tile.worldy() + Geometry.d4[relative].y * width * tilesize / 2f);
}
Draw.color();
@@ -230,7 +231,7 @@ public class Generator extends PowerBlock{
int i = 0;
for(i = 1; i < laserRange; i++){
Tile other = Vars.world.tile(tile.x + i * point.x, tile.y + i * point.y);
Tile other = world.tile(tile.x + i * point.x, tile.y + i * point.y);
if(other != null && other.block() instanceof PowerAcceptor){
Tile linked = other.getLinked();

View File

@@ -3,7 +3,7 @@ package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.resource.Item;
@@ -60,7 +60,7 @@ public class ItemPowerGenerator extends Generator{
TileEntity entity = tile.entity;
//TODO maybe don't draw it due to clutter
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 10, (float)entity.getItem(generateItem) / itemCapacity);
renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 10, (float)entity.getItem(generateItem) / itemCapacity);
}
@Override

View File

@@ -2,7 +2,7 @@ package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.resource.Item;
@@ -85,7 +85,7 @@ public class LiquidCrafter extends LiquidBlock{
float fract = (float)tile.entity.getItem(input) / itemCapacity;
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 6, fract);
renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 6, fract);
}
@Override

View File

@@ -2,7 +2,7 @@ package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.effect.DamageArea;
import io.anuke.mindustry.graphics.Fx;
@@ -82,14 +82,14 @@ public class NuclearReactor extends LiquidPowerGenerator{
if(entity.heat > smokeThreshold){
float smoke = 1.0f + (entity.heat - smokeThreshold) / (1f - smokeThreshold); //ranges from 1.0 to 2.0
if(Mathf.chance(smoke / 20.0 * Timers.delta())){
Effects.effect(Fx.reactorsmoke, tile.worldx() + Mathf.range(width * Vars.tilesize / 2f),
tile.worldy() + Mathf.random(height * Vars.tilesize / 2f));
Effects.effect(Fx.reactorsmoke, tile.worldx() + Mathf.range(width * tilesize / 2f),
tile.worldy() + Mathf.random(height * tilesize / 2f));
}
}
if(entity.heat >= 1f){
onDestroyed(tile);
Vars.world.removeBlock(tile);
world.removeBlock(tile);
}else{
distributeLaserPower(tile);
@@ -129,7 +129,7 @@ public class NuclearReactor extends LiquidPowerGenerator{
});
}
DamageArea.damageEntities(tile.worldx(), tile.worldy(), explosionRadius * Vars.tilesize, explosionDamage * 4);
DamageArea.damageEntities(tile.worldx(), tile.worldy(), explosionRadius * tilesize, explosionDamage * 4);
for(int i = 0; i < 20; i ++){
@@ -153,16 +153,16 @@ public class NuclearReactor extends LiquidPowerGenerator{
NuclearReactorEntity entity = tile.entity();
Vars.renderer.drawBar(Color.GREEN, tile.drawx(), tile.drawy() + 6 +
height*Vars.tilesize/2f, (float)entity.getItem(generateItem) / itemCapacity);
renderer.drawBar(Color.GREEN, tile.drawx(), tile.drawy() + 6 +
height*tilesize/2f, (float)entity.getItem(generateItem) / itemCapacity);
Draw.reset();
float fract = entity.heat;
if(fract > 0)
fract = Mathf.clamp(fract + 0.2f, 0.24f, 1f);
Vars.renderer.drawBar(Color.ORANGE, tile.drawx(),
tile.drawy() + Vars.tilesize * height/2f + 10, fract);
renderer.drawBar(Color.ORANGE, tile.drawx(),
tile.drawy() + tilesize * height/2f + 10, fract);
}
@Override
@@ -177,7 +177,7 @@ public class NuclearReactor extends LiquidPowerGenerator{
NuclearReactorEntity entity = tile.entity();
Draw.color(coolColor, hotColor, entity.heat);
Draw.rect("white", tile.drawx(), tile.drawy(), width * Vars.tilesize, height * Vars.tilesize);
Draw.rect("white", tile.drawx(), tile.drawy(), width * tilesize, height * tilesize);
if(entity.heat > flashThreshold){
float flash = 1f + ((entity.heat - flashThreshold) / (1f - flashThreshold)) * 5.4f;

View File

@@ -2,7 +2,7 @@ package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.resource.Item;
@@ -125,7 +125,7 @@ public class Smelter extends Block{
for(int i = 0; i < inputs.length; i ++){
float fract = ((float)tile.entity.getItem(inputs[i]))/capacity;
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 6 + i*4, fract);
renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 6 + i*4, fract);
}
}

View File

@@ -2,21 +2,22 @@ package io.anuke.mindustry.world.blocks.types.production;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.UpgradeRecipes;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.function.Listenable;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.style.TextureRegionDrawable;
import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.scene.ui.Tooltip;
import io.anuke.ucore.scene.ui.layout.Table;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.*;
public class WeaponFactory extends Block{
@@ -58,10 +59,10 @@ public class WeaponFactory extends Block{
tiptable.row();
tiptable.add(reqtable).left();
if(!control.hasWeapon(weapon)){
if(!control.upgrades().hasWeapon(weapon)){
for(ItemStack s : requirements){
int amount = Math.min(control.getAmount(s.item), s.amount);
int amount = Math.min(state.inventory.getAmount(s.item), s.amount);
reqtable.addImage(Draw.region("icon-" + s.item.name)).padRight(3).size(8*2);
reqtable.add(
(amount >= s.amount ? "" : "[RED]")
@@ -75,7 +76,7 @@ public class WeaponFactory extends Block{
tiptable.row();
tiptable.add("[gray]" + description).left();
tiptable.row();
if(control.hasWeapon(weapon)){
if(control.upgrades().hasWeapon(weapon)){
tiptable.add("$text.purchased").padTop(4).left();
}
tiptable.margin(8f);
@@ -88,18 +89,18 @@ public class WeaponFactory extends Block{
tip.setInstant(true);
ImageButton button = content.addImageButton("white", 8*4, () -> {
control.removeItems(requirements);
control.addWeapon(weapon);
Vars.ui.hudfrag.updateWeapons();
state.inventory.removeItems(requirements);
control.upgrades().addWeapon(weapon);
ui.hudfrag.updateWeapons();
run.listen();
Effects.sound("purchase");
if(Net.active() && Net.client()){
Vars.netClient.handleUpgrade(weapon);
if(Net.client()){
NetEvents.handleUpgrade(weapon);
}
}).size(49f, 54f).padBottom(-5).get();
button.setDisabled(() -> control.hasWeapon(weapon) || !control.hasItems(requirements));
button.setDisabled(() -> control.upgrades().hasWeapon(weapon) || !state.inventory.hasItems(requirements));
button.getStyle().imageUp = new TextureRegionDrawable(Draw.region(weapon.name));
button.addListener(tip);