Files
jelito/Assets/jelycho/Code/Main/JelychoGame.cs
2025-08-08 23:38:03 +02:00

105 lines
3.6 KiB
C#
Executable File

using System.Collections.Generic;
using RebootKit.Engine.Console;
using RebootKit.Engine.Main;
using RebootKit.Engine.Simulation;
using RebootReality.jelycho.Player;
using UnityEngine;
using UnityEngine.AddressableAssets;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootReality.jelycho.Main {
public class JelychoGame : Game {
static readonly Logger s_Logger = new Logger(nameof(JelychoGame));
[Header("Player")]
[SerializeField] AssetReferenceGameObject m_PlayerActorPrefab;
protected override void Awake() {
base.Awake();
// Time.timeScale = 0.2f;
}
protected override void OnPlayerBecameReady(ulong clientID) {
s_Logger.Info($"Player {clientID} became ready");
if (RR.IsServer()) {
PlayerActor actor = (PlayerActor) RR.SpawnActor(m_PlayerActorPrefab,
Vector3.zero,
Quaternion.identity);
RR.PossessActor(clientID, actor.ActorID);
}
}
public override void OnClientConnected(ulong clientID) {
s_Logger.Info($"Client {clientID} connected");
}
public override void OnClientDisconnected(ulong clientID) {
s_Logger.Info($"Client {clientID} disconnected");
}
}
public static class JelychoConsoleCommands {
[RCCMD("worlds", "Lists all worlds")]
public static void Worlds(string[] args) {
if (args.Length != 1) {
RR.WriteToConsole($"Usage: {args[0]}");
return;
}
RR.WriteToConsole("Worlds:");
foreach (WorldConfigAsset worldConfigAsset in RR.WorldConfigsAssets) {
RR.WriteToConsole($" {worldConfigAsset.Config.name}");
}
}
[RCCMD("connect_dev", "Connects to a local server for development purposes")]
public static void ConnectToLocalServer(string[] args) {
RR.WriteToConsole("Connecting to server...");
RR.Connect();
}
[RCCMD("connect", "Connects to a server with given Steam ID. Usage: connect <steam_id>")]
public static void ConnectToServer(string[] args) {
if (args.Length < 1 || args.Length > 2) {
RR.WriteToConsole($"Usage: {args[0]} <steam_id>");
return;
}
RR.WriteToConsole("Connecting to server...");
if (args.Length != 2) {
RR.WriteToConsole($"Usage: {args[0]} <steam_id>");
return;
}
if (ulong.TryParse(args[1], out ulong steamID)) {
RR.ConnectWithSteamID(steamID);
} else {
RR.WriteToConsole($"Invalid Steam ID: {args[1]}");
}
}
[RCCMD("disconnect", "Disconnects from the current server")]
public static void DisconnectFromServer(string[] args) {
if (args.Length != 1) {
RR.WriteToConsole($"Usage: {args[0]}");
return;
}
RR.Disconnect();
}
[RCCMD("version", "Displays the current game version")]
public static void GameVersion(string[] args) {
RR.WriteToConsole($"Game version: {Application.version}");
}
[RCCMD("nq", "Quits the game")]
public static void Nq(string[] args) {
Application.Quit();
}
}
}