{"action":"created","comment":{"url":"https://api.github.com/repos/OpenRA/OpenRA/pulls/comments/33672366","id":33672366,"diff_hunk":"@@ -0,0 +1,135 @@\n+#region Copyright & License Information\n+/*\n+ * Copyright 2007-2015 The OpenRA Developers (see AUTHORS)\n+ * This file is part of OpenRA, which is free software. It is made\n+ * available to you under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation. For more information,\n+ * see COPYING.\n+ */\n+#endregion\n+\n+using System;\n+using System.Linq;\n+using OpenRA.GameRules;\n+\n+namespace OpenRA.Traits\n+{\n+\t[Desc(\"Trait for music handling. Attach this to the world actor.\")]\n+\tpublic class MusicPlaylistInfo : ITraitInfo\n+\t{\n+\t\tpublic readonly string StartingMusic = null;\n+\t\tpublic readonly bool LoopStartingMusic = false;\n+\n+\t\tpublic object Create(ActorInitializer init) { return new MusicPlaylist(init.World, this); }\n+\t}\n+\n+\tpublic class MusicPlaylist\n+\t{\n+\t\tbool installed = false;\n+\t\tbool repeat;\n+\n+\t\tMusicInfo currentSong = null;\n+\t\tMusicInfo[] music;\n+\t\tMusicInfo[] random;\n+\n+\t\tpublic MusicInfo[] GetPlaylist { get { return music; } }\n+\t\tpublic bool GetInstalled { get { return installed; } }\n+\n+\t\tpublic MusicPlaylist(World world, MusicPlaylistInfo info)\n+\t\t{\n+\t\t\tinstalled = world.Map.Rules.InstalledMusic.Any();\n+\n+\t\t\tmusic = world.Map.Rules.InstalledMusic.Select(a => a.Value).ToArray();\n+\t\t\tif (!installed)\n+\t\t\t\treturn;\n+\n+\t\t\trandom = music.Shuffle(Game.CosmeticRandom).ToArray();\n+\n+\t\t\tif (Game.Settings.Sound.MapMusic && !string.IsNullOrEmpty(info.StartingMusic) && world.Map.Rules.Music.ContainsKey(info.StartingMusic))\n+\t\t\t{\n+\t\t\t\tcurrentSong = world.Map.Rules.Music[info.StartingMusic];\n+\t\t\t\trepeat = info.LoopStartingMusic;\n+\t\t\t}\n+\t\t\telse\n+\t\t\t{\n+\t\t\t\tcurrentSong = Game.Settings.Sound.Shuffle ? random.First() : music.First();\n+\t\t\t\trepeat = Game.Settings.Sound.Repeat;\n+\t\t\t}\n+\n+\t\t\tPlay();\n+\t\t}\n+\n+\t\tvoid Play()\n+\t\t{\n+\t\t\tif (currentSong == null)\n+\t\t\t\treturn;\n+\n+\t\t\tSound.PlayMusicThen(currentSong, () =>\n+\t\t\t{\n+\t\t\t\tif (!installed)\n+\t\t\t\t\treturn;\n+\n+\t\t\t\tif (!repeat)\n+\t\t\t\t\tcurrentSong = GetNextSong();\n+\t\t\t\tPlay();\n+\t\t\t});\n+\t\t}\n+\n+\t\tpublic void Play(MusicInfo music)\n+\t\t{\n+\t\t\tif (music == null)\n+\t\t\t\treturn;\n+\n+\t\t\tcurrentSong = music;\n+\t\t\trepeat = Game.Settings.Sound.Repeat;\n+\n+\t\t\tSound.PlayMusicThen(music, () =>\n+\t\t\t{\n+\t\t\t\tif (!installed)\n+\t\t\t\t\treturn;\n+\n+\t\t\t\tif (!repeat)\n+\t\t\t\t\tcurrentSong = GetNextSong();\n+\t\t\t\tPlay();\n+\t\t\t});\n+\t\t}\n+\n+\t\tpublic void Play(MusicInfo music, Action onComplete)\n+\t\t{\n+\t\t\tif (music == null)\n+\t\t\t\treturn;\n+\n+\t\t\tcurrentSong = music;\n+\t\t\tSound.PlayMusicThen(music, onComplete);\n+\t\t}\n+\n+\t\tpublic MusicInfo GetNextSong()\n+\t\t{\n+\t\t\tif (!installed)\n+\t\t\t\treturn null;\n+\n+\t\t\tvar songs = Game.Settings.Sound.Shuffle ? random : music;\n+\t\t\treturn songs.SkipWhile(m => m != currentSong)\n+\t\t\t\t.Skip(1).FirstOrDefault() ?? songs.FirstOrDefault();\n+\t\t}\n+\n+\t\tpublic MusicInfo GetPrevSong()\n+\t\t{\n+\t\t\tif (!installed)\n+\t\t\t\treturn null;\n+\n+\t\t\tvar songs = Game.Settings.Sound.Shuffle ? random : music;\n+\t\t\treturn songs.Reverse().SkipWhile(m => m != currentSong)\n+\t\t\t\t.Skip(1).FirstOrDefault() ?? songs.Reverse().FirstOrDefault();\n+\t\t}\n+\n+\t\tpublic void Dispose()","path":"OpenRA.Game/Traits/World/MusicPlaylist.cs","position":null,"original_position":126,"commit_id":"2d2daf5d609cf412d0f9d0d41f9208cb344e570d","original_commit_id":"d99c4f4151fceb5c2cb467d97b1cf497cbaa948c","user":{"login":"GraionDilach","id":1136302,"avatar_url":"https://avatars.githubusercontent.com/u/1136302?v=3","gravatar_id":"","url":"https://api.github.com/users/GraionDilach","html_url":"https://github.com/GraionDilach","followers_url":"https://api.github.com/users/GraionDilach/followers","following_url":"https://api.github.com/users/GraionDilach/following{/other_user}","gists_url":"https://api.github.com/users/GraionDilach/gists{/gist_id}","starred_url":"https://api.github.com/users/GraionDilach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GraionDilach/subscriptions","organizations_url":"https://api.github.com/users/GraionDilach/orgs","repos_url":"https://api.github.com/users/GraionDilach/repos","events_url":"https://api.github.com/users/GraionDilach/events{/privacy}","received_events_url":"https://api.github.com/users/GraionDilach/received_events","type":"User","site_admin":false},"body":"PS2.: Added the interface implementation.","created_at":"2015-07-01T12:15:27Z","updated_at":"2015-07-01T12:15:27Z","html_url":"https://github.com/OpenRA/OpenRA/pull/8562#discussion_r33672366","pull_request_url":"https://api.github.com/repos/OpenRA/OpenRA/pulls/8562","_links":{"self":{"href":"https://api.github.com/repos/OpenRA/OpenRA/pulls/comments/33672366"},"html":{"href":"https://github.com/OpenRA/OpenRA/pull/8562#discussion_r33672366"},"pull_request":{"href":"https://api.github.com/repos/OpenRA/OpenRA/pulls/8562"}}},"pull_request":{"url":"https://api.github.com/repos/OpenRA/OpenRA/pulls/8562","id":38608497,"html_url":"https://github.com/OpenRA/OpenRA/pull/8562","diff_url":"https://github.com/OpenRA/OpenRA/pull/8562.diff","patch_url":"https://github.com/OpenRA/OpenRA/pull/8562.patch","issue_url":"https://api.github.com/repos/OpenRA/OpenRA/issues/8562","number":8562,"state":"open","locked":false,"title":"Refactors the music player.","user":{"login":"GraionDilach","id":1136302,"avatar_url":"https://avatars.githubusercontent.com/u/1136302?v=3","gravatar_id":"","url":"https://api.github.com/users/GraionDilach","html_url":"https://github.com/GraionDilach","followers_url":"https://api.github.com/users/GraionDilach/followers","following_url":"https://api.github.com/users/GraionDilach/following{/other_user}","gists_url":"https://api.github.com/users/GraionDilach/gists{/gist_id}","starred_url":"https://api.github.com/users/GraionDilach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GraionDilach/subscriptions","organizations_url":"https://api.github.com/users/GraionDilach/orgs","repos_url":"https://api.github.com/users/GraionDilach/repos","events_url":"https://api.github.com/users/GraionDilach/events{/privacy}","received_events_url":"https://api.github.com/users/GraionDilach/received_events","type":"User","site_admin":false},"body":"Proper fix for #8559.\r\n\r\n<del>ATM it has one regression: due to the playlist getting set up before the shellmap's lua scripts, the game plays a maximum of two seconds maybe before the shellmap music at game start, depending on settings. That will probably need a StartingMusic trait.</del>","created_at":"2015-06-26T00:49:57Z","updated_at":"2015-07-01T12:15:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6ef3d77b8f71bffde9605dc413dd29bda2e0bcd9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OpenRA/OpenRA/pulls/8562/commits","review_comments_url":"https://api.github.com/repos/OpenRA/OpenRA/pulls/8562/comments","review_comment_url":"https://api.github.com/repos/OpenRA/OpenRA/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OpenRA/OpenRA/issues/8562/comments","statuses_url":"https://api.github.com/repos/OpenRA/OpenRA/statuses/2d2daf5d609cf412d0f9d0d41f9208cb344e570d","head":{"label":"GraionDilach:music-refactor","ref":"music-refactor","sha":"2d2daf5d609cf412d0f9d0d41f9208cb344e570d","user":{"login":"GraionDilach","id":1136302,"avatar_url":"https://avatars.githubusercontent.com/u/1136302?v=3","gravatar_id":"","url":"https://api.github.com/users/GraionDilach","html_url":"https://github.com/GraionDilach","followers_url":"https://api.github.com/users/GraionDilach/followers","following_url":"https://api.github.com/users/GraionDilach/following{/other_user}","gists_url":"https://api.github.com/users/GraionDilach/gists{/gist_id}","starred_url":"https://api.github.com/users/GraionDilach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GraionDilach/subscriptions","organizations_url":"https://api.github.com/users/GraionDilach/orgs","repos_url":"https://api.github.com/users/GraionDilach/repos","events_url":"https://api.github.com/users/GraionDilach/events{/privacy}","received_events_url":"https://api.github.com/users/GraionDilach/received_events","type":"User","site_admin":false},"repo":{"id":31671344,"name":"OpenRA","full_name":"GraionDilach/OpenRA","owner":{"login":"GraionDilach","id":1136302,"avatar_url":"https://avatars.githubusercontent.com/u/1136302?v=3","gravatar_id":"","url":"https://api.github.com/users/GraionDilach","html_url":"https://github.com/GraionDilach","followers_url":"https://api.github.com/users/GraionDilach/followers","following_url":"https://api.github.com/users/GraionDilach/following{/other_user}","gists_url":"https://api.github.com/users/GraionDilach/gists{/gist_id}","starred_url":"https://api.github.com/users/GraionDilach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GraionDilach/subscriptions","organizations_url":"https://api.github.com/users/GraionDilach/orgs","repos_url":"https://api.github.com/users/GraionDilach/repos","events_url":"https://api.github.com/users/GraionDilach/events{/privacy}","received_events_url":"https://api.github.com/users/GraionDilach/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/GraionDilach/OpenRA","description":"An open-source implementation of the Command & Conquer: Red Alert engine using .NET/Mono and OpenGL. Runs on Windows, Linux and Mac OS X.","fork":true,"url":"https://api.github.com/repos/GraionDilach/OpenRA","forks_url":"https://api.github.com/repos/GraionDilach/OpenRA/forks","keys_url":"https://api.github.com/repos/GraionDilach/OpenRA/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GraionDilach/OpenRA/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GraionDilach/OpenRA/teams","hooks_url":"https://api.github.com/repos/GraionDilach/OpenRA/hooks","issue_events_url":"https://api.github.com/repos/GraionDilach/OpenRA/issues/events{/number}","events_url":"https://api.github.com/repos/GraionDilach/OpenRA/events","assignees_url":"https://api.github.com/repos/GraionDilach/OpenRA/assignees{/user}","branches_url":"https://api.github.com/repos/GraionDilach/OpenRA/branches{/branch}","tags_url":"https://api.github.com/repos/GraionDilach/OpenRA/tags","blobs_url":"https://api.github.com/repos/GraionDilach/OpenRA/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GraionDilach/OpenRA/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GraionDilach/OpenRA/git/refs{/sha}","trees_url":"https://api.github.com/repos/GraionDilach/OpenRA/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GraionDilach/OpenRA/statuses/{sha}","languages_url":"https://api.github.com/repos/GraionDilach/OpenRA/languages","stargazers_url":"https://api.github.com/repos/GraionDilach/OpenRA/stargazers","contributors_url":"https://api.github.com/repos/GraionDilach/OpenRA/contributors","subscribers_url":"https://api.github.com/repos/GraionDilach/OpenRA/subscribers","subscription_url":"https://api.github.com/repos/GraionDilach/OpenRA/subscription","commits_url":"https://api.github.com/repos/GraionDilach/OpenRA/commits{/sha}","git_commits_url":"https://api.github.com/repos/GraionDilach/OpenRA/git/commits{/sha}","comments_url":"https://api.github.com/repos/GraionDilach/OpenRA/comments{/number}","issue_comment_url":"https://api.github.com/repos/GraionDilach/OpenRA/issues/comments{/number}","contents_url":"https://api.github.com/repos/GraionDilach/OpenRA/contents/{+path}","compare_url":"https://api.github.com/repos/GraionDilach/OpenRA/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GraionDilach/OpenRA/merges","archive_url":"https://api.github.com/repos/GraionDilach/OpenRA/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GraionDilach/OpenRA/downloads","issues_url":"https://api.github.com/repos/GraionDilach/OpenRA/issues{/number}","pulls_url":"https://api.github.com/repos/GraionDilach/OpenRA/pulls{/number}","milestones_url":"https://api.github.com/repos/GraionDilach/OpenRA/milestones{/number}","notifications_url":"https://api.github.com/repos/GraionDilach/OpenRA/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GraionDilach/OpenRA/labels{/name}","releases_url":"https://api.github.com/repos/GraionDilach/OpenRA/releases{/id}","created_at":"2015-03-04T17:55:26Z","updated_at":"2015-03-04T17:55:32Z","pushed_at":"2015-07-01T12:15:05Z","git_url":"git://github.com/GraionDilach/OpenRA.git","ssh_url":"git@github.com:GraionDilach/OpenRA.git","clone_url":"https://github.com/GraionDilach/OpenRA.git","svn_url":"https://github.com/GraionDilach/OpenRA","homepage":"http://www.openra.net","size":89534,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"bleed"}},"base":{"label":"OpenRA:bleed","ref":"bleed","sha":"faaa4849561411231211dd106d8ffc8b1df48d15","user":{"login":"OpenRA","id":409046,"avatar_url":"https://avatars.githubusercontent.com/u/409046?v=3","gravatar_id":"","url":"https://api.github.com/users/OpenRA","html_url":"https://github.com/OpenRA","followers_url":"https://api.github.com/users/OpenRA/followers","following_url":"https://api.github.com/users/OpenRA/following{/other_user}","gists_url":"https://api.github.com/users/OpenRA/gists{/gist_id}","starred_url":"https://api.github.com/users/OpenRA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpenRA/subscriptions","organizations_url":"https://api.github.com/users/OpenRA/orgs","repos_url":"https://api.github.com/users/OpenRA/repos","events_url":"https://api.github.com/users/OpenRA/events{/privacy}","received_events_url":"https://api.github.com/users/OpenRA/received_events","type":"Organization","site_admin":false},"repo":{"id":959908,"name":"OpenRA","full_name":"OpenRA/OpenRA","owner":{"login":"OpenRA","id":409046,"avatar_url":"https://avatars.githubusercontent.com/u/409046?v=3","gravatar_id":"","url":"https://api.github.com/users/OpenRA","html_url":"https://github.com/OpenRA","followers_url":"https://api.github.com/users/OpenRA/followers","following_url":"https://api.github.com/users/OpenRA/following{/other_user}","gists_url":"https://api.github.com/users/OpenRA/gists{/gist_id}","starred_url":"https://api.github.com/users/OpenRA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpenRA/subscriptions","organizations_url":"https://api.github.com/users/OpenRA/orgs","repos_url":"https://api.github.com/users/OpenRA/repos","events_url":"https://api.github.com/users/OpenRA/events{/privacy}","received_events_url":"https://api.github.com/users/OpenRA/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OpenRA/OpenRA","description":"Open Source real-time strategy game engine for early Westwood games such as Command & Conquer: Red Alert written in C# using SDL and OpenGL. Runs on Windows, Linux, *BSD and Mac OS X.","fork":false,"url":"https://api.github.com/repos/OpenRA/OpenRA","forks_url":"https://api.github.com/repos/OpenRA/OpenRA/forks","keys_url":"https://api.github.com/repos/OpenRA/OpenRA/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OpenRA/OpenRA/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OpenRA/OpenRA/teams","hooks_url":"https://api.github.com/repos/OpenRA/OpenRA/hooks","issue_events_url":"https://api.github.com/repos/OpenRA/OpenRA/issues/events{/number}","events_url":"https://api.github.com/repos/OpenRA/OpenRA/events","assignees_url":"https://api.github.com/repos/OpenRA/OpenRA/assignees{/user}","branches_url":"https://api.github.com/repos/OpenRA/OpenRA/branches{/branch}","tags_url":"https://api.github.com/repos/OpenRA/OpenRA/tags","blobs_url":"https://api.github.com/repos/OpenRA/OpenRA/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OpenRA/OpenRA/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OpenRA/OpenRA/git/refs{/sha}","trees_url":"https://api.github.com/repos/OpenRA/OpenRA/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OpenRA/OpenRA/statuses/{sha}","languages_url":"https://api.github.com/repos/OpenRA/OpenRA/languages","stargazers_url":"https://api.github.com/repos/OpenRA/OpenRA/stargazers","contributors_url":"https://api.github.com/repos/OpenRA/OpenRA/contributors","subscribers_url":"https://api.github.com/repos/OpenRA/OpenRA/subscribers","subscription_url":"https://api.github.com/repos/OpenRA/OpenRA/subscription","commits_url":"https://api.github.com/repos/OpenRA/OpenRA/commits{/sha}","git_commits_url":"https://api.github.com/repos/OpenRA/OpenRA/git/commits{/sha}","comments_url":"https://api.github.com/repos/OpenRA/OpenRA/comments{/number}","issue_comment_url":"https://api.github.com/repos/OpenRA/OpenRA/issues/comments{/number}","contents_url":"https://api.github.com/repos/OpenRA/OpenRA/contents/{+path}","compare_url":"https://api.github.com/repos/OpenRA/OpenRA/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OpenRA/OpenRA/merges","archive_url":"https://api.github.com/repos/OpenRA/OpenRA/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OpenRA/OpenRA/downloads","issues_url":"https://api.github.com/repos/OpenRA/OpenRA/issues{/number}","pulls_url":"https://api.github.com/repos/OpenRA/OpenRA/pulls{/number}","milestones_url":"https://api.github.com/repos/OpenRA/OpenRA/milestones{/number}","notifications_url":"https://api.github.com/repos/OpenRA/OpenRA/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OpenRA/OpenRA/labels{/name}","releases_url":"https://api.github.com/repos/OpenRA/OpenRA/releases{/id}","created_at":"2010-10-04T07:38:05Z","updated_at":"2015-07-01T10:13:01Z","pushed_at":"2015-07-01T12:15:09Z","git_url":"git://github.com/OpenRA/OpenRA.git","ssh_url":"git@github.com:OpenRA/OpenRA.git","clone_url":"https://github.com/OpenRA/OpenRA.git","svn_url":"https://github.com/OpenRA/OpenRA","homepage":"http://www.openra.net","size":179253,"stargazers_count":1994,"watchers_count":1994,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":718,"mirror_url":null,"open_issues_count":798,"forks":718,"open_issues":798,"watchers":1994,"default_branch":"bleed"}},"_links":{"self":{"href":"https://api.github.com/repos/OpenRA/OpenRA/pulls/8562"},"html":{"href":"https://github.com/OpenRA/OpenRA/pull/8562"},"issue":{"href":"https://api.github.com/repos/OpenRA/OpenRA/issues/8562"},"comments":{"href":"https://api.github.com/repos/OpenRA/OpenRA/issues/8562/comments"},"review_comments":{"href":"https://api.github.com/repos/OpenRA/OpenRA/pulls/8562/comments"},"review_comment":{"href":"https://api.github.com/repos/OpenRA/OpenRA/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OpenRA/OpenRA/pulls/8562/commits"},"statuses":{"href":"https://api.github.com/repos/OpenRA/OpenRA/statuses/2d2daf5d609cf412d0f9d0d41f9208cb344e570d"}}}}