コード例 #1
0
        public void TestEmbeddedProperties()
        {
            //Given
            var node = new DrawableNode();

            //When
            node.Load(@"
<Box xmlns=""osufx://osu.Framework/*""
    Size=""100,200""
    RelativeSizeAxes=""Both""/>");

            //Then
            Assert.Equal(typeof(Box).FullName, node.DrawableType.FullName);
            Assert.Collection(node.Properties,
                              size =>
            {
                Assert.Equal("Size", size.Name);
                Assert.IsType <EmbeddedDrawableProperty>(size);
                Assert.Equal(new Vector2(100, 200), ((EmbeddedDrawableProperty)size).ParsedValue);
            },
                              axes =>
            {
                Assert.Equal("RelativeSizeAxes", axes.Name);
                Assert.IsType <EmbeddedDrawableProperty>(axes);
                Assert.Equal(Axes.Both, ((EmbeddedDrawableProperty)axes).ParsedValue);
            });
        }
コード例 #2
0
ファイル: Drawable.cs プロジェクト: buzs/YmtEditor
        public void NumTextureChanged(int Value, int TexId)
        {
            NumTextures = Value;
            foreach (XmlNode tex in DrawableNode.SelectNodes("aTexData"))
            {
                if (onCreateDocElement == null)
                {
                    return;
                }
                tex.RemoveAll();
                XmlElement elemtex = (XmlElement)tex;
                elemtex.SetAttribute("itemType", "CPVTextureData");
                for (int i = 0; i < Value; i++)
                {
                    XmlElement elem_item = onCreateDocElement("Item");
                    elemtex.AppendChild(elem_item);
                    XmlElement elem_texId = onCreateDocElement("texId");
                    elem_item.AppendChild(elem_texId);
                    elem_texId.SetAttribute("value", TexId.ToString());

                    XmlElement elem_distr = onCreateDocElement("distribution");
                    elem_item.AppendChild(elem_distr);
                    elem_distr.SetAttribute("value", "255");
                }
            }
        }
コード例 #3
0
        public void TestLoadValidContainer()
        {
            //Given
            var node = new DrawableNode();

            //When
            node.Load(@"
<Container xmlns=""osufx://osu.Framework/*"">
    <Box/>
    <SpriteText/>
    <Container Name=""ContainerInContainer"">
        <Box/>
    </Container>
</Container>");

            // Then
            Assert.Equal(typeof(Container).FullName, node.DrawableType.FullName);
            Assert.Collection(node,
                              box => Assert.Equal(typeof(Box).FullName, box.DrawableType.FullName),
                              spriteText => Assert.Equal(typeof(SpriteText).FullName, spriteText.DrawableType.FullName),
                              container =>
            {
                Assert.Equal(typeof(Container).FullName, container.DrawableType.FullName);
                Assert.Collection(container,
                                  box => Assert.Equal(typeof(Box).FullName, box.DrawableType.FullName));
            });
        }
コード例 #4
0
 public DrawableCom()
 {
     DrawableNode = new DrawableNode()
     {
         Drawable = this
     };
 }
コード例 #5
0
        public static ExpressionSyntax GenerateChildInitializer(DrawableNode node)
        {
            var list = new List <ExpressionSyntax>();

            list.AddRange(node.Properties.Select(DrawablePropertyGenerator.GenerateInitializerSyntax));

            if (node.IsContainer && node.Any())
            {
                list.Add(GenerateChildrenInitializers(node));
            }

            var expression = (ExpressionSyntax)ObjectCreationExpression(
                type: ParseTypeName(node.DrawableType.FullName),
                argumentList: null,
                initializer: InitializerExpression(
                    kind: SyntaxKind.ObjectInitializerExpression,
                    expressions: SeparatedList <ExpressionSyntax>(list)
                    )
                );

            if (node.IsNameSpecified)
            {
                expression = AssignmentExpression(
                    kind: SyntaxKind.SimpleAssignmentExpression,
                    left: IdentifierName(node.GivenName),
                    right: expression
                    );
            }

            return(expression);
        }
コード例 #6
0
        public static BlockSyntax GenerateBody(DrawableNode node)
        {
            var list = new List <StatementSyntax>();

            list.AddRange(GenerateLocalBoundPropertyInitializers(node));
            list.Add(ExpressionStatement(GenerateChildrenInitializers(node)));

            return(Block(List <StatementSyntax>(list)));
        }
コード例 #7
0
        public static SyntaxList <MemberDeclarationSyntax> GenerateMembers(DrawableNode node)
        {
            var list = new List <MemberDeclarationSyntax>();

            list.AddRange(node.GeneratePropertySyntaxesOfDescendants());
            list.Add(node.GenerateConstructorSyntax());
            list.Add(node.GenerateBackgroundLoaderSyntax());

            return(List <MemberDeclarationSyntax>(list));
        }
コード例 #8
0
        public void TestNonexistentProperty()
        {
            //Given
            var node = new DrawableNode();

            //Then
            Assert.Throws <MarkupException>(() => node.Load(@"
<Box xmlns=""osufx://osu.Framework/*""
    MyNonexistentProperty=""1234""/>"));
        }
コード例 #9
0
ファイル: Drawable.cs プロジェクト: buzs/YmtEditor
 public void MaskChanged(int Value)
 {
     Mask = Value;
     if (DrawableNode != null)
     {
         foreach (XmlNode mask in DrawableNode.SelectNodes("propMask"))
         {
             mask.Attributes["value"].Value = Value.ToString();
         }
     }
 }
コード例 #10
0
 public static NamespaceDeclarationSyntax GenerateSyntax(this DrawableNode node, string namespaceName)
 {
     return(NamespaceDeclaration(
                name: ParseName(namespaceName),
                externs: List <ExternAliasDirectiveSyntax>(),
                usings: List <UsingDirectiveSyntax>(),
                members: SingletonList <MemberDeclarationSyntax>(
                    node.GenerateClassSyntax()
                    )
                ));
 }
コード例 #11
0
        public void TestInvalidChildrenProperty()
        {
            //Given
            var node = new DrawableNode();

            //Then
            Assert.Throws <MarkupException>(() => node.Load(@"
<Box xmlns=""osufx://osu.Framework/*""
    Name=""MyBox""
    Children=""Should throw exception here""/>"));
        }
コード例 #12
0
        public void TestLoadInvalidContainer()
        {
            //Given
            var node = new DrawableNode();

            //Then
            Assert.Throws <MarkupException>(() => node.Load(@"
<Box xmlns=""osufx://osu.Framework/*"">
    <Box/>
    <SpriteText/>
</Box>"));
        }
コード例 #13
0
        public void TestGenerate()
        {
            //Given
            var doc  = new DrawableNode();
            var code =
                @"public partial class MyContainer : osu.Framework.Graphics.Containers.Container
{
    public osu.Framework.Graphics.Shapes.Box MyBox { get; private set; }

    public MyContainer()
    {
        Name = ""MyContainer"";
        RelativeSizeAxes = osu.Framework.Graphics.Axes.Both;
    }

    [osu.Framework.Allocation.BackgroundDependencyLoaderAttribute]
    private void load()
    {
        Children = new osu.Framework.Graphics.Drawable[]
        {
            MyBox = new osu.Framework.Graphics.Shapes.Box
            {
                Name = ""MyBox"",
                Colour = osu.Framework.Graphics.Colour.ColourInfo.SingleColour(new osuTK.Graphics.Color4(1F, 0F, 1F, 1F))
            }
        };
    }
}";

            doc.Load(@"
<Container
    xmlns=""osufx://osu.Framework/*""
    Name=""MyContainer""
    RelativeSizeAxes=""Both"">
    <Box
        Name=""MyBox""
        Colour=""#ff00ff""/>
</Container>");

            //When
            string generated;

            using (var writer = new StringWriter())
            {
                doc.GenerateClass(writer);
                generated = writer.ToString();
            }

            //Then
            Console.WriteLine(generated);
            Assert.Equal(code.RemoveAllSpaces(), generated.RemoveAllSpaces());
        }
コード例 #14
0
 public static ConstructorDeclarationSyntax GenerateConstructorSyntax(this DrawableNode node)
 {
     return(ConstructorDeclaration(
                attributeLists: List <AttributeListSyntax>(),
                modifiers: TokenList(
                    Token(SyntaxKind.PublicKeyword)
                    ),
                identifier: Identifier(node.GivenName),
                parameterList: ParameterList(),
                initializer: null,
                body: GenerateBody(node)
                ));
 }
コード例 #15
0
        public void TestInvalidBindingName()
        {
            //Given
            var node = new DrawableNode();

            //When
            node.Load(@"
<Box xmlns=""osufx://osu.Framework/*""
    Name=""{Binding Local=BoxName}""/>");

            //Then
            Assert.Throws <MarkupException>(() => node.GivenName);
        }
コード例 #16
0
        private KeyValuePair <List <Drawable>, List <KeyValuePair <int, int> > > GetDrawableStructureFromNodes(List <Node <int, string> > nodes)
        {
            var objects     = new List <Drawable>();
            var connections = new List <KeyValuePair <int, int> >();
            var r           = new Random();

            for (var i = 1; i < nodes.Count + 1; i++)
            {
                var drawableNode = new DrawableNode(new Point(r.Next(60, displayPanel.Width - 60), r.Next(60, displayPanel.Height - 60)), i);
                objects.Add(drawableNode);
                connections.AddRange(nodes[i - 1].Neighbors.Select(n => new KeyValuePair <int, int>(i, nodes.IndexOf(nodes.First(p => p.GetId().Id == n.Id)) + 1)).ToArray());
            }
            return(new KeyValuePair <List <Drawable>, List <KeyValuePair <int, int> > >(objects, connections));
        }
コード例 #17
0
        public void TestLoad()
        {
            //Given
            var node = new DrawableNode();

            //When
            node.Load(@"
<Box xmlns=""osufx://osu.Framework/*""
    Name=""MyBox""/>");

            //Then
            Assert.Equal(typeof(Box).FullName, node.DrawableType.FullName);
            Assert.Equal("MyBox", node.GivenName);
        }
コード例 #18
0
        public static void GenerateClass(
            this DrawableNode node,
            TextWriter writer,
            string indentation   = "    ",
            string lineSeparator = null
            )
        {
            var syntax = node.GenerateClassSyntax().NormalizeWhitespace(
                indentation: indentation,
                eol: lineSeparator ?? Environment.NewLine
                );

            syntax.WriteTo(writer);
        }
コード例 #19
0
 public static ClassDeclarationSyntax GenerateClassSyntax(this DrawableNode node)
 {
     return(ClassDeclaration(
                attributeLists: List <AttributeListSyntax>(),
                modifiers: TokenList(
                    Token(SyntaxKind.PublicKeyword),
                    Token(SyntaxKind.PartialKeyword)
                    ),
                identifier: Identifier(node.GivenName),
                typeParameterList: null,
                baseList: BaseList(SingletonSeparatedList <BaseTypeSyntax>(
                                       SimpleBaseType(ParseTypeName(node.DrawableType.FullName))
                                       )),
                constraintClauses: List <TypeParameterConstraintClauseSyntax>(),
                members: GenerateMembers(node)
                ));
 }
コード例 #20
0
 public static ExpressionSyntax GenerateChildrenInitializers(DrawableNode node)
 {
     return(AssignmentExpression(
                kind: SyntaxKind.SimpleAssignmentExpression,
                left: IdentifierName(nameof(Container.Children)),
                right: ArrayCreationExpression(
                    type: ArrayType(
                        elementType: ParseTypeName(typeof(Drawable).FullName),
                        rankSpecifiers: SingletonList <ArrayRankSpecifierSyntax>(ArrayRankSpecifier())
                        ),
                    initializer: InitializerExpression(
                        kind: SyntaxKind.ArrayInitializerExpression,
                        expressions: SeparatedList <ExpressionSyntax>(
                            node.Select(GenerateChildInitializer)
                            )
                        )
                    )
                ));
 }
コード例 #21
0
ファイル: Drawable.cs プロジェクト: buzs/YmtEditor
        public void TextIDChanged(string Value)
        {
            TexId = Convert.ToInt32(Value);

            if (DrawableNode != null)
            {
                foreach (XmlNode tex in DrawableNode.SelectNodes("aTexData"))
                {
                    foreach (XmlNode texItem in tex.SelectNodes("Item"))
                    {
                        foreach (XmlNode texIdItem in texItem.SelectNodes("texId"))
                        {
                            XmlElement elemtexId = (XmlElement)texIdItem;
                            elemtexId.SetAttribute("value", Value);
                        }
                    }
                }
            }
        }
コード例 #22
0
 public static MethodDeclarationSyntax GenerateBackgroundLoaderSyntax(this DrawableNode node)
 {
     return(MethodDeclaration(
                attributeLists: SingletonList <AttributeListSyntax>(AttributeList(SingletonSeparatedList <AttributeSyntax>(
                                                                                      Attribute(ParseName(typeof(BackgroundDependencyLoaderAttribute).FullName))
                                                                                      ))),
                modifiers: TokenList(
                    Token(SyntaxKind.PrivateKeyword)
                    ),
                returnType: PredefinedType(
                    Token(SyntaxKind.VoidKeyword)
                    ),
                explicitInterfaceSpecifier: null,
                identifier: Identifier("load"),
                typeParameterList: null,
                parameterList: ParameterList(),
                constraintClauses: List <TypeParameterConstraintClauseSyntax>(),
                body: GenerateBody(node),
                expressionBody: null
                ));
 }
コード例 #23
0
        async Task updateAsync()
        {
            await Task.Delay(TimeSpan.FromMilliseconds(UpdateDebounceTime));

            try
            {
                // Read and parse markup
                var node = new DrawableNode();
                node.Load(_documentContent);

                // Create drawable from markup
                var drawable = node.CreateDrawable();

                Schedule(() =>
                {
                    _content.Child = drawable;
                    _content.FadeIn(200);

                    _statusText.Text = "Waiting...";
                    _statusText.FadeColour(Color4.White, 200);

                    _errorDisplay.FadeOut(200);
                });
            }
            catch (Exception e)
            {
                Schedule(() =>
                {
                    _statusText.Text = "Error!";
                    _statusText.FadeColour(DesignerColours.Error, 200);

                    _error.Value = e;
                    _errorDisplay.FadeIn(200);
                });
            }
        }
コード例 #24
0
        public void TestGenerate2()
        {
            var doc  = new DrawableNode();
            var code =
                @"public partial class MyScreen : osu.Framework.Screens.Screen
{
    public osu.Framework.Graphics.Containers.Container MyFirstContainer { get; private set; }
    public osu.Framework.Graphics.Containers.Container MySecondContainer { get; private set; }
    public osu.Framework.Graphics.Shapes.Box MyInnermostBox { get; private set; }

    public MyScreen()
    {
        Name = ""MyScreen"";
    }

    [osu.Framework.Allocation.BackgroundDependencyLoaderAttribute]
    private void load()
    {
        Children = new osu.Framework.Graphics.Drawable[]
        {
            MyFirstContainer = new osu.Framework.Graphics.Containers.Container
            {
                Name = ""MyFirstContainer"",
                RelativeSizeAxes = osu.Framework.Graphics.Axes.Both,
                Colour = osu.Framework.Graphics.Colour.ColourInfo.SingleColour(new osuTK.Graphics.Color4(1F, 0F, 1F, 1F)),
                Children = new osu.Framework.Graphics.Drawable[]
                {
                    new osu.Framework.Graphics.Shapes.Box
                    {
                        RelativeSizeAxes = osu.Framework.Graphics.Axes.Both
                    },
                    MySecondContainer = new osu.Framework.Graphics.Containers.Container
                    {
                        Name = ""MySecondContainer"",
                        RelativeSizeAxes = osu.Framework.Graphics.Axes.Both,
                        Colour = osu.Framework.Graphics.Colour.ColourInfo.GradientVertical(new osuTK.Graphics.Color4(0F, 0F, 1F, 1F), new osuTK.Graphics.Color4(1F, 0F, 0F, 1F)),
                        Padding = new osu.Framework.Graphics.MarginPadding(100F),
                        Children = new osu.Framework.Graphics.Drawable[]
                        {
                            MyInnermostBox = new osu.Framework.Graphics.Shapes.Box
                            {
                                Name = ""MyInnermostBox"",
                                RelativeSizeAxes = osu.Framework.Graphics.Axes.Both
                            }
                        }
                    }
                }
            }
        };
    }
}";

            doc.Load(@"
<Screen
    xmlns=""osufx://osu.Framework/*""
    Name=""MyScreen"">
    <Container
        Name=""MyFirstContainer""
        RelativeSizeAxes=""Both""
        Colour=""#ff00ff"">
        <Box
            RelativeSizeAxes=""Both""/>
        <Container
            Name=""MySecondContainer""
            RelativeSizeAxes=""Both""
            Colour=""gradient(vertical, #0000ff, #ff0000)""
            Padding=""100"">
            <Box
                Name=""MyInnermostBox""
                RelativeSizeAxes=""Both""/>
        </Container>
    </Container>
</Screen>");

            //When
            string generated;

            using (var writer = new StringWriter())
            {
                doc.GenerateClass(writer);
                generated = writer.ToString();
            }

            //Then
            Console.WriteLine(generated);
            Assert.Equal(code.RemoveAllSpaces(), generated.RemoveAllSpaces());
        }
コード例 #25
0
 public static IEnumerable <DrawableNode> EnumerateDescendantsWithName(DrawableNode node) =>
 node.RecursiveSelect(n => n).Where(n => n.IsNameSpecified);
コード例 #26
0
 public static IEnumerable <PropertyDeclarationSyntax> GeneratePropertySyntaxesOfDescendants(this DrawableNode node)
 {
     foreach (var d in EnumerateDescendantsWithName(node))
     {
         yield return(PropertyDeclaration(
                          attributeLists: List <AttributeListSyntax>(),
                          modifiers: TokenList(
                              Token(SyntaxKind.PublicKeyword)
                              ),
                          type: ParseTypeName(d.DrawableType.FullName),
                          explicitInterfaceSpecifier: null,
                          identifier: Identifier(d.GivenName),
                          accessorList: AccessorList(List <AccessorDeclarationSyntax>(new[]
         {
             AccessorDeclaration(
                 kind: SyntaxKind.GetAccessorDeclaration,
                 attributeLists: List <AttributeListSyntax>(),
                 modifiers: TokenList(),
                 keyword: Token(SyntaxKind.GetKeyword),
                 body: null,
                 semicolonToken: Token(SyntaxKind.SemicolonToken)
                 ),
             AccessorDeclaration(
                 kind: SyntaxKind.SetAccessorDeclaration,
                 attributeLists: List <AttributeListSyntax>(),
                 modifiers: TokenList(
                     Token(SyntaxKind.PrivateKeyword)
                     ),
                 keyword: Token(SyntaxKind.SetKeyword),
                 body: null,
                 semicolonToken: Token(SyntaxKind.SemicolonToken)
                 )
         }))
                          ));
     }
 }
コード例 #27
0
 public static IEnumerable <StatementSyntax> GenerateEmbeddedPropertyInitializers(DrawableNode node)
 {
     foreach (var property in node.Properties.OfType <EmbeddedDrawableProperty>())
     {
         yield return(ExpressionStatement(property.GenerateInitializerSyntax()));
     }
 }
コード例 #28
0
 public static BlockSyntax GenerateBody(DrawableNode node)
 {
     return(Block(List <StatementSyntax>(
                      GenerateEmbeddedPropertyInitializers(node)
                      )));
 }