108 lines
3.7 KiB
C#
108 lines
3.7 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using Cysharp.Threading.Tasks;
|
|
using R3;
|
|
using RebootKit.Engine.Extensions;
|
|
using RebootKit.Engine.Main;
|
|
using RebootKit.Engine.Services.Console;
|
|
using RebootKit.Engine.Services.Crosshair;
|
|
using RebootKit.Engine.Services.GameMode;
|
|
using RebootKit.Engine.Services.Simulation;
|
|
|
|
namespace RealityReboot.jelycho {
|
|
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}");
|
|
}
|
|
}
|
|
}
|
|
|
|
public class JelychoGame : IGame {
|
|
[Serializable]
|
|
public class Config {
|
|
public WorldConfigAsset mainMenuWorldConfig;
|
|
public GameModeAsset standardGameMode;
|
|
|
|
public WorldConfigAsset worldAstek;
|
|
}
|
|
|
|
readonly Config m_Config;
|
|
|
|
DisposableBag m_DisposableBag;
|
|
|
|
public JelychoGame(Config config) {
|
|
m_Config = config;
|
|
m_DisposableBag = new DisposableBag();
|
|
}
|
|
|
|
public async UniTask InitAsync(CancellationToken cancellationToken) {
|
|
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");
|
|
RR.World.LoadAsync(m_Config.mainMenuWorldConfig.Config, CancellationToken.None).Forget();
|
|
}
|
|
})
|
|
.AddTo(ref m_DisposableBag);
|
|
}
|
|
|
|
public void Dispose() {
|
|
m_DisposableBag.Dispose();
|
|
}
|
|
|
|
public void NewGame() {
|
|
RR.StartGameMode(m_Config.standardGameMode, m_Config.worldAstek.Config);
|
|
}
|
|
}
|
|
} |