private void StaticObjectManager_Added(object?sender, ManagerItemsChangedEventArgs <IStaticObject> e) { foreach (var staticObject in e.Items) { var staticObjectModel = new StaticObjectViewModel(_game, staticObject, _spriteBatch, true); _viewModelContext.GameObjects.Add(staticObjectModel); } }
public GameObjectsViewModel(GameObjectParams gameObjectParams) { _viewModelContext = gameObjectParams.SectorViewModelContext ?? throw new ArgumentException( $"{nameof(gameObjectParams.SectorViewModelContext)} is not defined.", nameof(gameObjectParams)); _player = gameObjectParams.Player ?? throw new ArgumentException($"{nameof(gameObjectParams.Player)} is not defined.", nameof(gameObjectParams)); _camera = gameObjectParams.Camera ?? throw new ArgumentException($"{nameof(gameObjectParams.Camera)} is not defined.", nameof(gameObjectParams)); _game = gameObjectParams.Game ?? throw new ArgumentException($"{nameof(gameObjectParams.Game)} is not defined.", nameof(gameObjectParams)); _spriteBatch = gameObjectParams.SpriteBatch ?? throw new ArgumentException($"{nameof(gameObjectParams.SpriteBatch)} is not defined.", nameof(gameObjectParams)); _uiState = gameObjectParams.UiState ?? throw new ArgumentException( $"{nameof(gameObjectParams.UiState)} is not defined.", nameof(gameObjectParams)); foreach (var actor in _viewModelContext.Sector.ActorManager.Items) { var actorViewModel = new ActorViewModel(actor, gameObjectParams); if (actor.Person == _player.MainPerson) { _uiState.ActiveActor = actorViewModel; } _viewModelContext.GameObjects.Add(actorViewModel); } foreach (var staticObject in _viewModelContext.Sector.StaticObjectManager.Items) { var staticObjectModel = new StaticObjectViewModel(gameObjectParams.Game, staticObject, gameObjectParams.SpriteBatch); _viewModelContext.GameObjects.Add(staticObjectModel); } var sector = _viewModelContext.Sector; sector.ActorManager.Removed += ActorManager_Removed; sector.StaticObjectManager.Added += StaticObjectManager_Added; sector.StaticObjectManager.Removed += StaticObjectManager_Removed; }