/// <summary> /// Turn a comma delimited list of planes into the modelplane set /// </summary> /// <param name="delimitedPlanes">comma delimited list of planes</param> private void SerializeModelFromDelimitedList(string delimitedPlanes) { //don't need to serialize nothing if (ModelType == DimensionalModelType.None) { return; } try { short yCount = 21; foreach (string myString in delimitedPlanes.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { DimensionalModelPlane newPlane = new DimensionalModelPlane(); string[] currentLineNodes = myString.Split(new char[] { ',' }); //Name is first newPlane.TagName = currentLineNodes[0]; newPlane.YAxis = yCount; short xCount = 1; foreach (string nodeString in currentLineNodes.Skip(1)) { DimensionalModelNode newNode = new DimensionalModelNode(); string[] nodeStringComponents = nodeString.Split(new char[] { '|' }); newNode.XAxis = xCount; newNode.YAxis = yCount; newNode.Style = string.IsNullOrWhiteSpace(nodeStringComponents[0]) ? DamageType.None : Render.CharacterToDamageType(nodeStringComponents[0]); //May not always indicate material id if (nodeStringComponents.Count() > 1 && string.IsNullOrWhiteSpace(nodeStringComponents[1])) { newNode.Composition = TemplateCache.Get <IMaterial>(long.Parse(nodeStringComponents[1])); } newPlane.ModelNodes.Add(newNode); xCount++; } //This ensures the linecount is always 21 for flats ModelPlanes.Add(newPlane); yCount--; } } catch (Exception ex) { LoggingUtility.LogError(ex); throw new FormatException("Invalid delimitedPlanes format.", ex); } }
/// <summary> /// Gets a node based on the X and Y axis /// </summary> /// <param name="xAxis">the X-Axis of the node to get</param> /// <param name="yAxis">the Y-Axis of the node to get</param> /// <returns>the node</returns> public IDimensionalModelNode GetNode(short xAxis, short yAxis) { IDimensionalModelPlane plane = ModelPlanes.FirstOrDefault(pl => pl.YAxis.Equals(yAxis)); if (plane != null) { return(plane.GetNode(xAxis)); } return(null); }
/// <summary> /// Checks if the model is valid for the physics engine /// </summary> /// <returns>validity</returns> public bool IsModelValid() { switch (ModelType) { case DimensionalModelType.Flat: //2d has 21 planes, but they're all flat (21 X nodes) return(ModelPlanes.Count == 21 && !ModelPlanes.Any(plane => string.IsNullOrWhiteSpace(plane.TagName) || plane.ModelNodes.Count != 21)); case DimensionalModelType.None: //0d is always valid, it doesn't care about the model return(true); } return(false); }
/// <summary> /// Gets the errors for data fitness /// </summary> /// <returns>a bunch of text saying how awful your data is</returns> public override IList <string> FitnessReport() { IList <string> dataProblems = base.FitnessReport(); if (ModelPlanes == null || !ModelPlanes.Any() || ModelPlanes.Any(m => m == null || string.IsNullOrWhiteSpace(m.TagName) || !m.ModelNodes.Any())) { dataProblems.Add("Model Planes are invalid."); } if (!IsModelValid()) { dataProblems.Add("Model is invalid entirely."); } return(dataProblems); }