/// <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; var newPlane = new DimensionalModelPlane(); short lineCount = 12; short yCount = 11; try { foreach (var myString in delimitedPlanes.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { //This is the tagName line if (lineCount == 12) { newPlane.TagName = myString; newPlane.YAxis = yCount; } else { var currentLineNodes = myString.Split(new char[] { ',' }); short xCount = 1; foreach (var nodeString in currentLineNodes) { var newNode = new DimensionalModelNode(); var nodeStringComponents = nodeString.Split(new char[] { '|' }); newNode.XAxis = xCount; newNode.ZAxis = ModelType == DimensionalModelType.Flat ? (short)0 : lineCount; newNode.YAxis = yCount; newNode.Style = String.IsNullOrWhiteSpace(nodeStringComponents[0]) ? DamageType.None : Render.CharacterToDamageType(nodeStringComponents[0]); newNode.Composition = nodeStringComponents.Count() < 2 || String.IsNullOrWhiteSpace(nodeStringComponents[1]) ? default(IMaterial) : default(IMaterial); //TODO: Implement materials -- ReferenceAccess.GetOne<IMaterial>(long.Parse(nodeStringComponents[1])); newPlane.ModelNodes.Add(newNode); xCount++; } //This ensures the linecount is always 12 for flats if (lineCount == 1 || ModelType == DimensionalModelType.Flat) { ModelPlanes.Add(newPlane); lineCount = 12; yCount--; newPlane = new DimensionalModelPlane(); continue; } } lineCount--; } } catch (Exception ex) { LoggingUtility.LogError(ex); throw new FormatException("Invalid delimitedPlanes format.", ex); } }
/// <summary> /// Turn the json we store in the db into the modelplanes /// </summary> /// <param name="modelJson">json we store in the db</param> private void DeserializeModel(string modelJson) { //Don't bother even trying if (ModelType == DimensionalModelType.None) return; dynamic planes = JsonConvert.DeserializeObject(modelJson); foreach (dynamic plane in planes) { var newPlane = new DimensionalModelPlane(); newPlane.TagName = plane.TagName; newPlane.YAxis = plane.YAxis; foreach (dynamic node in plane.ModelNodes) { var newNode = new DimensionalModelNode(); newNode.XAxis = node.XAxis; newNode.ZAxis = node.ZAxis; newNode.YAxis = newPlane.YAxis; newNode.Style = node.Style; newNode.Composition = node.Composition; newPlane.ModelNodes.Add(newNode); } ModelPlanes.Add(newPlane); } }