/// <summary> /// Loads a conditional branch of a tile type from the given XML element. /// </summary> /// <param name="fromElem">The XML element to load from.</param> /// <param name="tile">The tile type being loaded.</param> /// <param name="tileset">The tileset being loaded.</param> private static void LoadBranch(XElement fromElem, IsoTileType tile, TileSet tileset) { /// Check whether the branch element has exactly 2 child elements. XElement conditionElem = null; XElement actionElem = null; int i = 0; foreach (XElement child in fromElem.Elements()) { if (i == 0) { conditionElem = child; } else if (i == 1) { actionElem = child; } else { throw new TileSetException("Unexpected nodes in conditional branch!"); } i++; } if (i != 2) { throw new TileSetException("Missing nodes in conditional branch!"); } /// Check the action element. if (actionElem.Name != XmlTileSetConstants.THEN_ELEM) { throw new TileSetException(string.Format("Unexpected node '{0}' at conditional branch!", actionElem.Name)); } /// Load the condition and start defining the conditional branch. IIsoTileCondition condition = LoadCondition(conditionElem, tileset); tile.BeginConditionalBranch(condition); /// Load the variants of the conditional branch. foreach (XElement variantElem in actionElem.Elements(XmlTileSetConstants.VARIANT_ELEM)) { LoadVariant(variantElem, tile, tileset); } /// Close the conditional branch. tile.EndConditionalBranch(); }
/// <summary> /// Begins a new conditional branch. /// </summary> /// <param name="condition">The condition.</param> public void BeginConditionalBranch(IIsoTileCondition condition) { if (this.tileset.IsFinalized) { throw new InvalidOperationException("TileSet already finalized!"); } if (condition == null) { throw new ArgumentNullException("condition"); } if (this.defaultBranch != null) { throw new InvalidOperationException("Defining the default branch is in progress!"); } if (this.tmpCurrentBranch != null) { throw new InvalidOperationException("Call TileType.EndConditionalBranch before starting another conditional branch!"); } /// Start a new conditional branch this.tmpCurrentBranch = new Tuple <List <IsoTileVariant>, IIsoTileCondition>(new List <IsoTileVariant>(), condition); this.variants.Add(this.tmpCurrentBranch); }