150 lines
5.4 KiB
C#
Executable File
150 lines
5.4 KiB
C#
Executable File
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using Cysharp.Threading.Tasks;
|
|
using R3;
|
|
using RebootKit.Engine.Main;
|
|
using RebootKit.Engine.Services.Console;
|
|
using RebootKit.Engine.Services.Crosshair;
|
|
using RebootKit.Engine.Services.GameMode;
|
|
using RebootKit.Engine.Services.Simulation;
|
|
using UnityEngine;
|
|
using Logger = RebootKit.Engine.Foundation.Logger;
|
|
|
|
namespace RebootReality.jelycho.Main {
|
|
public static class JelychoConsoleCommands {
|
|
[RCCMD("start", "Starts game mode with given name. Usage: start <game_mode_name> <world_name>")]
|
|
public static void StartGameMode(string[] args) {
|
|
if (args.Length != 3) {
|
|
RR.Console.WriteToOutput($"Usage: {args[0]} <game_mode_name> <world_name>");
|
|
return;
|
|
}
|
|
|
|
string worldName = args[2];
|
|
WorldConfigAsset worldConfig = RR.WorldConfigsAssets.FirstOrDefault(t => t.Config.name.Equals(worldName));
|
|
if (worldConfig is null) {
|
|
RR.Console.WriteToOutput($"World '{worldName}' not found");
|
|
return;
|
|
}
|
|
|
|
foreach (GameModeAsset gameModeAsset in RR.GameModesAssets) {
|
|
if (gameModeAsset.name == args[1]) {
|
|
RR.Console.WriteToOutput($"Starting game mode '{gameModeAsset.name}'");
|
|
RR.StartGameMode(gameModeAsset, worldConfig.Config);
|
|
return;
|
|
}
|
|
}
|
|
|
|
RR.Console.WriteToOutput($"Game mode '{args[1]}' not found");
|
|
}
|
|
|
|
[RCCMD("gamemodes", "Lists all game modes")]
|
|
public static void GameModes(string[] args) {
|
|
if (args.Length != 1) {
|
|
RR.Console.WriteToOutput($"Usage: {args[0]}");
|
|
return;
|
|
}
|
|
|
|
RR.Console.WriteToOutput("Game modes:");
|
|
foreach (GameModeAsset gameModeAsset in RR.GameModesAssets) {
|
|
RR.Console.WriteToOutput($" {gameModeAsset.name}");
|
|
}
|
|
}
|
|
|
|
[RCCMD("worlds", "Lists all worlds")]
|
|
public static void Worlds(string[] args) {
|
|
if (args.Length != 1) {
|
|
RR.Console.WriteToOutput($"Usage: {args[0]}");
|
|
return;
|
|
}
|
|
|
|
RR.Console.WriteToOutput("Worlds:");
|
|
foreach (WorldConfigAsset worldConfigAsset in RR.WorldConfigsAssets) {
|
|
RR.Console.WriteToOutput($" {worldConfigAsset.Config.name}");
|
|
}
|
|
}
|
|
|
|
[RCCMD("connect", "Connects to a server with given Steam ID. Usage: connect <steam_id>")]
|
|
public static void ConnectToServer(string[] args) {
|
|
RR.Console.WriteToOutput("Connecting to server...");
|
|
|
|
if (args.Length != 1) {
|
|
RR.Console.WriteToOutput($"Usage: {args[0]} <steam_id>");
|
|
return;
|
|
}
|
|
|
|
RR.ConnectToLobby();
|
|
}
|
|
|
|
[RCCMD("disconnect", "Disconnects from the current server")]
|
|
public static void DisconnectFromServer(string[] args) {
|
|
if (args.Length != 1) {
|
|
RR.Console.WriteToOutput($"Usage: {args[0]}");
|
|
return;
|
|
}
|
|
|
|
RR.Disconnect();
|
|
}
|
|
}
|
|
|
|
public class JelychoGame : IGame {
|
|
static readonly Logger s_Logger = new Logger(nameof(JelychoGame));
|
|
|
|
[Serializable]
|
|
public class Config {
|
|
public string mainMenuWorld = "main_menu";
|
|
public string mainGameplayWorld = "dev";
|
|
|
|
public string standardGameMode = "gm_standard";
|
|
}
|
|
|
|
readonly Config m_Config;
|
|
|
|
DisposableBag m_DisposableBag;
|
|
|
|
public JelychoGame(Config config) {
|
|
m_Config = config;
|
|
m_DisposableBag = new DisposableBag();
|
|
}
|
|
|
|
public async UniTask InitAsync(CancellationToken cancellationToken) {
|
|
Screen.SetResolution(1600, 900, FullScreenMode.Windowed);
|
|
|
|
RR.CreateService<CrosshairService>();
|
|
await UniTask.Yield();
|
|
}
|
|
|
|
public void Run() {
|
|
RR.GameModes.ActiveGameMode.Subscribe(gameMode => {
|
|
if (gameMode == null) {
|
|
RR.Console.WriteToOutput("Game mode stopped, loading main menu world");
|
|
|
|
WorldConfigAsset mainMenuWorldConfigAsset = RR.GetWorldConfigAsset(m_Config.mainMenuWorld);
|
|
RR.World.LoadAsync(mainMenuWorldConfigAsset.Config, CancellationToken.None).Forget();
|
|
}
|
|
})
|
|
.AddTo(ref m_DisposableBag);
|
|
}
|
|
|
|
public void Dispose() {
|
|
m_DisposableBag.Dispose();
|
|
}
|
|
|
|
public void NewGame() {
|
|
NewGameAsync().Forget();
|
|
}
|
|
|
|
async UniTask NewGameAsync() {
|
|
RR.HostServer();
|
|
await UniTask.WaitForSeconds(0.5f);
|
|
|
|
s_Logger.Info("Starting new game");
|
|
s_Logger.Info($"Is connected: {RR.IsClient()}");
|
|
s_Logger.Info($"Is host: {RR.IsHost()}");
|
|
|
|
GameModeAsset gameModeAsset = RR.GetGameMode(m_Config.standardGameMode);
|
|
WorldConfigAsset worldConfigAsset = RR.GetWorldConfigAsset(m_Config.mainGameplayWorld);
|
|
RR.StartGameMode(gameModeAsset, worldConfigAsset.Config);
|
|
}
|
|
}
|
|
} |