public static StoryboardUpdater ParseStoryboard(Stream osuFileStream, Stream osbFileStream)
        {
            var objects  = CombineStoryboardObjects(ParseStoryboardFile(osbFileStream), ParseStoryboardFile(osuFileStream));
            var instance = new StoryboardUpdater(objects);

            return(instance);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //path of standard beatmap folder which contains storyboard.
            Console.Write("Input beatmap folder path. > ");
            var beatmap_folder = Console.ReadLine();

            //time we need to update.
            Console.Write("Input time value. > ");
            var update_time = int.Parse(Console.ReadLine());

            //not allow lib output anything.
            Setting.AllowLog = false;

            #region Get beatmap info about osb file and osu file.

            //for convenience
            var beatmap_info = BeatmapFolderInfo.Parse(beatmap_folder);

            #endregion

            #region Get storyboard objects and create updater for controling objects in timeline.

            //get storyboard objects from .osb file
            var osb_object_list = GetStoryboardObjectsFromFile(beatmap_info.osb_file_path);
            osb_object_list.Sort((a, b) => (int)(a.FileLine - b.FileLine));

            //get storyboard objects from first .osu file in folder
            var osu_object_list = GetStoryboardObjectsFromFile(beatmap_info.DifficultFiles.First().Value);
            osu_object_list.Sort((a, b) => (int)(a.FileLine - b.FileLine));

            //combine .osu objects and .osb objects
            var storyboard_objects = CombineStoryboardObjects(osb_object_list, osu_object_list);

            //add optimzer and use
            StoryboardOptimzerManager.AddOptimzer <RuntimeOptimzer>(); // or StoryboardOptimzerManager.AddOptimzer(new RuntimeOptimzer());
            StoryboardOptimzerManager.AddOptimzer <ParserStaticOptimzer>();

            StoryboardOptimzerManager.Optimze(4, storyboard_objects);

            //create updater
            var updater = new StoryboardUpdater(storyboard_objects);

            #endregion

            //Update storyboard to the specified time , and then you could take UpdatingStoryboardObjects and render them.
            updater.Update(update_time);

            //Maybe collection element is different if you call Update() within difference time.
            var updating_objects = updater.UpdatingStoryboardObjects;

            //draw them.
            foreach (var obj in updating_objects)
            {
                Draw(obj);
            }

            Console.ReadLine();
        }
        public async Task PrepareRenderResource(StoryboardUpdater updater, IDirectoryReader reader)
        {
            storyboardUpdater = updater;

            var textureResourceMap = new Dictionary <string, TextureResource>();

            foreach (var obj in updater.StoryboardObjectList)
            {
                switch (obj)
                {
                case StoryboardBackgroundObject background:
                    var resource = await _get(obj.ImageFilePath);

                    if (resource.IsValid)
                    {
                        background.AdjustScale(resource.Size.Height);
                    }
                    else
                    {
                        Log.Warn($"not found image:{obj.ImageFilePath}");
                    }

                    break;

                case StoryboardAnimation animation:
                    for (int index = 0; index < animation.FrameCount; index++)
                    {
                        string path = animation.FrameBaseImagePath + index + animation.FrameFileExtension;

                        if (!(await _get(path)).IsValid)
                        {
                            Log.Warn($"not found image:{path}");
                            continue;
                        }
                    }
                    break;

                default:
                    if (!(await _get(obj.ImageFilePath)).IsValid)
                    {
                        Log.Warn($"not found image:{obj.ImageFilePath}");
                    }
                    break;
                }
            }

            Console.WriteLine($"--------textureResourceMap--------");
            foreach (var pair in textureResourceMap)
            {
                Console.WriteLine($"{pair.Key}  \b  {pair.Value.Texture.Id}");
            }
            Console.WriteLine($"----------------------------------");

            RenderKernel.ApplyRenderResource(glContext, textureResourceMap);

            async Task <TextureResource> _get(string image_name)
            {
                var fix_image = image_name;

                //for Flex
                if (string.IsNullOrWhiteSpace(Path.GetExtension(fix_image)))
                {
                    fix_image += ".png";
                }

                if (textureResourceMap.TryGetValue(image_name, out var resource))
                {
                    return(resource);
                }

                //load
                string file_path = fix_image;

                resource = await _load_tex(file_path);

                if (!resource.IsValid)
                {
                    //todo: 从皮肤文件夹获取皮肤文件 file_path = Path.Combine(PlayerSetting.UserSkinPath ?? string.Empty, fix_image);

                    /*
                     * if (!_load_tex(file_path, out resource))
                     * {
                     *  if ((!image_name.EndsWith("-0")) && _get(image_name + "-0", out resource))
                     *      return true;
                     * }*/
                }

                if (resource.IsValid)
                {
                    textureResourceMap[image_name] = resource;
                    Log.Debug($"Created Storyboard sprite instance from image file :{fix_image}");
                }

                return(resource);
            }

            async Task <TextureResource> _load_tex(string file_path)
            {
                try
                {
                    var stream = reader.ReadFile(file_path);

                    if (stream is null)
                    {
                        return(default);