NicoM1 / IceEntity

A simple framework for managing entitys, components, and live-at-runtime scripts in haxeflixel
MIT License
58 stars 7 forks source link

XML templates instead of instances #12

Closed Ohmnivore closed 10 years ago

Ohmnivore commented 10 years ago

I may be wrong, but I understood so far that XML entity definitions create instances of the objects they describe. That's cool, but what if I want to initialize two objects that use the same XML definitions. I'd have to copy paste the entire XML definition for every "clone" of that object.

I think it makes more sense to use XML for templates. Basically templates will have the same XML fields as it is right now, minus "x" and "y" fields. At the init stage of the game, the XML templates should be parsed into instances of container classes (essentially Entities that aren't added to the EntityManager.instance) and whenever someone wants to instantiate new entities from an XML definition he just calls ex: EntityManager.addFromXML("Name of the entity/ID/some sort of identifier", 10, 100). This function copies the container Entity's properties into a new instance that is then treated as a proper Entity.

NicoM1 commented 10 years ago

hmm, good idea about not having to copy out the same xml, I like that, but I think, if I/we go this route, there should be an xml attribute available to auto-instantiate that entity, as, ideally, you should be about to create an entire scene without needing any more code that the buildfromxml()...great thoughts though:D

NicoM1 commented 10 years ago

@Ohmnivore what about having two new elements: <template/> and <instance/> template would behave identically to the current entity declaration, while instance would be specified somewhere below the template, and would allow you to add an instance of the template

NicoM1 commented 10 years ago

My proposal (not implemented, just what popped into my head):

<entity tag="grass" template="grasstemp"/> //if template is null, create the entity as before

<instance template="grasstemp" tag="grass01" x="0" y="0"/> //only required attribute is "template" if others are supplied, they override those values on the template
Ohmnivore commented 10 years ago

Can't see a better way to do it than that.

NicoM1 commented 10 years ago

ok, sounds good, ugg I'd way rather work on this than parsing, but its more important.....

NicoM1 commented 10 years ago

I'm gonna work on this, as I know you said you're out of town, and I'd like to wait until you look over the new parser before I publish. I'm just going to do this issue on top of #9 otherwise there will be too many merge conflicts to handle. Also, sorry about all the updates, not sure if you're reading them where you are, or will just get a giant stack when you get back, but it helps me to write what I'm thinking, and then you at least will understand whats going on if you do some work on something

NicoM1 commented 10 years ago

meant #13

NicoM1 commented 10 years ago

Closed by #13