Bugfixes, added saving/loading maps in editor for web version

This commit is contained in:
Anuken
2018-05-31 23:49:43 -04:00
parent 418467e467
commit 23d07600f7
10 changed files with 103 additions and 68 deletions

View File

@@ -86,7 +86,7 @@ project(":desktop") {
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-controllers-lwjgl3:$gdxVersion" compile "com.badlogicgames.gdx:gdx-controllers-lwjgl3:$gdxVersion"
compile 'com.github.MinnDevelopment:java-discord-rpc:v2.0.0' compile 'com.github.MinnDevelopment:java-discord-rpc:v2.0.0'
compile 'com.yuvimasory:orange-extensions:1.3.0' //compile 'com.yuvimasory:orange-extensions:1.3.0'
} }
} }
@@ -149,7 +149,7 @@ project(":core") {
apply plugin: "java" apply plugin: "java"
dependencies { dependencies {
compile project(":annotations") //compileOnly project(":annotations")
boolean comp = System.properties["release"] == null || System.properties["release"] == "false" boolean comp = System.properties["release"] == null || System.properties["release"] == "false"
@@ -174,9 +174,9 @@ project(":core") {
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion" compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
} }
compileJava.options.compilerArgs = [ //compileJava.options.compilerArgs = [
"-processor", "io.anuke.annotations.AnnotationProcessor" // "-processor", "io.anuke.annotations.AnnotationProcessor"
] //]
} }
project(":server") { project(":server") {

View File

@@ -9,7 +9,6 @@ import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.SyncEntity; import io.anuke.mindustry.entities.SyncEntity;
import io.anuke.mindustry.entities.bullet.BulletType; import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.gen.CallServer;
import io.anuke.mindustry.io.Version; import io.anuke.mindustry.io.Version;
import io.anuke.mindustry.net.*; import io.anuke.mindustry.net.*;
import io.anuke.mindustry.net.Administration.PlayerInfo; import io.anuke.mindustry.net.Administration.PlayerInfo;
@@ -161,7 +160,8 @@ public class NetServer extends Module{
}); });
Net.handleServer(InvokePacket.class, (id, packet) -> { Net.handleServer(InvokePacket.class, (id, packet) -> {
CallServer.readPacket(packet.writeBuffer, packet.type, connections.get(id)); //TODO implement
//CallServer.readPacket(packet.writeBuffer, packet.type, connections.get(id));
}); });
Net.handleServer(EntityShootPacket.class, (id, packet) -> { Net.handleServer(EntityShootPacket.class, (id, packet) -> {

View File

@@ -39,9 +39,7 @@ import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings; import io.anuke.ucore.util.Strings;
import java.io.DataInputStream; import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
@@ -134,22 +132,33 @@ public class MapEditorDialog extends Dialog implements Disposable{
t.addImageTextButton("$text.editor.export", "icon-save-map", isize, () -> createDialog("$text.editor.export", t.addImageTextButton("$text.editor.export", "icon-save-map", isize, () -> createDialog("$text.editor.export",
"$text.editor.exportfile", "$text.editor.exportfile.description", "icon-file", (Listenable)() -> { "$text.editor.exportfile", "$text.editor.exportfile.description", "icon-file", (Listenable)() -> {
Platform.instance.showFileChooser("$text.saveimage", "Map Files", file -> { if(!gwt) {
file = file.parent().child(file.nameWithoutExtension() + "." + mapExtension); Platform.instance.showFileChooser("$text.saveimage", "Map Files", file -> {
FileHandle result = file; file = file.parent().child(file.nameWithoutExtension() + "." + mapExtension);
ui.loadAnd(() -> { FileHandle result = file;
ui.loadAnd(() -> {
try{ try {
if(!editor.getTags().containsKey("name")){ if (!editor.getTags().containsKey("name")) {
editor.getTags().put("name", result.nameWithoutExtension()); editor.getTags().put("name", result.nameWithoutExtension());
}
MapIO.writeMap(result.write(false), editor.getTags(), editor.getMap());
} catch (Exception e) {
ui.showError(Bundles.format("text.editor.errorimagesave", Strings.parseException(e, false)));
Log.err(e);
} }
MapIO.writeMap(result.write(false), editor.getTags(), editor.getMap()); });
}catch (Exception e){ }, false, mapExtension);
ui.showError(Bundles.format("text.editor.errorimagesave", Strings.parseException(e, false))); }else{
Log.err(e); try {
} ByteArrayOutputStream ba = new ByteArrayOutputStream();
}); MapIO.writeMap(ba, editor.getTags(), editor.getMap());
}, false, mapExtension); Platform.instance.downloadFile(editor.getTags().get("name", "unknown") + "." + mapExtension, ba.toByteArray());
}catch (IOException e){
ui.showError(Bundles.format("text.editor.errorimagesave", Strings.parseException(e, false)));
Log.err(e);
}
}
}, },
"$text.editor.exportimage", "$text.editor.exportimage.description", "icon-file-image", (Listenable)() -> { "$text.editor.exportimage", "$text.editor.exportimage.description", "icon-file-image", (Listenable)() -> {
if(gwt){ if(gwt){

View File

@@ -1,9 +1,6 @@
package io.anuke.mindustry.net; package io.anuke.mindustry.net;
import com.badlogic.gdx.utils.Pools; import com.badlogic.gdx.utils.Pools;
import io.anuke.annotations.Annotations.Local;
import io.anuke.annotations.Annotations.RemoteClient;
import io.anuke.annotations.Annotations.RemoteServer;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.SyncEntity; import io.anuke.mindustry.entities.SyncEntity;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
@@ -18,25 +15,6 @@ import static io.anuke.mindustry.Vars.*;
public class NetEvents { public class NetEvents {
@RemoteClient
@Local
public static void friendlyFireChange(boolean enabled){
state.friendlyFire = enabled;
if(Net.server()) netCommon.sendMessage(enabled ? "[accent]Friendly fire enabled." : "[accent]Friendly fire disabled.");
}
@RemoteServer
public static void notifySomethingFromClient(Player player, int x, float y, String asdsad, long l){
}
@RemoteClient
@Local
public static void notifySomethingFromServerLocal(int y, float x, boolean w){
}
public static void handleGameOver(){ public static void handleGameOver(){
Net.send(Pools.obtain(GameOverPacket.class), SendMode.tcp); Net.send(Pools.obtain(GameOverPacket.class), SendMode.tcp);
} }
@@ -128,12 +106,6 @@ public class NetEvents {
Net.send(packet, SendMode.tcp); Net.send(packet, SendMode.tcp);
} }
@RemoteClient
@Local
public static void adminSet(Player player, boolean admin){
player.isAdmin = admin;
}
public static void handleAdministerRequest(Player target, AdminAction action){ public static void handleAdministerRequest(Player target, AdminAction action){
AdministerRequestPacket packet = Pools.obtain(AdministerRequestPacket.class); AdministerRequestPacket packet = Pools.obtain(AdministerRequestPacket.class);
packet.id = target.id; packet.id = target.id;

View File

@@ -7,7 +7,6 @@ import com.badlogic.gdx.utils.reflect.ReflectionException;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.SyncEntity; import io.anuke.mindustry.entities.SyncEntity;
import io.anuke.mindustry.gen.CallClient;
import io.anuke.mindustry.io.Version; import io.anuke.mindustry.io.Version;
import io.anuke.mindustry.net.Packet.ImportantPacket; import io.anuke.mindustry.net.Packet.ImportantPacket;
import io.anuke.mindustry.net.Packet.UnimportantPacket; import io.anuke.mindustry.net.Packet.UnimportantPacket;
@@ -42,7 +41,8 @@ public class Packets {
type = buffer.get(); type = buffer.get();
if(Net.client()){ if(Net.client()){
CallClient.readPacket(buffer, type); //TODO implement
//CallClient.readPacket(buffer, type);
}else{ }else{
byte[] bytes = new byte[writeLength]; byte[] bytes = new byte[writeLength];
buffer.get(bytes); buffer.get(bytes);

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.ui.dialogs; package io.anuke.mindustry.ui.dialogs;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.gen.CallClient;
import io.anuke.mindustry.net.Administration.PlayerInfo; import io.anuke.mindustry.net.Administration.PlayerInfo;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetConnection; import io.anuke.mindustry.net.NetConnection;
@@ -49,7 +48,7 @@ public class AdminsDialog extends FloatingDialog {
for(Player player : playerGroup.all()){ for(Player player : playerGroup.all()){
NetConnection c = Net.getConnection(player.clientid); NetConnection c = Net.getConnection(player.clientid);
if(c != null){ if(c != null){
CallClient.adminSet(player, false); //CallClient.adminSet(player, false);
break; break;
} }
} }

View File

@@ -3,7 +3,6 @@ package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.gen.CallClient;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetConnection; import io.anuke.mindustry.net.NetConnection;
import io.anuke.mindustry.net.NetEvents; import io.anuke.mindustry.net.NetEvents;
@@ -161,12 +160,12 @@ public class PlayerListFragment implements Fragment{
if(netServer.admins.isAdmin(id, connection.address)){ if(netServer.admins.isAdmin(id, connection.address)){
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> { ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
netServer.admins.unAdminPlayer(id); netServer.admins.unAdminPlayer(id);
CallClient.adminSet(player, false); //CallClient.adminSet(player, false);
}); });
}else{ }else{
ui.showConfirm("$text.confirm", "$text.confirmadmin", () -> { ui.showConfirm("$text.confirm", "$text.confirmadmin", () -> {
netServer.admins.adminPlayer(id, connection.address); netServer.admins.adminPlayer(id, connection.address);
CallClient.adminSet(player, true); //CallClient.adminSet(player, true);
}); });
} }
}).update(b ->{ }).update(b ->{

View File

@@ -1,6 +1,5 @@
#Sun May 20 12:43:04 EDT 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

View File

@@ -1,7 +1,7 @@
apply plugin: "java" apply plugin: "java"
gwt { gwt {
gwtVersion='2.8.2' // Should match the gwt version used for building the gwt backend gwtVersion='2.8.0' // Should match the gwt version used for building the gwt backend
maxHeapSize="2G" // Default 256m is not enough for gwt compiler. GWT is HUNGRY maxHeapSize="2G" // Default 256m is not enough for gwt compiler. GWT is HUNGRY
minHeapSize="1G" minHeapSize="1G"

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.backends.gwt.GwtApplication;
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration; import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback; import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState; import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Base64Coder; import com.badlogic.gdx.utils.Base64Coder;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Document;
@@ -19,7 +20,10 @@ import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.core.Platform; import io.anuke.mindustry.core.Platform;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.ucore.core.Settings; import io.anuke.ucore.core.Settings;
import io.anuke.ucore.function.Consumer;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Date; import java.util.Date;
import java.util.Random; import java.util.Random;
@@ -27,7 +31,7 @@ public class HtmlLauncher extends GwtApplication {
static final int WIDTH = 800; static final int WIDTH = 800;
static final int HEIGHT = 600; static final int HEIGHT = 600;
static HtmlLauncher instance; static HtmlLauncher instance;
boolean canJoin = true; static Consumer<FileHandle> fileCons;
@Override @Override
public PreloaderCallback getPreloaderCallback () { public PreloaderCallback getPreloaderCallback () {
@@ -46,7 +50,6 @@ public class HtmlLauncher extends GwtApplication {
preloaderPanel.add(meterPanel); preloaderPanel.add(meterPanel);
getRootPanel().add(preloaderPanel); getRootPanel().add(preloaderPanel);
return new PreloaderCallback() { return new PreloaderCallback() {
@Override @Override
public void error (String file) { public void error (String file) {
System.out.println("error: " + file); System.out.println("error: " + file);
@@ -55,8 +58,7 @@ public class HtmlLauncher extends GwtApplication {
@Override @Override
public void update (PreloaderState state) { public void update (PreloaderState state) {
meterStyle.setWidth(100f * state.getProgress(), Unit.PCT); meterStyle.setWidth(100f * state.getProgress(), Unit.PCT);
} }
}; };
} }
@@ -99,8 +101,16 @@ public class HtmlLauncher extends GwtApplication {
Platform.instance = new Platform(){ Platform.instance = new Platform(){
DateTimeFormat format = DateTimeFormat.getFormat("EEE, dd MMM yyyy HH:mm:ss"); DateTimeFormat format = DateTimeFormat.getFormat("EEE, dd MMM yyyy HH:mm:ss");
@Override @Override
public void showFileChooser(String text, String content, Consumer<FileHandle> cons, boolean open, String filetype) {
if(!open) return; //can't save files on gwt
fileCons = cons;
createFileChooser();
}
@Override
public String format(Date date){ public String format(Date date){
return format.format(date); return format.format(date);
} }
@@ -131,6 +141,11 @@ public class HtmlLauncher extends GwtApplication {
} }
return Base64Coder.decode(uuid); return Base64Coder.decode(uuid);
} }
@Override
public void downloadFile(String name, byte[] bytes) {
downloadBytes(name, new String(Base64Coder.encode(bytes)));
}
}; };
return new Mindustry(); return new Mindustry();
@@ -165,6 +180,38 @@ public class HtmlLauncher extends GwtApplication {
} }
} }
native void createFileChooser() /*-{
function getBase64(file, callback) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(){ callback(reader.result); }
reader.onerror = function(error){ console.log(error); }
}
var input = document.createElement('input');
input.type = 'file';
input.onchange = function() {
getBase64(input.files[0], function(data){ @io.anuke.mindustry.client.HtmlLauncher::handleFileSelect(Ljava/lang/String;)(data); });
};
input.click();
}-*/;
native void downloadBytes(String name, String base64) /*-{
var binaryString = window.atob(base64);
var binaryLen = binaryString.length;
var bytes = new Uint8Array(binaryLen);
for (var i = 0; i < binaryLen; i++) {
var ascii = binaryString.charCodeAt(i);
bytes[i] = ascii;
}
var blob = new Blob([bytes]);
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = name;
link.click();
}-*/;
native int getWindowInnerWidth() /*-{ native int getWindowInnerWidth() /*-{
return $wnd.innerWidth; return $wnd.innerWidth;
}-*/; }-*/;
@@ -181,4 +228,14 @@ public class HtmlLauncher extends GwtApplication {
public static void handleResize() { public static void handleResize() {
instance.scaleCanvas(); instance.scaleCanvas();
} }
public static void handleFileSelect(String base64){
ByteArrayInputStream stream = new ByteArrayInputStream(Base64Coder.decode(base64.substring("data:;base64,".length())));
fileCons.accept(new FileHandle(){
@Override
public InputStream read() {
return stream;
}
});
}
} }