Skip to content

Commit

Permalink
Fixed overlapping toys in the bonus section.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hermanest committed Dec 19, 2024
1 parent 7abc84d commit 9dcb646
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions Source/3_AssetBundle/Christmas/ChristmasTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private async Task LoadOrnaments(ChristmasTreeSettings settings) {
var tasks = new Task[size];

foreach (var ornament in _ornaments) {
ornament.Deinit();
OrnamentsPool.Despawn(ornament);
}
_ornaments.Clear();
Expand Down
1 change: 1 addition & 0 deletions Source/8_UI/Christmas/ChristmasOrnamentsPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public ChristmasTreeOrnament Spawn(int id) {
}

public void Despawn(ChristmasTreeOrnament ornament) {
ornament.OrnamentDeinitEvent -= Despawn;
var cache = GetCache(ornament.BundleId);
cache.Push(ornament);
}
Expand Down
2 changes: 2 additions & 0 deletions Source/8_UI/Christmas/ChristmasTreeOrnament.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public void Deinit() {
_grabbed = false;
_hovered = false;
gameObject.SetActive(false);
OrnamentDeinitEvent = null;
OrnamentGrabbedEvent = null;
}

private void Awake() {
Expand Down
11 changes: 9 additions & 2 deletions Source/8_UI/Christmas/TreeEditor/OrnamentStoreCell.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BeatLeader.Models;
using System.Threading;
using BeatLeader.Models;
using BeatLeader.UI.MainMenu;
using BeatSaberMarkupLanguage;
using BeatSaberMarkupLanguage.Components;
Expand All @@ -21,6 +22,8 @@ internal class OrnamentStoreCell : MonoBehaviour {

private int _bundleId;
private MapDetail? _song = null;

private readonly SemaphoreSlim _semaphore = new(1, 1);

public void Setup(ChristmasOrnamentPool pool, GameObject parent) {
_pool = pool;
Expand Down Expand Up @@ -65,6 +68,8 @@ public async void SetOrnamentStatus(DailyTreeStatus status) {
}

public async void SetBonusOrnamentStatus(BonusOrnament status) {
await _semaphore.WaitAsync();

_bundleId = status.bundleId;
await _pool.PreloadAsync(status.bundleId);
ReloadNextInstance(true);
Expand All @@ -74,6 +79,8 @@ public async void SetBonusOrnamentStatus(BonusOrnament status) {
if (status.description.Length > 0) {
_hint.text = status.description;
}

_semaphore.Release();
}

private void Awake() {
Expand Down Expand Up @@ -103,7 +110,7 @@ private void ReloadNextInstance(bool despawn = false) {
_previewInstance.Deinit();
_pool.Despawn(_previewInstance);
}

_previewInstance = _pool.Spawn(_bundleId);
_previewInstance.transform.SetParent(transform, false);
_previewInstance.transform.localPosition = new Vector3(0.0f, 2.5f, 0.0f);
Expand Down

0 comments on commit 9dcb646

Please sign in to comment.