public IEnumerator TestRemoveImmediate() { var cacher = new DummyCacher(); var agent = new CacherAgent <string, DummyCacherData>(cacher); Assert.AreEqual(cacher, agent.Cacher); agent.UseDelayedRemove = false; agent.RemoveDelay = 0f; Assert.IsNull(agent.Listener); Assert.IsFalse(cacher.IsCached("A")); agent.Request("A"); Assert.IsFalse(cacher.IsCached("A")); Assert.IsNull(agent.Listener.Value); yield return(new WaitForSecondsRealtime(1.5f)); var value = agent.Listener.Value; Assert.IsTrue(cacher.IsCached("A")); Assert.IsNotNull(value); Assert.IsFalse(value.IsDestroyed); agent.Remove(); Assert.IsFalse(cacher.IsCached("A")); Assert.IsNull(agent.Listener); Assert.IsTrue(value.IsDestroyed); }
private void Init() { // Initialize music cacher agent. musicAgent = new CacherAgent <string, IMusicAudio>(MusicCacher); musicAgent.OnFinished += OnMusicAudioLoaded; ResetOptions(); }
private void Init() { mapTagRecycler = new ManagedRecycler <MapMetaTag>(CreateMapTag); OnTriggered += () => { if (Active && Mapset != null) { if (Model.SelectedMapset.Value != Mapset) { Model.SelectMapset(Mapset); } else { Model.NavigateToPrepare(); } } }; container = CreateChild <UguiObject>("container"); { container.Anchor = AnchorType.CenterStretch; container.SetOffsetVertical(5f); container.Width = UnfocusedWidth; highlight = container.CreateChild <UguiSprite>("highlight"); { highlight.Size = new Vector2(1920f, 144f); highlight.SpriteName = "glow-128"; highlight.Alpha = UnfocusedHighlightAlpha; highlight.IsRaycastTarget = false; highlight.AddEffect(new AdditiveShaderEffect()); } glow = container.CreateChild <UguiSprite>("glow"); { glow.Anchor = AnchorType.Fill; glow.RawSize = new Vector2(30f, 30f); glow.SpriteName = "glow-circle-32"; glow.ImageType = Image.Type.Sliced; glow.Color = UnfocusedGlowColor; } thumbContainer = container.CreateChild <UguiSprite>("thumb"); { thumbContainer.Anchor = AnchorType.Fill; thumbContainer.RawSize = Vector2.zero; thumbContainer.SpriteName = "circle-32"; thumbContainer.ImageType = Image.Type.Sliced; thumbContainer.Color = Color.black; thumbContainer.AddEffect(new MaskEffect()); thumbImage = thumbContainer.CreateChild <UguiTexture>("image"); { thumbImage.Anchor = AnchorType.Fill; thumbImage.RawSize = Vector2.zero; thumbImage.Color = UnfocusedThumbColor; } } titleLabel = container.CreateChild <Label>("title"); { titleLabel.Anchor = AnchorType.TopStretch; titleLabel.Pivot = PivotType.Top; titleLabel.Y = -8f; titleLabel.Height = 32f; titleLabel.SetOffsetHorizontal(20f); titleLabel.IsItalic = true; titleLabel.IsBold = true; titleLabel.WrapText = true; titleLabel.Alignment = TextAnchor.MiddleLeft; titleLabel.FontSize = 22; titleShadow = titleLabel.AddEffect(new ShadowEffect()).Component; titleShadow.style = ShadowStyle.Shadow; titleShadow.effectColor = Color.black; titleShadow.enabled = false; } artistLabel = container.CreateChild <Label>("artist"); { artistLabel.Anchor = AnchorType.BottomStretch; artistLabel.Pivot = PivotType.Bottom; artistLabel.Y = 8f; artistLabel.Height = 24f; artistLabel.SetOffsetHorizontal(20f); artistLabel.WrapText = true; artistLabel.Alignment = TextAnchor.MiddleLeft; artistLabel.FontSize = 18; artistShadow = artistLabel.AddEffect(new ShadowEffect()).Component; artistShadow.style = ShadowStyle.Shadow; artistShadow.effectColor = Color.black; artistShadow.enabled = false; } creatorLabel = container.CreateChild <Label>("creator"); { creatorLabel.Anchor = AnchorType.BottomStretch; creatorLabel.Pivot = PivotType.Bottom; creatorLabel.Y = 8f; creatorLabel.Height = 24f; creatorLabel.SetOffsetHorizontal(20f); creatorLabel.WrapText = true; creatorLabel.Alignment = TextAnchor.MiddleRight; creatorLabel.FontSize = 18; creatorShadow = creatorLabel.AddEffect(new ShadowEffect()).Component; creatorShadow.style = ShadowStyle.Shadow; creatorShadow.effectColor = Color.black; creatorShadow.enabled = false; } mapTagGrid = container.CreateChild <UguiGrid>("map-tag-grid"); { mapTagGrid.Anchor = AnchorType.TopStretch; mapTagGrid.Pivot = PivotType.Top; mapTagGrid.Y = -8f; mapTagGrid.Height = MapTagCellSize.y; mapTagGrid.SetOffsetHorizontal(20f); mapTagGrid.Alignment = TextAnchor.MiddleRight; mapTagGrid.Axis = GridLayoutGroup.Axis.Horizontal; mapTagGrid.SpaceWidth = 8f; mapTagGrid.CellSize = MapTagCellSize; mapTagGrid.Limit = 0; } } backgroundAgent = new CacherAgent <IMap, IMapBackground>(BackgroundCacher) { UseDelayedRemove = true, RemoveDelay = 2f }; backgroundAgent.OnFinished += OnBackgroundLoaded; OnEnableInited(); }
public IEnumerator TestRequest() { var cacher = new DummyCacher(); var agent = new CacherAgent <string, DummyCacherData>(cacher); Assert.AreEqual(cacher, agent.Cacher); agent.UseDelayedRemove = false; agent.RemoveDelay = 0f; Assert.IsNull(agent.Listener); Assert.IsFalse(cacher.IsCached("A")); // Request data A. agent.Request("A"); Assert.IsFalse(cacher.IsCached("A")); Assert.IsNotNull(agent.Listener); float limit = 2f; while (!cacher.IsCached("A")) { Debug.Log("Progress: " + agent.Listener.Progress); limit -= Time.deltaTime; if (limit <= 0) { Assert.Fail("Request should've finished by now!"); } yield return(null); } Assert.IsTrue(cacher.IsCached("A")); Assert.AreEqual(1f, agent.Listener.Progress); Assert.IsNotNull(agent.Listener.Value); Assert.AreEqual("A", agent.Listener.Key); Assert.AreEqual("A", agent.Listener.Value.Key); Assert.IsFalse(agent.Listener.Value.IsDestroyed); // Request data B. agent.Request("B"); Assert.IsFalse(cacher.IsCached("B")); Assert.AreEqual(0f, agent.Listener.Progress); Assert.AreEqual("B", agent.Listener.Key); Assert.IsNull(agent.Listener.Value); limit = 2f; while (!cacher.IsCached("B")) { Debug.Log("Progress: " + agent.Listener.Progress); limit -= Time.deltaTime; if (limit <= 0) { Assert.Fail("Request should've finished by now!"); } yield return(null); } Assert.IsTrue(cacher.IsCached("B")); Assert.AreEqual(1f, agent.Listener.Progress); Assert.IsNotNull(agent.Listener.Value); Assert.AreEqual("B", agent.Listener.Key); Assert.AreEqual("B", agent.Listener.Value.Key); Assert.IsFalse(agent.Listener.Value.IsDestroyed); }
public MapSelection(IMusicCacher musicCacher, IBackgroundCacher backgroundCacher, IGameConfiguration gameConfiguration, IMapsetConfiguration mapsetConfiguration, IMapConfiguration mapConfiguration) { if (musicCacher == null) { throw new ArgumentNullException(nameof(musicCacher)); } if (backgroundCacher == null) { throw new ArgumentNullException(nameof(backgroundCacher)); } if (gameConfiguration == null) { throw new ArgumentNullException(nameof(gameConfiguration)); } this.musicCacher = musicCacher; this.backgroundCacher = backgroundCacher; this.mapsetConfiguration = mapsetConfiguration; this.mapConfiguration = mapConfiguration; // Initial background. bindableBackground.Value = emptyBackground = new MapBackground(null); // Setup music loader musicAgent = new CacherAgent <IMap, IMusicAudio>(musicCacher) { UseDelayedRemove = true, RemoveDelay = 2f, }; musicAgent.OnFinished += (music) => { bindableMusic.Value = music; }; // Setup background loader backgroundAgent = new CacherAgent <IMap, IMapBackground>(backgroundCacher) { UseDelayedRemove = true, RemoveDelay = 2f, }; backgroundAgent.OnFinished += (background) => { bindableBackground.Value = background; }; // Listen to game mode change event from config. gameConfiguration.OnLoad += delegate { // Retrieve initial game mode saved in config. currentMode = gameConfiguration.RulesetMode.Value; }; gameConfiguration.RulesetMode.OnValueChanged += (newMode, oldMode) => { // Only if change of mode if (oldMode != newMode) { currentMode = newMode; // Automatically change to variant playable for this new mode. if (Map.Value != null) { SelectMap(Map.Value.OriginalMap.GetPlayable(newMode)); } } }; }