Sort buildings and upgrades by PP (#253)

This commit is contained in:
Fabian
2020-11-23 16:41:46 +01:00
committed by GitHub
parent cd52377639
commit bcef69a344
4 changed files with 104 additions and 4 deletions

View File

@@ -589,7 +589,8 @@ CM.ConfigData.TimeFormat = {label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX
CM.ConfigData.SayTime = {label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}};
CM.ConfigData.GrimoireBar = {label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true};
CM.ConfigData.Scale = {label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}};
CM.ConfigData.SortBuildings = {label: ['Sort Buildings: Default', 'Sort Buildings: PP'], desc: 'Sort the display of buildings in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateBuildings();}};
CM.ConfigData.SortUpgrades = {label: ['Sort Upgrades: Default', 'Sort Upgrades: PP'], desc: 'Sort the display of upgrades in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateUpgrades();}};
/********
* Data *
********/
@@ -831,6 +832,14 @@ CM.Disp.CreateCssArea = function() {
CM.Disp.Css.type = 'text/css';
document.head.appendChild(CM.Disp.Css);
// given the architecture of your code, you probably want these lines somewhere else,
// but I stuck them here for convenience
l("products").style.display = "grid";
l("storeBulk").style.gridRow = "1/1";
l("upgrades").style.display = "flex";
l("upgrades").style["flex-wrap"] = "wrap";
}
CM.Disp.CreateBotBar = function() {
@@ -1218,6 +1227,24 @@ CM.Disp.UpdateBuildings = function() {
l('productPrice' + Game.Objects[i].id).style.color = '';
}
}
// Build array of pointers, sort by pp, use array index (+2) as the grid row number
// (grid rows are 1-based indexing, and row 1 is the bulk buy/sell options)
var arr = Object.keys(CM.Cache.Objects).map(k =>
{
var o = CM.Cache.Objects[k];
o.name = k;
o.id = Game.Objects[k].id;
return o;
});
if (CM.Config.SortBuildings)
arr.sort((a, b) => a.pp - b.pp);
else
arr.sort((a, b) => a.id - b.id);
for (var x = 0; x < arr.length; x++)
Game.Objects[arr[x].name].l.style.gridRow = (x + 2) + "/" + (x + 2);
}
CM.Disp.CreateUpgradeBar = function() {
@@ -1345,6 +1372,25 @@ CM.Disp.UpdateUpgrades = function() {
l('CMUpgradeBarPurple').textContent = purple;
l('CMUpgradeBarGray').textContent = gray;
}
// Build array of pointers, sort by pp, set flex positions
var arr = [];
for (var x = 0; x < Game.UpgradesInStore.length; x++){
var o = {};
o.name = Game.UpgradesInStore[x].name;
o.price = Game.UpgradesInStore[x].basePrice;
o.pp = CM.Cache.Upgrades[o.name].pp;
arr.push(o);
}
if (CM.Config.SortUpgrades)
arr.sort((a, b) => a.pp - b.pp);
else
arr.sort((a, b) => a.price - b.price);
for (var x = 0; x < Game.UpgradesInStore.length; x++){
l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1
}
}
CM.Disp.UpdateColors = function() {
@@ -1733,6 +1779,8 @@ CM.Disp.AddMenuPref = function(title) {
frag.appendChild(listing('BotBar'));
frag.appendChild(listing('TimerBar'));
frag.appendChild(listing('TimerBarPos'));
frag.appendChild(listing('SortBuildings'));
frag.appendChild(listing('SortUpgrades'));
frag.appendChild(listing('BuildColor'));
frag.appendChild(listing('BulkBuildColor'));
frag.appendChild(listing('UpBarColor'));
@@ -3027,7 +3075,9 @@ CM.ConfigDefault = {
GrimoireBar: 1,
Scale: 2,
StatsPref: {Lucky: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1},
Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}
Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'},
SortBuildings: 0,
SortUpgrades: 0
};
CM.ConfigPrefix = 'CMConfig';