Lyeeedar / StructuredXmlEditor

An editor for structured xml, providing a graphical interface.
Apache License 2.0
93 stars 15 forks source link

How to create a recursive struct? #5

Closed jbhaywood closed 9 months ago

jbhaywood commented 7 years ago

How can I create a Foo struct that contains a collection of Foos? I tried creating an empty struct under the collection with the same name as the main struct but got an error when saving. And it's not clear to me how Reference is supposed to work. The docs imply that the Keys field should be populated, but it's blank when I create one and I'm not sure what it's expecting.

Before I spend more time experimenting or crack open the code, I thought I'd check to see if there's a correct way to do this, if it's supported at all. As a suggestion, it would great if the new item combo box for a collection child contained already created structs as options. Does that make sense?

Anyway, great tool. I'm currently using it on my new roguelike project. :^)

JSandusky commented 7 years ago

If you still haven't figured this out (or for anyone else). Set "Keys" for the reference to the name of your struct containing the collection.

When polymorphism is desired then don't uses spaces (ie. "MyStruct,MyOtherStruct" not "MyStruct, MyOtherStruct". (For cleaner output to use from the reading side set the "Reference" field's name to match the right name)

Note: I ran into gotcha's with trying to reference a definition that appeared further down in the definitions file, however, no problems with definitions in other files.

Definition: Def layout

Edit: Edit layout

Output XML will come out as:

<TagInfos xmlns:meta="Editor">
    <Contents Boolean="True">
        <DangerObject>
            <Number>72</Number>
            <Reference meta:RefKey="TagInfos">
                <Contents>
                    <DangerObject>
                        <Boolean>true</Boolean>
                    </DangerObject>
                    <DangerObject>
                        <Number>32</Number>
                    </DangerObject>
                </Contents>
            </Reference>
        </DangerObject>
    </Contents>
</TagInfos>

More cleanly setup polymorph collection output:

<CollectionTest xmlns:meta="Editor">
    <CollectionTest meta:RefKey="CollectionTest">
        <CollectionTest meta:RefKey="CollectionTest">
            <Colour>255,255,255,255</Colour>
            <Colour>255,255,255,255</Colour>
            <Colour>255,255,255,255</Colour>
        </CollectionTest>
        <Colour>255,255,255,255</Colour>
        <Colour>255,255,255,255</Colour>
        <Colour>255,255,255,255</Colour>
    </CollectionTest>
    <Colour>255,255,255,255</Colour>
    <Colour>255,255,255,255</Colour>
    <Colour>255,255,255,255</Colour>
    <Colour>255,255,255,255</Colour>
    <Colour>255,255,255,255</Colour>
</CollectionTest>