Beispiel #1
0
        public RendererSurface GetRendererSurface(Guid guid)
        {
            if (BoolEx.Nomalize(rendererInfos?.ContainsKey(guid)))
            {
                return(rendererInfos[guid]);
            }

            return(null);
        }
Beispiel #2
0
        public PBinder GetComponentBinder(Guid guid)
        {
            if (BoolEx.Nomalize(binderInfos?.ContainsKey(guid)))
            {
                return(binderInfos[guid]);
            }

            return(null);
        }
        public static Configuration Read(string filePath)
        {
            XmlReaderSettings configReaderSettings = new XmlReaderSettings {
                ValidationType  = ValidationType.Schema,
                ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.ReportValidationWarnings
            };

            string configSchemaPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + ".xsd");

            configReaderSettings.Schemas.Add(null, configSchemaPath);

            XmlDocument document = new XmlDocument();

            using (XmlReader configReader = XmlReader.Create(filePath, configReaderSettings))
                document.Load(configReader);

            // Before validating using the schema, first check if the configuration file's version matches with the supported version.
            XmlElement rootElement = document.DocumentElement;
            string     fileVersionRaw;

            if (rootElement.HasAttribute("Version"))
            {
                fileVersionRaw = rootElement.GetAttribute("Version");
            }
            else
            {
                fileVersionRaw = "1.0";
            }

            if (fileVersionRaw != Configuration.CurrentVersion)
            {
                throw new FormatException(string.Format(
                                              "The configuration file is either outdated or too new. Expected version was: {0}. File version is: {1}",
                                              Configuration.CurrentVersion, fileVersionRaw
                                              ));
            }

            Configuration resultingConfig = new Configuration();

            resultingConfig.MaxHousesPerUser             = int.Parse(rootElement["MaxHousesPerUser"].InnerText);
            resultingConfig.MinSize                      = HouseSizeConfig.FromXmlElement(rootElement["MinHouseSize"]);
            resultingConfig.MaxSize                      = HouseSizeConfig.FromXmlElement(rootElement["MaxHouseSize"]);
            resultingConfig.AllowTShockRegionOverlapping = BoolEx.ParseEx(rootElement["AllowTShockRegionOverlapping"].InnerText);
            resultingConfig.DefaultZIndex                = int.Parse(rootElement["DefaultZIndex"].InnerText);

            return(resultingConfig);
        }
        public static Configuration Read(string filePath)
        {
            XmlReaderSettings configReaderSettings = new XmlReaderSettings {
                ValidationType  = ValidationType.Schema,
                ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.ReportValidationWarnings
            };

            string configSchemaPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + ".xsd");

            configReaderSettings.Schemas.Add(null, configSchemaPath);

            XmlDocument document = new XmlDocument();

            using (XmlReader configReader = XmlReader.Create(filePath, configReaderSettings))
                document.Load(configReader);

            // Before validating using the schema, first check if the configuration file's version matches with the supported version.
            XmlElement rootElement = document.DocumentElement;
            string     fileVersionRaw;

            if (rootElement.HasAttribute("Version"))
            {
                fileVersionRaw = rootElement.GetAttribute("Version");
            }
            else
            {
                fileVersionRaw = "1.0";
            }

            if (fileVersionRaw != Configuration.CurrentVersion)
            {
                throw new FormatException(string.Format(
                                              "The configuration file is either outdated or too new. Expected version was: {0}. File version is: {1}",
                                              Configuration.CurrentVersion, fileVersionRaw
                                              ));
            }

            Configuration resultingConfig = new Configuration(false);

            resultingConfig.OverrideVanillaCircuits = BoolEx.ParseEx(rootElement["OverrideVanillaCircuits"].InnerXml);
            resultingConfig.AdvancedCircuitsEnabled = BoolEx.ParseEx(rootElement["AdvancedCircuitsEnabled"].InnerText);
            resultingConfig.MaxTrapsPerCircuit      = int.Parse(rootElement["MaxTrapsPerCircuit"].InnerText);
            resultingConfig.MaxStatuesPerCircuit    = int.Parse(rootElement["MaxStatuesPerCircuit"].InnerText);
            resultingConfig.MaxPumpsPerCircuit      = int.Parse(rootElement["MaxPumpsPerCircuit"].InnerText);
            resultingConfig.MaxCircuitLength        = int.Parse(rootElement["MaxCircuitLength"].InnerText);
            if (string.IsNullOrWhiteSpace(rootElement["MaxTimerActivityTime"].InnerText))
            {
                resultingConfig.MaxTimerActivityTime = TimeSpan.Zero;
            }
            else
            {
                TimeSpan maxTimerActivityTime;
                if (TimeSpanEx.TryParseShort(rootElement["MaxTimerActivityTime"].InnerText, out maxTimerActivityTime))
                {
                    resultingConfig.MaxTimerActivityTime = maxTimerActivityTime;
                }
            }
            resultingConfig.SignConfig           = SignConfig.FromXmlElement(rootElement["SignConfig"]);
            resultingConfig.BlockActivatorConfig = BlockActivatorConfig.FromXmlElement(rootElement["BlockActivatorConfig"]);

            XmlElement pumpConfigsNode = rootElement["PumpConfigs"];

            foreach (XmlNode pumpConfigNode in pumpConfigsNode.ChildNodes)
            {
                XmlElement pumpConfigElement = (pumpConfigNode as XmlElement);
                if (pumpConfigElement == null)
                {
                    continue;
                }

                PaintColor paintColor = (PaintColor)Enum.Parse(typeof(PaintColor), pumpConfigElement.Attributes["Paint"].Value);
                resultingConfig.PumpConfigs.Add(paintColor, PumpConfig.FromXmlElement(pumpConfigElement));
            }

            XmlElement trapConfigsNode = rootElement["TrapConfigs"];

            foreach (XmlNode trapConfigNode in trapConfigsNode.ChildNodes)
            {
                XmlElement trapConfigElement = (trapConfigNode as XmlElement);
                if (trapConfigElement == null)
                {
                    continue;
                }

                TrapStyle  trapStyle  = (TrapStyle)Enum.Parse(typeof(TrapStyle), trapConfigElement.Attributes["TrapType"].Value);
                PaintColor paintColor = (PaintColor)Enum.Parse(typeof(PaintColor), trapConfigElement.Attributes["Paint"].Value);
                resultingConfig.TrapConfigs.Add(new TrapConfigKey(trapStyle, paintColor), TrapConfig.FromXmlElement(trapConfigElement));
            }

            /*XmlElement explosivesConfigsNode = rootElement["ExplosivesConfigs"];
             * foreach (XmlNode explosivesConfigNode in explosivesConfigsNode.ChildNodes) {
             * XmlElement explosivesConfigElement = (explosivesConfigNode as XmlElement);
             * if (explosivesConfigElement == null)
             *  continue;
             *
             * ComponentConfigProfile componentConfigProfile = (ComponentConfigProfile)Enum.Parse(typeof(ComponentConfigProfile), explosivesConfigElement.Attributes["Profile"].Value);
             * resultingConfig.explosivesConfigs.Add(componentConfigProfile, ExplosivesConfig.FromXmlElement(explosivesConfigElement));
             * }*/

            XmlElement wirelessTransmitterConfigsNode = rootElement["WirelessTransmitterConfigs"];

            foreach (XmlNode wirelessTransmitterConfigNode in wirelessTransmitterConfigsNode.ChildNodes)
            {
                XmlElement wirelessTransmitterConfigElement = (wirelessTransmitterConfigNode as XmlElement);
                if (wirelessTransmitterConfigElement == null)
                {
                    continue;
                }

                PaintColor paintColor = (PaintColor)Enum.Parse(typeof(PaintColor), wirelessTransmitterConfigElement.Attributes["Paint"].Value);
                resultingConfig.WirelessTransmitterConfigs.Add(paintColor, WirelessTransmitterConfig.FromXmlElement(wirelessTransmitterConfigElement));
            }

            XmlElement statueConfigsNode = rootElement["StatueConfigs"];

            foreach (XmlNode statueConfigNode in statueConfigsNode.ChildNodes)
            {
                XmlElement statueConfigElement = (statueConfigNode as XmlElement);
                if (statueConfigElement == null)
                {
                    continue;
                }

                StatueStyle statueStyle = (StatueStyle)Enum.Parse(typeof(StatueStyle), statueConfigElement.Attributes["StatueType"].Value);
                resultingConfig.StatueConfigs.Add(statueStyle, StatueConfig.FromXmlElement(statueConfigElement));
            }

            return(resultingConfig);
        }
