public void AddServiceAndGetServiceTest() { string s = "Hello"; services.AddService(typeof(string), s); string s2 = (string)services.GetService(typeof(string)); Assert.AreSame(s, s2, "Service was not correctly added"); }
public void TestServiceConstructor() { var services = new GameServiceContainer(); using (var manager = new MockInputManager(services)) { Assert.IsNotNull(services.GetService(typeof(IInputService))); } Assert.IsNull(services.GetService(typeof(IInputService))); }
/// <summary> /// Initializes a new instance of the <see cref="BallFactory"/> using the specified services. /// </summary> /// <param name="services">The services to use when creating a new ball.</param> public BallFactory(GameServiceContainer services) { // Get services _gameInfo = services.GetService <GameInfo>(); _audioManager = services.GetService <AudioManager>(); GraphicsDeviceManager graphics = services.GetService <GraphicsDeviceManager>(); _ballPixel = new Texture2D(graphics.GraphicsDevice, 1, 1); _ballPixel.FillColor(Color.White); }
public AppoloCircles(GameServiceContainer services) { Services = services; _spriteBatch = Services.GetService <SpriteBatch>(); _graphics = Services.GetService <GraphicsDeviceManager>(); var w = _graphics.PreferredBackBufferWidth; var h = _graphics.PreferredBackBufferHeight; circles = new List <Circle>(); //var radius = h * 0.45f; float radius = w * 0.1f; float x = w / 2; float y = h / 2 - radius; var c1 = new Circle(new Vector2(x, y), radius, (int)(radius * 0.5f), 1, Color.White); x -= radius; y += (float)(radius * Math.Sqrt(3)); var c2 = new Circle(new Vector2(x, y), radius, (int)(radius * 0.5f), 1, Color.White); x += 2 * radius; var c3 = new Circle(new Vector2(x, y), radius, (int)(radius * 0.5f), 1, Color.White); circles.Add(c1); circles.Add(c2); circles.Add(c3); for (int i = 0; i < 1; i++) { var firstCircle = circles[0]; var fr = firstCircle.radius; var fp = firstCircle.position; radius = fr * 0.5f; var pos = new Vector2(x, y); var circle = new Circle(pos, radius, (int)(radius * 0.5f), 1, Color.White); //circles.Add(circle); } var d = SolveTheApollonius(1, c1, c2, c3); circles.Add(d); circles.Add(SolveTheApollonius(5, c1, c2, d)); }
/// <summary> /// Initializes a new instance of <see cref="PaddleFactory"/> using the specified services. /// </summary> /// <param name="services">The services to use when creating new paddles.</param> public PaddleFactory(GameServiceContainer services) { // Get services _gameInfo = services.GetService <GameInfo>(); _settingsManager = services.GetService <SettingsManager>(); _inputManager = services.GetService <InputManager>(); _actorRegistry = services.GetService <ActorRegistry>(); GraphicsDeviceManager graphics = services.GetService <GraphicsDeviceManager>(); _paddlePixel = new Texture2D(graphics.GraphicsDevice, 1, 1); _paddlePixel.FillColor(Color.White); }
protected virtual void ProcessTileMap() { if (TileMap == null) { return; } int renderLayer = (int)RenderLayer.One; foreach (var tileLayer in TileMap.Layers.OfType <TileMapTileLayer>()) { TileMapLayerRenderer renderer = new TileMapLayerRenderer(tileLayer); renderer.RenderLayer = (RenderLayer)renderLayer; EntityManager.AddEntity(renderer); renderLayer++; } foreach (var tileMapObjLayer in TileMap.Layers.OfType <TileMapObjectLayer>()) { foreach (var tileMapObj in tileMapObjLayer.Objects .Where(o => o.ObjectType == TileMapObjectType.Point && o.Type == OBJECT_TYPE_GAME_ENTITY)) { ITileMapPlaceable placeableObj = _tileMapEntitiyFactory.CreateEntity(tileMapObj); EntityManager.AddEntity(placeableObj); } foreach (var tileMapObj in tileMapObjLayer.Objects .Where(o => (o.ObjectType == TileMapObjectType.Polygon || o.ObjectType == TileMapObjectType.Rectangle) && o.Type == OBJECT_TYPE_COLLIDER)) { TileMapCollisionObject collisionObject = new TileMapCollisionObject(tileMapObj, _debugTexture); Collider collider = null; if (tileMapObj.ObjectType == TileMapObjectType.Polygon) { collider = _gameServices.GetService <IPhysicsManager>()?.CreatePolygonCollider(collisionObject, ((TileMapPolygonObject)tileMapObj).Vertices, 0); } else { collider = _gameServices.GetService <IPhysicsManager>()?.CreateRectCollider(collisionObject, ((TileMapRectangleObject)tileMapObj).Size, false); } collisionObject.Collider = collider; this.EntityManager.AddEntity(collisionObject); } } }
public void TestDispose() { GameServiceContainer gameServices = new GameServiceContainer(); MockedGraphicsDeviceService mockedGraphics = new MockedGraphicsDeviceService(); gameServices.AddService(typeof(IGraphicsDeviceService), mockedGraphics); using( SharedContentManager contentManager = new SharedContentManager(gameServices) ) { object service = gameServices.GetService(typeof(ISharedContentService)); Assert.AreSame(contentManager, service); } // Make sure the service was unregistered again when the shared content manager // got disposed object serviceAfterDispose = gameServices.GetService(typeof(ISharedContentService)); Assert.IsNull(serviceAfterDispose); }
/// <summary>Immediately releases all resources used the GUI manager</summary> public void Dispose() { // Unregister the service if we have registered it before if (_gameServices != null) { var registeredService = _gameServices.GetService(typeof(IGuiService)); if (ReferenceEquals(registeredService, this)) { _gameServices.RemoveService(typeof(IGuiService)); } } // Dispose the input capturer, if necessary if (_inputCapturer != null) { var disposableInputCapturer = _inputCapturer as IDisposable; disposableInputCapturer?.Dispose(); _updateableInputCapturer = null; _inputCapturer = null; } // Dispose the GUI visualizer, if necessary if (_guiVisualizer != null) { var disposableguiVisualizer = _guiVisualizer as IDisposable; disposableguiVisualizer?.Dispose(); _updateableGuiVisualizer = null; _guiVisualizer = null; } }
public void TestStandardConstructor() { var gameServices = new GameServiceContainer(); using (GuiManager guiManager = new GuiManager(gameServices)) { Assert.IsNotNull(gameServices.GetService(typeof(IGuiService))); } }
public TimeService(GameServiceContainer services) { _services = services; _penumbra = _services.GetService <PenumbraComponent>(); CurrentTime = new DateTime(); CurrentTime = CurrentTime.AddHours(12); }
/// <summary> /// サービスを取得します。 /// サービスが存在しない場合には InvalidOperationException を発生させます。 /// </summary> /// <param name="container">GameServiceContainer。</param> /// <param name="serviceType">サービスの型。</param> /// <returns>サービス。</returns> public static object GetRequiredService(this GameServiceContainer container, Type serviceType) { var service = container.GetService(serviceType); if (service == null) { throw new InvalidOperationException(string.Format("Service '{0}' not found", serviceType)); } return(service); }
protected void AddServiceToGame(Type i_Type) { GameServiceContainer gameServices = this.Game.Services; if (gameServices.GetService(i_Type) != null) { gameServices.RemoveService(i_Type); } gameServices.AddService(i_Type, this); }
/// <summary> /// Gets the service /// </summary> /// <returns>The service.</returns> /// <param name="self">Self.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static T GetService <T>(this GameServiceContainer self) where T : class { var service = self.GetService(typeof(T)); if (service == null) { return(null); } return((T)service); }
/// <summary> /// attempts to get the service and if it does not exist it will be created. Requires a parameterless /// constructor. /// </summary> /// <returns>The or add service.</returns> /// <param name="self">Self.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static T GetOrAddService <T>(this GameServiceContainer self) where T : class, new() { var service = self.GetService(typeof(T)); if (service == null) { return(AddService(self, new T())); } return((T)service); }
public void TestCompatibilityConstructor() { var gameServices = new GameServiceContainer(); using ( GuiManager guiManager = new GuiManager( gameServices, this.mockedGraphicsDeviceService, this.mockedInputService ) ) { Assert.IsNotNull(gameServices.GetService(typeof(IGuiService))); } }
public void TestServiceRegistration() { GameServiceContainer gameServices = new GameServiceContainer(); MockedGraphicsDeviceService mockedGraphics = new MockedGraphicsDeviceService(); gameServices.AddService(typeof(IGraphicsDeviceService), mockedGraphics); using( SharedContentManager contentManager = new SharedContentManager(gameServices) ) { object service = gameServices.GetService(typeof(ISharedContentService)); Assert.AreSame(contentManager, service); } }
public static Grid FromBitmap(GameServiceContainer services, string bitmapName) { var texture = ((ContentManager)services.GetService(typeof(ContentManager))).Load <Texture2D>(bitmapName); var grid = new Grid(texture.Width, texture.Height); for (var i = 0; i < grid.Size.Width; i++) { for (var j = 0; j < grid.Size.Height; j++) { var c = new Color[1]; texture.GetData(0, new Rectangle(i, j, 1, 1), c, 0, 1); grid.Weight[i, j] = (byte)((c[0].R + c[0].G + c[0].B) / 3); } } return(grid); }
public void Initialize(GameServiceContainer gameServices, ContentManager content, PropertyMap propMap, Vector2 position) { Health = propMap.GetInt("Health"); Tag = propMap["Tag"]; _spriteSheet = content.Load <Texture2D>(SPRITE_SHEET_PATH); Sprite = new Sprite(0, 0, SPRITE_SIZE, SPRITE_SIZE, _spriteSheet); Position = position; IPhysicsManager physicsManager = gameServices.GetService <IPhysicsManager>(); this.Collider = physicsManager.CreateRectCollider(this, new Vector2(ROCK_SIZE), false); _debugTexture = content.Load <Texture2D>(DEBUG_TEXTURE_PATH); }
/// <summary>Immediately releases all resources and unregisters the component</summary> public virtual void Dispose() { // Unregister the service if we registered it to the game service container GameServiceContainer serviceContainer = this.serviceProvider as GameServiceContainer; if (serviceContainer != null) { object registeredService = serviceContainer.GetService( typeof(ISharedContentService) ); if (ReferenceEquals(registeredService, this)) { serviceContainer.RemoveService(typeof(ISharedContentService)); } } // Release all content stored in the content manager if (this.contentManager != null) { this.contentManager.Dispose(); this.contentManager = null; } }
public object GetService(Type serviceType) { return(_services.GetService(serviceType)); }
public Shrub(GameServiceContainer services, Tile tile) : base(services, tile) { _playerCharacter = services.GetService <PlayerCharacter>(); }
public static T GetService <T>(this GameServiceContainer services) { return((T)services.GetService(typeof(T))); }
public T Get <T>() => (T)services.GetService(typeof(T));
/// <summary> /// サービスを取得します。 /// </summary> /// <typeparam name="T">サービスの型。</typeparam> /// <param name="container">GameServiceContainer。</param> /// <returns>サービス。</returns> public static T GetService <T>(this GameServiceContainer container) where T : class { return(container.GetService(typeof(T)) as T); }
/// <summary> /// Get the object of a type out of the container. /// </summary> /// <typeparam name="T">The type of the object to request.</typeparam> /// <returns>The object that was requested or null.</returns> public static T Get <T>() { return((T)_container.GetService(typeof(T))); }
public GenericGameObject(GameServiceContainer services, string assetName, string spriteName = null) : base(services) { _playerCharacter = services.GetService <PlayerCharacter>(); _assetName = assetName; _spriteName = spriteName; }
public TimePanel(GameServiceContainer services) { _timeService = services.GetService <TimeService>(); Triggers.Add(new ToggleVisibilityKeyboardTrigger(this, Keys.B)); }
public HanafudaController(GameServiceContainer services) { inputManager = services.GetService <IInputHandler>(); }
public Tent(GameServiceContainer services) : base(services) { _penumbra = services.GetService <PenumbraComponent>(); _playerCharacter = services.GetService <PlayerCharacter>(); }
public PlayerCharacter(GameServiceContainer services) : base(services) { _mapService = services.GetService <MapService>(); _gameObjectManager = services.GetService <GameObjectManager>(); _camera = services.GetService <Camera2D>(); }