From dde09d8794de2c6effd238504249a21a77802ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Buratto?= <46575243+joaoburatto@users.noreply.github.com> Date: Wed, 4 Jan 2023 20:00:53 -0300 Subject: [PATCH] Rework application settings (#947) * Rework how application settings are handled * Add default prefab generator path change * Code cleanup and fix missing reference * Fix unused import * Rename editor ckey and initialize variable * Add null check on permission system * Fix issue where local player ckey was null * change a letter --- Assets/AddressableAssetsData/link.xml | 16 -- Assets/AddressableAssetsData/link.xml.meta | 7 - .../ApplicationSettings.asset} | 14 +- .../ApplicationSettings.asset.meta} | 2 +- .../DefaultPrefabObjects.asset} | 2 +- .../Data}/DefaultPrefabObjects.asset.meta | 0 Assets/Content/FishNet.meta | 8 - Assets/Content/FishNet/Runtime.meta | 8 - .../Runtime/SS3DSpawnablePrefabs.asset.meta | 8 - Assets/FishNet.meta | 8 - Assets/FishNet/Runtime.meta | 8 - .../Runtime/DefaultPrefabObjects.asset | 15 -- Assets/Scenes/Startup.unity | 57 ++++++- .../cecil-0.11.4/Mono.Cecil.sln.meta | 7 - .../Tugboat/LiteNetLib/LiteNetLib.csproj.meta | 7 - Assets/Scripts/SS3D/Core/ApplicationMode.cs | 9 -- .../Scripts/SS3D/Core/ApplicationMode.cs.meta | 3 - .../SS3D/Core/ApplicationStateManager.cs | 111 ------------- .../SS3D/Core/ApplicationStateSystem.cs | 87 ++++++++++ ...cs.meta => ApplicationStateSystem.cs.meta} | 2 +- .../Core/Events/ApplicationStartedEvent.cs | 7 +- .../Scripts/SS3D/Core/Intro/IntroUIHelper.cs | 17 +- .../Scripts/SS3D/Core/SessionNetworkHelper.cs | 152 ------------------ .../Scripts/SS3D/Core/SessionNetworkSystem.cs | 60 +++++++ ...r.cs.meta => SessionNetworkSystem.cs.meta} | 0 Assets/Scripts/SS3D/Core/Settings.meta | 3 + .../SS3D/Core/Settings/ApplicationSettings.cs | 83 ++++++++++ .../Core/Settings/ApplicationSettings.cs.meta | 3 + .../LocalPlayer.cs} | 7 +- .../LocalPlayer.cs.meta} | 0 .../Scripts/SS3D/Core/Settings/NetworkType.cs | 9 ++ .../SS3D/Core/Settings/NetworkType.cs.meta | 3 + .../SS3D/Core/Utils/ApplicationModeView.cs | 4 +- .../SS3D/Core/Utils/CommandLineArgs.cs | 16 +- .../SS3D/Core/Utils/CommandLineArgsSystem.cs | 108 +++++++++++++ .../Core/Utils/CommandLineArgsSystem.cs.meta | 3 + .../SS3D/Networking/UnauthorizedPlayer.cs | 3 +- .../Interactions/RadialInteractionView.cs | 18 +-- .../Systems/Permissions/DisableIfNotAdmin.cs | 3 +- .../Systems/Permissions/PermissionSystem.cs | 10 +- .../SS3D/{Core => }/Utils/ListExtensions.cs | 8 +- .../{Core => }/Utils/ListExtensions.cs.meta | 0 ...tor.PrefabObjects.Generation.Settings.json | 1 + ProjectSettings/ProjectSettings.asset | 1 + 44 files changed, 477 insertions(+), 421 deletions(-) delete mode 100644 Assets/AddressableAssetsData/link.xml delete mode 100644 Assets/AddressableAssetsData/link.xml.meta rename Assets/Content/{FishNet/Runtime/DefaultPrefabObjects.asset => Data/ApplicationSettings.asset} (50%) rename Assets/Content/{FishNet/Runtime/DefaultPrefabObjects.asset.meta => Data/ApplicationSettings.asset.meta} (79%) rename Assets/Content/{FishNet/Runtime/SS3DSpawnablePrefabs.asset => Data/DefaultPrefabObjects.asset} (98%) rename Assets/{FishNet/Runtime => Content/Data}/DefaultPrefabObjects.asset.meta (100%) delete mode 100644 Assets/Content/FishNet.meta delete mode 100644 Assets/Content/FishNet/Runtime.meta delete mode 100644 Assets/Content/FishNet/Runtime/SS3DSpawnablePrefabs.asset.meta delete mode 100644 Assets/FishNet.meta delete mode 100644 Assets/FishNet/Runtime.meta delete mode 100644 Assets/FishNet/Runtime/DefaultPrefabObjects.asset delete mode 100644 Assets/Scripts/External/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil.sln.meta delete mode 100644 Assets/Scripts/External/FishNet/Runtime/Transporting/Transports/Tugboat/LiteNetLib/LiteNetLib.csproj.meta delete mode 100644 Assets/Scripts/SS3D/Core/ApplicationMode.cs delete mode 100644 Assets/Scripts/SS3D/Core/ApplicationMode.cs.meta delete mode 100644 Assets/Scripts/SS3D/Core/ApplicationStateManager.cs create mode 100644 Assets/Scripts/SS3D/Core/ApplicationStateSystem.cs rename Assets/Scripts/SS3D/Core/{ApplicationStateManager.cs.meta => ApplicationStateSystem.cs.meta} (93%) delete mode 100644 Assets/Scripts/SS3D/Core/SessionNetworkHelper.cs create mode 100644 Assets/Scripts/SS3D/Core/SessionNetworkSystem.cs rename Assets/Scripts/SS3D/Core/{SessionNetworkHelper.cs.meta => SessionNetworkSystem.cs.meta} (100%) create mode 100644 Assets/Scripts/SS3D/Core/Settings.meta create mode 100644 Assets/Scripts/SS3D/Core/Settings/ApplicationSettings.cs create mode 100644 Assets/Scripts/SS3D/Core/Settings/ApplicationSettings.cs.meta rename Assets/Scripts/SS3D/Core/{Utils/LocalPlayerAccountUtility.cs => Settings/LocalPlayer.cs} (78%) rename Assets/Scripts/SS3D/Core/{Utils/LocalPlayerAccountUtility.cs.meta => Settings/LocalPlayer.cs.meta} (100%) create mode 100644 Assets/Scripts/SS3D/Core/Settings/NetworkType.cs create mode 100644 Assets/Scripts/SS3D/Core/Settings/NetworkType.cs.meta create mode 100644 Assets/Scripts/SS3D/Core/Utils/CommandLineArgsSystem.cs create mode 100644 Assets/Scripts/SS3D/Core/Utils/CommandLineArgsSystem.cs.meta rename Assets/Scripts/SS3D/{Core => }/Utils/ListExtensions.cs (65%) rename Assets/Scripts/SS3D/{Core => }/Utils/ListExtensions.cs.meta (100%) create mode 100644 Library/FishNet.Runtime.Editor.PrefabObjects.Generation.Settings.json diff --git a/Assets/AddressableAssetsData/link.xml b/Assets/AddressableAssetsData/link.xml deleted file mode 100644 index e2f9acfc75..0000000000 --- a/Assets/AddressableAssetsData/link.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Assets/AddressableAssetsData/link.xml.meta b/Assets/AddressableAssetsData/link.xml.meta deleted file mode 100644 index 06ae9953ea..0000000000 --- a/Assets/AddressableAssetsData/link.xml.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 1f25990106b9f14468d8810687731d70 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Content/FishNet/Runtime/DefaultPrefabObjects.asset b/Assets/Content/Data/ApplicationSettings.asset similarity index 50% rename from Assets/Content/FishNet/Runtime/DefaultPrefabObjects.asset rename to Assets/Content/Data/ApplicationSettings.asset index 77e196144b..2819f2b7e3 100644 --- a/Assets/Content/FishNet/Runtime/DefaultPrefabObjects.asset +++ b/Assets/Content/Data/ApplicationSettings.asset @@ -9,7 +9,15 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3ad70174b079c2f4ebc7931d3dd1af6f, type: 3} - m_Name: DefaultPrefabObjects + m_Script: {fileID: 11500000, guid: 890a57b29b24482196b55e1ac5de1b43, type: 3} + m_Name: ApplicationSettings m_EditorClassIdentifier: - _prefabs: [] + _preload: 1 + _type: 0 + Ckey: editorUser + ServerAddress: 127.0.0.1 + NetworkType: 2 + SkipIntro: 1 + EnableDiscord: 0 + EditorServerAddress: 127.0.0.1 + EditorServerCkey: editorUser diff --git a/Assets/Content/FishNet/Runtime/DefaultPrefabObjects.asset.meta b/Assets/Content/Data/ApplicationSettings.asset.meta similarity index 79% rename from Assets/Content/FishNet/Runtime/DefaultPrefabObjects.asset.meta rename to Assets/Content/Data/ApplicationSettings.asset.meta index fd0da87466..996a4afd25 100644 --- a/Assets/Content/FishNet/Runtime/DefaultPrefabObjects.asset.meta +++ b/Assets/Content/Data/ApplicationSettings.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7d7c255dd6e3ef848ae8788e9bd163f2 +guid: 7bad4d05fa044614c9a82b0a36151e72 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/Assets/Content/FishNet/Runtime/SS3DSpawnablePrefabs.asset b/Assets/Content/Data/DefaultPrefabObjects.asset similarity index 98% rename from Assets/Content/FishNet/Runtime/SS3DSpawnablePrefabs.asset rename to Assets/Content/Data/DefaultPrefabObjects.asset index 464618cfc4..b31b1396b5 100644 --- a/Assets/Content/FishNet/Runtime/SS3DSpawnablePrefabs.asset +++ b/Assets/Content/Data/DefaultPrefabObjects.asset @@ -10,7 +10,7 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 3ad70174b079c2f4ebc7931d3dd1af6f, type: 3} - m_Name: SS3DSpawnablePrefabs + m_Name: DefaultPrefabObjects m_EditorClassIdentifier: _prefabs: - {fileID: 562230263738288595, guid: 59f05e8a3a1d4b94eb5222aed605e260, type: 3} diff --git a/Assets/FishNet/Runtime/DefaultPrefabObjects.asset.meta b/Assets/Content/Data/DefaultPrefabObjects.asset.meta similarity index 100% rename from Assets/FishNet/Runtime/DefaultPrefabObjects.asset.meta rename to Assets/Content/Data/DefaultPrefabObjects.asset.meta diff --git a/Assets/Content/FishNet.meta b/Assets/Content/FishNet.meta deleted file mode 100644 index 69f6fc2394..0000000000 --- a/Assets/Content/FishNet.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: c8c01604e3a5219409837abdf20a9afb -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Content/FishNet/Runtime.meta b/Assets/Content/FishNet/Runtime.meta deleted file mode 100644 index a75ee130e5..0000000000 --- a/Assets/Content/FishNet/Runtime.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 36753b75af1d28c41a2f663ee5006f53 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Content/FishNet/Runtime/SS3DSpawnablePrefabs.asset.meta b/Assets/Content/FishNet/Runtime/SS3DSpawnablePrefabs.asset.meta deleted file mode 100644 index 7c3cf3a82c..0000000000 --- a/Assets/Content/FishNet/Runtime/SS3DSpawnablePrefabs.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 36555033d2a8fc94b95184be45446100 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FishNet.meta b/Assets/FishNet.meta deleted file mode 100644 index 6919c37254..0000000000 --- a/Assets/FishNet.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: dde478ea33859a348bcd16f1fd6e19e0 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FishNet/Runtime.meta b/Assets/FishNet/Runtime.meta deleted file mode 100644 index ae35cfbc10..0000000000 --- a/Assets/FishNet/Runtime.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: a574284d84e45ed458ddd9307bd79c43 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FishNet/Runtime/DefaultPrefabObjects.asset b/Assets/FishNet/Runtime/DefaultPrefabObjects.asset deleted file mode 100644 index 77e196144b..0000000000 --- a/Assets/FishNet/Runtime/DefaultPrefabObjects.asset +++ /dev/null @@ -1,15 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3ad70174b079c2f4ebc7931d3dd1af6f, type: 3} - m_Name: DefaultPrefabObjects - m_EditorClassIdentifier: - _prefabs: [] diff --git a/Assets/Scenes/Startup.unity b/Assets/Scenes/Startup.unity index 7ee632aeef..f28ec8b9f9 100644 --- a/Assets/Scenes/Startup.unity +++ b/Assets/Scenes/Startup.unity @@ -134,7 +134,7 @@ GameObject: - component: {fileID: 193002072} - component: {fileID: 193002073} m_Layer: 0 - m_Name: Persistent Startup Managers + m_Name: Persistent Startup Systems m_TagString: Untagged m_Icon: {fileID: 2800000, guid: 7ec379b7eb9a9a846b5ed6ea220115b9, type: 3} m_NavMeshLayer: 0 @@ -154,6 +154,7 @@ Transform: m_Children: - {fileID: 1607392372} - {fileID: 1628220426} + - {fileID: 1966326254} m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -224,7 +225,7 @@ MonoBehaviour: _objectPool: {fileID: 0} _persistence: 0 _logging: {fileID: 0} - _spawnablePrefabs: {fileID: 11400000, guid: 36555033d2a8fc94b95184be45446100, type: 2} + _spawnablePrefabs: {fileID: 11400000, guid: 59af76506e3115f479c03aedaf5de785, type: 2} --- !u!114 &340427414 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1512,7 +1513,7 @@ GameObject: - component: {fileID: 1607392372} - component: {fileID: 1607392373} m_Layer: 0 - m_Name: Application State Manager + m_Name: Application State System m_TagString: Untagged m_Icon: {fileID: 2800000, guid: 1bce13c2663afd54382ddd17e34235cd, type: 3} m_NavMeshLayer: 0 @@ -1545,10 +1546,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 16bada615ca6f634d83ad055a8203a51, type: 3} m_Name: m_EditorClassIdentifier: - _testingSkipIntroInEditor: 1 - _testingDiscordIntegrationInEditor: 0 - _testingClientInEditor: 1 - _testingServerInEditor: 1 --- !u!1 &1628220425 GameObject: m_ObjectHideFlags: 0 @@ -1560,7 +1557,7 @@ GameObject: - component: {fileID: 1628220426} - component: {fileID: 1628220427} m_Layer: 0 - m_Name: Session Network Helper + m_Name: Session Network System m_TagString: Untagged m_Icon: {fileID: 2800000, guid: 449023493f4f5bf459d6bde76b93d2f4, type: 3} m_NavMeshLayer: 0 @@ -1789,6 +1786,50 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1966326253 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1966326254} + - component: {fileID: 1966326255} + m_Layer: 0 + m_Name: Command Line Args System + m_TagString: Untagged + m_Icon: {fileID: 2800000, guid: ebb14ff33e73f254daf273bbdb2c4b73, type: 3} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1966326254 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1966326253} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 193002072} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1966326255 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1966326253} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 851dde348ae5407fba100fe7e4b584c5, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &2092657031 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/External/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil.sln.meta b/Assets/Scripts/External/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil.sln.meta deleted file mode 100644 index aa8a077601..0000000000 --- a/Assets/Scripts/External/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil.sln.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 246f31a0e00fea74a93125fec6d80da8 -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/External/FishNet/Runtime/Transporting/Transports/Tugboat/LiteNetLib/LiteNetLib.csproj.meta b/Assets/Scripts/External/FishNet/Runtime/Transporting/Transports/Tugboat/LiteNetLib/LiteNetLib.csproj.meta deleted file mode 100644 index f9c48e96e4..0000000000 --- a/Assets/Scripts/External/FishNet/Runtime/Transporting/Transports/Tugboat/LiteNetLib/LiteNetLib.csproj.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 2ad85b0f43f25f1499c27a4dca23ddd8 -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SS3D/Core/ApplicationMode.cs b/Assets/Scripts/SS3D/Core/ApplicationMode.cs deleted file mode 100644 index bf008e9719..0000000000 --- a/Assets/Scripts/SS3D/Core/ApplicationMode.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace SS3D.Core -{ - public enum ApplicationMode - { - ServerOnly = 0, - Host = 1, - Client = 2, - } -} \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/ApplicationMode.cs.meta b/Assets/Scripts/SS3D/Core/ApplicationMode.cs.meta deleted file mode 100644 index 481072e6dc..0000000000 --- a/Assets/Scripts/SS3D/Core/ApplicationMode.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 77e3b768b19249a4afd9f97762ef6bf3 -timeCreated: 1665269156 \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/ApplicationStateManager.cs b/Assets/Scripts/SS3D/Core/ApplicationStateManager.cs deleted file mode 100644 index bcee413a99..0000000000 --- a/Assets/Scripts/SS3D/Core/ApplicationStateManager.cs +++ /dev/null @@ -1,111 +0,0 @@ -using Coimbra; -using DG.Tweening; -using SS3D.Data; -using UDiscord; -using UnityEngine; - -namespace SS3D.Core -{ - /// - /// Responsible for controlling the game state, persistent throughout the application - /// Should hopefully be the only Singleton in the project - /// - public sealed class ApplicationStateManager : MonoBehaviour - { - public static ApplicationStateManager Instance; - - [Header("Test Cases")] - [SerializeField] private bool _testingSkipIntroInEditor; - [SerializeField] private bool _testingDiscordIntegrationInEditor; - [SerializeField] private bool _testingClientInEditor; - [SerializeField] private bool _testingServerInEditor; - - public static bool IsServer { get; private set; } - public static bool IsClient { get; private set; } - public static bool EnableDiscordIntegration { get; private set; } - public static bool SkipIntro { get; private set; } - - private void Awake() - { - PreProcessTestParams(); - InitializeSingleton(); - InitializeEssentialSystems(); - InitializeSubsystems(); - } - - private void InitializeSubsystems() - { - if (EnableDiscordIntegration) - { - DiscordManager.Initialize(); - } - else - { - FindObjectOfType().Destroy(); - } - Database.Icons.PreloadAssets(); - } - - public void InitializeApplication() - { - Debug.Log($"[{nameof(ApplicationStateManager)}] - Initializing application"); - InitializeNetworkSession(); - } - - private void PreProcessTestParams() - { - if (Application.isEditor) - { - IsClient = _testingClientInEditor; - IsServer = _testingServerInEditor; - SkipIntro = _testingSkipIntroInEditor; - EnableDiscordIntegration = _testingDiscordIntegrationInEditor; - - return; - } - - _testingServerInEditor = false; - _testingSkipIntroInEditor = false; - _testingClientInEditor = false; - _testingDiscordIntegrationInEditor = false; - } - - private void InitializeSingleton() - { - Debug.Log($"[{nameof(ApplicationStateManager)}] - Initializing Application State Manager singleton"); - - if (Instance == null) - { - Instance = this; - } - } - - private static void InitializeEssentialSystems() - { - Debug.Log($"[{nameof(ApplicationStateManager)}] - Initializing essential systems"); - DOTween.Init(); - } - - private static void InitializeNetworkSession() - { - Debug.Log($"[{nameof(ApplicationStateManager)}] - Initializing network session"); - SessionNetworkHelper.InitiateNetworkSession(); - } - - public static void SetSkipIntro(bool state) - { - SkipIntro = state; - } - - public static void SetDiscordIntegration(bool state) - { - EnableDiscordIntegration = state; - } - - public static void SetServerOnly(bool state) - { - IsServer = state; - IsClient = !state; - } - } -} diff --git a/Assets/Scripts/SS3D/Core/ApplicationStateSystem.cs b/Assets/Scripts/SS3D/Core/ApplicationStateSystem.cs new file mode 100644 index 0000000000..ade6f3d0b7 --- /dev/null +++ b/Assets/Scripts/SS3D/Core/ApplicationStateSystem.cs @@ -0,0 +1,87 @@ +using Coimbra; +using DG.Tweening; +using SS3D.Core.Settings; +using SS3D.Core.Utils; +using SS3D.Data; +using SS3D.Logging; +using UDiscord; + +namespace SS3D.Core +{ + /// + /// Initializes all the core information needed, subsystems and assets pre-loading. + /// + public sealed class ApplicationStateSystem : Behaviours.System + { + /// + /// Initializes all required systems for the application. + /// + public void InitializeApplication() + { + Punpun.Say(this, "Initializing application", Logs.Important); + + InitializeApplicationSettings(); + InitializeSubsystems(); + InitializeNetworkSession(); + } + + /// + /// Initializes the application settings based on the command line args or the Project Settings if in Editor. + /// + private void InitializeApplicationSettings() + { + CommandLineArgsSystem startArgsSystem = SystemLocator.Get(); + + startArgsSystem.LoadApplicationSettings(); + startArgsSystem.ProcessCommandLineArgs(); + } + + /// + /// Initializes the subsystems, like pre-loading assets and integrations. + /// + private void InitializeSubsystems() + { + DOTween.Init(); + + InitializeDiscordIntegration(); + InitializeAssetData(); + } + + /// + /// Initializes all the assets from the AssetData. + /// + private void InitializeAssetData() + { + Database.Icons.PreloadAssets(); + } + + /// + /// Initializes the Discord integration is enabled on the application systems. + /// + private void InitializeDiscordIntegration() + { + ApplicationSettings applicationSettings = ScriptableSettings.GetOrFind(); + bool enableDiscordIntegration = applicationSettings.EnableDiscord; + + if (enableDiscordIntegration) + { + DiscordManager.Initialize(); + } + else + { + FindObjectOfType().Destroy(); + } + } + + /// + /// Initializes the network session, connect, hosting, or starting a server-only application. + /// + private void InitializeNetworkSession() + { + Punpun.Say(this, "Initializing network session", Logs.Important); + + SessionNetworkSystem sessionNetworkSystem = SystemLocator.Get(); + sessionNetworkSystem.InitializeNetworkSession(); + } + } +} diff --git a/Assets/Scripts/SS3D/Core/ApplicationStateManager.cs.meta b/Assets/Scripts/SS3D/Core/ApplicationStateSystem.cs.meta similarity index 93% rename from Assets/Scripts/SS3D/Core/ApplicationStateManager.cs.meta rename to Assets/Scripts/SS3D/Core/ApplicationStateSystem.cs.meta index d77a32540b..1e938f9d29 100644 --- a/Assets/Scripts/SS3D/Core/ApplicationStateManager.cs.meta +++ b/Assets/Scripts/SS3D/Core/ApplicationStateSystem.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 0 + executionOrder: 5 icon: {fileID: 2800000, guid: 1bce13c2663afd54382ddd17e34235cd, type: 3} userData: assetBundleName: diff --git a/Assets/Scripts/SS3D/Core/Events/ApplicationStartedEvent.cs b/Assets/Scripts/SS3D/Core/Events/ApplicationStartedEvent.cs index 14d8f0ff5c..6fdb7e262c 100644 --- a/Assets/Scripts/SS3D/Core/Events/ApplicationStartedEvent.cs +++ b/Assets/Scripts/SS3D/Core/Events/ApplicationStartedEvent.cs @@ -1,16 +1,17 @@ using Coimbra.Services.Events; +using SS3D.Core.Settings; namespace SS3D.Core.Events { public partial struct ApplicationStartedEvent : IEvent { public readonly string Ckey; - public readonly ApplicationMode ApplicationMode; + public readonly NetworkType NetworkType; - public ApplicationStartedEvent(string ckey, ApplicationMode applicationMode) + public ApplicationStartedEvent(string ckey, NetworkType networkType) { Ckey = ckey; - ApplicationMode = applicationMode; + NetworkType = networkType; } } } \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/Intro/IntroUIHelper.cs b/Assets/Scripts/SS3D/Core/Intro/IntroUIHelper.cs index 9dd1e8bee2..75b289ee9f 100644 --- a/Assets/Scripts/SS3D/Core/Intro/IntroUIHelper.cs +++ b/Assets/Scripts/SS3D/Core/Intro/IntroUIHelper.cs @@ -1,4 +1,6 @@ +using Coimbra; using DG.Tweening; +using SS3D.Core.Settings; using UnityEngine; using UnityEngine.Serialization; @@ -13,7 +15,7 @@ public sealed class IntroUIHelper : MonoBehaviour [Header("UI")] [SerializeField] private CanvasGroup _introUiCanvasGroup; [FormerlySerializedAs("_connectionUiFade")] [SerializeField] private CanvasGroup _connectionUiCanvasGroup; - + [Header("Settings")] [SerializeField] private float _fadeInDuration; [SerializeField] private float _fadeOutDuration; @@ -29,10 +31,15 @@ private void Start() private void Setup() { - if (ApplicationStateManager.SkipIntro) + ApplicationSettings applicationSettings = ScriptableSettings.GetOrFind(); + + if (applicationSettings.SkipIntro) { Destroy(_temporaryAudioSource); - ApplicationStateManager.Instance.InitializeApplication(); + + ApplicationStateSystem applicationStateSystem = SystemLocator.Get(); + applicationStateSystem.InitializeApplication(); + _introUiCanvasGroup.alpha = 0; _connectionUiCanvasGroup.alpha = 1; } @@ -51,7 +58,9 @@ private void TurnOnConnectionUIAfterFade() { _introUiCanvasGroup.DOFade(0, _fadeOutDuration).SetDelay(_splashScreenFreezeDuration).OnComplete(() => { - ApplicationStateManager.Instance.InitializeApplication(); + ApplicationStateSystem applicationStateSystem = SystemLocator.Get(); + applicationStateSystem.InitializeApplication(); + _connectionUiCanvasGroup.DOFade(1, _fadeInDuration).SetDelay(2); }); }).SetEase(Ease.InCubic); diff --git a/Assets/Scripts/SS3D/Core/SessionNetworkHelper.cs b/Assets/Scripts/SS3D/Core/SessionNetworkHelper.cs deleted file mode 100644 index 2f2cf92c96..0000000000 --- a/Assets/Scripts/SS3D/Core/SessionNetworkHelper.cs +++ /dev/null @@ -1,152 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using FishNet; -using FishNet.Managing; -using SS3D.Core.Behaviours; -using SS3D.Core.Events; -using SS3D.Core.Utils; -using UnityEngine; - -namespace SS3D.Core -{ - /// - /// Helps the NetworkManager to understand what we should do in this instance, - /// if we are a server, or a client, and process respective data. - /// - /// TODO: Could use a refactor - /// - public sealed class SessionNetworkHelper : Actor - { - private static List _commandLineArgs; - - private static bool _isHost; - private static bool _serverOnly; - private static string _ip; - private static string _ckey; - - private const string EditorServerIP = "127.0.0.1"; - private const string EditorServerUsername = "editorUser"; - - private void Awake() - { - ProcessCommandLineArgs(); - } - - // Gets the command line arguments from the executable, for example: "-server=localhost" - private static void GetCommandLineArgs() - { - try - { - _commandLineArgs = Environment.GetCommandLineArgs().ToList(); - } - catch (Exception e) - { - Debug.LogError($"[{nameof(SessionNetworkHelper)}] - GetCommandLineArgs: {e}"); - throw; - } - } - - // Uses the args to determine if we have to connect or host, etc - private static void ProcessCommandLineArgs() - { - if (Application.isEditor) - { - _isHost = ApplicationStateManager.IsServer && ApplicationStateManager.IsClient; - _ip = EditorServerIP; - _ckey = EditorServerUsername; - _serverOnly = ApplicationStateManager.IsServer && !ApplicationStateManager.IsClient; - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Testing application on the editor as {_ckey}"); - } - else - { - GetCommandLineArgs(); - foreach (string arg in _commandLineArgs) - { - if (arg.Contains(CommandLineArgs.Host)) - { - _isHost = true; - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Command args - {CommandLineArgs.Host} - is true"); - } - - if (arg.Contains(CommandLineArgs.Ip)) - { - _ip = arg.Replace(CommandLineArgs.Ip, ""); - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Command args - {CommandLineArgs.Ip} - {_ip}"); - } - - if (arg.Contains(CommandLineArgs.Ckey)) - { - _ckey = arg.Replace(CommandLineArgs.Ckey, ""); - ApplicationStateManager.SetServerOnly(false); - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Command args - {CommandLineArgs.Ckey} - {_ckey}"); - } - - if (arg.Contains(CommandLineArgs.SkipIntro)) - { - ApplicationStateManager.SetSkipIntro(true); - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Command args - {CommandLineArgs.SkipIntro} - {true}"); - } - - if (arg.Contains(CommandLineArgs.EnableDiscordIntegration)) - { - ApplicationStateManager.SetDiscordIntegration(true); - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Command args - {CommandLineArgs.EnableDiscordIntegration} - {true}"); - } - - if (arg.Contains(CommandLineArgs.ServerOnly)) - { - ApplicationStateManager.SetServerOnly(true); - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Command args - {CommandLineArgs.ServerOnly} - {true}"); - } - } - - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Testing application on executable"); - } - - LocalPlayerAccountUtility.UpdateCkey(_ckey); - } - - /// - /// Uses the processed args to proceed with game network initialization - /// - public static void InitiateNetworkSession() - { - ProcessCommandLineArgs(); - - NetworkManager networkManager = InstanceFinder.NetworkManager; - if (networkManager == null) - { - networkManager = InstanceFinder.NetworkManager; - InitiateNetworkSession(); - } - - ApplicationMode applicationMode; - - if (_serverOnly) - { - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Hosting a new headless server"); - networkManager.ServerManager.StartConnection(); - applicationMode = ApplicationMode.ServerOnly; - } - else if (_isHost) - { - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Hosting a new server"); - networkManager.ServerManager.StartConnection(); - networkManager.ClientManager.StartConnection(); - - applicationMode = ApplicationMode.Host; - } - else - { - Debug.Log($"[{nameof(SessionNetworkHelper)}] - Joining server {_ip} as {_ckey}"); - networkManager.ClientManager.StartConnection(_ip); - - applicationMode = ApplicationMode.Client; - } - - ApplicationStartedEvent applicationStartedEvent = new(_ckey, applicationMode); - applicationStartedEvent.Invoke(null!); - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/SessionNetworkSystem.cs b/Assets/Scripts/SS3D/Core/SessionNetworkSystem.cs new file mode 100644 index 0000000000..70d39e1033 --- /dev/null +++ b/Assets/Scripts/SS3D/Core/SessionNetworkSystem.cs @@ -0,0 +1,60 @@ +using System; +using Coimbra; +using FishNet; +using FishNet.Managing; +using SS3D.Core.Events; +using SS3D.Core.Settings; +using SS3D.Logging; +using UnityEngine; + +namespace SS3D.Core +{ + /// + /// Helps the NetworkManager to understand what we should do in this instance, + /// if we are a server, or a client, and process respective data. + /// + public sealed class SessionNetworkSystem : Behaviours.System + { + /// + /// Uses the processed args to proceed with game network initialization + /// + public void InitializeNetworkSession() + { + NetworkManager networkManager = InstanceFinder.NetworkManager; + if (networkManager == null) + { + networkManager = InstanceFinder.NetworkManager; + InitializeNetworkSession(); + } + + ApplicationSettings applicationSettings = ScriptableSettings.GetOrFind(); + + string ckey = applicationSettings.Ckey; + string serverAddress = applicationSettings.ServerAddress; + NetworkType networkType = applicationSettings.NetworkType; + + switch (networkType) + { + case NetworkType.ServerOnly: + Debug.Log($"[{nameof(SessionNetworkSystem)}] - Hosting a new headless server"); + networkManager.ServerManager.StartConnection(); + break; + case NetworkType.Client: + + Punpun.Say(this, $"Joining server {serverAddress} as {ckey}", Logs.Important); + networkManager.ClientManager.StartConnection(serverAddress); + break; + case NetworkType.Host: + Debug.Log($"[{nameof(SessionNetworkSystem)}] - Hosting a new server"); + networkManager.ServerManager.StartConnection(); + networkManager.ClientManager.StartConnection(); + break; + default: + throw new ArgumentOutOfRangeException(); + } + + ApplicationStartedEvent applicationStartedEvent = new(ckey, networkType); + applicationStartedEvent.Invoke(this); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/SessionNetworkHelper.cs.meta b/Assets/Scripts/SS3D/Core/SessionNetworkSystem.cs.meta similarity index 100% rename from Assets/Scripts/SS3D/Core/SessionNetworkHelper.cs.meta rename to Assets/Scripts/SS3D/Core/SessionNetworkSystem.cs.meta diff --git a/Assets/Scripts/SS3D/Core/Settings.meta b/Assets/Scripts/SS3D/Core/Settings.meta new file mode 100644 index 0000000000..f33cede37a --- /dev/null +++ b/Assets/Scripts/SS3D/Core/Settings.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b15463cde35542908436f614cd74f17d +timeCreated: 1672789024 \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/Settings/ApplicationSettings.cs b/Assets/Scripts/SS3D/Core/Settings/ApplicationSettings.cs new file mode 100644 index 0000000000..3ba61ef982 --- /dev/null +++ b/Assets/Scripts/SS3D/Core/Settings/ApplicationSettings.cs @@ -0,0 +1,83 @@ +using System; +using Coimbra; +using UnityEngine; + +namespace SS3D.Core.Settings +{ + /// + /// Used to define settings for the overall SS3D application in the Project Settings. + /// + [ProjectSettings("Project/SS3D", "Application Settings")] + public class ApplicationSettings : ScriptableSettings + { + /// + /// The Ckey used to authenticate users. Will be used along an API key when said API exists. + /// TODO: Update this when we have an API. + /// Defined via command line args when in a built executable or the EditorServerCkey when in the Editor. + /// + [HideInInspector] + public string Ckey = string.Empty; + + /// + /// The server address used when we start connecting to a server. + /// Defined via command line args when in a built executable or the EditorServerAddress when in the Editor. + /// + [HideInInspector] + public string ServerAddress; + + /// + /// Defines what type of connection to start when starting the application. + /// Defined via command line args when in a built executable or the value in the Project Settings window. + /// + [Tooltip("The selected option is only considered when in Editor. Built executables use the command args.")] + [Header("Network Settings")] + public NetworkType NetworkType; + + /// + /// Defined via command line args when in a built executable or the value in the Project Settings window. + /// + [Header("Other Settings")] + [Tooltip("If enabled, the intro animation will be skipped.")] + public bool SkipIntro; + + /// + /// Defined via command line args when in a built executable or the value in the Project Settings window. + /// + [Tooltip("If enabled, the discord integration plugin will run.")] + public bool EnableDiscord; + + /// + /// Defined by the value in the Project Settings window. + /// + [Header("Editor Only Settings")] + [Tooltip("The server address to connect to as a client, when in the Editor.")] + public string EditorServerAddress = "127.0.0.1"; + + /// + /// Defined by the value in the Project Settings window. + /// + [Tooltip("The username used when connecting to a server via the Editor.")] + public string EditorServerCkey = "editorUser"; + + /// + /// Resets our settings if we are ona built executable. + /// + public void ResetOnBuildApplication() + { + SkipIntro = false; + EnableDiscord = false; + NetworkType = NetworkType.Client; + ServerAddress = string.Empty; + Ckey = string.Empty; + } + + /// + /// Sets the editor settings overrides. + /// + public void SetEditorSettings() + { + Ckey = EditorServerCkey; + ServerAddress = EditorServerAddress; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/Settings/ApplicationSettings.cs.meta b/Assets/Scripts/SS3D/Core/Settings/ApplicationSettings.cs.meta new file mode 100644 index 0000000000..bac07452be --- /dev/null +++ b/Assets/Scripts/SS3D/Core/Settings/ApplicationSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 890a57b29b24482196b55e1ac5de1b43 +timeCreated: 1672789034 \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/Utils/LocalPlayerAccountUtility.cs b/Assets/Scripts/SS3D/Core/Settings/LocalPlayer.cs similarity index 78% rename from Assets/Scripts/SS3D/Core/Utils/LocalPlayerAccountUtility.cs rename to Assets/Scripts/SS3D/Core/Settings/LocalPlayer.cs index c26a436699..ea7c61068f 100644 --- a/Assets/Scripts/SS3D/Core/Utils/LocalPlayerAccountUtility.cs +++ b/Assets/Scripts/SS3D/Core/Settings/LocalPlayer.cs @@ -1,9 +1,9 @@ -namespace SS3D.Core.Utils +namespace SS3D.Core.Settings { /// /// Holds data from the Hub to send the server when we connect /// - public static class LocalPlayerAccountUtility + public static class LocalPlayer { /// /// Unique client key, originally used in BYOND's user management, nostalgically used @@ -12,8 +12,7 @@ public static class LocalPlayerAccountUtility public static void UpdateCkey(string ckey) { - Ckey = ckey; + Ckey = ckey; } - } } diff --git a/Assets/Scripts/SS3D/Core/Utils/LocalPlayerAccountUtility.cs.meta b/Assets/Scripts/SS3D/Core/Settings/LocalPlayer.cs.meta similarity index 100% rename from Assets/Scripts/SS3D/Core/Utils/LocalPlayerAccountUtility.cs.meta rename to Assets/Scripts/SS3D/Core/Settings/LocalPlayer.cs.meta diff --git a/Assets/Scripts/SS3D/Core/Settings/NetworkType.cs b/Assets/Scripts/SS3D/Core/Settings/NetworkType.cs new file mode 100644 index 0000000000..55e19d239e --- /dev/null +++ b/Assets/Scripts/SS3D/Core/Settings/NetworkType.cs @@ -0,0 +1,9 @@ +namespace SS3D.Core.Settings +{ + public enum NetworkType + { + ServerOnly, + Client, + Host, + } +} \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/Settings/NetworkType.cs.meta b/Assets/Scripts/SS3D/Core/Settings/NetworkType.cs.meta new file mode 100644 index 0000000000..cfb64d464d --- /dev/null +++ b/Assets/Scripts/SS3D/Core/Settings/NetworkType.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 52af1ad145754c4a9c469600f0b476a8 +timeCreated: 1672789637 \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/Utils/ApplicationModeView.cs b/Assets/Scripts/SS3D/Core/Utils/ApplicationModeView.cs index bfb5ccf116..3c96eb30dd 100644 --- a/Assets/Scripts/SS3D/Core/Utils/ApplicationModeView.cs +++ b/Assets/Scripts/SS3D/Core/Utils/ApplicationModeView.cs @@ -23,9 +23,9 @@ protected override void OnAwake() private void HandleApplicationStarted(ref EventContext context, in ApplicationStartedEvent e) { string ckey = e.Ckey.Colorize(LogColors.GetLogColor(Logs.Generic)); - string mode = e.ApplicationMode.ToString().Colorize(LogColors.GetLogColor(Logs.Physics)); + string mode = e.NetworkType.ToString().Colorize(LogColors.GetLogColor(Logs.Physics)); string appName = Application.productName.Colorize(LogColors.GetLogColor(Logs.Important)); - string appVersion = $"v{Application.version}".Colorize(LogColors.GetLogColor(Logs.ServerOnly)); + string appVersion = $"{Application.version}".Colorize(LogColors.GetLogColor(Logs.ServerOnly)); string unityVersion = $"{Application.unityVersion}".Colorize(LogColors.GetLogColor(Logs.ClientOnly)); string date = $"{DateTime.Now.Day:00}/{DateTime.Now.Month:00}/{DateTime.Now.Year:0000}".Colorize(LogColors.GetLogColor(Logs.Generic)); diff --git a/Assets/Scripts/SS3D/Core/Utils/CommandLineArgs.cs b/Assets/Scripts/SS3D/Core/Utils/CommandLineArgs.cs index bb9ddc6272..ebe79fe940 100644 --- a/Assets/Scripts/SS3D/Core/Utils/CommandLineArgs.cs +++ b/Assets/Scripts/SS3D/Core/Utils/CommandLineArgs.cs @@ -1,18 +1,17 @@ namespace SS3D.Core.Utils { /// - /// Stores all the constants for CMD arguments for easy access and readability - /// - /// For bool args simply add the arg + /// Stores all the constants for CMD arguments for easy access and readability. + /// For bool args simply add the arg. /// public static class CommandLineArgs { /// - /// The "-serveronly" arg in the executable + /// The "-serveronly" arg in the executable. /// public const string ServerOnly = "-serveronly"; /// - /// The "-host" arg in the executable + /// The "-host" arg in the executable. /// public const string Host = "-host"; /// @@ -22,8 +21,7 @@ public static class CommandLineArgs /// /// String. /// This is temporary, in production use, this will not exist, - /// and be replaced by the token, and then the server will get the - /// Username. + /// and be replaced by the token, and then the server will get the Username. /// public const string Ckey = "-ckey="; /// @@ -33,12 +31,12 @@ public static class CommandLineArgs public const string AccessToken = "-token="; /// /// Bool. - /// Skips the intro + /// Skips the intro. /// public const string SkipIntro = "-skipintro"; /// /// Bool. - /// Disables the discord integration + /// Disables the discord integration. /// public const string EnableDiscordIntegration = "-enablediscordintegration"; } diff --git a/Assets/Scripts/SS3D/Core/Utils/CommandLineArgsSystem.cs b/Assets/Scripts/SS3D/Core/Utils/CommandLineArgsSystem.cs new file mode 100644 index 0000000000..c182d34736 --- /dev/null +++ b/Assets/Scripts/SS3D/Core/Utils/CommandLineArgsSystem.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Coimbra; +using SS3D.Core.Settings; +using SS3D.Logging; +using UnityEngine; + +namespace SS3D.Core.Utils +{ + /// + /// Loads the command line args and processes them for the application settings. + /// + public class CommandLineArgsSystem : Behaviours.System + { + private List _commandLineArgs; + private ApplicationSettings _applicationSettings; + + /// + /// Loads the application settings data, doing appropriate changes depending on play mode. + /// + public void LoadApplicationSettings() + { + _applicationSettings = ScriptableSettings.GetOrFind(); + + if (!Application.isEditor) + { + _applicationSettings.ResetOnBuildApplication(); + } + else + { + _applicationSettings.SetEditorSettings(); + } + } + + /// + /// Loads and processes all command line args + /// + public void ProcessCommandLineArgs() + { + LoadCommandLineArgs(); + + _applicationSettings = ScriptableSettings.GetOrFind(); + + foreach (string arg in _commandLineArgs) + { + ProcessCommandArg(arg); + } + } + + /// + /// Gets the command line arguments from the executable, for example: "-server=localhost" + /// + private void ProcessCommandArg(string arg) + { + if (arg.Contains(CommandLineArgs.Host)) + { + _applicationSettings.NetworkType = NetworkType.Host; + } + + if (arg.Contains(CommandLineArgs.Ip)) + { + _applicationSettings.ServerAddress = arg.Replace(CommandLineArgs.Ip, ""); + } + + if (arg.Contains(CommandLineArgs.Ckey)) + { + string ckey = arg.Replace(CommandLineArgs.Ckey, ""); + + _applicationSettings.Ckey = ckey; + } + + if (arg.Contains(CommandLineArgs.SkipIntro)) + { + _applicationSettings.SkipIntro = true; + } + + if (arg.Contains(CommandLineArgs.EnableDiscordIntegration)) + { + _applicationSettings.EnableDiscord = true; + } + + if (arg.Contains(CommandLineArgs.ServerOnly)) + { + _applicationSettings.NetworkType = NetworkType.ServerOnly; + } + + LocalPlayer.UpdateCkey(_applicationSettings.Ckey); + + } + + /// + /// Tries to load the command line args from the executable. + /// + private void LoadCommandLineArgs() + { + try + { + _commandLineArgs = Environment.GetCommandLineArgs().ToList(); + } + catch (Exception e) + { + Punpun.Say(this, $"Failed to load command line arguments: {e}"); + throw; + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Core/Utils/CommandLineArgsSystem.cs.meta b/Assets/Scripts/SS3D/Core/Utils/CommandLineArgsSystem.cs.meta new file mode 100644 index 0000000000..f6586cf38d --- /dev/null +++ b/Assets/Scripts/SS3D/Core/Utils/CommandLineArgsSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 851dde348ae5407fba100fe7e4b584c5 +timeCreated: 1672789931 \ No newline at end of file diff --git a/Assets/Scripts/SS3D/Networking/UnauthorizedPlayer.cs b/Assets/Scripts/SS3D/Networking/UnauthorizedPlayer.cs index 4b5e009a2d..718951a934 100644 --- a/Assets/Scripts/SS3D/Networking/UnauthorizedPlayer.cs +++ b/Assets/Scripts/SS3D/Networking/UnauthorizedPlayer.cs @@ -1,5 +1,6 @@ using FishNet; using FishNet.Object; +using SS3D.Core.Settings; using SS3D.Core.Utils; using SS3D.Systems.PlayerControl.Messages; using UnityEngine; @@ -21,7 +22,7 @@ public override void OnStartClient() [Client] private void Setup() { - string ckey = LocalPlayerAccountUtility.Ckey; + string ckey = LocalPlayer.Ckey; bool testingServerOnlyInEditor = IsServer && !IsHost && Application.isEditor; if (testingServerOnlyInEditor) diff --git a/Assets/Scripts/SS3D/Systems/Interactions/RadialInteractionView.cs b/Assets/Scripts/SS3D/Systems/Interactions/RadialInteractionView.cs index 585084eae3..a8d5e03618 100644 --- a/Assets/Scripts/SS3D/Systems/Interactions/RadialInteractionView.cs +++ b/Assets/Scripts/SS3D/Systems/Interactions/RadialInteractionView.cs @@ -2,10 +2,9 @@ using System.Collections.Generic; using System.Linq; using DG.Tweening; -using SS3D.Core.Behaviours; -using SS3D.Core.Utils; using SS3D.Interactions; using SS3D.Interactions.Interfaces; +using SS3D.Utils; using UnityEngine; namespace SS3D.Systems.Interactions @@ -57,9 +56,9 @@ protected override void HandleUpdate(in float deltaTime) } UpdateIndicator(); - } + } - private void Setup() + private void Setup() { Interactions = new List(); @@ -147,8 +146,7 @@ private void Show() Position = screenPos; _selectedObject = _interactionButtons.First().GameObjectCache; - Interactions.First(); - + UpdateIndicator(); _scaleSequence?.Kill(); @@ -161,7 +159,7 @@ private void Show() .Append(TransformCache .DOScale(1, ScaleDuration) .SetEase(Ease.OutCirc)); - + _fadeSequence .Append(_canvasGroup .DOFade(1, ScaleDuration) @@ -188,7 +186,7 @@ private void Disappear() .Append(TransformCache .DOScale(0, ScaleDuration) .SetEase(Ease.OutCirc)); - + _fadeSequence.Append(_canvasGroup .DOFade(0, ScaleDuration) .SetEase(Ease.OutElastic)); @@ -197,10 +195,10 @@ private void Disappear() _fadeSequence.Play(); _canvasGroup.interactable = false; - + ResetInteractionsMenu(); } - + /// /// Clears the interactions menu /// diff --git a/Assets/Scripts/SS3D/Systems/Permissions/DisableIfNotAdmin.cs b/Assets/Scripts/SS3D/Systems/Permissions/DisableIfNotAdmin.cs index cd1391cc3e..20ba2ac572 100644 --- a/Assets/Scripts/SS3D/Systems/Permissions/DisableIfNotAdmin.cs +++ b/Assets/Scripts/SS3D/Systems/Permissions/DisableIfNotAdmin.cs @@ -5,6 +5,7 @@ using Cysharp.Threading.Tasks; using SS3D.Core; using SS3D.Core.Behaviours; +using SS3D.Core.Settings; using SS3D.Core.Utils; using SS3D.Systems.Permissions.Events; using UnityEngine; @@ -26,7 +27,7 @@ protected override void OnAwake() private void HandleUserPermissionsUpdated(ref EventContext context, in UserPermissionsChangedEvent e) { - _ckey = LocalPlayerAccountUtility.Ckey; + _ckey = LocalPlayer.Ckey; DisableObjects(); } diff --git a/Assets/Scripts/SS3D/Systems/Permissions/PermissionSystem.cs b/Assets/Scripts/SS3D/Systems/Permissions/PermissionSystem.cs index 357bc24b9b..c1a710c47e 100644 --- a/Assets/Scripts/SS3D/Systems/Permissions/PermissionSystem.cs +++ b/Assets/Scripts/SS3D/Systems/Permissions/PermissionSystem.cs @@ -59,6 +59,14 @@ public bool TryGetUserRole(string ckey, out ServerRoleTypes userPermission) LoadPermissions(); } + if (string.IsNullOrEmpty(ckey)) + { + Punpun.Yell(this, "Ckey null while trying to get user role"); + + userPermission = ServerRoleTypes.None; + return false; + } + bool containsKey = _userPermissions.ContainsKey(ckey); userPermission = containsKey ? _userPermissions[ckey] : ServerRoleTypes.None; @@ -68,7 +76,7 @@ public bool TryGetUserRole(string ckey, out ServerRoleTypes userPermission) [Server] public void ChangeUserPermission(string ckey, ServerRoleTypes role) { - // TODO: This + // TODO: This // Add new user permission to list // Add new user permission to text file } diff --git a/Assets/Scripts/SS3D/Core/Utils/ListExtensions.cs b/Assets/Scripts/SS3D/Utils/ListExtensions.cs similarity index 65% rename from Assets/Scripts/SS3D/Core/Utils/ListExtensions.cs rename to Assets/Scripts/SS3D/Utils/ListExtensions.cs index 9cd3d9c8bb..0cabeaaf06 100644 --- a/Assets/Scripts/SS3D/Core/Utils/ListExtensions.cs +++ b/Assets/Scripts/SS3D/Utils/ListExtensions.cs @@ -1,10 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; -namespace SS3D.Core.Utils +namespace SS3D.Utils { - public static class ListExtensions + public static class ListExtensions { public static bool IsNullOrEmpty(this List list) { diff --git a/Assets/Scripts/SS3D/Core/Utils/ListExtensions.cs.meta b/Assets/Scripts/SS3D/Utils/ListExtensions.cs.meta similarity index 100% rename from Assets/Scripts/SS3D/Core/Utils/ListExtensions.cs.meta rename to Assets/Scripts/SS3D/Utils/ListExtensions.cs.meta diff --git a/Library/FishNet.Runtime.Editor.PrefabObjects.Generation.Settings.json b/Library/FishNet.Runtime.Editor.PrefabObjects.Generation.Settings.json new file mode 100644 index 0000000000..13446b457f --- /dev/null +++ b/Library/FishNet.Runtime.Editor.PrefabObjects.Generation.Settings.json @@ -0,0 +1 @@ +{"Enabled":true,"FullRebuild":true,"LogToConsole":true,"SaveChanges":true,"AssetPath":"Assets\\Content\\Data\\DefaultPrefabObjects.asset","SearchScope":1,"ExcludedFolders":[],"IncludedFolders":["Assets\\Content*"]} \ No newline at end of file diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index a9176527fc..c92c5077ab 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -139,6 +139,7 @@ PlayerSettings: bundleVersion: 0.1 preloadedAssets: - {fileID: 11400000, guid: cdf9511d9049fa14ab0433934f3537ec, type: 2} + - {fileID: 11400000, guid: 7bad4d05fa044614c9a82b0a36151e72, type: 2} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1