refactor: wip
This commit is contained in:
parent
4b61948f68
commit
0cb7131435
5 changed files with 69 additions and 45 deletions
|
|
@ -1,10 +1,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using BepInEx;
|
||||
using CoreNet.Config;
|
||||
using GB.Config;
|
||||
using GB.Core;
|
||||
using GB.Game;
|
||||
using CoreNet.Utils;
|
||||
using GB.Platform.Lobby;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -22,20 +19,6 @@ public class GBSUGui : MonoBehaviour
|
|||
private string error_msg = "Unknown error!";
|
||||
|
||||
readonly IInputSystem inputSystem = UnityInput.Current;
|
||||
string serverip = null;
|
||||
int serverport = 5999;
|
||||
bool hosting = false;
|
||||
private void Start()
|
||||
{
|
||||
if (CommandLineParser.Instance.KeyExists("-ip"))
|
||||
{
|
||||
serverip = CommandLineParser.Instance.GetValueForKey("-ip", true);
|
||||
}
|
||||
if (CommandLineParser.Instance.KeyExists("-port"))
|
||||
{
|
||||
int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", true), out serverport);
|
||||
}
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (inputSystem.GetKeyDown(KeyCode.RightShift))
|
||||
|
|
@ -77,7 +60,7 @@ Set CLI arguments: -ip, -port
|
|||
{
|
||||
Application.Quit(0);
|
||||
}
|
||||
if (serverip != null)
|
||||
if (Helper.serverip != null)
|
||||
{
|
||||
if (GUI.Button(new Rect(20f, 260f, 170f, 30f), "Host"))
|
||||
{
|
||||
|
|
@ -85,18 +68,14 @@ Set CLI arguments: -ip, -port
|
|||
{
|
||||
if (File.Exists(Helper.RotationFolderPath + "config.json"))
|
||||
{
|
||||
hosting = true;
|
||||
Helper.hosting = true;
|
||||
|
||||
AudioListener.volume = 0; // mute game audio
|
||||
|
||||
Plugin.AddServerComp(); // add custom GBSU server component
|
||||
|
||||
try
|
||||
{
|
||||
RotationConfig gameConfig = GBConfigLoader.LoadRotationConfig("config.json", true); // load rotation config from Config/Rotation/config.json
|
||||
ServerConfig serverConfig = NetConfigLoader.LoadServerConfig(); // load default server config, because it can be overridden by args like -ip and -port
|
||||
MonoSingleton<Global>.Instance.UNetManager.LaunchServer(serverConfig); // launch the server with the server config
|
||||
MonoSingleton<Global>.Instance.UNetManager.GetComponent<GameManagerNew>().ChangeRotationConfig(gameConfig, 0); // set server's rotationconfig
|
||||
Plugin.AddServerComp(); // add custom GBSU server component
|
||||
GBSUServer.StartServer();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
@ -119,13 +98,9 @@ Make sure to download a file from the examples given and rename it to config.jso
|
|||
{
|
||||
if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Online)
|
||||
{
|
||||
if (!hosting)
|
||||
if (!Helper.hosting)
|
||||
{
|
||||
LobbyManager.Instance.LobbyStates.IP = serverip;
|
||||
LobbyManager.Instance.LobbyStates.Port = serverport;
|
||||
LobbyManager.Instance.LobbyStates.CurrentState = LobbyState.State.Ready | LobbyState.State.InGame;
|
||||
LobbyManager.Instance.LocalBeasts.SetupNetMemberContext(true);
|
||||
MonoSingleton<Global>.Instance.UNetManager.LaunchClient(serverip, serverport);
|
||||
GBSUClient.JoinServer(Helper.serverip, Helper.serverport);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -153,14 +128,7 @@ Make sure to download a file from the examples given and rename it to config.jso
|
|||
}
|
||||
if (GUI.Button(new Rect(20f, 330f, 170f, 30f), "Toggle VSync"))
|
||||
{
|
||||
if (QualitySettings.vSyncCount == 0)
|
||||
{
|
||||
QualitySettings.vSyncCount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
QualitySettings.vSyncCount = 0;
|
||||
}
|
||||
Helper.FlipVSync();
|
||||
}
|
||||
|
||||
GUI.Label(new Rect(20f, 365f, 365f, 400f), $@"
|
||||
|
|
@ -195,7 +163,7 @@ Please refer to the documentation for more information.");
|
|||
}
|
||||
private string UpdateScoreDisplay()
|
||||
{
|
||||
if (hosting)
|
||||
if (Helper.hosting)
|
||||
{
|
||||
string scoreString = "Score:\n";
|
||||
foreach (var pair in Plugin.GameScore)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue