mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-31 01:44:22 +07:00
Bugfixes, added saving/loading maps in editor for web version
This commit is contained in:
parent
418467e467
commit
23d07600f7
10
build.gradle
10
build.gradle
@ -86,7 +86,7 @@ project(":desktop") {
|
||||
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
||||
compile "com.badlogicgames.gdx:gdx-controllers-lwjgl3:$gdxVersion"
|
||||
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"
|
||||
|
||||
dependencies {
|
||||
compile project(":annotations")
|
||||
//compileOnly project(":annotations")
|
||||
|
||||
boolean comp = System.properties["release"] == null || System.properties["release"] == "false"
|
||||
|
||||
@ -174,9 +174,9 @@ project(":core") {
|
||||
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
|
||||
}
|
||||
|
||||
compileJava.options.compilerArgs = [
|
||||
"-processor", "io.anuke.annotations.AnnotationProcessor"
|
||||
]
|
||||
//compileJava.options.compilerArgs = [
|
||||
// "-processor", "io.anuke.annotations.AnnotationProcessor"
|
||||
//]
|
||||
}
|
||||
|
||||
project(":server") {
|
||||
|
@ -9,7 +9,6 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.gen.CallServer;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
import io.anuke.mindustry.net.*;
|
||||
import io.anuke.mindustry.net.Administration.PlayerInfo;
|
||||
@ -161,7 +160,8 @@ public class NetServer extends Module{
|
||||
});
|
||||
|
||||
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) -> {
|
||||
|
@ -39,9 +39,7 @@ import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
|
||||
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",
|
||||
"$text.editor.exportfile", "$text.editor.exportfile.description", "icon-file", (Listenable)() -> {
|
||||
Platform.instance.showFileChooser("$text.saveimage", "Map Files", file -> {
|
||||
file = file.parent().child(file.nameWithoutExtension() + "." + mapExtension);
|
||||
FileHandle result = file;
|
||||
ui.loadAnd(() -> {
|
||||
if(!gwt) {
|
||||
Platform.instance.showFileChooser("$text.saveimage", "Map Files", file -> {
|
||||
file = file.parent().child(file.nameWithoutExtension() + "." + mapExtension);
|
||||
FileHandle result = file;
|
||||
ui.loadAnd(() -> {
|
||||
|
||||
try{
|
||||
if(!editor.getTags().containsKey("name")){
|
||||
editor.getTags().put("name", result.nameWithoutExtension());
|
||||
try {
|
||||
if (!editor.getTags().containsKey("name")) {
|
||||
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){
|
||||
ui.showError(Bundles.format("text.editor.errorimagesave", Strings.parseException(e, false)));
|
||||
Log.err(e);
|
||||
}
|
||||
});
|
||||
}, false, mapExtension);
|
||||
});
|
||||
}, false, mapExtension);
|
||||
}else{
|
||||
try {
|
||||
ByteArrayOutputStream ba = new ByteArrayOutputStream();
|
||||
MapIO.writeMap(ba, editor.getTags(), editor.getMap());
|
||||
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)() -> {
|
||||
if(gwt){
|
||||
|
@ -1,9 +1,6 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
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.SyncEntity;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
@ -18,25 +15,6 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
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(){
|
||||
Net.send(Pools.obtain(GameOverPacket.class), SendMode.tcp);
|
||||
}
|
||||
@ -128,12 +106,6 @@ public class NetEvents {
|
||||
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){
|
||||
AdministerRequestPacket packet = Pools.obtain(AdministerRequestPacket.class);
|
||||
packet.id = target.id;
|
||||
|
@ -7,7 +7,6 @@ import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.gen.CallClient;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||
@ -42,7 +41,8 @@ public class Packets {
|
||||
type = buffer.get();
|
||||
|
||||
if(Net.client()){
|
||||
CallClient.readPacket(buffer, type);
|
||||
//TODO implement
|
||||
//CallClient.readPacket(buffer, type);
|
||||
}else{
|
||||
byte[] bytes = new byte[writeLength];
|
||||
buffer.get(bytes);
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.gen.CallClient;
|
||||
import io.anuke.mindustry.net.Administration.PlayerInfo;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
@ -49,7 +48,7 @@ public class AdminsDialog extends FloatingDialog {
|
||||
for(Player player : playerGroup.all()){
|
||||
NetConnection c = Net.getConnection(player.clientid);
|
||||
if(c != null){
|
||||
CallClient.adminSet(player, false);
|
||||
//CallClient.adminSet(player, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package io.anuke.mindustry.ui.fragments;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.gen.CallClient;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
@ -161,12 +160,12 @@ public class PlayerListFragment implements Fragment{
|
||||
if(netServer.admins.isAdmin(id, connection.address)){
|
||||
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
|
||||
netServer.admins.unAdminPlayer(id);
|
||||
CallClient.adminSet(player, false);
|
||||
//CallClient.adminSet(player, false);
|
||||
});
|
||||
}else{
|
||||
ui.showConfirm("$text.confirm", "$text.confirmadmin", () -> {
|
||||
netServer.admins.adminPlayer(id, connection.address);
|
||||
CallClient.adminSet(player, true);
|
||||
//CallClient.adminSet(player, true);
|
||||
});
|
||||
}
|
||||
}).update(b ->{
|
||||
|
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,5 @@
|
||||
#Sun May 20 12:43:04 EDT 2018
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
|
||||
|
@ -1,7 +1,7 @@
|
||||
apply plugin: "java"
|
||||
|
||||
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
|
||||
minHeapSize="1G"
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
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.net.Net;
|
||||
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.Random;
|
||||
|
||||
@ -27,7 +31,7 @@ public class HtmlLauncher extends GwtApplication {
|
||||
static final int WIDTH = 800;
|
||||
static final int HEIGHT = 600;
|
||||
static HtmlLauncher instance;
|
||||
boolean canJoin = true;
|
||||
static Consumer<FileHandle> fileCons;
|
||||
|
||||
@Override
|
||||
public PreloaderCallback getPreloaderCallback () {
|
||||
@ -46,7 +50,6 @@ public class HtmlLauncher extends GwtApplication {
|
||||
preloaderPanel.add(meterPanel);
|
||||
getRootPanel().add(preloaderPanel);
|
||||
return new PreloaderCallback() {
|
||||
|
||||
@Override
|
||||
public void error (String file) {
|
||||
System.out.println("error: " + file);
|
||||
@ -55,8 +58,7 @@ public class HtmlLauncher extends GwtApplication {
|
||||
@Override
|
||||
public void update (PreloaderState state) {
|
||||
meterStyle.setWidth(100f * state.getProgress(), Unit.PCT);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -99,8 +101,16 @@ public class HtmlLauncher extends GwtApplication {
|
||||
|
||||
Platform.instance = new Platform(){
|
||||
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){
|
||||
return format.format(date);
|
||||
}
|
||||
@ -131,6 +141,11 @@ public class HtmlLauncher extends GwtApplication {
|
||||
}
|
||||
return Base64Coder.decode(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadFile(String name, byte[] bytes) {
|
||||
downloadBytes(name, new String(Base64Coder.encode(bytes)));
|
||||
}
|
||||
};
|
||||
|
||||
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() /*-{
|
||||
return $wnd.innerWidth;
|
||||
}-*/;
|
||||
@ -181,4 +228,14 @@ public class HtmlLauncher extends GwtApplication {
|
||||
public static void handleResize() {
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user