Compatibility with content mods (#350)
This commit is contained in:
committed by
GitHub
parent
3d965943c0
commit
66ac922ae2
61
src/Disp.js
61
src/Disp.js
@@ -256,6 +256,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';
|
||||
@@ -272,15 +302,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');
|
||||
@@ -290,36 +319,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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user