mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-28 07:22:21 -08:00
Added NetClient/NetServer classes
This commit is contained in:
parent
79e18f7f4d
commit
4a2b2dee72
8 changed files with 60 additions and 52 deletions
|
|
@ -21,7 +21,7 @@ allprojects {
|
|||
appName = "Mindustry"
|
||||
gdxVersion = '1.9.8'
|
||||
aiVersion = '1.8.1'
|
||||
uCoreVersion = 'afc7fe249f';
|
||||
uCoreVersion = 'c732038b35';
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ public class Mindustry extends ModuleCore {
|
|||
module(Vars.control = new Control());
|
||||
module(Vars.renderer = new Renderer());
|
||||
module(Vars.ui = new UI());
|
||||
module(Vars.network = new Network());
|
||||
module(Vars.netServer = new NetServer());
|
||||
module(Vars.netClient = new NetClient());
|
||||
}
|
||||
|
||||
public void loadBundle(){
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package io.anuke.mindustry;
|
|||
import com.badlogic.gdx.Application.ApplicationType;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.I18NBundle;
|
||||
|
||||
import io.anuke.mindustry.core.*;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
|
|
@ -80,7 +79,8 @@ public class Vars{
|
|||
public static Renderer renderer;
|
||||
public static UI ui;
|
||||
public static World world;
|
||||
public static Network network;
|
||||
public static NetServer netServer;
|
||||
public static NetClient netClient;
|
||||
|
||||
public static Player player;
|
||||
|
||||
|
|
|
|||
22
core/src/io/anuke/mindustry/core/NetClient.java
Normal file
22
core/src/io/anuke/mindustry/core/NetClient.java
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package io.anuke.mindustry.core;
|
||||
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
|
||||
public class NetClient extends Module {
|
||||
|
||||
public NetClient(){
|
||||
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(!Net.client()) return;
|
||||
|
||||
if(!GameState.is(State.menu) && Net.active()){
|
||||
|
||||
}else{
|
||||
Net.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
25
core/src/io/anuke/mindustry/core/NetServer.java
Normal file
25
core/src/io/anuke/mindustry/core/NetServer.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package io.anuke.mindustry.core;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class NetServer extends Module{
|
||||
|
||||
public NetServer(){
|
||||
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(!Net.server()) return;
|
||||
|
||||
if(!GameState.is(State.menu) && Net.active()){
|
||||
|
||||
}else{
|
||||
Net.closeServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package io.anuke.mindustry.core;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Network extends Module{
|
||||
private boolean isHosting;
|
||||
|
||||
public Network(){
|
||||
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(GameState.is(State.playing) && Net.active()){
|
||||
if(Net.server()){
|
||||
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(isHosting && GameState.is(State.menu)){
|
||||
Net.closeServer();
|
||||
isHosting = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void hostServer(int port) throws IOException{
|
||||
if(isHosting){
|
||||
throw new IOException("Already hosting a server!");
|
||||
}
|
||||
|
||||
Net.host(port);
|
||||
isHosting = true;
|
||||
}
|
||||
|
||||
public boolean isHosting(){
|
||||
return isHosting;
|
||||
}
|
||||
}
|
||||
|
|
@ -100,6 +100,11 @@ public class Net{
|
|||
return server;
|
||||
}
|
||||
|
||||
/**Whether this is a client or not.*/
|
||||
public static boolean client(){
|
||||
return !server;
|
||||
}
|
||||
|
||||
/**Register classes that will be sent. Must be done for all classes.*/
|
||||
public static void registerClasses(Class<?>... classes){
|
||||
clientProvider.register(classes);
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@ import static io.anuke.mindustry.Vars.ui;
|
|||
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.scene.Element;
|
||||
import io.anuke.ucore.scene.builders.build;
|
||||
import io.anuke.ucore.scene.builders.imagebutton;
|
||||
import io.anuke.ucore.scene.ui.ConfirmDialog;
|
||||
import io.anuke.ucore.scene.ui.ImageButton;
|
||||
import io.anuke.ucore.scene.ui.TextField.TextFieldFilter.DigitsOnlyFilter;
|
||||
import io.anuke.ucore.scene.ui.layout.Cell;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
|
|
@ -68,13 +67,13 @@ public class MenuDialog extends FloatingDialog{
|
|||
Vars.ui.showError("$text.server.invalidport");
|
||||
}else{
|
||||
try{
|
||||
Vars.network.hostServer(result);
|
||||
Net.host(result);
|
||||
}catch (IOException e){
|
||||
Vars.ui.showError(Bundles.format("text.server.error", Strings.parseException(e, false)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}).disabled(b -> Vars.network.isHosting());
|
||||
}).disabled(b -> Net.active() || (Net.active() && !Net.server()));
|
||||
|
||||
content().row();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue