fCraft.BlockDB.LoadSettings C# (CSharp) Method

LoadSettings() public method

public LoadSettings ( System.Xml.Linq.XElement el ) : void
el System.Xml.Linq.XElement
return void
        public void LoadSettings( XElement el )
        {
            XAttribute temp;
            if ( ( temp = el.Attribute( "enabled" ) ) != null ) {
                YesNoAuto enabledStateTemp;
                if ( EnumUtil.TryParse( temp.Value, out enabledStateTemp, true ) ) {
                    EnabledState = enabledStateTemp;
                } else {
                    Logger.Log( LogType.Warning,
                                "WorldManager: Could not parse BlockDB \"enabled\" attribute of world \"{0}\", assuming \"Auto\"",
                                World.Name );
                    EnabledState = YesNoAuto.Auto;
                }
            }

            if ( ( temp = el.Attribute( "preload" ) ) != null ) {
                bool isPreloadedTemp;
                if ( Boolean.TryParse( temp.Value, out isPreloadedTemp ) ) {
                    IsPreloaded = isPreloadedTemp;
                } else {
                    Logger.Log( LogType.Warning,
                                "WorldManager: Could not parse BlockDB \"preload\" attribute of world \"{0}\", assuming NOT preloaded.",
                                World.Name );
                }
            }
            if ( ( temp = el.Attribute( "limit" ) ) != null ) {
                int limitTemp;
                if ( Int32.TryParse( temp.Value, out limitTemp ) ) {
                    Limit = limitTemp;
                } else {
                    Logger.Log( LogType.Warning,
                                "WorldManager: Could not parse BlockDB \"limit\" attribute of world \"{0}\", assuming NO limit.",
                                World.Name );
                }
            }
            if ( ( temp = el.Attribute( "timeLimit" ) ) != null ) {
                int timeLimitSeconds;
                if ( Int32.TryParse( temp.Value, out timeLimitSeconds ) ) {
                    TimeLimit = TimeSpan.FromSeconds( timeLimitSeconds );
                } else {
                    Logger.Log( LogType.Warning,
                                "WorldManager: Could not parse BlockDB \"timeLimit\" attribute of world \"{0}\", assuming NO time limit.",
                                World.Name );
                }
            }
        }

Usage Example

Example #1
0
        public World([NotNull] string name, [NotNull] XElement el)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (el == null)
            {
                throw new ArgumentNullException("el");
            }
            if (!IsValidName(name))
            {
                throw new ArgumentException("Unacceptable world name.");
            }
            Name    = name;
            BlockDB = new BlockDB(this);
            UpdatePlayerList();

            XAttribute tempAttr;

            // load hidden status
            if ((tempAttr = el.Attribute("hidden")) != null)
            {
                bool isHidden;
                if (Boolean.TryParse(tempAttr.Value, out isHidden))
                {
                    IsHidden = isHidden;
                }
                else
                {
                    Logger.Log(LogType.Warning,
                               "World: Could not parse \"hidden\" attribute of world \"{0}\", assuming NOT hidden.",
                               Name);
                }
            }

            // load access and build security
            XElement tempEl;

            if ((tempEl = el.Element(AccessSecurityXmlTagName)) != null)
            {
                AccessSecurity = new SecurityController(tempEl, true);
            }
            else if ((tempEl = el.Element("accessSecurity")) != null)
            {
                AccessSecurity = new SecurityController(tempEl, true);
            }
            else
            {
                AccessSecurity = new SecurityController();
            }

            if ((tempEl = el.Element(BuildSecurityXmlTagName)) != null)
            {
                BuildSecurity = new SecurityController(tempEl, true);
            }
            else if ((tempEl = el.Element("buildSecurity")) != null)
            {
                BuildSecurity = new SecurityController(tempEl, true);
            }
            else
            {
                BuildSecurity = new SecurityController();
            }

            // load backup interval
            if ((tempAttr = el.Attribute("backup")) != null)
            {
                if (!tempAttr.Value.ToTimeSpan(out backupInterval))
                {
                    backupInterval = BackupIntervalDefault;
                    Logger.Log(LogType.Warning,
                               "WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default ({1}).",
                               Name,
                               BackupInterval.ToMiniString());
                }
            }
            else
            {
                BackupInterval = BackupIntervalDefault;
            }

            // load BlockDB settings
            XElement blockEl = el.Element(BlockDB.XmlRootName);

            if (blockEl != null)
            {
                BlockDB.LoadSettings(blockEl);
            }

            // load map (if needed)
            Preload = (el.Attribute("noUnload") != null);

            // load environment settings
            XElement envEl = el.Element(EnvironmentXmlTagName);

            if (envEl != null)
            {
                if ((tempAttr = envEl.Attribute("cloud")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out CloudColor))
                    {
                        CloudColor = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"cloud\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   Name);
                    }
                }
                if ((tempAttr = envEl.Attribute("fog")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out FogColor))
                    {
                        FogColor = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"fog\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   Name);
                    }
                }
                if ((tempAttr = envEl.Attribute("sky")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out SkyColor))
                    {
                        SkyColor = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"sky\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   Name);
                    }
                }
                if ((tempAttr = envEl.Attribute("level")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out EdgeLevel))
                    {
                        EdgeLevel = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"level\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   Name);
                    }
                }
                if ((tempAttr = envEl.Attribute("edge")) != null)
                {
                    Block block;
                    if (!Map.GetBlockByName(tempAttr.Value, false, out block))
                    {
                        EdgeBlock = Block.Water;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).",
                                   Name);
                    }
                    else
                    {
                        if (Map.GetEdgeTexture(block) == null)
                        {
                            EdgeBlock = Block.Water;
                            Logger.Log(LogType.Warning,
                                       "WorldManager: Unacceptable blocktype given for \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).",
                                       Name);
                        }
                        else
                        {
                            EdgeBlock = block;
                        }
                    }
                }
            }
        }
All Usage Examples Of fCraft.BlockDB::LoadSettings