示例#1
0
        public static XElement SerializeVariable(WitcherMenuVariable var)
        {
            switch (var.Variabletype)
            {
            case WitcherMenuVariableType.OPTIONS:
                return(new XElement("Var",
                                    new XAttribute("id", var.ID),
                                    new XAttribute("displayName", var.DisplayName),
                                    new XAttribute("displayType", var.Variabletype),
                                    new XAttribute("tags", string.Join(";", var.Tags)),
                                    SerializeOptions(var.Options)));

            case WitcherMenuVariableType.SLIDER:
                return(new XElement("Var",
                                    new XAttribute("id", var.ID),
                                    new XAttribute("displayName", var.DisplayName),
                                    new XAttribute("displayType",
                                                   var.Variabletype + ";" + var.MinValue + ";" + var.MaxValue + ";" + var.Step),
                                    new XAttribute("tags", string.Join(";", var.Tags))));

            case WitcherMenuVariableType.TOGGLE:
                return(new XElement("Var",
                                    new XAttribute("id", var.ID),
                                    new XAttribute("displayName", var.DisplayName),
                                    new XAttribute("displayType", var.Variabletype),
                                    new XAttribute("tags", string.Join(";", var.Tags))));

            default:
                throw new Exception("Invalid variable type!");
            }
        }
示例#2
0
        public static WitcherMenuVariable DeserializeVariable(XElement element)
        {
            var ret = new WitcherMenuVariable
            {
                ID          = element.Attribute("id")?.Value,
                DisplayName = element.Attribute("displayName")?.Value,
                Tags        = element.Attribute("tags")?.Value.Split(';').ToList()
            };

            if (element.Attribute("displayType") != null && element.Attribute("displayType").Value.StartsWith("TOGGLE"))
            {
                ret.Variabletype = WitcherMenuVariableType.TOGGLE;
            }
            else if (element.Attribute("displayType").Value.StartsWith("SLIDER"))
            {
                ret.Variabletype = WitcherMenuVariableType.SLIDER;
                var split = element.Attribute("displayType").Value.Split(';');
                if (split.Length > 3)
                {
                    ret.MinValue = split[1];
                    ret.MaxValue = split[2];
                    ret.Step     = split[3];
                }
            }
            else if (element.Attribute("displayType").Value.StartsWith("OPTIONS"))
            {
                ret.Variabletype = WitcherMenuVariableType.OPTIONS;
                ret.Options      = DeseralizeOptions(element.Element("OptionsArray"));
            }
            else
            {
                throw new Exception("Invalid variable type! Can't parse. Type: " + element.Attribute("displayType")?.Value);
            }
            return(ret);
        }