Compatibility with content mods (#350)

This commit is contained in:
staticvariablejames
2020-11-26 11:01:06 -06:00
committed by GitHub
parent 3d965943c0
commit 66ac922ae2
4 changed files with 82 additions and 48 deletions

View File

@@ -1016,6 +1016,36 @@ CM.Disp.CreateCssArea = function() {
l("upgrades").style["flex-wrap"] = "wrap";
}
/**
* Extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building.
*
* This function is called by CM.Disp.CreateBotBar on initialization of Cookie Monster,
* and also in CM.Sim.CopyData if a new building (added by another mod) is discovered.
*/
CM.Disp.CreateBotBarBuildingColumn = function(buildingName) {
if(!CM.Disp.BotBar) {
CM.Disp.CreateBotBar();
return; // CreateBotBar will call this function again
}
var type = CM.Disp.BotBar.firstChild.firstChild.childNodes[0];
var bonus = CM.Disp.BotBar.firstChild.firstChild.childNodes[1];
var pp = CM.Disp.BotBar.firstChild.firstChild.childNodes[2];
var time = CM.Disp.BotBar.firstChild.firstChild.childNodes[3];
var i = buildingName;
var header = type.appendChild(document.createElement('td'));
header.appendChild(document.createTextNode((i.indexOf(' ') != -1 ? i.substring(0, i.indexOf(' ')) : i) + ' ('));
var span = header.appendChild(document.createElement('span'));
span.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
header.appendChild(document.createTextNode(')'));
bonus.appendChild(document.createElement('td'));
pp.appendChild(document.createElement('td'));
time.appendChild(document.createElement('td'));
}
CM.Disp.CreateBotBar = function() {
CM.Disp.BotBar = document.createElement('div');
CM.Disp.BotBar.id = 'CMBotBar';
@@ -1032,15 +1062,14 @@ CM.Disp.CreateBotBar = function() {
CM.Disp.BotBar.style.overflow = 'auto';
CM.Disp.BotBar.style.textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black';
var table = document.createElement('table');
var table = CM.Disp.BotBar.appendChild(document.createElement('table'));
table.style.width = '100%';
table.style.textAlign = 'center';
table.style.whiteSpace = 'nowrap';
// TODO figure a better way
//table.style.tableLayout = 'fixed';
//table.style.overflow = 'hidden';
var tbody = document.createElement('tbody');
table.appendChild(tbody);
var tbody = table.appendChild(document.createElement('tbody'));
var firstCol = function(text, color) {
var td = document.createElement('td');
@@ -1050,36 +1079,20 @@ CM.Disp.CreateBotBar = function() {
return td;
}
var type = document.createElement('tr');
var type = tbody.appendChild(document.createElement('tr'));
type.style.fontWeight = 'bold';
type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow));
tbody.appendChild(type);
var bonus = document.createElement('tr');
var bonus = tbody.appendChild(document.createElement('tr'));
bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue));
tbody.appendChild(bonus);
var pp = document.createElement('tr');
var pp = tbody.appendChild(document.createElement('tr'));
pp.appendChild(firstCol('Payback Period', CM.Disp.colorBlue));
tbody.appendChild(pp);
var time = document.createElement('tr');
var time = tbody.appendChild(document.createElement('tr'));
time.appendChild(firstCol('Time Left', CM.Disp.colorBlue));
tbody.appendChild(time);
for (var i in Game.Objects) {
var header = document.createElement('td');
header.appendChild(document.createTextNode((i.indexOf(' ') != -1 ? i.substring(0, i.indexOf(' ')) : i) + ' ('));
var span = document.createElement('span');
span.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
header.appendChild(span);
header.appendChild(document.createTextNode(')'));
type.appendChild(header);
bonus.appendChild(document.createElement('td'));
pp.appendChild(document.createElement('td'));
time.appendChild(document.createElement('td'));
CM.Disp.CreateBotBarBuildingColumn(i);
}
CM.Disp.BotBar.appendChild(table);
l('wrapper').appendChild(CM.Disp.BotBar);
}
@@ -3677,6 +3690,8 @@ CM.Sim.CopyData = function() {
var you = CM.Sim.Objects[i];
if (you == undefined) {
CM.Sim.InitData();
you = CM.Sim.Objects[i]; // Not undefined anymore
CM.Disp.CreateBotBarBuildingColumn(i); // New building! Add it to the bottom bar
}
you.amount = me.amount;
you.level = me.level;
@@ -3688,6 +3703,7 @@ CM.Sim.CopyData = function() {
var you = CM.Sim.Upgrades[i];
if (you == undefined) {
CM.Sim.InitData();
you = CM.Sim.Upgrades[i];
}
you.bought = me.bought;
}
@@ -3698,6 +3714,7 @@ CM.Sim.CopyData = function() {
var you = CM.Sim.Achievements[i];
if (you == undefined) {
CM.Sim.InitData();
you = CM.Sim.Achievements[i];
}
you.won = me.won;
}