protected override void OnContextSet() { List <DependencyResolver.DependencyBase> inheritedDependencies = null; if (DependencyResolver?.Dependencies.Count > 0) { inheritedDependencies = DependencyResolver.Dependencies; } IApplication currentApp; var category = string.Empty; if ((currentApp = new ContextBindingStrategy(Context, false).Resolve <IApplication>()) != null) { category = $"App({currentApp.GetType().Name})"; } else { category = $"Thread({Thread.CurrentThread.Name})"; } DependencyResolver = new DependencyResolver(new ContextBindingStrategy(Context, true).Resolve <IScheduler>(), Context, $"{category} System[{GetType().Name}]") { DefaultStrategy = new DefaultAppObjectStrategy(this, World) }; DependencyResolver.OnComplete(OnDependenciesResolved); if (inheritedDependencies != null) { DependencyResolver.Dependencies.AddRange(inheritedDependencies); } }
public void HasGameWorld() { var app = RetrieveApplication(); var gameWorld = new ContextBindingStrategy(app.Data.Context, true).Resolve <GameWorld>(); Assert.IsTrue(gameWorld != null); }
public void EntitiesCanBeCreated() { var app = RetrieveApplication(); var gameWorld = new ContextBindingStrategy(app.Data.Context, true).Resolve <GameWorld>(); var entity = gameWorld.CreateEntity(); Assert.IsTrue(entity.Id > 0); }
public void TestDataIsCorrect() { TestFeatureExist(); // important! var app = RetrieveApplication(); var gameWorld = new ContextBindingStrategy(app.Data.Context, false).Resolve <GameWorld>(); var ent = gameWorld.CreateEntity(); gameWorld.AddComponent(ent, new IntComponent()); Global.Loop(); }
public unsafe void TestCustomSerializer() { TestFeatureExist(); // important! var app = RetrieveApplication(); var gameWorld = new ContextBindingStrategy(app.Data.Context, false).Resolve <GameWorld>(); var sendSystem = app.Data.Collection.GetOrCreate(c => new SendWorldStateSystem(c)); var serializer = new CustomIntSerializer(); sendSystem.SetComponentSerializer(gameWorld.AsComponentType <IntComponent>(), serializer); var ent = gameWorld.CreateEntity(); gameWorld.AddComponent(ent, new IntComponent()); Global.Loop(); Assert.AreEqual(serializer.Passed, 1); }
public GameHostModule(Entity source, Context ctxParent, GameHostModuleDescription description) { if (!description.IsNameIdValid()) { throw new InvalidOperationException($"The mod '{description.NameId}' has invalid characters!"); } Source = source; Ctx = new Context(ctxParent); Storage = this.storage = new(); DllStorage = new DllStorage(GetType().Assembly); ReferencedDisposables = new List <IDisposable>(); var strategy = new ContextBindingStrategy(Ctx, true); var storage = strategy.Resolve <IStorage>(); if (storage == null) { throw new NullReferenceException(nameof(storage)); } storage.GetOrCreateDirectoryAsync($"ModuleData/{description.NameId}").ContinueWith(OnRequiredDirectoryFound); }