/// <summary>
        /// Create a new CodeLens instance around a given editor session
        /// from the component registry.
        /// </summary>
        /// <param name="components">
        /// The component registry to provider other components and to register the CodeLens provider in.
        /// </param>
        /// <param name="editorSession">The editor session context of the CodeLens provider.</param>
        /// <returns>A new CodeLens provider for the given editor session.</returns>
        public static CodeLensFeature Create(
            IComponentRegistry components,
            EditorSession editorSession)
        {
            var codeLenses =
                new CodeLensFeature(
                    editorSession,
                    JsonSerializer.Create(Constants.JsonSerializerSettings),
                    components.Get <ILogger>());

            var messageHandlers = components.Get <IMessageHandlers>();

            messageHandlers.SetRequestHandler(
                CodeLensRequest.Type,
                codeLenses.HandleCodeLensRequest);

            messageHandlers.SetRequestHandler(
                CodeLensResolveRequest.Type,
                codeLenses.HandleCodeLensResolveRequest);

            codeLenses.Providers.Add(
                new ReferencesCodeLensProvider(
                    editorSession));

            codeLenses.Providers.Add(
                new PesterCodeLensProvider(
                    editorSession));

            editorSession.Components.Register <ICodeLenses>(codeLenses);

            return(codeLenses);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers the feature components in this module with the
        /// host editor.
        /// </summary>
        /// <param name="components">
        /// The IComponentRegistry where feature components will be registered.
        /// </param>
        public static void Register(IComponentRegistry components)
        {
            ILogger logger = components.Get <ILogger>();

            components.Register <IHtmlContentViews>(
                new HtmlContentViewsFeature(
                    components.Get <IMessageSender>(),
                    logger));

            logger.Write(
                LogLevel.Normal,
                "PowerShell Editor Services VS Code module loaded.");
        }
        public static void Initialize(IComponentRegistry componentRegistry)
        {
            if (_isRunning) throw new AlreadyInitializedException();

            var app = componentRegistry.Get<IMongoMigration>();
            app.Run();

            _isRunning = true;
        }
Exemplo n.º 4
0
        public static CodeLensFeature Create(
            IComponentRegistry components,
            EditorSession editorSession)
        {
            var codeLenses =
                new CodeLensFeature(
                    editorSession,
                    components.Get <IMessageHandlers>(),
                    components.Get <ILogger>());

            codeLenses.Providers.Add(
                new ReferencesCodeLensProvider(
                    editorSession));

            codeLenses.Providers.Add(
                new PesterCodeLensProvider(
                    editorSession));

            editorSession.Components.Register <ICodeLenses>(codeLenses);

            return(codeLenses);
        }
        public override void Update(GameTime gameTime)
        {
            // Get running worlds.
            IReadOnlyList <IWorld> worlds = worldManager.GetWorldsInState(WorldState.Running);

            // For each running world, update physics.
            foreach (IWorld world in worlds)
            {
                // Store component manager.
                IComponentManager componentManager = world.ComponentManager;

                // Check if the world has the required component registries.
                if (!componentManager.ContainsRegistry <PhysicsComponent>() ||
                    !componentManager.ContainsRegistry <PositionComponent>())
                {
                    continue;
                }

                // Get component registries.
                IComponentRegistry <PhysicsComponent> physicsComponents =
                    (IComponentRegistry <PhysicsComponent>)componentManager.GetRegistry <PhysicsComponent>();
                IComponentRegistry <PositionComponent> positionComponents =
                    (IComponentRegistry <PositionComponent>)componentManager.GetRegistry <PositionComponent>();

                // Iterate physics components.
                for (int i = 0; i < physicsComponents.Count; i++)
                {
                    // Get components
                    PhysicsComponent  physics  = physicsComponents[i];
                    PositionComponent position = positionComponents.Get(physics.EntityID);

                    // Update physics.

                    // Calculate delta time.
                    float dt = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000;

                    // Calculate velocity.
                    physics.VelocityX += (physics.AccelerationX * dt) + physics.GravityX;
                    physics.VelocityY += (physics.AccelerationY * dt) + physics.GravityY;

                    // Update position.
                    position.X += physics.VelocityX * dt;
                    position.Y += physics.VelocityY * dt;

                    // Store.
                    physicsComponents[i] = physics;
                    positionComponents.Set(position);
                }
            }
        }
Exemplo n.º 6
0
        public override void Update(GameTime gameTime)
        {
            // Check if there events to process.
            if (scoreEvents.Count == 0)
            {
                return;
            }

            // Get HUD world.
            IWorld world = worldManager.GetWorld((int)WorldID.HudWorld);

            // Get text render component registry.
            IComponentRegistry <TextRenderComponent> textRenders =
                (IComponentRegistry <TextRenderComponent>)world.ComponentManager.GetRegistry <TextRenderComponent>();

            foreach (ScoreEvent score in scoreEvents)
            {
                // Update score and text.
                if (score.Player == 1)
                {
                    player1Score += score.Amount;
                    TextRenderComponent component = textRenders.Get(player1Text);
                    component.Text = player1Score.ToString();
                    textRenders.Set(component);
                }
                else
                {
                    player2Score += score.Amount;
                    TextRenderComponent component = textRenders.Get(player2Text);
                    component.Text = player2Score.ToString();
                    textRenders.Set(component);
                }
            }

            // Clear list.
            scoreEvents.Clear();
        }
        public static DocumentSymbolFeature Create(
            IComponentRegistry components,
            EditorSession editorSession)
        {
            var documentSymbols =
                new DocumentSymbolFeature(
                    editorSession,
                    components.Get <IMessageHandlers>(),
                    components.Get <ILogger>());

            documentSymbols.Providers.Add(
                new ScriptDocumentSymbolProvider(
                    editorSession.PowerShellContext.LocalPowerShellVersion.Version));

            documentSymbols.Providers.Add(
                new PsdDocumentSymbolProvider());

            documentSymbols.Providers.Add(
                new PesterDocumentSymbolProvider());

            editorSession.Components.Register <IDocumentSymbols>(documentSymbols);

            return(documentSymbols);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Renders a world.
        /// </summary>
        /// <param name="world">The world to render.</param>
        private void RenderWorld(IWorld world)
        {
            // Store component manager.
            IComponentManager componentManager = world.ComponentManager;

            // Check if the world has the required component registries.
            if (!componentManager.ContainsRegistry <PositionComponent>() ||
                !componentManager.ContainsRegistry <Texture2DRenderComponent>() ||
                !componentManager.ContainsRegistry <TransformComponent>())
            {
                return;
            }

            // Get component registries.
            IComponentRegistry <PositionComponent> positionComponents =
                (IComponentRegistry <PositionComponent>)componentManager.GetRegistry <PositionComponent>();
            IComponentRegistry <Texture2DRenderComponent> texture2DComponents =
                (IComponentRegistry <Texture2DRenderComponent>)componentManager.GetRegistry <Texture2DRenderComponent>();
            IComponentRegistry <TransformComponent> transformComponents =
                (IComponentRegistry <TransformComponent>)componentManager.GetRegistry <TransformComponent>();

            // Begin sprite batch.
            spriteBatch.Begin();

            // Iterate Texture 2D components.
            for (int i = 0; i < texture2DComponents.Count; i++)
            {
                // Get components.
                Texture2DRenderComponent texture   = texture2DComponents[i];
                PositionComponent        position  = positionComponents.Get(texture.EntityID);
                TransformComponent       transform = transformComponents.Get(texture.EntityID);

                // Render.
                spriteBatch.Draw(texture.Texture, new Vector2(position.X, position.Y), null, Color.White,
                                 transform.Rotation, new Vector2(0, 0), transform.Scale, SpriteEffects.None, 0);
            }

            // End sprite batch.
            spriteBatch.End();
        }
Exemplo n.º 9
0
        public override void Update(GameTime gameTime)
        {
            // Get running worlds.
            IReadOnlyList <IWorld> worlds = worldManager.GetWorldsInState(WorldState.Running);

            // Iterate through worlds.
            foreach (IWorld world in worlds)
            {
                // Check if the world has the sprite font component.
                if (!world.ComponentManager.ContainsRegistry <TextRenderComponent>())
                {
                    continue;
                }

                // Get component registries.
                IComponentRegistry <PositionComponent> positionComponents =
                    (IComponentRegistry <PositionComponent>)world.ComponentManager.GetRegistry <PositionComponent>();
                IComponentRegistry <TextRenderComponent> spriteFontComponents =
                    (IComponentRegistry <TextRenderComponent>)world.ComponentManager.GetRegistry <TextRenderComponent>();

                // Begin sprite batch.
                spriteBatch.Begin();

                // Iterate through sprite font components and render.
                foreach (TextRenderComponent component in spriteFontComponents)
                {
                    // Get position.
                    PositionComponent position = positionComponents.Get(component.EntityID);

                    // Render text.
                    spriteBatch.DrawString(component.Font, component.Text, new Vector2(position.X, position.Y), component.Colour);
                }

                // End sprite batch.
                spriteBatch.End();
            }
        }
Exemplo n.º 10
0
        public override void Update(GameTime gameTime)
        {
            // Var to store collision event data.
            IList <CollisionEvent> collisionEvents = new List <CollisionEvent>();

            // Get running worlds.
            IReadOnlyList <IWorld> worlds = worldManager.GetWorldsInState(WorldState.Running);

            // Run through running worlds and check for collisions.
            foreach (IWorld world in worlds)
            {
                // Store component manager.
                IComponentManager componentManager = world.ComponentManager;

                // Check if the world has the required component registries.
                if (!componentManager.ContainsRegistry <CircleCollisionComponent>() ||
                    !componentManager.ContainsRegistry <CollidableComponent>() ||
                    !componentManager.ContainsRegistry <PositionComponent>() ||
                    !componentManager.ContainsRegistry <TransformComponent>())
                {
                    continue;
                }

                // Get component registries.
                IComponentRegistry <CircleCollisionComponent> circleCollisionComponents =
                    (IComponentRegistry <CircleCollisionComponent>)componentManager.GetRegistry <CircleCollisionComponent>();
                IComponentRegistry <CollidableComponent> collidableComponents =
                    (IComponentRegistry <CollidableComponent>)componentManager.GetRegistry <CollidableComponent>();
                IComponentRegistry <PositionComponent> positionComponents =
                    (IComponentRegistry <PositionComponent>)componentManager.GetRegistry <PositionComponent>();
                IComponentRegistry <TransformComponent> transformComponents =
                    (IComponentRegistry <TransformComponent>)componentManager.GetRegistry <TransformComponent>();

                // Iterate circle collision components.
                for (int i = 0; i < circleCollisionComponents.Count; i++)
                {
                    // Get components.
                    CircleCollisionComponent circle    = circleCollisionComponents[i];
                    PositionComponent        position  = positionComponents.Get(circle.EntityID);
                    TransformComponent       transform = transformComponents.Get(circle.EntityID);

                    // Iterate collidable components and calculate collision.
                    for (int j = 0; j < collidableComponents.Count; j++)
                    {
                        // Get components for collidable entity.
                        CollidableComponent collidable          = collidableComponents[j];
                        PositionComponent   collidablePosition  = positionComponents.Get(collidable.EntityID);
                        TransformComponent  collidableTransform = transformComponents.Get(collidable.EntityID);

                        // Calculate the radius of the entities.
                        float rA = (transform.Scale * transform.Width) / 2;
                        float rB = (collidableTransform.Scale * collidableTransform.Width) / 2;

                        // Check if the distance between the two entities is less than the radii.
                        if (Vector2.Distance(new Vector2(position.X, position.Y),
                                             new Vector2(collidablePosition.X, collidablePosition.Y)) < (rA + rB))
                        {
                            // Entities collided.
                            collisionEvents.Add(new CollisionEvent(circle.EntityID, collidable.EntityID, world.ID));
                        }
                    }
                }
            }

            // An entity can be both a collider and a collidable, so filter out any events where this is true.
            // We could check this before performing the collision detection but we want to avoid
            // branch predictions in the hot path as much as possible.
            collisionEvents = collisionEvents.Where(x => x.Collidable != x.Collider).ToList();

            // Emit events.
            foreach (CollisionEvent collisionEvent in collisionEvents)
            {
                eventManager.Emit(collisionEvent);
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Gets the registered instance of the specified
 /// component type or throws a KeyNotFoundException if
 /// no instance has been registered.
 /// </summary>
 /// <param name="componentRegistry">
 /// The IComponentRegistry instance.
 /// </param>
 /// <returns>The implementation of the specified type.</returns>
 public static TComponent Get <TComponent>(
     this IComponentRegistry componentRegistry)
     where TComponent : class
 {
     return((TComponent)componentRegistry.Get(typeof(TComponent)));
 }
        public override void Update(GameTime gameTime)
        {
            // Var to store collision event data.
            IList <CollisionEvent> collisionEvents = new List <CollisionEvent>();

            // Get running worlds.
            IReadOnlyList <IWorld> worlds = worldManager.GetWorldsInState(WorldState.Running);

            // Run through running worlds and check for collisions.
            foreach (IWorld world in worlds)
            {
                // Store component manager.
                IComponentManager componentManager = world.ComponentManager;

                // Check if the world has the required component registries.
                if (!componentManager.ContainsRegistry <CollidableComponent>() ||
                    !componentManager.ContainsRegistry <HitboxCollisionComponent>() ||
                    !componentManager.ContainsRegistry <PositionComponent>() ||
                    !componentManager.ContainsRegistry <TransformComponent>())
                {
                    continue;
                }

                // Get component registries.
                IComponentRegistry <CollidableComponent> collidableComponents =
                    (IComponentRegistry <CollidableComponent>)componentManager.GetRegistry <CollidableComponent>();
                IComponentRegistry <HitboxCollisionComponent> hitboxCollisionComponents =
                    (IComponentRegistry <HitboxCollisionComponent>)componentManager.GetRegistry <HitboxCollisionComponent>();
                IComponentRegistry <PositionComponent> positionComponents =
                    (IComponentRegistry <PositionComponent>)componentManager.GetRegistry <PositionComponent>();
                IComponentRegistry <TransformComponent> transformComponents =
                    (IComponentRegistry <TransformComponent>)componentManager.GetRegistry <TransformComponent>();

                // Iterate hitbox collision components.
                for (int i = 0; i < hitboxCollisionComponents.Count; i++)
                {
                    // Get components.
                    HitboxCollisionComponent hitbox    = hitboxCollisionComponents[i];
                    PositionComponent        position  = positionComponents.Get(hitbox.EntityID);
                    TransformComponent       transform = transformComponents.Get(hitbox.EntityID);

                    // Iterate collidable components and calculate collision.
                    for (int j = 0; j < collidableComponents.Count; j++)
                    {
                        // Get components for collidable entity.
                        CollidableComponent collidable          = collidableComponents[j];
                        PositionComponent   collidablePosition  = positionComponents.Get(collidable.EntityID);
                        TransformComponent  collidableTransform = transformComponents.Get(collidable.EntityID);

                        // Create hitboxes.
                        Rectangle entityA = new Rectangle((int)position.X, (int)position.Y, transform.Width, transform.Height);
                        Rectangle entityB = new Rectangle((int)collidablePosition.X, (int)collidablePosition.Y,
                                                          collidableTransform.Width, collidableTransform.Height);

                        // Perform collision detection.
                        if (entityA.Intersects(entityB))
                        {
                            // Entities collided.
                            collisionEvents.Add(new CollisionEvent(hitbox.EntityID, collidable.EntityID, world.ID));
                        }
                    }
                }
            }

            // An entity can be both a collider and a collidable, so filter out any events where this is true.
            // We could check this before performing the collision detection but we want to avoid
            // branch predictions in the hot path as much as possible.
            collisionEvents = collisionEvents.Where(x => x.Collidable != x.Collider).ToList();

            // Emit events.
            foreach (CollisionEvent collisionEvent in collisionEvents)
            {
                eventManager.Emit(collisionEvent);
            }
        }