/// <summary> /// Creates a new instance of Level class. /// </summary> public Level() { this.countDown = new CountDownDefinition(); this.pipeQueue = new PipeQueueDefinition(); this.squareMap = new SquareMapDefinition(); }
/// <summary> /// Applies definition to square map. /// </summary> /// <param name="definition">The square map definition to apply from.</param> public void FromDefinition(SquareMapDefinition definition) { if (definition != null) { /* normally, we would not use element service upon definition parse. * however, squaremap is somewhat special, since it redefines contents * of squaremap as well. therefore, we clear maps content and recreate * its items using element service. * */ IElementService elements = this.GetElementService(); if (elements != null) { /* clear first */ this.Clear(); this.boundary = definition.Boundary; foreach (SquareMapItemDefinition itemDefinition in definition) { ISquareMapItemElement item = elements.CreateSquareMapItem(itemDefinition); if (item != null) { this.SetItem(item); } } } } }
/// <summary> /// Returns definition for square map. /// </summary> /// <returns>The definition for this square map.</returns> public SquareMapDefinition ToDefinition() { SquareMapDefinition definition = new SquareMapDefinition(); definition.Boundary = this.boundary; foreach (ISquareMapItemElement item in this.items.Values) { definition.Put(item.ToDefinition()); } return definition; }
/// <summary> /// Creates square map. /// </summary> /// <param name="definition">The square map definition used to create square map.</param> /// <returns>Newly created square map if possible, otherwise null.</returns> public ISquareMapElement CreateSquareMap(SquareMapDefinition definition) { ISquareMapElement element = this.CreateSquareMap(); if (element != null) { element.FromDefinition(definition); } return element; }