Пример #1
0
        public void Setup()
        {
            _componentFactory = IoCManager.Resolve <IComponentFactory>();

            _componentFactory.Register <ThrowsInAddComponent>();
            _componentFactory.Register <ThrowsInExposeDataComponent>();
            _componentFactory.Register <ThrowsInInitializeComponent>();
            _componentFactory.Register <ThrowsInStartupComponent>();

            var compMan = IoCManager.Resolve <IComponentManager>();

            compMan.Initialize();

            EntityManager = IoCManager.Resolve <IServerEntityManager>();
            MapManager    = IoCManager.Resolve <IMapManager>();
            MapManager.Initialize();
            MapManager.Startup();

            MapManager.CreateNewMapEntity(MapId.Nullspace);

            var manager = IoCManager.Resolve <IPrototypeManager>();

            manager.LoadFromStream(new StringReader(PROTOTYPES));
            manager.Resync();

            //NOTE: The grids have not moved, so we can assert worldpos == localpos for the test
        }
Пример #2
0
        public void TestHotReload()
        {
            _maps.CreateNewMapEntity(new MapId(0));
            var entity          = _entities.SpawnEntity(DummyId, MapCoordinates.Nullspace);
            var entityComponent = entity.GetComponent <HotReloadTestComponentOne>();

            Assert.That(entityComponent.Value, Is.EqualTo(5));
            Assert.False(entity.HasComponent <HotReloadTestComponentTwo>());

            var reloaded = false;

            _prototypes.PrototypesReloaded += _ => reloaded = true;

            _prototypes.ReloadPrototypes(new List <IPrototype>());

            Assert.True(reloaded);
            reloaded = false;

            Assert.That(entityComponent.Value, Is.EqualTo(5));
            Assert.False(entity.HasComponent <HotReloadTestComponentTwo>());

            var changedPrototypes = _prototypes.LoadString(ReloadedPrototypes, true);

            _prototypes.ReloadPrototypes(changedPrototypes);

            Assert.True(reloaded);
            reloaded = false;

            // Existing component values are not modified in the current implementation
            Assert.That(entityComponent.Value, Is.EqualTo(5));

            // New components are added
            Assert.True(entity.HasComponent <HotReloadTestComponentTwo>());

            changedPrototypes = _prototypes.LoadString(InitialPrototypes, true);
            _prototypes.ReloadPrototypes(changedPrototypes);

            Assert.True(reloaded);
            reloaded = false;

            // Existing component values are not modified in the current implementation
            Assert.That(entityComponent.Value, Is.EqualTo(5));

            // Old components are removed
            Assert.False(entity.HasComponent <HotReloadTestComponentTwo>());
        }