protected IEnumerable <CGameCtnGhost> ExtractAllGhosts(CGameCtnChallenge map)
        {
            var ghosts = Enumerable.Empty <CGameCtnGhost>();

            if (map.ClipIntro != null)
            {
                ghosts = ghosts.Concat(ExtractGhosts(map.ClipIntro));
            }
            if (map.ClipGroupInGame != null)
            {
                ghosts = ghosts.Concat(ExtractAllGhosts(map.ClipGroupInGame));
            }
            if (map.ClipGroupEndRace != null)
            {
                ghosts = ghosts.Concat(ExtractAllGhosts(map.ClipGroupEndRace));
            }
            if (map.ClipPodium != null)
            {
                ghosts = ghosts.Concat(ExtractGhosts(map.ClipPodium));
            }
            if (map.ClipAmbiance != null)
            {
                ghosts = ghosts.Concat(ExtractGhosts(map.ClipAmbiance));
            }

            return(ghosts);
        }
Exemple #2
0
    /// <summary>
    /// Gets the map thumbnail as <see cref="Bitmap"/>.
    /// </summary>
    /// <param name="node">CGameCtnChallenge</param>
    /// <returns>Thumbnail as <see cref="Bitmap"/>.</returns>
    public static Bitmap GetThumbnailBitmap(this CGameCtnChallenge node)
    {
        using var ms = new MemoryStream(node.Thumbnail);
        var bitmap = (Bitmap)Image.FromStream(ms);

        bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
        return(bitmap);
    }
Exemple #3
0
    /// <summary>
    /// Replaces a thumbnail (any popular image format) to use for the map.
    /// </summary>
    /// <param name="node">CGameCtnChallenge</param>
    /// <param name="stream">Stream to import from.</param>
    public static Bitmap ImportThumbnail(this CGameCtnChallenge node, Stream stream)
    {
        var bitmap = new Bitmap(stream);

        using var ms = new MemoryStream();

        ExportThumbnail(node, ms, ImageFormat.Jpeg);
        node.Thumbnail = ms.ToArray();

        return(bitmap);
    }
        /// <summary>
        /// Exports the map's thumbnail.
        /// </summary>
        /// <param name="node">CGameCtnChallenge</param>
        /// <param name="stream">Stream to export to.</param>
        /// <param name="format">Image format to use.</param>
        public static void ExportThumbnail(this CGameCtnChallenge node, Stream stream, ImageFormat format)
        {
            if (node.Thumbnail == null)
            {
                return;
            }

            var thumbnail = GetThumbnailBitmap(node);

            if (format == ImageFormat.Jpeg)
            {
                var encoding = new EncoderParameters(1);
                encoding.Param[0] = new EncoderParameter(Encoder.Quality, 90L);
                var encoder = ImageCodecInfo.GetImageDecoders().Where(x => x.FormatID == ImageFormat.Jpeg.Guid).First();

                thumbnail.Save(stream, encoder, encoding);
            }
            else
            {
                thumbnail.Save(stream, format);
            }
        }
 /// <summary>
 /// Replaces a thumbnail (any popular image format) to use for the map.
 /// </summary>
 /// <param name="node">CGameCtnChallenge</param>
 /// <param name="fileName">File to import from.</param>
 public static Bitmap ImportThumbnail(this CGameCtnChallenge node, string fileName)
 {
     using (var fs = File.OpenRead(fileName))
         return(ImportThumbnail(node, fs));
 }
 /// <summary>
 /// Exports the map's thumbnail.
 /// </summary>
 /// <param name="node">CGameCtnChallenge</param>
 /// <param name="fileName">File to export to.</param>
 /// <param name="format">Image format to use.</param>
 public static void ExportThumbnail(this CGameCtnChallenge node, string fileName, ImageFormat format)
 {
     using (var fs = File.OpenWrite(fileName))
         ExportThumbnail(node, fs, format);
 }