From e4f72fad0c1fbefed54475028fbc91919ec3bbdf Mon Sep 17 00:00:00 2001
From: Arkerthan <arkerthan@gmail.com>
Date: Sat, 15 Feb 2020 21:57:32 +0100
Subject: [PATCH] split cell.js for easier maintance

---
 js/002-config/fc-js-init.js                   |   1 -
 .../cell.js => 004-base/arcologyBuilding.js}  | 138 ------------------
 src/arcologyBuilding/apartments.js            | 105 +++++++++++++
 src/zz1-last/initArcologyBuilding.js          |  29 ++++
 4 files changed, 134 insertions(+), 139 deletions(-)
 rename src/{arcologyBuilding/cell.js => 004-base/arcologyBuilding.js} (50%)
 create mode 100644 src/arcologyBuilding/apartments.js
 create mode 100644 src/zz1-last/initArcologyBuilding.js

diff --git a/js/002-config/fc-js-init.js b/js/002-config/fc-js-init.js
index e955b52bd8f..7f6482afd10 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 6ca9fc6bf9b..e375e4efc33 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 00000000000..b31f1855847
--- /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 00000000000..3282d884ebf
--- /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);
+	};
+}
-- 
GitLab