Beispiel #1
0
        /// <summary>
        /// Erstellt eine neue Wetterdatei mit zwei Standard-Zeitbereichen
        /// </summary>
        /// <returns>Standard Wetterdatei</returns>
        public static WeatherFile CreateNewDefaultFile()
        {
            WeatherFile f = new WeatherFile();

            WeatherTimeRange r1 = new WeatherTimeRange(f);

            r1.Begin = new TimeSpan(17, 0, 0);
            r1.End   = new TimeSpan(9, 0, 0);
            WeatherTimeRange r2 = new WeatherTimeRange(f);

            r2.Begin = new TimeSpan(3, 0, 0);
            r2.End   = new TimeSpan(23, 0, 0);
            using (f.EnterNoUndoSection())
            {
                f.WeatherSet.Add(r1);
                f.WeatherSet.Add(r2);
            }
            return(f);
        }
Beispiel #2
0
        protected override void LoadFromDoc(System.Xml.Linq.XDocument doc)
        {
            _weatherSet = new UndoAwareObservableCollection <WeatherTimeRange>(this);
            //WeatherSet.AllowNew = false;
            XElement root = (XElement)doc.FirstNode;

            XElement rootProps = doc.Elements().First().Element(FileDescriptions.FILE_GENERAL_EL_PROPS);

            if (rootProps != null)
            {
                _header = rootProps.Attribute(FileDescriptions.FILE_WEATHER_AT_PROPS_HEADER).Read <string>(string.Empty);
            }

            XElement illumination = root.Element(FileDescriptions.FILE_WEATHER_EL_ILLUMINATION);

            Illumination = AmbientIllumination.ReadFromXml(illumination, this, OwnPath);
            if (Illumination == null)
            {
                Illumination = new AmbientIllumination(this);
            }

            var set = root.Element(FileDescriptions.FILE_WEATHER_EL_WEATHER_SET);

            if (set != null)
            {
                List <WeatherTimeRange> tempL = new List <WeatherTimeRange>();
                foreach (XElement timeRange in set.Elements(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE))
                {
                    WeatherTimeRange r = WeatherTimeRange.ReadFromXml(timeRange, this, OwnPath);
                    if (r != null)
                    {
                        tempL.Add(r);
                    }
                }
                foreach (var it in tempL.OrderBy(w => w.Begin))
                {
                    _weatherSet.Add(it);
                }
            }

            ClearUndoRedo();
        }
Beispiel #3
0
        public static WeatherTimeRange ReadFromXml(XElement xmlEl, IUndoManager undoManager, L3dFilePath ownerPath = null)
        {
            if (xmlEl != null && xmlEl.Name == FileDescriptions.FILE_WEATHER_EL_TIME_RANGE)
            {
                XElement props = xmlEl.Element(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_PROPS);
                if (props != null)
                {
                    WeatherTimeRange t = new WeatherTimeRange(undoManager, ownerPath);
                    using (var tk = undoManager.EnterNoUndoSection())
                    {
                        t._begin            = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_BEGIN).ReadTime();
                        t._end              = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_END).ReadTime();
                        t._brightnessFactor = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_BRIGHTNESS_FACTOR).Read <float>(1.0f);
                        t._sightDistance    = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SIGHT_DISTANCE).Read <int>(6000);

                        foreach (L3dVariable v in xmlEl.Elements(FileDescriptions.File_WEATHER_EL_TIME_RANGE_VARIABLE).Select(el =>
                        {
                            return(new L3dVariable(undoManager)
                            {
                                Name = el.Attribute(FileDescriptions.File_WEATHER_AT_TIME_RANGE_VARIABLE_NAME).Read <string>("UnnamedVar"),
                                Value = el.Value
                            });
                        }))
                        {
                            t.Variables.Add(v);
                        }

                        XElement skybox = xmlEl.Element(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_SKYBOX);
                        if (skybox != null)
                        {
                            props = skybox.Element(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_SKYBOX_TEXTURES);
                            if (props != null)
                            {
                                t.TextureNorth = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURENORTH).Read <string>(string.Empty), ownerPath);
                                t.TextureEast  = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREEAST).Read <string>(string.Empty), ownerPath);
                                t.TextureSouth = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURESOUTH).Read <string>(string.Empty), ownerPath);
                                t.TextureWest  = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREWEST).Read <string>(string.Empty), ownerPath);
                                t.TextureAbove = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREABOVE).Read <string>(string.Empty), ownerPath);

                                t.TextureNorthTileU = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURENORTH_TILE_U).Read <float>(0);
                                t.TextureNorthTileV = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURENORTH_TILE_V).Read <float>(0);
                                t.TextureEastTileU  = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREEAST_TILE_U).Read <float>(0);
                                t.TextureEastTileV  = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREEAST_TILE_V).Read <float>(0);
                                t.TextureSouthTileU = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURESOUTH_TILE_U).Read <float>(0);
                                t.TextureSouthTileV = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURESOUTH_TILE_V).Read <float>(0);
                                t.TextureWestTileU  = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREWEST_TILE_U).Read <float>(0);
                                t.TextureWestTileV  = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREWEST_TILE_V).Read <float>(0);
                                t.TextureAboveTileU = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREABOVE_TILE_U).Read <float>(0);
                                t.TextureAboveTileV = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREABOVE_TILE_V).Read <float>(0);
                            }
                        }

                        XElement xmlPreci = xmlEl.Element(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_PRECIPITATION);
                        if (xmlPreci != null)
                        {
                            t._snowfall = xmlPreci.Attribute(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_PRECIPITATION_TYPE).Read <int>(0) == 1;
                        }

                        return(t);
                    }
                }
            }
            return(null);
        }