private FlowParser(string xmlPath, Version currentVersion) { TextAsset flowFile = Resources.Load<TextAsset>(xmlPath); if (flowFile != null) { string error = string.Empty; XDocument doc = XDocument.Parse(flowFile.text); m_XML = doc; Version fileVersion = ParseVersion(); if (fileVersion == INVALID_VERSION) { Services.Logger.LogWithCategory(LoggerConstants.FLOW_CATEGORY, LogType.Error, "FLow XML at path {0}'s version is invalid. Either you haven't specified it or something is wrong!", xmlPath); return; } else if (fileVersion < currentVersion) { Services.Logger.LogWithCategory(LoggerConstants.FLOW_CATEGORY, LogType.Warning, "Flow XML at path {0}'s version is smaller then the currently supported version. Right now there's no different parsing for older versions but eventually we'll put backwards compatibility.", xmlPath); } else if (fileVersion > currentVersion) { Services.Logger.LogWithCategory(LoggerConstants.FLOW_CATEGORY, LogType.Error, "FLow XML at path {0}'s version is bigger then the currently supported version. Either this game is out of date for this file or something is really wrong.", xmlPath); return; } m_GeneralInformation = ParseInfo(ref error); if (!string.IsNullOrEmpty(error)) { throw new Exception(string.Format("An error happened while parsing the XML: {0}", error)); } m_GeneralActions = ParseGeneralActions(ref error); if (!string.IsNullOrEmpty(error)) { throw new Exception(string.Format("An error happened while parsing the XML: {0}", error)); } m_Views = ParseViews(ref error); if (!string.IsNullOrEmpty(error)) { throw new Exception(string.Format("An error happened while parsing the XML: {0}", error)); } } else { Services.Logger.LogWithCategory(LoggerConstants.FLOW_CATEGORY, LogType.Error, "No XML file found at {0}.", xmlPath); } }
/// <summary> /// Parses the general information out of the XML file. /// </summary> /// <param name="error">String that is set if an error happens.</param> /// <returns>Parsed information.</returns> protected GeneralInformation ParseInfo(ref string error) { GeneralInformation info = new GeneralInformation(FlowManager.DEFAULT_STARTING_VIEW, FlowManager.DEFAULT_MODAL_DEPTH_OFFSET, FlowManager.DEFAULT_MODAL_CANVAS_OFFSET); XElement infoElement = m_XML.Root.Element(INFO_ELEMENT_KEY); if (infoElement != null && infoElement.HasAttributes) { XAttribute curAttribute = infoElement.Attribute(STARTING_VIEW_ATTRIBUTE_KEY); if (curAttribute != null) { info.StartingView = curAttribute.Value; } else { error = string.Format("{0} does not contain the attribute {1}. Invalid XML element.", INFO_ELEMENT_KEY, STARTING_VIEW_ATTRIBUTE_KEY); return info; } curAttribute = infoElement.Attribute(MODAL_DEPTH_OFFSET_ATTRIBUTE_KEY); if (curAttribute != null) { info.ModalDepthOffset = System.Convert.ToInt32(curAttribute.Value); } curAttribute = infoElement.Attribute(OVERLAY_PREFAB_PATH_ATTRIBUTE_KEY); if (curAttribute != null) { info.OverlayPrefabPath = curAttribute.Value; } curAttribute = infoElement.Attribute(MODAL_CANVAS_OFFSET_ATTRIBUTE_KEY); if (curAttribute != null) { info.ModalCanvasOffset = System.Convert.ToInt32(curAttribute.Value); } } else { error = INFO_ELEMENT_KEY + " element in the XML is invalid."; return info; } return info; }