diff --git a/src/001-lib/04-ScopeMacro/ScopeMacro.js b/src/001-lib/04-ScopeMacro/ScopeMacro.js deleted file mode 100644 index e350fbdcde4389f09dda44035ff3eecca43d3978..0000000000000000000000000000000000000000 --- a/src/001-lib/04-ScopeMacro/ScopeMacro.js +++ /dev/null @@ -1,57 +0,0 @@ -Macro.add('scope', { - skipArgs : true, - tags : null, - handler() { - const oldTemporary = State.temporary; - const restoreOldTemporary = function() { - let keys = Object.keys(oldTemporary); - for(let i=0; i<keys.length; ++i) { - let key = keys[i]; - let obj = oldTemporary[key]; - State.temporary[key] = obj; - } - }; - let keepOverwrites = false; - try { - State.clearTemporary(); - if(/^\s*as\s+child\s*$/.test(this.args.raw)) { - restoreOldTemporary(); - keepOverwrites = true; - } else { - const varRe = new RegExp(`(${Patterns.variable})`, 'g'); - let match; - /* - Cache the existing values of the variables and add a shadow. - */ - while ((match = varRe.exec(this.args.raw)) !== null) { - const varName = match[1]; - const varKey = varName.slice(1); - if(varName[0] === '$') { - return this.error("Global variable '" + varName + "'cannot be scoped."); - } - - if (!oldTemporary.hasOwnProperty(varKey)) { - continue; - } - - State.temporary[varKey] = oldTemporary[varKey]; - } - } - new Wikifier(this.output, this.payload[0].contents.trim()); - } finally { - if(!keepOverwrites) { - State.clearTemporary(); - restoreOldTemporary(); - } else { - const overwrites = State.temporary; - State.clearTemporary(); - let keys = Object.keys(oldTemporary); - for(let i=0; i<keys.length; ++i) { - let key = keys[i]; - let obj = overwrites[key]; - State.temporary[key] = obj; - } - } - } - } -}); diff --git a/src/Corporation/corporate.js b/src/Corporation/corporate.js index 7fd01f6e73b8a352189b7e049b014a0aaf59a02b..204edfd1f1c9d4375ac465250d008aa7edfe6344 100644 --- a/src/Corporation/corporate.js +++ b/src/Corporation/corporate.js @@ -60,7 +60,6 @@ App.Corporate.Init = function() { constructor(corp, suffix="") { this.corp = corp; this.suffix = suffix; - this.clear(); } get operations( ) { return this.getStored('OpCost'); } set operations(value) { this.setStored('OpCost', value); } @@ -900,13 +899,6 @@ App.Corporate.Init = function() { c.economicBoost = 0; } }; - - if(V.corp.DivTrainSurgeryTimer !== undefined) { - let timer = V.corp.DivTrainSurgeryTimer; - // Note: originally the timer was capped at 20, so the founding week isn't guaranteed to be correct. - V.corp.DivSurgeryFounded = V.week - timer; - delete V.corp.DivTrainSurgeryTimer; - } }; diff --git a/src/Corporation/corporateLedger.js b/src/Corporation/corporateLedger.js new file mode 100644 index 0000000000000000000000000000000000000000..a01a12557afbb72e42f5568641040a4bd814c6c4 --- /dev/null +++ b/src/Corporation/corporateLedger.js @@ -0,0 +1,102 @@ +/** Create the DOM ledger table + * @param {object} ledger - One of the members of App.Corporate.ledger, such as .current or .old + * @param {number} week - Week number (usually V.week, for the current ledger, or V.week-1, for the old one) + * @returns {HTMLTableElement} + */ +App.Corporate.writeLedger = function(ledger, week) { + /** Add a row to the ledger + * @param {HTMLElement} table + * @param {string} cellType + * @param {string} caption + * @param {number} [value] + * @param {string|Node} [note] + */ + function createRow(table, cellType, caption, value, note) { + const row = App.UI.DOM.appendNewElement("tr", table); + /** @type {HTMLTableCellElement} */ + const leftCell = App.UI.DOM.appendNewElement(cellType, row, caption); + if (jsDef(value)) { + const rightCell = App.UI.DOM.appendNewElement(cellType, row, App.UI.DOM.makeElement("div", formatCash(value))); + if (note) { + App.UI.DOM.appendNewElement("div", rightCell, note, "minor-note"); + } + } else { + leftCell.colSpan = 2; + } + } + + /** Format cash with color, DOM style (probably should be a shared function) + * @param {number} cash + * @returns {HTMLSpanElement} + */ + function formatCash(cash) { + let span = App.UI.DOM.makeElement('span', cashFormat(cash)); + if (cash === 0) { + span.classList.add("gray"); + } else { + span.classList.add("cash"); + if (cash < 0) { + span.classList.add("dec"); + } else if (cash > 0) { + span.classList.add("inc"); + } + } + return span; + } + + /** Build the cheat textbox for liquidity + * @param {number} cash - initial value + * @returns {HTMLInputElement} + */ + function makeCheatTextbox(cash) { + return App.UI.DOM.makeTextBox(cash, (v) => { + App.Corporate.cheatCash(v); + updateLedgerTable(); + }, true); + } + + function buildLedgerTable() { + const table = document.createElement('table'); + table.className = "corporate"; + table.id = "corporate-ledger"; + + const thead = App.UI.DOM.appendNewElement('thead', table); + createRow(thead, "th", `Ledger for ${asDateString(week)} - ${asDateString(week + 1)}`); + const tbody = App.UI.DOM.appendNewElement('tbody', table); + createRow(tbody, "td", "Revenue", ledger.revenue); + if (V.cheatMode && ledger.foreignRevenue > 0) { + createRow(tbody, "td", "Including Neighbor Bonus", ledger.foreignRevenue); + } + createRow(tbody, "td", "Operating Expenses", forceNeg(ledger.operations)); + createRow(tbody, "td", "Slave Expenses", forceNeg(ledger.slaves)); + createRow(tbody, "td", "Asset Expenses", forceNeg(ledger.development)); + if (V.cheatMode) { + createRow(tbody, "td", `Economic ${ledger.economicBoost < 0 ? "Expenses" : "Windfall"}`, ledger.economicBoost); + } + createRow(tbody, "td", "Overhead", forceNeg(ledger.overhead)); + let econNote = ''; + if (ledger.economy > 100) { + econNote = "* Profits benefited from a strong economy."; + } else if (ledger.economy > 60) { + econNote = "* Profits were lowered by the weak economy."; + } else { + econNote = "* Profits were severely depressed by the failing economy."; + } + createRow(tbody, "td", "Profit", ledger.profit, econNote); + + createRow(tbody, "th", "Totals"); + createRow(tbody, "td", "Liquidity", App.Corporate.cash, V.cheatMode ? makeCheatTextbox(App.Corporate.cash) : undefined); + createRow(tbody, "td", "Corporate Value", App.Corporate.value); + createRow(tbody, "td", "Dividend for Payout", App.Corporate.dividend, `Pays out on ${asDateString(V.week + App.Corporate.dividendTimer, -1)}, + ${App.Corporate.dividendTimer === 1 ? `the end of this week` : `in ${App.Corporate.dividendTimer} weeks`} + `); + + return table; + } + + function updateLedgerTable() { + $('#corporate-ledger').replaceWith(buildLedgerTable()); + } + + return buildLedgerTable(); +}; diff --git a/src/Corporation/corporateWidgets.tw b/src/Corporation/corporateWidgets.tw deleted file mode 100644 index 14e57d4a7545356cce98f6d8efc0e23e4b3eb1ea..0000000000000000000000000000000000000000 --- a/src/Corporation/corporateWidgets.tw +++ /dev/null @@ -1,87 +0,0 @@ -:: corporate widgets [widget nobr] - -/* -Usage: -<<CorporateLedger _ledger $week>> - - _ledger: One of the members of App.Corporate.ledger, such as .current or .old - $week: The current week or the previous week, depending on whether you used current or old. -*/ -<<widget "CorporateLedger">> -<<scope>> -<<set _ledger = $args[0]>> -<<set _week = $args[1]>> -<table class="corporate"> -<thead> -<tr><th colspan="2">Ledger for <<= asDateString(_week) >> - <<= asDateString(_week + 1, -1) >></th></tr> -</thead> -<tbody> -/*Returns last week's revenue, gets calculated in corporationDevelopments, but slaves sold here also added to it for next week*/ -<tr><td>Revenue</td><td><<= cashFormatColor(_ledger.revenue)>></td></tr> -<<if ($cheatMode) && ($cheatModeM) && App.Corporate.foreignRevenue > 0>> - <tr><td>Including Neighbor Bonus</td><td><<= cashFormatColor(_ledger.foreignRevenue)>></td></tr> -<</if>> -/*Just like revenue, except for operating expenses (all calculated in corporationDevelopments)*/ -<tr><td>Operating Expenses</td><td><<= cashFormatColor(_ledger.operations, true)>></td></tr> -/*buying slaves to work on adds to this expense, works just like revenue*/ -<tr><td>Slave Expenses</td><td><<= cashFormatColor(_ledger.slaves, true)>></td></tr> -/*costs associated with expanding divisions end up here, reports costs from last week, not current*/ -<tr><td>Asset Expenses</td><td><<= cashFormatColor(_ledger.development, true)>></td></tr> -<<if ($cheatMode) && ($cheatModeM)>> - <tr> - <td>Economic <<if _ledger.economicBoost < 0>>Expenses<<else>>Windfall<</if>></td> - <td><<= cashFormatColor(_ledger.economicBoost)>></td> - </tr> -<</if>> -<tr><td>Overhead</td><td><<= cashFormatColor(_ledger.overhead, true)>></td></tr> -<tr><td>Profit</td><td> -<div><<= cashFormatColor(_ledger.profit)>></div> -<<if _ledger.economicBoost > 0>> -<div class="minor-note"> - <<if _ledger.economy > 100>> - * Profits benefited from a strong economy. - <<elseif _ledger.economy > 60>> - * Profits were lowered by the weak economy. - <<else>> - * Profits were severely depressed by the failing economy. - <</if>> -</div> -<</if>> -</td></tr> -</tbody> -<thead> -<tr><th colspan="2">Totals</th></tr> -</thead> -<tbody> -<tr> - <td>Liquidity</td> - <td> - <<if ($cheatMode) && ($cheatModeM)>> - <span id="corp-cash"><<= cashFormatColor(App.Corporate.cash)>></span> - <<set _tCorpCash = App.Corporate.cash>> - <<textbox "_tCorpCash" _tCorpCash>> - <<link "Apply">> - <<set App.Corporate.cheatCash(_tCorpCash)>> - <<replace "#corp-cash">><<= cashFormatColor(App.Corporate.cash)>><</replace>> - <</link>> - <<else>> - <<= cashFormatColor(App.Corporate.cash)>> - <</if>> - </td> -</tr> -<tr><td>Corporate Value</td><td><<= cashFormatColor(App.Corporate.value)>></td></tr> -<tr> -<td>Dividend for Payout</td> -<td> -<div><<= cashFormatColor(App.Corporate.dividend)>></div> -<div class="minor-note">Pays out on <<=asDateString($args[1] + App.Corporate.dividendTimer, -1)>>, <<if App.Corporate.dividendTimer == 1>> - the end of this week -<<else>> - in <<= App.Corporate.dividendTimer >> weeks -<</if>> -</div> -</td></tr> -</tbody> -</table> -<</scope>> -<</widget>> diff --git a/src/Corporation/corporationDevelopments.tw b/src/Corporation/corporationDevelopments.tw index b6554c11444d7834101c6409c1ac529473b1d414..a664bf48726b515a19e1c114be50c8b0f7e3d254 100644 --- a/src/Corporation/corporationDevelopments.tw +++ b/src/Corporation/corporationDevelopments.tw @@ -10,7 +10,6 @@ <h2>Operational Results</h2> /*Divisions doing their thing*/ <<set _weekLedger = App.Corporate.endWeek()>> -/* TODO: I would like to move some of the following loop into a new loop. It should go Process -> Transfer -> Sell -> Buy (most expensive to least) to give the best chance of auto-buy having enough money to make purchases. */ <<for _d range _weekLedger.divisionLedgers>> <<set _div = _d.division>> /* Reporting on number of slaves being processed or completed processing */ @@ -53,8 +52,7 @@ <</for>> /*Aggregate Corporation Results*/ -<<set _ledger = App.Corporate.ledger.current>>/*Note: You can't just pass the object directly into a widget. */ -<<CorporateLedger _ledger $week>> +<<includeDOM App.Corporate.writeLedger(App.Corporate.ledger.current, $week)>> /*Division Expansion Tokens*/ <<if _weekLedger.canExpandNow>> diff --git a/src/Corporation/manageCorporation.tw b/src/Corporation/manageCorporation.tw index 3ac259e971c36fcd0530ab2d7ca04967bb2da7d2..454175169ada074b595ffcf15c28e6da08488943 100644 --- a/src/Corporation/manageCorporation.tw +++ b/src/Corporation/manageCorporation.tw @@ -61,9 +61,7 @@ <<if App.Corporate.foundedDate>> <div class="founding">Founded on <<= asDateString(App.Corporate.foundedDate)>></div> <</if>> -<<set _ledger = App.Corporate.ledger.old>>/*You can't pass the object directly into the widget. */ -<<set _lastWeek = $week - 1>> -<<CorporateLedger _ledger _lastWeek>> +<<includeDOM App.Corporate.writeLedger(App.Corporate.ledger.old, $week-1)>> <h1>Division Management</h1> <<for _div range App.Corporate.divisionList.filter(x => x.founded)>> diff --git a/src/gui/css/mainStyleSheet.css b/src/gui/css/mainStyleSheet.css index 8c5fe85aa2dc48c0163f7f298a378f68423e2663..37d1b869d0b7d0a87ddcaf78e6982284e498065c 100644 --- a/src/gui/css/mainStyleSheet.css +++ b/src/gui/css/mainStyleSheet.css @@ -255,6 +255,10 @@ table.corporate tbody tr:nth-child(odd) { table.corporate td { vertical-align: top; } +table.corporate tbody th, table.corporate thead th { + background-color: black; + font-weight: bold; +} .minor-note { font-size: 0.75em; font-style: italic;