More commands added to server, new logging

This commit is contained in:
Anuken
2018-01-28 14:18:21 -05:00
parent adfa66a73b
commit 205c4e723a
26 changed files with 308 additions and 178 deletions

View File

@@ -3,8 +3,8 @@ package io.anuke.mindustry;
import io.anuke.mindustry.core.*;
import io.anuke.mindustry.io.BlockLoader;
import io.anuke.mindustry.io.BundleLoader;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.modules.ModuleCore;
import io.anuke.ucore.util.Log;
import static io.anuke.mindustry.Vars.*;
@@ -12,6 +12,7 @@ public class Mindustry extends ModuleCore {
@Override
public void init(){
Log.setUseColors(false);
BundleLoader.load();
BlockLoader.load();
@@ -24,11 +25,4 @@ public class Mindustry extends ModuleCore {
module(netClient = new NetClient());
module(netCommon = new NetCommon());
}
//hack
@Override
public void render() {
super.render();
Inputs.update();
}
}

View File

@@ -7,9 +7,9 @@ import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
@@ -109,7 +109,7 @@ public class Pathfind{
/**Re-calculate paths for all enemies. Runs when a path changes while moving.*/
private void remakePath(){
for(int i = 0; i < enemyGroup.amount(); i ++){
for(int i = 0; i < enemyGroup.size(); i ++){
Enemy enemy = enemyGroup.all().get(i);
enemy.node = -1;
}
@@ -160,7 +160,7 @@ public class Pathfind{
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);
Log.info("Time elapsed: {0}ms\nAverage MS per path: {1}", Timers.elapsed(), Timers.elapsed()/amount);
}
/**Reset and clear the paths.*/

View File

@@ -2,7 +2,6 @@ package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
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.core.GameState.State;
@@ -20,8 +19,8 @@ import io.anuke.mindustry.net.NetworkIO;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Map;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.BaseBulletType;
@@ -29,6 +28,7 @@ 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.Log;
import java.io.DataInputStream;
import java.io.IOException;
@@ -91,7 +91,7 @@ public class NetClient extends Module {
});
Net.handleClient(WorldData.class, data -> {
UCore.log("Recieved world data: " + data.stream.available() + " bytes.");
Log.info("Recieved world data: {0} bytes.", data.stream.available());
NetworkIO.loadWorld(data.stream);
player.set(world.getSpawnX(), world.getSpawnY());
@@ -101,12 +101,12 @@ public class NetClient extends Module {
});
Net.handleClient(CustomMapPacket.class, packet -> {
UCore.log("Recieved custom map: " + packet.stream.available() + " bytes.");
Log.info("Recieved custom map: {0} bytes.", packet.stream.available());
//custom map is always sent before world data
Pixmap pixmap = NetworkIO.loadMap(packet.stream);
Map map = NetworkIO.loadMap(packet.stream);
world.maps().setNetworkMap(pixmap);
world.maps().setNetworkMap(map);
MapAckPacket ack = new MapAckPacket();
Net.send(ack, SendMode.tcp);
@@ -128,7 +128,7 @@ public class NetClient extends Module {
if (entity == null || id == player.id) {
if (id != player.id) {
UCore.log("Requesting entity " + id, "group " + group.getType());
Log.info("Requesting entity {0}, group {1}.", id, group.getType().toString().replace("class io.anuke.mindustry.entities.", ""));
EntityRequestPacket req = new EntityRequestPacket();
req.id = id;
Net.send(req, SendMode.udp);
@@ -228,7 +228,7 @@ public class NetClient extends Module {
} catch (IOException e) {
throw new RuntimeException(e);
} catch (Exception e) {
UCore.error(e);
Log.err(e);
//do nothing else...
//TODO fix
}

View File

@@ -30,14 +30,20 @@ public class NetCommon extends Module {
});
Net.handle(PlacePacket.class, (packet) -> {
control.input().placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
if(headless)
world.placeBlock(packet.x, packet.y, Block.getByID(packet.block), packet.rotation);
else
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.handle(BreakPacket.class, (packet) -> {
control.input().breakBlockInternal(packet.x, packet.y, false);
if(headless)
world.removeBlock(world.tile(packet.x, packet.y));
else
control.input().breakBlockInternal(packet.x, packet.y, false);
});
Net.handle(ChatPacket.class, (packet) -> {

View File

@@ -16,12 +16,12 @@ 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.EntityGroup;
import io.anuke.ucore.modules.Module;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Mathf;
import java.io.ByteArrayInputStream;
@@ -41,7 +41,7 @@ public class NetServer extends Module{
public NetServer(){
Net.handleServer(Connect.class, (id, connect) -> UCore.log("Connection found: " + connect.addressTCP));
Net.handleServer(Connect.class, (id, connect) -> {});
Net.handleServer(ConnectPacket.class, (id, packet) -> {
@@ -50,7 +50,7 @@ public class NetServer extends Module{
return;
}
UCore.log("Sending world data to client (ID=" + id + ")");
Log.info("Sending world data to client (ID = {0})", id);
Player player = new Player();
player.clientid = id;
@@ -63,12 +63,12 @@ public class NetServer extends Module{
if(world.getMap().custom){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
NetworkIO.writeMap(world.getMap().pixmap, stream);
NetworkIO.writeMap(world.getMap(), stream);
CustomMapPacket data = new CustomMapPacket();
data.stream = new ByteArrayInputStream(stream.toByteArray());
Net.sendStream(id, data);
UCore.log("Sending custom map: Packed " + stream.size() + " uncompressed bytes of MAP data.");
Log.info("Sending custom map: Packed {0}uncompressed bytes of MAP data.", stream.size());
}else{
//hack-- simulate the map ack packet recieved to send the world data to the client.
Net.handleServerReceived(id, new MapAckPacket());
@@ -86,7 +86,7 @@ public class NetServer extends Module{
data.stream = new ByteArrayInputStream(stream.toByteArray());
Net.sendStream(id, data);
UCore.log("Packed " + stream.size() + " uncompressed bytes of WORLD data.");
Log.info("Packed {0} uncompressed bytes of WORLD data.", stream.size());
});
Net.handleServer(ConnectConfirmPacket.class, (id, packet) -> {
@@ -183,7 +183,6 @@ public class NetServer extends Module{
p.android = player.isAndroid;
Net.sendTo(dest, p, SendMode.tcp);
log("Replying to entity request (" + id + "): player, " + id);
} else if (enemyGroup.getByID(id) != null) {
Enemy enemy = enemyGroup.getByID(id);
EnemySpawnPacket e = new EnemySpawnPacket();
@@ -195,9 +194,8 @@ public class NetServer extends Module{
e.type = enemy.type.id;
e.health = (short) enemy.health;
Net.sendTo(dest, e, SendMode.tcp);
log("Replying to entity request(" + id + "): enemy, " + id);
} else {
Gdx.app.error("Mindustry", "Entity request target not found!");
Log.err("Entity request target not found!");
}
});
@@ -229,12 +227,12 @@ public class NetServer extends Module{
if(Timers.get("serverSync", serverSyncTime)){
//scan through all groups with syncable entities
for(EntityGroup<?> group : Entities.getAllGroups()) {
if(group.amount() == 0 || !(group.all().first() instanceof SyncEntity)) continue;
if(group.size() == 0 || !(group.all().first() instanceof SyncEntity)) continue;
//get write size for one entity (adding 4, as you need to write the ID as well)
int writesize = SyncEntity.getWriteSize((Class<? extends SyncEntity>)group.getType()) + 4;
//amount of entities
int amount = group.amount();
int amount = group.size();
//maximum amount of entities per packet
int maxsize = 64;
@@ -362,7 +360,6 @@ public class NetServer extends Module{
}
packet.stream = new ByteArrayInputStream(bs.toByteArray());
//UCore.log("Sent block update stream to " + client + " / " + packet.stream.available());
Net.sendStream(client, packet);
}

View File

@@ -253,7 +253,7 @@ public class Renderer extends RendererModule{
}
void drawShield(){
if(shieldGroup.amount() == 0 && shieldDraws.size == 0) return;
if(shieldGroup.size() == 0 && shieldDraws.size == 0) return;
Graphics.surface(renderer.shieldSurface, false);
Draw.color(Color.ROYAL);

View File

@@ -1,25 +1,32 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.ApplicationLogger;
import com.badlogic.gdx.Gdx;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Packets.ChatPacket;
import io.anuke.mindustry.world.Map;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Sounds;
import io.anuke.ucore.modules.Module;
import io.anuke.ucore.util.ColorCodes;
import io.anuke.ucore.util.CommandHandler;
import io.anuke.ucore.util.CommandHandler.Command;
import io.anuke.ucore.util.CommandHandler.Response;
import io.anuke.ucore.util.CommandHandler.ResponseType;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Strings;
import java.io.IOException;
import java.util.Scanner;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.ucore.util.ColorCodes.*;
import static io.anuke.ucore.util.Log.*;
;
public class ServerControl extends Module {
private final CommandHandler handler = new CommandHandler("");
@@ -29,11 +36,21 @@ public class ServerControl extends Module {
Effects.setEffectProvider((a, b, c, d, e) -> {});
Sounds.setHeadless(true);
//override default handling
//override default handling of chat packets
Net.handle(ChatPacket.class, (packet) -> {
info("&y" + (packet.name == null ? "" : packet.name) + ": &lb{0}", packet.text);
});
//don't do anything at all for GDX logging
Gdx.app.setApplicationLogger(new ApplicationLogger() {
@Override public void log(String tag, String message) { }
@Override public void log(String tag, String message, Throwable exception) { }
@Override public void error(String tag, String message) { }
@Override public void error(String tag, String message, Throwable exception) { }
@Override public void debug(String tag, String message) { }
@Override public void debug(String tag, String message, Throwable exception) { }
});
registerCommands();
Thread thread = new Thread(this::readCommands, "Server Controls");
thread.setDaemon(true);
@@ -61,9 +78,10 @@ public class ServerControl extends Module {
state.set(State.menu);
});
handler.register("host", "<mapname>", "Open the server with a specific map.", arg -> {
handler.register("host", "<mapname> <mode>", "Open the server with a specific map.", arg -> {
if(state.is(State.playing)){
err("Already hosting. Type 'stop' to stop hosting first.");
return;
}
String search = arg[0];
@@ -78,24 +96,102 @@ public class ServerControl extends Module {
return;
}
GameMode mode = null;
try{
mode = GameMode.valueOf(arg[1]);
}catch (IllegalArgumentException e){
err("No gamemode '{0}' found.", arg[1]);
return;
}
info("Loading map...");
state.mode = mode;
logic.reset();
world.loadMap(result);
state.set(State.playing);
info("Map loaded.");
try {
Net.host(port);
info("Server opened.");
}catch (IOException e){
UCore.error(e);
host();
});
handler.register("status", "", "Display server status.", arg -> {
if(state.is(State.menu)){
info("&lyStatus: &rserver closed");
}else{
info("&lyStatus: &lcPlaying on map &fi{0}&fb &lb/&lc Wave {1} &lb/&lcDifficulty {2}", Strings.capitalize(world.getMap().name), state.wave, state.difficulty.name());
if(playerGroup.size() > 0) {
info("&lyPlayers: {0}", playerGroup.size());
for (Player p : playerGroup.all()) {
print(" &y" + p.name);
}
}else{
info("&lyNo players connected.");
}
}
});
handler.register("say", "<message>", "Send a message to all players.", arg -> {
if(!state.is(State.playing)) {
err("Not hosting. Host a game first.");
return;
}
netCommon.sendMessage("[pink][[Server]:[] " + arg[0]);
info("&ly[Server]: &lb{0}", arg[0]);
}).mergeArgs();
handler.register("difficulty", "<difficulty>", "Set game difficulty.", arg -> {
try{
Difficulty diff = Difficulty.valueOf(arg[0]);
state.difficulty = diff;
info("Difficulty set to '{0}'.", arg[0]);
}catch (IllegalArgumentException e){
err("No difficulty with name '{0}' found.", arg[0]);
}
});
handler.register("load", "<slot>", "Load a save from a slot.", arg -> {
if(state.is(State.playing)){
err("Already hosting. Type 'stop' to stop hosting first.");
return;
}else if(!Strings.canParseInt(arg[0])){
err("Invalid save slot '{0}'.", arg[0]);
return;
}
int slot = Strings.parseInt(arg[0]);
if(!SaveIO.isSaveValid(slot)){
err("No save data found for slot.");
return;
}
SaveIO.loadFromSlot(slot);
info("Save loaded.");
host();
state.set(State.playing);
});
handler.register("save", "<slot>", "Save game state to a slot.", arg -> {
if(!state.is(State.playing)){
err("Not hosting. Host a game first.");
return;
}else if(!Strings.canParseInt(arg[0])){
err("Invalid save slot '{0}'.", arg[0]);
return;
}
int slot = Strings.parseInt(arg[0]);
SaveIO.saveToSlot(slot);
info("Saved to slot {0}.", slot);
});
}
private void readCommands(){
Scanner scan = new Scanner(System.in);
System.out.print(LIGHT_BLUE + "> " + RESET);
while(true){
String line = scan.nextLine();
@@ -107,32 +203,16 @@ public class ServerControl extends Module {
} else if (response.type == ResponseType.invalidArguments) {
err("Invalid command arguments. Usage: " + response.command.text + " " + response.command.params);
}
System.out.print(LIGHT_BLUE + "> " + RESET);
});
}
}
private void print(String text, Object... args){
System.out.println(format(text, args) + RESET);
}
private void info(String text, Object... args){
print(LIGHT_GREEN + BOLD + format(text, args));
}
private void err(String text, Object... args){
print(LIGHT_RED + BOLD + format(text, args));
}
private String format(String text, Object... args){
for(int i = 0; i < args.length; i ++){
text = text.replace("{" + i + "}", args[i].toString());
private void host(){
try {
Net.host(port);
}catch (IOException e){
Log.err(e);
state.set(State.menu);
}
for(String color : ColorCodes.getColorCodes()){
text = text.replace("&" + color, ColorCodes.getColorText(color));
}
return text;
}
}

View File

@@ -4,7 +4,7 @@ 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;
import io.anuke.ucore.util.Log;
public class BlockLoader {
static final ObjectIntMap<String> defaultMap = map(
@@ -123,7 +123,7 @@ public class BlockLoader {
blockmap.put(defaultMap.get(string, -1), block);
}
UCore.log("Total blocks loaded: " + Block.getAllBlocks().size);
Log.info("Total blocks loaded: {0}", Block.getAllBlocks().size);
}
public static Block getByOldID(int id){

View File

@@ -3,12 +3,14 @@ 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 io.anuke.ucore.util.Log;
import java.util.Locale;
import static io.anuke.mindustry.Vars.headless;
public class BundleLoader {
private static boolean externalBundle = false;
@@ -18,7 +20,6 @@ public class BundleLoader {
loadBundle();
}
private static Locale getLocale(){
String loc = Settings.getString("locale");
if(loc.equals("default")){
@@ -46,7 +47,7 @@ public class BundleLoader {
Locale locale = Locale.ENGLISH;
Core.bundle = I18NBundle.createBundle(handle, locale);
}catch (Exception e){
UCore.error(e);
Log.err(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();
@@ -55,7 +56,7 @@ public class BundleLoader {
FileHandle handle = Gdx.files.internal("bundles/bundle");
Locale locale = getLocale();
UCore.log("Got locale: " + locale);
if(!headless) Log.info("Got locale: {0}", locale);
Core.bundle = I18NBundle.createBundle(handle, locale);
}
}

View File

@@ -9,9 +9,9 @@ import com.badlogic.gdx.utils.*;
import com.badlogic.gdx.utils.Json.Serializer;
import com.badlogic.gdx.utils.JsonWriter.OutputType;
import io.anuke.mindustry.world.Map;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.graphics.Pixmaps;
import io.anuke.ucore.util.Log;
import static io.anuke.mindustry.Vars.*;
@@ -32,17 +32,13 @@ public class Maps implements Disposable{
return maps.values();
}
public void setNetworkMap(Pixmap pixmap){
public void setNetworkMap(Map map){
if(networkMap != null){
networkMap.pixmap.dispose();
networkMap = null;
}
networkMap = new Map();
networkMap.custom = true;
networkMap.pixmap = pixmap;
networkMap.visible = false;
networkMap.name = "network map";
networkMap.id = -1;
networkMap = map;
}
public Map getMap(int id){
@@ -155,7 +151,7 @@ public class Maps implements Disposable{
}
return true;
}catch(Exception e){
if(!android) UCore.error(e);
if(!android) Log.err(e);
Gdx.app.error("Mindustry-Maps", "Failed loading map file: " + file);
return false;
}

View File

@@ -66,26 +66,31 @@ public class Save15 extends SaveFileVersion {
int playerhealth = stream.readInt();
player.x = playerx;
player.y = playery;
player.health = playerhealth;
state.mode = GameMode.values()[mode];
Core.camera.position.set(playerx, playery, 0);
if(!headless) {
player.x = playerx;
player.y = playery;
player.health = playerhealth;
state.mode = GameMode.values()[mode];
Core.camera.position.set(playerx, playery, 0);
//weapons
//weapons
control.upgrades().getWeapons().clear();
control.upgrades().getWeapons().add(Weapon.blaster);
player.weaponLeft = player.weaponRight = Weapon.blaster;
control.upgrades().getWeapons().clear();
control.upgrades().getWeapons().add(Weapon.blaster);
player.weaponLeft = player.weaponRight = Weapon.blaster;
int weapons = stream.readByte();
int weapons = stream.readByte();
for(int i = 0; i < weapons; i ++){
control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
for (int i = 0; i < weapons; i++) {
control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
}
ui.hudfrag.updateWeapons();
}else{
byte b = stream.readByte();
for(int i = 0; i < b; i ++) stream.readByte();
}
ui.hudfrag.updateWeapons();
//inventory
int totalItems = stream.readByte();
@@ -98,7 +103,7 @@ public class Save15 extends SaveFileVersion {
state.inventory.getItems()[item.id] = amount;
}
ui.hudfrag.updateItems();
if(!headless) ui.hudfrag.updateItems();
//enemies
@@ -134,7 +139,7 @@ public class Save15 extends SaveFileVersion {
state.wave = wave;
state.wavetime = wavetime;
if(!android)
if(!android && !headless)
player.add();
//map
@@ -142,7 +147,7 @@ public class Save15 extends SaveFileVersion {
int seed = stream.readInt();
world.loadMap(world.maps().getMap(mapid), seed);
renderer.clearTiles();
if(!headless) renderer.clearTiles();
for(Enemy enemy : enemiesToUpdate){
enemy.node = -2;
@@ -225,16 +230,23 @@ public class Save15 extends SaveFileVersion {
stream.writeShort(block.id);
}
stream.writeFloat(player.x); //player x/y
stream.writeFloat(player.y);
if(!headless) {
stream.writeFloat(player.x); //player x/y
stream.writeFloat(player.y);
stream.writeInt(player.health); //player health
stream.writeInt(player.health); //player health
stream.writeByte(control.upgrades().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 < control.upgrades().getWeapons().size; i ++){
stream.writeByte(control.upgrades().getWeapons().get(i).id); //weapon ordinal
//start at 1, because the first weapon is always the starter - ignore that
for (int i = 1; i < control.upgrades().getWeapons().size; i++) {
stream.writeByte(control.upgrades().getWeapons().get(i).id); //weapon ordinal
}
}else{
stream.writeFloat(0);
stream.writeFloat(0);
stream.writeInt(0);
stream.writeByte(0);
}
//--INVENTORY--

View File

@@ -12,7 +12,6 @@ import io.anuke.mindustry.world.ColorMapper.BlockPair;
import io.anuke.mindustry.world.Map;
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.core.Timers;
import io.anuke.ucore.graphics.Draw;
@@ -24,6 +23,7 @@ import io.anuke.ucore.scene.builders.table;
import io.anuke.ucore.scene.ui.*;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Strings;
import java.util.Arrays;
@@ -63,7 +63,7 @@ public class MapEditorDialog extends Dialog{
}
}catch (Exception e){
ui.showError(Bundles.format("text.editor.errorimageload", Strings.parseException(e, false)));
UCore.error(e);
Log.err(e);
}
ui.loadfrag.hide();
});
@@ -80,7 +80,7 @@ public class MapEditorDialog extends Dialog{
Pixmaps.write(editor.pixmap(), result);
}catch (Exception e){
ui.showError(Bundles.format("text.editor.errorimagesave", Strings.parseException(e, false)));
if(!android) UCore.error(e);
if(!android) Log.err(e);
}
ui.loadfrag.hide();
});
@@ -96,6 +96,7 @@ public class MapEditorDialog extends Dialog{
copy.id = -1;
copy.pixmap = Pixmaps.copy(map.pixmap);
copy.texture = new Texture(copy.pixmap);
copy.oreGen = map.oreGen;
editor.beginEdit(copy);
ui.loadfrag.hide();
view.clearStack();
@@ -277,8 +278,16 @@ public class MapEditorDialog extends Dialog{
new label(() -> Bundles.format("text.editor.brushsize", MapEditor.brushSizes[(int)slider.getValue()])).left();
row();
add(slider).growX().padTop(4f);
}}.growX().end();
}}.growX().padBottom(-6).end();
row();
new table("button"){{
get().addCheck("$text.oregen", b -> {
editor.getMap().oreGen = b;
}).update(c -> c.setChecked(editor.getMap().oreGen)).padTop(3).padBottom(3);
}}.growX().padBottom(-6).end();
row();
addBlockSelection(get());
@@ -362,7 +371,7 @@ public class MapEditorDialog extends Dialog{
Table extra = new Table("button");
extra.labelWrap(() -> editor.getDrawBlock().formalName).width(180f).center();
table.add(extra).growX();
table.add(extra).padBottom(-6).growX();
table.row();
table.add(pane).growY().fillX();
}

View File

@@ -4,14 +4,15 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.reflect.ClassReflection;
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.function.BiConsumer;
import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.util.Log;
import java.io.IOException;
@@ -37,7 +38,7 @@ public class Net{
if(!headless){
ui.showError(text);
}else{
UCore.log(text);
Log.err(text);
}
}
@@ -92,9 +93,9 @@ public class Net{
/**Send an object to all connected clients, or to the server if this is a client.*/
public static void send(Object object, SendMode mode){
if(server){
serverProvider.send(object, mode);
if(serverProvider != null) serverProvider.send(object, mode);
}else {
clientProvider.send(object, mode);
if(clientProvider != null) clientProvider.send(object, mode);
}
}
@@ -160,7 +161,7 @@ public class Net{
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.");
Log.info("Recieved {0}, but ignoring data, as client is not loaded.", ClassReflection.getSimpleName(object.getClass()));
}
}else{
Gdx.app.error("Mindustry::Net", "Unhandled packet type: '" + object.getClass() + "'!");

View File

@@ -7,10 +7,7 @@ import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.ColorMapper;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.WorldGenerator;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.types.BlockPart;
import io.anuke.mindustry.world.blocks.types.Rock;
@@ -23,8 +20,10 @@ import static io.anuke.mindustry.Vars.*;
public class NetworkIO {
public static void writeMap(Pixmap map, OutputStream os){
public static void writeMap(Map map, OutputStream os){
try(DataOutputStream stream = new DataOutputStream(os)){
stream.writeBoolean(map.oreGen);
stream.writeShort(map.getWidth());
stream.writeShort(map.getHeight());
@@ -33,7 +32,7 @@ public class NetworkIO {
int pos = 0;
while(pos < cap){
int color = map.getPixel(pos % width, pos / width);
int color = map.pixmap.getPixel(pos % width, pos / width);
byte id = ColorMapper.getColorID(color);
int length = 1;
@@ -44,7 +43,7 @@ public class NetworkIO {
pos ++;
int next = map.getPixel(pos % width, pos / width);
int next = map.pixmap.getPixel(pos % width, pos / width);
if(next != color){
pos --;
break;
@@ -64,8 +63,10 @@ public class NetworkIO {
}
}
public static Pixmap loadMap(InputStream is){
public static Map loadMap(InputStream is){
try(DataInputStream stream = new DataInputStream(is)){
boolean ores = stream.readBoolean();
short width = stream.readShort();
short height = stream.readShort();
Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888);
@@ -83,8 +84,15 @@ public class NetworkIO {
}
}
Map map = new Map();
map.oreGen = ores;
map.custom = true;
map.pixmap = pixmap;
map.visible = false;
map.name = "network map";
map.id = -1;
return pixmap;
return map;
}catch (IOException e){
throw new RuntimeException(e);
}

View File

@@ -5,7 +5,6 @@ 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;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.style.Drawable;
@@ -14,6 +13,7 @@ import io.anuke.ucore.scene.ui.ScrollPane;
import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.ui;
@@ -238,7 +238,7 @@ public class JoinDialog extends FloatingDialog {
ui.showError(Bundles.format("text.connectfail", error));
ui.loadfrag.hide();
UCore.error(e);
Log.err(e);
}
});
}

View File

@@ -1,16 +1,17 @@
package io.anuke.mindustry.ui.dialogs;
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;
import io.anuke.ucore.scene.ui.ScrollPane;
import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Log;
import java.util.Locale;
import static io.anuke.mindustry.Vars.ui;
public class LanguageDialog extends FloatingDialog{
private Locale[] locales = {Locale.ENGLISH, new Locale("fr", "FR"),
new Locale("es", "LA"), new Locale("pt", "BR"), new Locale("ko"), new Locale("in", "ID")};
@@ -36,7 +37,7 @@ public class LanguageDialog extends FloatingDialog{
if(ui.getLocale().equals(loc)) return;
Settings.putString("locale", loc.toString());
Settings.save();
UCore.log("Setting locale: " + loc.toString());
Log.info("Setting locale: {0}", loc.toString());
ui.showInfo("$text.language.restart");
});
langs.add(button).group(group).update(t -> {

View File

@@ -4,13 +4,13 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.io.Saves.SaveSlot;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.ui.ScrollPane;
import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Strings;
import java.io.IOException;
@@ -163,7 +163,7 @@ public class LoadDialog extends FloatingDialog{
state.set(State.playing);
ui.paused.hide();
}catch(Exception e){
UCore.error(e);
Log.err(e);
ui.paused.hide();
state.set(State.menu);
logic.reset();

View File

@@ -156,9 +156,9 @@ public class HudFragment implements Fragment{
row();
new label(() -> "[blue]requests: " + renderer.getBlocks().getRequests()).left();
row();
new label(() -> "[purple]tiles: " + tileGroup.amount()).left();
new label(() -> "[purple]tiles: " + tileGroup.size()).left();
row();
new label(() -> "[purple]enemies: " + enemyGroup.amount()).left();
new label(() -> "[purple]enemies: " + enemyGroup.size()).left();
row();
new label(() -> "[orange]noclip: " + noclip).left();
row();
@@ -178,7 +178,7 @@ public class HudFragment implements Fragment{
if(debugNet) {
new table() {{
new label(() -> "players: " + playerGroup.amount());
new label(() -> "players: " + playerGroup.size());
row();
new label(() -> "" + playerGroup.all());
}}.end();

View File

@@ -26,8 +26,8 @@ public class PlayerListFragment implements Fragment{
new table(){{
new table("pane"){{
margin(14f);
new label(() -> Bundles.format(playerGroup.amount() == 1 ? "text.players.single" :
"text.players", playerGroup.amount()));
new label(() -> Bundles.format(playerGroup.size() == 1 ? "text.players.single" :
"text.players", playerGroup.size()));
row();
content.marginRight(13f).marginLeft(13f);
ScrollPane pane = new ScrollPane(content, "clear");
@@ -51,9 +51,9 @@ public class PlayerListFragment implements Fragment{
if(!(Net.active() && !state.is(State.menu))){
visible = false;
}
if(playerGroup.amount() != last){
if(playerGroup.size() != last){
rebuild();
last = playerGroup.amount();
last = playerGroup.size();
}
});

View File

@@ -3,8 +3,8 @@ package io.anuke.mindustry.world.blocks.types.distribution;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Log;
public class TunnelConveyor extends Block{
protected int maxdist = 3;
@@ -32,10 +32,11 @@ public class TunnelConveyor extends Block{
Timers.run(25, () -> {
if(to.block() != before) return;
//TODO fix
try {
to.block().handleItem(item, to, tunnel);
}catch (NullPointerException e){
UCore.error(e);
Log.err(e);
}
});
}