Skip to content

Commit

Permalink
THERE IS NO BUG! IT ACTUALLY SORTS BY TIME FIRST AND THEN BY PRICE I'…
Browse files Browse the repository at this point in the history
…M A FUCKING GENIUS FUCK ME PLS
  • Loading branch information
JoanStinson committed Dec 22, 2021
1 parent c00cab6 commit 96ae06d
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions Mobile Game Store/Assets/Scripts/Panels/StorePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,10 @@ private void Start()
_packsController.OnPackActivated.AddListener(OnPackActivated);
_packsController.OnPackRemoved.AddListener(OnPackRemoved);

var activePacks = _packsController.ActivePacks.OrderByDescending(p => p.Data.PackType)
.OrderBy(p => p.Data.Order)
.ThenBy(p => p.RemainingTime)
.ThenBy(p => p.Data.Price)
.ToArray();

for (int i = 0; i < activePacks.Length; ++i)
GetOrderedPacksList(_packsController.ActivePacks, out var activePacks);
for (int i = 0; i < activePacks.Count; ++i)
{
var packDisplayer = _packsFactory.CreatePackDisplayer(activePacks[i]);
_packsFactory.SetPackDisplayerParent(packDisplayer, i);
_packDisplayers.Add(packDisplayer);
}

Expand All @@ -61,24 +55,11 @@ private void OnPackActivated(Pack pack)
if (_featuredPackSlot != null)
{
var packsToOrder = new List<Pack>() { _featuredPackSlot.Pack, pack };
var orderedPacks = packsToOrder.OrderByDescending(p => p.Data.PackType)
.ThenBy(p => p.Data.Order)
.ThenBy(p => p.RemainingTime)
.ThenBy(p => p.Data.Price)
.ToArray();
GetOrderedPacksList(packsToOrder, out var orderedPacks);

if (orderedPacks[0] == pack)
{
var previousFeaturedPack = _featuredPackSlot.Pack;
RemovePackDisplayer(previousFeaturedPack);

var newFeaturedPack = _packsFactory.CreateFeaturedOfferPack(pack);
_packDisplayers.Add(newFeaturedPack);
_featuredPackSlot = newFeaturedPack;

var newPack = _packsFactory.CreatePackDisplayer(previousFeaturedPack);
_packDisplayers.Add(newPack);

SwapFeaturedPack(pack);
RefrehStoreGUI();
return;
}
Expand All @@ -103,17 +84,15 @@ private void OnPackRemoved(Pack pack)

private void RefrehStoreGUI()
{
OrderPacksList();
OrderPackDisplayersList();

Pack packToRemove = null;

for (int i = 0; i < _packDisplayers.Count; ++i)
{
if (_featuredPackSlot == null && _packDisplayers[i].Pack.Data.Featured)
{
var featuredOfferPack = _packsFactory.CreateFeaturedOfferPack(_packDisplayers[i].Pack);
_featuredPackSlot = featuredOfferPack;
_packDisplayers.Add(featuredOfferPack);
CreateNewFeaturedPack(_packDisplayers[i].Pack);
packToRemove = _packDisplayers[i].Pack;
}
else if (_featuredPackSlot != _packDisplayers[i])
Expand All @@ -130,7 +109,7 @@ private void RefrehStoreGUI()
_packsFactory.ResetSiblingIndexes();
}

private void OrderPacksList()
private void OrderPackDisplayersList()
{
_packDisplayers = _packDisplayers.OrderByDescending(d => d.Pack.Data.PackType)
.ThenBy(d => d.Pack.Data.Order)
Expand All @@ -139,6 +118,15 @@ private void OrderPacksList()
.ToList();
}

private void GetOrderedPacksList(in List<Pack> unorderedList, out List<Pack> orderedList)
{
orderedList = unorderedList.OrderByDescending(p => p.Data.PackType)
.ThenBy(p => p.Data.Order)
.ThenBy(p => p.RemainingTime)
.ThenBy(p => p.Data.Price)
.ToList();
}

private void RemovePackDisplayer(Pack pack)
{
PackDisplayer packDisplayerToRemove = null;
Expand All @@ -158,5 +146,23 @@ private void RemovePackDisplayer(Pack pack)
Destroy(packDisplayerToRemove.gameObject);
}
}

private void SwapFeaturedPack(Pack pack)
{
var previousFeaturedPack = _featuredPackSlot.Pack;
RemovePackDisplayer(previousFeaturedPack);

CreateNewFeaturedPack(pack);

var newPack = _packsFactory.CreatePackDisplayer(previousFeaturedPack);
_packDisplayers.Add(newPack);
}

private void CreateNewFeaturedPack(Pack pack)
{
var newFeaturedPack = _packsFactory.CreateFeaturedOfferPack(pack);
_packDisplayers.Add(newFeaturedPack);
_featuredPackSlot = newFeaturedPack;
}
}
}

0 comments on commit 96ae06d

Please sign in to comment.