Beispiel #1
0
        /// <summary>
        /// Reads the map components and tries to parse a doom map.
        /// </summary>
        /// <param name="components">The map components.</param>
        /// <param name="map">The map that was generated, or null if this
        /// returns false.</param>
        /// <returns>True on success, false on failure.</returns>
        public static bool TryRead(MapComponents components, out MapData map)
        {
            if (!components.IsValid() || components.MapType != MapType.Doom)
            {
                map = null;
                return(false);
            }

            try
            {
                map = new MapData(components.Name);
                ReadVerticesOrThrow(map, components);
                ReadSectorsOrThrow(map, components);
                ReadSidesOrThrow(map, components);
                ReadLinesOrThrow(map, components);
                ReadThingsOrThrow(map, components);

                return(true);
            }
            catch
            {
                map = null;
                return(false);
            }
        }
        public IEnumerator <MapComponents> GetEnumerator()
        {
            IEntry        lastEntry  = null;
            bool          makingMap  = false;
            MapComponents components = new MapComponents(mapName);

            foreach (IEntry entry in wad)
            {
                bool isMapEntry = IsMapEntry(entry.Path.Name);

                if (makingMap)
                {
                    if (isMapEntry)
                    {
                        components.Track(entry);
                    }
                    else
                    {
                        makingMap = false;

                        if (components.IsValid())
                        {
                            yield return(components);
                        }

                        components  = new MapComponents(mapName);
                        glLevelName = "";
                    }
                }
                else if (isMapEntry)
                {
                    if (lastEntry != null)
                    {
                        glLevelName = $"GL_{lastEntry.Path.Name}";

                        // This is a way of checking if our 'hacky override' to
                        // support external map naming should be done or not. If
                        // there is no level name to override (empty string for the
                        // name) then we know we should use the marker name.
                        if (mapName.Empty)
                        {
                            components = new MapComponents(lastEntry.Path.Name);
                        }
                    }

                    // It is the case that we could have a map with no marker
                    // entry at the beginning. Such a case is a malformed map
                    // and the builder will know what to do here if the last
                    // entry is null.
                    components.TrackMapMarker(lastEntry);
                    components.Track(entry);
                    makingMap = true;
                }

                lastEntry = entry;
            }

            // If we run out of entries but have a map that is potentially done
            // yet not processed, return it.
            if (components.IsValid())
            {
                yield return(components);
            }
        }