{"TotalCount":6,"Files":[{"Ident":"brax.autoloader","Path":"UnitTests/LibraryTest.cs","FileName":"LibraryTest.cs","PackageType":"library","CodeKind":"UnitTest","AssetVersionId":67330,"IsPrivate":false,"Code":"using Braxnet;\r\nusing Sandbox;\r\n\r\n[TestClass]\r\npublic partial class LibraryTests\r\n{\r\n\t[TestMethod]\r\n\tpublic void SceneTest()\r\n\t{\r\n\t\tvar scene = new Scene();\r\n\t\tusing ( scene.Push() )\r\n\t\t{\r\n\t\t\t// var go = new GameObject();\r\n\t\t\tAssert.AreEqual( 1, scene.Directory.GameObjectCount );\r\n\t\t\tAssert.IsTrue( scene.Directory.FindByName( \u0022LibraryTestComponent\u0022 ) != null );\r\n\t\t}\r\n\t}\r\n\r\n}\r\n\r\n[Autoload]\r\npublic class LibraryTestComponent : Component\r\n{\r\n\t\r\n}\r\n"},{"Ident":"brax.autoloader","Path":"Code/Autoloader.cs","FileName":"Autoloader.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":67330,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing Sandbox;\r\n\r\nnamespace Braxnet;\r\n\r\n/// \u003Csummary\u003E\r\n///  Creates objects with components that have the Autoload attribute. Will stay between scenes.\r\n/// \u003C/summary\u003E\r\npublic sealed class Autoloader : GameObjectSystem\r\n{\r\n\t\r\n\tprivate readonly Dictionary\u003CTypeDescription, Component\u003E _components = new();\r\n\t\r\n\tpublic T GetComponent\u003CT\u003E() where T : Component\r\n\t{\r\n\t\tif ( _components.TryGetValue( TypeLibrary.GetType\u003CT\u003E(), out var comp ) )\r\n\t\t{\r\n\t\t\treturn (T)comp;\r\n\t\t}\r\n\r\n\t\treturn null;\r\n\t}\r\n\r\n\tprivate bool HasComponent( TypeDescription type )\r\n\t{\r\n\t\treturn Scene.GetAllComponents( type.GetType() ).Any();\r\n\t}\r\n\r\n\tpublic Autoloader( Scene scene ) : base( scene )\r\n\t{\r\n\t\tif ( Scene.IsEditor ) return;\r\n\t\t\r\n\t\tLog.Trace( $\u0022Autoloader initialized on scene {scene.Name}\u0022 );\r\n\r\n\t\tvar autoloadTypes = TypeLibrary.GetTypesWithAttribute\u003CAutoloadAttribute\u003E().ToList();\r\n\r\n\t\tif ( !autoloadTypes.Any() )\r\n\t\t{\r\n\t\t\tLog.Trace( \u0022No types to autoload\u0022 );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tforeach ( var type in autoloadTypes )\r\n\t\t{\r\n\t\t\tif ( !HasComponent( type.Type ) )\r\n\t\t\t{\r\n\t\t\t\tif ( type.Attribute.Prefab != null )\r\n\t\t\t\t{\r\n\t\t\t\t\tvar obj = SceneUtility.GetPrefabScene( ResourceLibrary.Get\u003CPrefabFile\u003E( type.Attribute.Prefab ) ).Clone();\r\n\t\t\t\t\t_components[type.Type] = obj.Components.Get( type.Type.GetType() );\r\n\t\t\t\t\tobj.Name = type.Type.Name;\r\n\t\t\t\t\tobj.Flags |= GameObjectFlags.DontDestroyOnLoad;\r\n\t\t\t\t\tLog.Trace( $\u0022Autoloading prefab {type.Type.Name} -\u003E {obj}\u0022 );\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tvar obj = Scene.CreateObject();\r\n\t\t\t\t\t_components[type.Type] = obj.Components.Create( type.Type );\r\n\t\t\t\t\tobj.Name = type.Type.Name;\r\n\t\t\t\t\tobj.Flags |= GameObjectFlags.DontDestroyOnLoad;\r\n\t\t\t\t\tLog.Trace( $\u0022Autoloading {type.Type.Name} -\u003E {obj}\u0022 );\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n///  Components with this attribute will be created by the Autoloader on scene start.\r\n/// \u003C/summary\u003E\r\n[AttributeUsage( AttributeTargets.Class )]\r\npublic sealed class AutoloadAttribute : Attribute\r\n{\r\n\tpublic string Prefab { get; set; }\r\n\tpublic AutoloadAttribute()\r\n\t{\r\n\t}\r\n\t\r\n\tpublic AutoloadAttribute( string prefab )\r\n\t{\r\n\t\tPrefab = prefab;\r\n\t}\r\n}\r\n"},{"Ident":"brax.autoloader","Path":".obj/__compiler_extra.cs","FileName":"__compiler_extra.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":67330,"IsPrivate":false,"Code":"global using static Sandbox.Internal.GlobalGameNamespace;\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022AddonTitle\u0022, \u0022Autoloader\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022AddonIdent\u0022, \u0022autoloader\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022OrgIdent\u0022, \u0022brax\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022Ident\u0022, \u0022brax.autoloader\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022CompileTime\u0022, \u00228/19/2024 6:05:21 PM\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022EngineVersion\u0022, \u002217\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022EngineMinorVersion\u0022, \u00221\u0022 )]\r\n\r\n[assembly: System.Runtime.Versioning.TargetFramework( \u0022.NETCoreApp,Version=v7.0\u0022, FrameworkDisplayName = \u0022.NET 7.0\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyVersion(\u00220.0.109.0\u0022)]\r\n[assembly: global::System.Reflection.AssemblyFileVersion(\u00220.0.109.0\u0022)]"},{"Ident":"brax.autoloader","Path":"Autoloader.cs","FileName":"Autoloader.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":67330,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing Sandbox;\r\n\r\nnamespace Braxnet;\r\n\r\n/// \u003Csummary\u003E\r\n///  Creates objects with components that have the Autoload attribute. Will stay between scenes.\r\n/// \u003C/summary\u003E\r\npublic sealed class Autoloader : GameObjectSystem\r\n{\r\n\t\r\n\tprivate readonly Dictionary\u003CTypeDescription, Component\u003E _components = new();\r\n\t\r\n\tpublic T GetComponent\u003CT\u003E() where T : Component\r\n\t{\r\n\t\tif ( _components.TryGetValue( TypeLibrary.GetType\u003CT\u003E(), out var comp ) )\r\n\t\t{\r\n\t\t\treturn (T)comp;\r\n\t\t}\r\n\r\n\t\treturn null;\r\n\t}\r\n\r\n\tprivate bool HasComponent( TypeDescription type )\r\n\t{\r\n\t\treturn Scene.GetAllComponents( type.GetType() ).Any();\r\n\t}\r\n\r\n\tpublic Autoloader( Scene scene ) : base( scene )\r\n\t{\r\n\t\tif ( Scene.IsEditor ) return;\r\n\t\t\r\n\t\tLog.Trace( $\u0022Autoloader initialized on scene {scene.Name}\u0022 );\r\n\r\n\t\tvar autoloadTypes = TypeLibrary.GetTypesWithAttribute\u003CAutoloadAttribute\u003E().ToList();\r\n\r\n\t\tif ( !autoloadTypes.Any() )\r\n\t\t{\r\n\t\t\tLog.Trace( \u0022No types to autoload\u0022 );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tforeach ( var type in autoloadTypes )\r\n\t\t{\r\n\t\t\tif ( !HasComponent( type.Type ) )\r\n\t\t\t{\r\n\t\t\t\tif ( type.Attribute.Prefab != null )\r\n\t\t\t\t{\r\n\t\t\t\t\tvar obj = SceneUtility.GetPrefabScene( ResourceLibrary.Get\u003CPrefabFile\u003E( type.Attribute.Prefab ) ).Clone();\r\n\t\t\t\t\t_components[type.Type] = obj.Components.Get( type.Type.GetType() );\r\n\t\t\t\t\tobj.Name = type.Type.Name;\r\n\t\t\t\t\tobj.Flags |= GameObjectFlags.DontDestroyOnLoad;\r\n\t\t\t\t\tLog.Trace( $\u0022Autoloading prefab {type.Type.Name} -\u003E {obj}\u0022 );\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tvar obj = Scene.CreateObject();\r\n\t\t\t\t\t_components[type.Type] = obj.Components.Create( type.Type );\r\n\t\t\t\t\tobj.Name = type.Type.Name;\r\n\t\t\t\t\tobj.Flags |= GameObjectFlags.DontDestroyOnLoad;\r\n\t\t\t\t\tLog.Trace( $\u0022Autoloading {type.Type.Name} -\u003E {obj}\u0022 );\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n///  Components with this attribute will be created by the Autoloader on scene start.\r\n/// \u003C/summary\u003E\r\n[AttributeUsage( AttributeTargets.Class )]\r\npublic sealed class AutoloadAttribute : Attribute\r\n{\r\n\tpublic string Prefab { get; set; }\r\n\tpublic AutoloadAttribute()\r\n\t{\r\n\t}\r\n\t\r\n\tpublic AutoloadAttribute( string prefab )\r\n\t{\r\n\t\tPrefab = prefab;\r\n\t}\r\n}\r\n"},{"Ident":"brax.autoloader","Path":"UnitTests/UnitTest.cs","FileName":"UnitTest.cs","PackageType":"library","CodeKind":"UnitTest","AssetVersionId":67330,"IsPrivate":false,"Code":"global using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n\r\n[TestClass]\r\npublic class TestInit\r\n{\r\n\t[AssemblyInitialize]\r\n\tpublic static void ClassInitialize( TestContext context )\r\n\t{\r\n\t\tSandbox.Application.InitUnitTest();\r\n\t}\r\n}\r\n"},{"Ident":"brax.autoloader","Path":"__gen_RazorNamespace.cs","FileName":"__gen_RazorNamespace.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":67330,"IsPrivate":false,"Code":"global using Microsoft.AspNetCore.Components; \nglobal using Microsoft.AspNetCore.Components.Rendering;\n"}]}