diff --git a/js/002-config/fc-js-init.js b/js/002-config/fc-js-init.js index e955b52bd8f0cac8d2a4f8ef3d1d3d6bb76dbbda..7f6482afd104d9f214bd39cf9002e64c8796d2f4 100644 --- a/js/002-config/fc-js-init.js +++ b/js/002-config/fc-js-init.js @@ -6,7 +6,6 @@ var App = { }; App.Arcology = { Cell: {}, - Row: {} }; App.Art = {}; App.Data = {}; diff --git a/src/arcologyBuilding/cell.js b/src/004-base/arcologyBuilding.js similarity index 50% rename from src/arcologyBuilding/cell.js rename to src/004-base/arcologyBuilding.js index 6ca9fc6bf9b2127623e35e06a0cd9de0b13dacba..e375e4efc337c1634693ceb0b38acf8553d216ea 100644 --- a/src/arcologyBuilding/cell.js +++ b/src/004-base/arcologyBuilding.js @@ -1,5 +1,4 @@ App.Arcology.Cell.BaseCell = class { - /** * @param {number} owner * @param {number} width @@ -115,7 +114,6 @@ App.Arcology.Cell.BaseCell = class { } return fragment; } - } /** @@ -134,139 +132,3 @@ App.Arcology.Cell.BaseCell = class { return []; } }; - -App.Arcology.Cell.Apartment = class Apartment extends App.Arcology.Cell.BaseCell { - /** - * @param owner - * @param type 1: luxury, 2: normal, 3: dense - */ - constructor(owner, type = 1) { - super(owner, 1); - this.type = type; - } - - /** - * @returns {string} - */ - getColorClass() { - switch (this.type) { - case 1: - return "luxuryApartments"; - case 2: - return "apartments"; - case 3: - return "denseApartments"; - } - return super.getColorClass(); - } - - /** - * @param {Array<number>} path - * @returns {Node} - */ - cellContent(path) { - let message = ""; - switch (this.type) { - case 1: - message = "Luxury Apartments"; - break; - case 2: - message = "Apartments"; - break; - case 3: - message = "Dense Apartments"; - break; - } - return App.Arcology.getCellLink(path, message); - } - - /** - * @return {string} - * @private - */ - _getSetting() { - let r = ""; - - switch (this.type) { - case 1: - r = "improved for occupancy by the Free Cities' wealthiest citizens"; - break; - case 2: - r = "occupied by citizens of varying wealth and social standing"; - break; - case 3: - r = "upgraded for dense occupancy by as many citizens as possible"; - break; - } - - if (this.owner === 1) { - r = `This is a sector of the arcology's living areas, ${r}. You control this part of the arcology and all these tenants pay you rent.`; - } else { - r = `This is a privately-owned sector of the arcology's living areas, ${r}.`; - } - - return r; - } - - /** - * @return {Array<{name: string, action: function, cost: number, note?: string}>} - * @private - */ - _getUpgrades() { - const upgrades = []; - - if (this.type !== 3) { - upgrades.push({ - name: "Upgrade this sector of apartments for dense occupancy by as many citizens as possible.", - action: () => { this.type = 3; }, - cost: Math.trunc(10000 * V.upgradeMultiplierArcology), - }); - } - if (this.type !== 1) { - upgrades.push({ - name: "Improve this sector of apartments for occupancy by the Free Cities' wealthiest citizens.", - action: () => { this.type = 1; }, - cost: Math.trunc(10000 * V.upgradeMultiplierArcology), - }); - } - if (this.type !== 2) { - upgrades.push({ - name: "Return this sector to standard, mixed housing.", - action: () => { this.type = 2; }, - cost: Math.trunc(10000 * V.upgradeMultiplierArcology), - }); - } - - return upgrades; - } -}; - -/* add functions to allow for saving/restoring to every cell */ -for (let cellKey in App.Arcology.Cell) { - App.Arcology.Cell[cellKey].prototype._init = function(obj) { - // Clone the given object's own properties into our own properties. - Object.keys(obj).forEach(function(pn) { - this[pn] = clone(obj[pn]); - }, this); - - // Return `this` to make usage easier. - return this; - }; - App.Arcology.Cell[cellKey].prototype.clone = function() { - // Return a new instance containing our own data. - return (new this.constructor)._init(this); - }; - App.Arcology.Cell[cellKey].prototype.toJSON = function() { - // Return a code string that will create a new instance containing our - // own data. - // - // NOTE: Supplying `this` directly as the `reviveData` parameter to the - // `JSON.reviveWrapper()` call will trigger out of control recursion in - // the serializer, so we must pass it a clone of our own data instead. - const ownData = {}; - Object.keys(this).forEach(function(pn) { - ownData[pn] = clone(this[pn]); - }, this); - return JSON.reviveWrapper(`(new ${this.constructor}())._init($ReviveData$)`, ownData); - }; -} diff --git a/src/arcologyBuilding/apartments.js b/src/arcologyBuilding/apartments.js new file mode 100644 index 0000000000000000000000000000000000000000..b31f185584712fbead6fd1c57ce6a24d4072af2f --- /dev/null +++ b/src/arcologyBuilding/apartments.js @@ -0,0 +1,105 @@ +App.Arcology.Cell.Apartment = class Apartment extends App.Arcology.Cell.BaseCell { + /** + * @param owner + * @param type 1: luxury, 2: normal, 3: dense + */ + constructor(owner, type = 1) { + super(owner, 1); + this.type = type; + } + + /** + * @returns {string} + */ + getColorClass() { + switch (this.type) { + case 1: + return "luxuryApartments"; + case 2: + return "apartments"; + case 3: + return "denseApartments"; + } + return super.getColorClass(); + } + + /** + * @param {Array<number>} path + * @returns {Node} + */ + cellContent(path) { + let message = ""; + switch (this.type) { + case 1: + message = "Luxury Apartments"; + break; + case 2: + message = "Apartments"; + break; + case 3: + message = "Dense Apartments"; + break; + } + return App.Arcology.getCellLink(path, message); + } + + /** + * @return {string} + * @private + */ + _getSetting() { + let r = ""; + + switch (this.type) { + case 1: + r = "improved for occupancy by the Free Cities' wealthiest citizens"; + break; + case 2: + r = "occupied by citizens of varying wealth and social standing"; + break; + case 3: + r = "upgraded for dense occupancy by as many citizens as possible"; + break; + } + + if (this.owner === 1) { + r = `This is a sector of the arcology's living areas, ${r}. You control this part of the arcology and all these tenants pay you rent.`; + } else { + r = `This is a privately-owned sector of the arcology's living areas, ${r}.`; + } + + return r; + } + + /** + * @return {Array<{name: string, action: function, cost: number, note?: string}>} + * @private + */ + _getUpgrades() { + const upgrades = []; + + if (this.type !== 3) { + upgrades.push({ + name: "Upgrade this sector of apartments for dense occupancy by as many citizens as possible.", + action: () => { this.type = 3; }, + cost: Math.trunc(10000 * V.upgradeMultiplierArcology), + }); + } + if (this.type !== 1) { + upgrades.push({ + name: "Improve this sector of apartments for occupancy by the Free Cities' wealthiest citizens.", + action: () => { this.type = 1; }, + cost: Math.trunc(10000 * V.upgradeMultiplierArcology), + }); + } + if (this.type !== 2) { + upgrades.push({ + name: "Return this sector to standard, mixed housing.", + action: () => { this.type = 2; }, + cost: Math.trunc(10000 * V.upgradeMultiplierArcology), + }); + } + + return upgrades; + } +}; diff --git a/src/zz1-last/initArcologyBuilding.js b/src/zz1-last/initArcologyBuilding.js new file mode 100644 index 0000000000000000000000000000000000000000..3282d884ebf5d95ff337ba790d87a780b9cbd9f1 --- /dev/null +++ b/src/zz1-last/initArcologyBuilding.js @@ -0,0 +1,29 @@ +/* add functions to allow for saving/restoring to every cell */ +for (let cellKey in App.Arcology.Cell) { + App.Arcology.Cell[cellKey].prototype._init = function(obj) { + // Clone the given object's own properties into our own properties. + Object.keys(obj).forEach(function(pn) { + this[pn] = clone(obj[pn]); + }, this); + + // Return `this` to make usage easier. + return this; + }; + App.Arcology.Cell[cellKey].prototype.clone = function() { + // Return a new instance containing our own data. + return (new this.constructor)._init(this); + }; + App.Arcology.Cell[cellKey].prototype.toJSON = function() { + // Return a code string that will create a new instance containing our + // own data. + // + // NOTE: Supplying `this` directly as the `reviveData` parameter to the + // `JSON.reviveWrapper()` call will trigger out of control recursion in + // the serializer, so we must pass it a clone of our own data instead. + const ownData = {}; + Object.keys(this).forEach(function(pn) { + ownData[pn] = clone(this[pn]); + }, this); + return JSON.reviveWrapper(`(new ${this.constructor}())._init($ReviveData$)`, ownData); + }; +}