Ejemplo n.º 1
0
        public static IEnumerable <SyntaxNode> Build(
            this RoslynEcsTranslator translator,
            SetComponentNodeModel model,
            IPortModel portModel)
        {
            var componentType    = model.ComponentType.Resolve(model.GraphModel.Stencil);
            var componentInputs  = model.GetPortsForComponent().ToArray();
            var entitySyntax     = translator.BuildPort(model.EntityPort).SingleOrDefault() as ExpressionSyntax;
            var componentSyntax  = translator.BuildComponentFromInput(componentType, componentInputs);
            var entityTranslator = translator.context.GetEntityManipulationTranslator();

            return(entityTranslator.SetComponent(translator.context, entitySyntax, componentType, componentSyntax));
        }
Ejemplo n.º 2
0
        public static IEnumerable <SyntaxNode> Build(this RoslynEcsTranslator translator, SetComponentNodeModel model,
                                                     IPortModel portModel)
        {
            var query            = translator.context.IterationContext.Query;
            var queryDeclaration = query.ComponentQueryDeclarationModel;
            var componentTypes   = model.GetComponentTypesFromEntityPort();

            if (!model.ComponentType.Equals(TypeHandle.Unknown) && !componentTypes.Any(c => c == model.ComponentType))
            {
                var componentName = model.ComponentType.Name(translator.Stencil);
                var queryCopy     = queryDeclaration;

                translator.AddError(
                    model,
                    $"A component of type {componentName} is required, which the query {queryDeclaration.Name} " +
                    "doesn't specify",
                    new CompilerQuickFix(
                        $"Add {componentName} to the query",
                        s => s.Dispatch(new AddComponentToQueryAction(
                                            queryCopy,
                                            model.ComponentType,
                                            ComponentDefinitionFlags.None))));

                return(Enumerable.Empty <SyntaxNode>());
            }

            if (!queryDeclaration.Components.Any())
            {
                translator.AddError(model, $"The query {queryDeclaration.Name} doesn't contain any component.");
                return(Enumerable.Empty <SyntaxNode>());
            }

            if (model.ComponentType.Equals(TypeHandle.Unknown))
            {
                translator.AddError(model, "You must select a valid component type");
                return(Enumerable.Empty <SyntaxNode>());
            }

            var entitySyntax     = translator.BuildEntityFromPortOrCurrentIteration(model.EntityPort);
            var componentType    = model.ComponentType.Resolve(model.GraphModel.Stencil);
            var componentInputs  = model.GetPortsForComponent().ToArray();
            var componentSyntax  = translator.BuildComponentFromInput(componentType, componentInputs);
            var entityTranslator = translator.context.GetEntityManipulationTranslator();

            return(entityTranslator.SetComponent(translator.context, entitySyntax, componentType, componentSyntax));
        }