private void LoadChannelsFromCollection(String dir) { CSLMusicMod.Log("Looking for channels in " + dir); if (!Directory.Exists(dir)) { CSLMusicMod.Log("Skipping: Directory does not exist."); return; } // Load json channel configuration foreach (String filename in Directory.GetFiles(dir)) { if (Path.GetExtension(filename) == ".json") { UserRadioChannel channel = UserRadioChannel.LoadFromJson(filename); if (channel != null) { channel.m_DefinitionDirectory = dir; m_Stations[channel.m_Name] = channel; } else { Debug.LogError("[CSLMusic] Error: Cannot load channel from " + filename); } } } }
private void CreateLegacyChannel(String name, String[] collections, String dir) { UserRadioChannel channel = new UserRadioChannel(name); channel.m_Collections = new HashSet <string>(collections); channel.m_ThumbnailFile = "thumbnail_package.png"; if (dir != null) { channel.m_DefinitionDirectory = dir; } m_Stations[channel.m_Name] = channel; }
private void CreateDefaultMixChannel() { UserRadioChannel channel = new UserRadioChannel("CSLMusic Mix"); channel.m_ThumbnailFile = "thumbnail_mix.png"; channel.m_Collections = new HashSet <string>(m_Songs.Values.Where(song => !song.m_isVanilla || ModOptions.Instance.AddVanillaSongsToMusicMix).Select(song => song.m_Collection)); // Default channel loads from all collections List <RadioContentInfo.ContentType> allowedcontent = new List <RadioContentInfo.ContentType>(); if (ModOptions.Instance.MixContentBlurb) { allowedcontent.Add(RadioContentInfo.ContentType.Blurb); } if (ModOptions.Instance.MixContentBroadcast) { allowedcontent.Add(RadioContentInfo.ContentType.Broadcast); } if (ModOptions.Instance.MixContentCommercial) { allowedcontent.Add(RadioContentInfo.ContentType.Commercial); } if (ModOptions.Instance.MixContentMusic) { allowedcontent.Add(RadioContentInfo.ContentType.Music); } if (ModOptions.Instance.MixContentTalk) { allowedcontent.Add(RadioContentInfo.ContentType.Talk); } channel.m_SupportedContent = allowedcontent.ToArray(); if (allowedcontent.Count != 0) { m_Stations[channel.m_Name] = channel; } }
public static UserRadioChannel LoadFromJson(String filename) { try { string data = File.ReadAllText(filename); JsonData json = JsonMapper.ToObject(data); UserRadioChannel channel = new UserRadioChannel(); channel.m_Name = (String)json["name"]; if (json.Keys.Contains("collections")) { List <String> collections = new List <string>(); foreach (JsonData v in json["collections"]) { collections.Add((String)v); } channel.m_Collections = new HashSet <string>(collections); } else { channel.m_Collections = new HashSet <string>(new string[] { channel.m_Name }); } if (json.Keys.Contains("thumbnail")) { channel.m_ThumbnailFile = Path.Combine(Path.GetDirectoryName(filename), (String)json["thumbnail"]); } if (json.Keys.Contains("schedule")) { List <RadioChannelInfo.State> states = new List <RadioChannelInfo.State>(); foreach (JsonData entry in json["schedule"]) { RadioChannelInfo.State state = new RadioChannelInfo.State(); state.m_contentType = (RadioContentInfo.ContentType)Enum.Parse(typeof(RadioContentInfo.ContentType), (String)entry["type"], true); state.m_minCount = (int)entry["min"]; state.m_maxCount = (int)entry["max"]; states.Add(state); } channel.m_StateChain = states.ToArray(); } // Named conditions var namedConditions = new Dictionary <string, RadioContextCondition>(); if (json.Keys.Contains("filters") && json["filters"].IsObject) { foreach (var name in json["filters"].Keys) { var entry = json["filters"][name]; var cond = RadioContextCondition.LoadFromJsonUsingType(entry); if (cond != null) { namedConditions[name] = cond; } } } if (json.Keys.Contains("contexts")) { foreach (JsonData entry in json["contexts"]) { var context = RadioContext.LoadFromJson(entry, namedConditions); if (context != null) { context.m_RadioChannel = channel; channel.m_Contexts.Add(context); // Auto-load collections that are defined in contexts foreach (var coll in context.m_Collections) { channel.m_Collections.Add(coll); } } } } return(channel); } catch (Exception ex) { Debug.LogError(ex); return(null); } }
/// <summary> /// Rebuilds the allowed content for a channel. /// </summary> /// <param name="channel">Channel.</param> private void RebuildDisallowedContentForChannel(RadioChannelData channel) { if (channel.Info == null) { return; } HashSet <RadioContentInfo> disallowed; if (!DisallowedContent.TryGetValue(channel.Info, out disallowed)) { disallowed = new HashSet <RadioContentInfo>(); DisallowedContent[channel.Info] = disallowed; } else { disallowed.Clear(); } UserRadioChannel userchannel = AudioManagerHelper.GetUserChannelInfo(channel.Info); if (userchannel != null) { // If the channel is a custom channel, we can check for context and for content disabling // The method returns NULL if all songs apply! var allowedsongs = userchannel.GetApplyingSongs(); if (allowedsongs == null) { if (ModOptions.Instance.EnableDisabledContent && ModOptions.Instance.DisabledContent.Count != 0) { foreach (UserRadioContent usercontent in userchannel.m_Content) { if (usercontent.m_VanillaContentInfo != null) { bool isenabled = (!ModOptions.Instance.EnableDisabledContent || AudioManagerHelper.ContentIsEnabled(usercontent.m_VanillaContentInfo)); if (!isenabled) { disallowed.Add(usercontent.m_VanillaContentInfo); } } } } } else { foreach (UserRadioContent usercontent in userchannel.m_Content) { if (usercontent.m_VanillaContentInfo != null) { bool isincontext = (!ModOptions.Instance.EnableContextSensitivity || allowedsongs.Contains(usercontent)); bool isenabled = (!ModOptions.Instance.EnableDisabledContent || AudioManagerHelper.ContentIsEnabled(usercontent.m_VanillaContentInfo)); if (!isincontext || !isenabled) { disallowed.Add(usercontent.m_VanillaContentInfo); } } } } } else { // If the channel is a vanilla channel, we can still disable content AudioManager mgr = Singleton <AudioManager> .instance; if (mgr.m_radioContents.m_size > 0) { for (int i = 0; i < mgr.m_radioContents.m_size; ++i) { var content = mgr.m_radioContents[i]; if (content.Info != null && content.Info.m_radioChannels != null && content.Info.m_radioChannels.Contains(channel.Info)) { if (!AudioManagerHelper.ContentIsEnabled(content.Info)) { disallowed.Add(content.Info); } } } } } }