Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

You're not likely to have too many components in your game. I suggest you set up something simple like a switch statement:

switch(componentName) {
     case "Movement":
        entity.AddComponent(new MovementComponent.ParseXML(componentXML));
        break;
     case "Render":
        entity.AddComponent(new RenderComponent.ParseXML(componentXML));
        break;
     ...

}

Each component has a function called ParseFile that reads all the XML contained within the <Component> element. This way, each component knows how to parse itself from the XML file, and parsing code is kept with the components. I set up something similar for a game of mine and it works great. I've also posted some details about it here: How can I implement smart scripting, in my game?How can I implement smart scripting, in my game? and here Storing items in external data filesStoring items in external data files

You're not likely to have too many components in your game. I suggest you set up something simple like a switch statement:

switch(componentName) {
     case "Movement":
        entity.AddComponent(new MovementComponent.ParseXML(componentXML));
        break;
     case "Render":
        entity.AddComponent(new RenderComponent.ParseXML(componentXML));
        break;
     ...

}

Each component has a function called ParseFile that reads all the XML contained within the <Component> element. This way, each component knows how to parse itself from the XML file, and parsing code is kept with the components. I set up something similar for a game of mine and it works great. I've also posted some details about it here: How can I implement smart scripting, in my game? and here Storing items in external data files

You're not likely to have too many components in your game. I suggest you set up something simple like a switch statement:

switch(componentName) {
     case "Movement":
        entity.AddComponent(new MovementComponent.ParseXML(componentXML));
        break;
     case "Render":
        entity.AddComponent(new RenderComponent.ParseXML(componentXML));
        break;
     ...

}

Each component has a function called ParseFile that reads all the XML contained within the <Component> element. This way, each component knows how to parse itself from the XML file, and parsing code is kept with the components. I set up something similar for a game of mine and it works great. I've also posted some details about it here: How can I implement smart scripting, in my game? and here Storing items in external data files

Source Link
House
  • 73.3k
  • 17
  • 185
  • 273

You're not likely to have too many components in your game. I suggest you set up something simple like a switch statement:

switch(componentName) {
     case "Movement":
        entity.AddComponent(new MovementComponent.ParseXML(componentXML));
        break;
     case "Render":
        entity.AddComponent(new RenderComponent.ParseXML(componentXML));
        break;
     ...

}

Each component has a function called ParseFile that reads all the XML contained within the <Component> element. This way, each component knows how to parse itself from the XML file, and parsing code is kept with the components. I set up something similar for a game of mine and it works great. I've also posted some details about it here: How can I implement smart scripting, in my game? and here Storing items in external data files