Beispiel #5
0
        public static Configuration Read(string filePath)
        {
            XmlReaderSettings configReaderSettings = new XmlReaderSettings {
                ValidationType  = ValidationType.Schema,
                ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.ReportValidationWarnings
            };

            string configSchemaPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + ".xsd");

            configReaderSettings.Schemas.Add(null, configSchemaPath);

            XmlDocument document = new XmlDocument();

            using (XmlReader configReader = XmlReader.Create(filePath, configReaderSettings))
                document.Load(configReader);

            // Before validating using the schema, first check if the configuration file's version matches with the supported version.
            XmlElement rootElement = document.DocumentElement;
            string     fileVersionRaw;

            if (rootElement.HasAttribute("Version"))
            {
                fileVersionRaw = rootElement.GetAttribute("Version");
            }
            else
            {
                fileVersionRaw = "1.0";
            }

            if (fileVersionRaw != Configuration.CurrentVersion)
            {
                throw new FormatException(string.Format(
                                              "The configuration file is either outdated or too new. Expected version was: {0}. File version is: {1}",
                                              Configuration.CurrentVersion, fileVersionRaw
                                              ));
            }

            Configuration resultingConfig = new Configuration();

            Configuration.UpdateTileIdArrayByString(resultingConfig.ManuallyProtectableTiles, rootElement["ManuallyProtectableTiles"].InnerXml);
            Configuration.UpdateTileIdArrayByString(resultingConfig.AutoProtectedTiles, rootElement["AutoProtectedTiles"].InnerXml);
            Configuration.UpdateTileIdArrayByString(resultingConfig.NotDeprotectableTiles, rootElement["NotDeprotectableTiles"].InnerXml);
            resultingConfig.MaxProtectionsPerPlayerPerWorld = int.Parse(rootElement["MaxProtectionsPerPlayerPerWorld"].InnerText);
            resultingConfig.MaxBankChestsPerPlayer          = int.Parse(rootElement["MaxBankChestsPerPlayer"].InnerXml);

            XmlElement subElement = rootElement["AllowRefillChestContentChanges"];

            if (subElement == null)
            {
                resultingConfig.AllowRefillChestContentChanges = true;
            }
            else
            {
                resultingConfig.AllowRefillChestContentChanges = BoolEx.ParseEx(subElement.InnerXml);
            }

            resultingConfig.EnableBedSpawnProtection             = BoolEx.ParseEx(rootElement["EnableBedSpawnProtection"].InnerXml);
            resultingConfig.LoginRequiredForChestUsage           = BoolEx.ParseEx(rootElement["LoginRequiredForChestUsage"].InnerXml);
            resultingConfig.AutoShareRefillChests                = BoolEx.ParseEx(rootElement["AutoShareRefillChests"].InnerXml);
            resultingConfig.AllowChainedSharing                  = BoolEx.ParseEx(rootElement["AllowChainedSharing"].InnerXml);
            resultingConfig.AllowChainedShareAltering            = BoolEx.ParseEx(rootElement["AllowChainedShareAltering"].InnerXml);
            resultingConfig.AllowWiringProtectedBlocks           = BoolEx.ParseEx(rootElement["AllowWiringProtectedBlocks"].InnerXml);
            resultingConfig.AutoDeprotectEverythingOnDestruction = BoolEx.ParseEx(rootElement["AutoDeprotectEverythingOnDestruction"].InnerXml);
            resultingConfig.NotifyAutoProtections                = BoolEx.ParseEx(rootElement["NotifyAutoProtection"].InnerXml);
            resultingConfig.NotifyAutoDeprotections              = BoolEx.ParseEx(rootElement["NotifyAutoDeprotection"].InnerXml);
            resultingConfig.DungeonChestProtection               = BoolEx.ParseEx(rootElement["DungeonChestProtection"].InnerXml);
            resultingConfig.QuickStackNearbyRange                = float.Parse(rootElement["QuickStackNearbyRange"].InnerXml);
            resultingConfig.MaxProtectorChests = int.Parse(rootElement["MaxProtectorChests"].InnerXml);
            resultingConfig.TradeChestPayment  = int.Parse(rootElement["TradeChestPayment"].InnerXml);

            XmlElement maxBankChestsElement = rootElement["MaxBankChests"];

            resultingConfig.MaxBankChests = new Dictionary <string, int>();
            foreach (XmlNode node in maxBankChestsElement)
            {
                XmlElement limitElement = node as XmlElement;
                if (limitElement != null)
                {
                    resultingConfig.MaxBankChests.Add(limitElement.GetAttribute("Group"), int.Parse(limitElement.InnerXml));
                }
            }

            XmlElement tradeChestItemGroupsElement = rootElement["TradeChestItemGroups"];

            resultingConfig.TradeChestItemGroups = new Dictionary <string, HashSet <int> >();
            foreach (XmlNode node in tradeChestItemGroupsElement)
            {
                XmlElement itemGroupElement = node as XmlElement;
                if (itemGroupElement != null)
                {
                    string groupName = itemGroupElement.GetAttribute("Name").ToLowerInvariant();
                    var    itemIds   = new HashSet <int>(itemGroupElement.InnerText.Split(',').Select(idRaw => int.Parse(idRaw)));
                    resultingConfig.TradeChestItemGroups.Add(groupName, itemIds);
                }
            }

            return(resultingConfig);
        }