/// <summary> /// Refreshes the types of columns displayed for judgemnt type hit count. /// </summary> public void RefreshColumns(IModeService service) { // In case of a null service, just display all labels. if (service == null) { Logger.LogWarning($"RankingColumn.RefreshColumn - The specified mode service is null."); judgementLabels.ForEach(l => l.Active = true); return; } // Only display judgement types that are used by this mode. var timing = service.CreateTiming(); int activeCount = 0; judgementLabels.ForEach(l => l.Active = false); foreach (var result in timing.SupportedHitResults()) { activeCount++; judgementLabels[(int)result].Active = true; } // Position these labels. for (int i = 0; i < judgementLabels.Count; i++) { if (judgementLabels[i].Active) { activeCount--; judgementLabels[i].X = JudgementLabelStartX - (activeCount * JudgementLabelInterval); } } }
public virtual T Get(string name) { if (IsDisposed) { throw new ObjectDisposedException(nameof(ResourceAtlas <T>)); } // If exists in atlas, return it. if (atlas.TryGetValue(name, out T result)) { return(result); } // If doesn't exist, load from resources. var loaded = LoadFromResources(name); if (loaded == null) { Logger.LogWarning($"ResourceAtlas.Get - Could not load resource ({name}) of type ({nameof(T)})"); } else { Set(name, loaded); } return(loaded); }
public void DeleteMapset(IMapset mapset) { if (mapset == null) { Logger.LogWarning("Attempted to delete a null mapset."); return; } // If this mapset is currently selected, make it select the previous mapset. var selectedMapset = selection.Mapset.Value; if (selectedMapset == mapset) { // If there is only one mapset left in all mapsets, just remove selection. if (allMapsets.Count <= 1) { selection.SelectMapset(null); } else { // Determine which mapset list to choose the previous map from. var mapsetsList = ( (displayedMapsets.Contains(mapset) && displayedMapsets.Count == 1) || displayedMapsets.Count == 0 ? allMapsets : displayedMapsets ); selection.SelectMapset(mapsetsList.GetPrevious(mapset)); } } store.Delete(mapset as Mapset); allMapsets.Remove(mapset); displayedMapsets.Remove(mapset); OnDeleteMapset?.Invoke(mapset); }
public void DeleteMap(IOriginalMap map) { if (map == null) { Logger.LogWarning("Attempted to delete a null map."); return; } var mapset = map.Detail.Mapset; if (mapset == null) { throw new Exception($"Could not retrieve the mapset of specified map: {map.Metadata.Artist} - {map.Metadata.Title}"); } // Delete the mapset itself if there is only one map. if (mapset.Maps.Count == 1) { DeleteMapset(mapset); return; } // If this map is currently selected, make it select the previous map. var selectedOriginal = selection.Map.Value?.OriginalMap; if (selectedOriginal == map) { selection.SelectMap(mapset.GetMapBefore(selectedOriginal)); } store.DeleteMap(map); mapset.Maps.Remove(map); OnDeleteMap?.Invoke(map); }
public ColorPalette GetHitResultColor(HitResultType type) { if (hitResultColors.TryGetValue(type, out ColorPalette value)) { return(value); } Logger.LogWarning($"ColorPreset.GetHitResultColor - Unknown type: {type}"); return(new ColorPalette(Color.white)); }
public ColorPalette GetDifficultyColor(DifficultyType type) { if (difficultyColors.TryGetValue(type, out ColorPalette value)) { return(value); } Logger.LogWarning($"ColorPreset.GetDifficultyColor - Unknown type: {type}"); return(new ColorPalette(Color.black)); }
/// <summary> /// Returns the Graphic component from the specified objct. /// </summary> protected Graphic GetGraphic(IGraphicObject obj) { var graphic = obj.RawObject.GetComponent <Graphic>(); if (graphic == null) { Logger.LogWarning("BaseShaderEffect.GetGraphic - Graphic component not found for object: " + obj.Name); } return(graphic); }
/// <summary> /// Creates a playable map for specified service. /// </summary> private IPlayableMap CreatePlayable(IModeService service) { if (service == null) { Logger.LogWarning($"OriginalMap.CreatePlayable - A null servicer is passed. Skipping this mode."); return(null); } // Conversion var converter = service.CreateConverter(this); if (!converter.IsConvertible) { return(null); } var convertedMap = converter.Convert(); if (convertedMap == null) { Logger.LogWarning($"OriginalMap.CreatePlayable - Failed to convert map for mode: {service.GameMode}"); return(null); } // Processing var processor = service.CreateProcessor(convertedMap); processor.PreProcess(); foreach (var o in convertedMap.HitObjects) { o.ApplyMapProperties(convertedMap.ControlPoints, convertedMap.Detail.Difficulty); } processor.PostProcess(); // Calculate difficulty. var difficultyCalculator = service.CreateDifficultyCalculator(convertedMap); if (difficultyCalculator == null) { Logger.LogWarning($"OriginalMap.CreatePlayable - Difficulty calculator is null for mode: {service.GameMode}"); return(null); } convertedMap.Difficulty = difficultyCalculator.Calculate(); if (convertedMap.Difficulty == null) { Logger.LogWarning($"OriginalMap.CreatePlayable - Failed to calculate difficulty for mode: {service.GameMode}"); return(null); } // Finished convertedMap.PlayableMode = service.GameMode; return(convertedMap); }
/// <summary> /// Creates a new Color with string values. /// Supported formats: /// #{rr}{gg}{bb}{aa} /// #{rr}{gg}{bb} /// ** Cases are non-sensitive. /// ** Hashtag (#) not required. /// </summary> public static Color Create(string str) { int r = 255, g = 255, b = 255, a = 255; if (str[0] == '#') { str = str.Substring(1); } switch (str.Length) { case 3: r = ParseHex(str[0]) * 16 + ParseHex(str[0]); g = ParseHex(str[1]) * 16 + ParseHex(str[1]); b = ParseHex(str[2]) * 16 + ParseHex(str[2]); break; case 4: r = ParseHex(str[0]) * 16 + ParseHex(str[0]); g = ParseHex(str[1]) * 16 + ParseHex(str[1]); b = ParseHex(str[2]) * 16 + ParseHex(str[2]); a = ParseHex(str[3]) * 16 + ParseHex(str[3]); break; case 6: r = ParseHex(str[0]) * 16 + ParseHex(str[1]); g = ParseHex(str[2]) * 16 + ParseHex(str[3]); b = ParseHex(str[4]) * 16 + ParseHex(str[5]); break; case 8: r = ParseHex(str[0]) * 16 + ParseHex(str[1]); g = ParseHex(str[2]) * 16 + ParseHex(str[3]); b = ParseHex(str[4]) * 16 + ParseHex(str[5]); a = ParseHex(str[6]) * 16 + ParseHex(str[7]); break; default: Logger.LogWarning($"HexColor.Create - Invalid hex string: {str}"); break; } return(new Color( r * ByteReciprocal, g * ByteReciprocal, b * ByteReciprocal, a * ByteReciprocal )); }
public void CreatePlayable(IModeManager modeManager) { // Playable maps shouldn't support this action. if (IsPlayable) { Logger.LogWarning($"OriginalMap.CreatePlayable - This action is not supported for playable maps!"); return; } this.playableMaps.Clear(); foreach (var service in modeManager.PlayableServices()) { var playableMap = CreatePlayable(service); if (playableMap != null) { this.playableMaps[service.GameMode] = playableMap; } } }
/// <summary> /// Disposes the view based on its hide action type. /// </summary> protected virtual void DisposeInternal(INavigationView view) { view.OnPostHide(); switch (view.HideAction) { case HideActionType.Recycle: view.Active = false; break; case HideActionType.Destroy: views.Remove(view); GameObject.Destroy(view.RawObject); break; default: Logger.LogWarning($"Navigator.DisposeInternal - Unsupported hide action type: {view.HideAction}"); break; } }
public void TestLogger() { LogAssert.ignoreFailingMessages = true; Logger.Log("1"); Logger.LogWarning("2"); Logger.LogError("3"); Logger.OnWarning += (message) => { Logger.Log($"Dispatched warning: {message}"); }; Logger.OnError += (message) => { Logger.Log($"Dispatched error: {message}"); }; Logger.Log("a"); Logger.LogWarning("b"); Logger.LogError("c"); }
/// <summary> /// Shows the map actions dialog overlay. /// </summary> public void ShowMapActions(IOriginalMap map) { if (map == null) { Logger.LogWarning("Attempted to show map actions for a null map."); return; } var dialogModel = OverlayNavigator.Show <DialogOverlay>().Model; dialogModel.SetMessage($"Select an action for the version ({map.Detail.Version})"); dialogModel.AddOption(new DialogOption() { Callback = () => OnMapActionDelete(map), Label = "Delete", Color = ColorPreset.Warning }); dialogModel.AddOption(new DialogOption() { Label = "Cancel", Color = ColorPreset.Negative }); }
public void TestDummyLogger() { LogAssert.ignoreFailingMessages = true; var dummy = new DummyLogService(); Logger.Register(dummy); Assert.IsFalse(dummy.LoggedNormal); Assert.IsFalse(dummy.LoggedWarning); Assert.IsFalse(dummy.LoggedError); Logger.Log("AA"); Logger.LogWarning("BB"); try { Logger.LogError("CC"); } catch (Exception) {} Assert.IsTrue(dummy.LoggedNormal); Assert.IsTrue(dummy.LoggedWarning); Assert.IsTrue(dummy.LoggedError); }
/// <summary> /// Decodes color value for specified line. /// </summary> protected void DecodeColor(T result, string line) { var pair = GetKeyValue(line); bool isCombo = pair.Key.StartsWith("Combo", StringComparison.Ordinal); string[] colorData = pair.Value.Split(','); // Invalid format if (colorData.Length < 3 || colorData.Length > 4) { Logger.LogWarning( $"OsuDecoder.DecodeColor - Invalid color data format. Must be (R, G, B) or (R, G, B, A). ({pair.Value})" ); return; } // Try parse color Color color; try { color = new Color( byte.Parse(colorData[0]) / 255f, byte.Parse(colorData[1]) / 255f, byte.Parse(colorData[2]) / 255f, (colorData.Length > 3 ? byte.Parse(colorData[3]) : 255) / 255f ); } catch (Exception) { Logger.LogWarning( $"OsuDecoder.DecodeColor - Invalid color element. Each element must be a valid byte value. ({pair.Value})" ); return; } // If a combo color property if (isCombo) { IComboColorable colorable = result as IComboColorable; if (colorable == null) { return; } // Remove default combo colors first. if (!hasComboColor) { colorable.ComboColors.Clear(); hasComboColor = true; } // Add color colorable.ComboColors.Add(color); } else { ICustomColorable colorable = result as ICustomColorable; if (colorable == null) { return; } // Add color colorable.CustomColors[pair.Key] = color; } }