From: Erik V. <eri...@hc...> - 2007-07-29 11:15:43
|
> Sounds like we will also need a game type selector during startup, so > that we can toggle between these behaviors. This is a general subject that we have to face one day, so why not now. We already have a generic variant selection mechanism (see 1835/Game.xml), but currently all it does is assigning a string value to a variable, leaving it to the code to interpret that value. Unboubtedly we will also need toggles which can be set independently of each other. Let's start with a simple case: the 1830 optional 6-train, which we have not implemented yet (leaving it to the user to change the value in Game.xml if so wanted). I think we need a generic mechanism to make values that are explicitly assigned in the XML dependent on variant and toggle settings. We could define the toggle itself like <Option name="WithOptional6Train" default="no"/> which would let the UI show a popup after game selection, but how can we refer to such toggles in the rest of the XML? For the 6-trains we now have <Train name="6" majorStops="6" cost="630" amount="2" startPhase="6" rustedTrain="3" releasedTrain="D"/> This is actually kind of a shorthand for a nested structure like <Train> <Name>6</Name> <MajorStops>6</MajorStops> ... etc. </Train> which I tend to avoid because it is more verbose and needs a little bit more code to parse. The latter structure would be easier to adapt to toggles, though, e.g. like <Train> ... <Amount option="WithOptional6Train" value="yes">3</Amount> <Amount option="WithOptional6Train" value="no">2</Amount> ... etc. </Train> For this project I am rather thinking of a way to configure and code such exceptions that retains the current XML structure. Proposal: <Train name="6" majorStops="6" cost="630" startPhase="6" rustedTrain="3" releasedTrain="D"> <IfOption name="WithOptional6Train" value="yes"> <Attribute amount="3"/> </IfOption> <IfOption name="WithOptional6Train" value="no"> <Attribute amount="2"/> </IfOption> </Train> and for Variant-dependent values we could similarly have <IfVariant name="Standard"> <Attribute .../> </IfVariant> This would give us a generic way to code conditional values. I could then write a common utility method that would take any DOM (parsed XML) element, like <Train> in the above case, and return a map with all its contained attributes (including those contained in inner Attribute nodes), taking variants and all game options into account. This approach would even simplify the current XML parsing code (which is bulky enough as it is). Any other nested elements must of course still be decoded explicitly. Any comments or better proposals? You'll understand that my main consideration is conciseness of the XML parsing code. Erik. |