Complete overhaul of code structure and relevant files (#639)
This commit is contained in:
11
src/Sim/InitializeData/InitAchievement.js
Normal file
11
src/Sim/InitializeData/InitAchievement.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* This function constructs an object with the static properties of an achievement
|
||||
* @param {string} achievementName Name of the Achievement
|
||||
* @returns {Object} you The static object
|
||||
*/
|
||||
export default function InitAchievement(achievementName) {
|
||||
const me = Game.Achievements[achievementName];
|
||||
const you = {};
|
||||
you.name = me.name;
|
||||
return you;
|
||||
}
|
||||
31
src/Sim/InitializeData/InitData.js
Normal file
31
src/Sim/InitializeData/InitData.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/** Functions used to create static objects of Buildings, Upgrades and Achievements */
|
||||
|
||||
import CopyData from '../SimulationData/CopyData';
|
||||
import { SimAchievements, SimObjects, SimUpgrades } from '../VariablesAndData';
|
||||
import InitAchievement from './InitAchievement';
|
||||
import InitialBuildingData from './InitialBuildingData';
|
||||
import InitUpgrade from './InitUpgrade';
|
||||
|
||||
/**
|
||||
* This function creates static objects for Buildings, Upgrades and Achievements
|
||||
*/
|
||||
export default function InitData() {
|
||||
// Buildings
|
||||
SimObjects = [];
|
||||
for (const i of Object.keys(Game.Objects)) {
|
||||
SimObjects[i] = InitialBuildingData(i);
|
||||
}
|
||||
|
||||
// Upgrades
|
||||
SimUpgrades = [];
|
||||
for (const i of Object.keys(Game.Upgrades)) {
|
||||
SimUpgrades[i] = InitUpgrade(i);
|
||||
}
|
||||
|
||||
// Achievements
|
||||
SimAchievements = [];
|
||||
for (const i of Object.keys(Game.Achievements)) {
|
||||
SimAchievements[i] = InitAchievement(i);
|
||||
}
|
||||
CopyData();
|
||||
}
|
||||
30
src/Sim/InitializeData/InitUpgrade.js
Normal file
30
src/Sim/InitializeData/InitUpgrade.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import SimHas from '../ReplacedGameFunctions/SimHas';
|
||||
import SimHasGod from '../ReplacedGameFunctions/SimHasGod';
|
||||
|
||||
/**
|
||||
* This function constructs an object with the static properties of an upgrade
|
||||
* @param {string} upgradeName Name of the Upgrade
|
||||
* @returns {Object} you The static object
|
||||
*/
|
||||
export default function InitUpgrade(upgradeName) {
|
||||
const me = Game.Upgrades[upgradeName];
|
||||
const you = {};
|
||||
// Some upgrades have a function for .power (notably the valentine cookies)
|
||||
you.power = me.power;
|
||||
if (typeof (me.power) === 'function') {
|
||||
me.power = function () {
|
||||
let pow = 2;
|
||||
if (SimHas('Starlove')) pow = 3;
|
||||
if (Game.hasGod) {
|
||||
const godLvl = SimHasGod('seasons');
|
||||
if (godLvl === 1) pow *= 1.3;
|
||||
else if (godLvl === 2) pow *= 1.2;
|
||||
else if (godLvl === 3) pow *= 1.1;
|
||||
}
|
||||
return pow;
|
||||
};
|
||||
}
|
||||
you.pool = me.pool;
|
||||
you.name = me.name;
|
||||
return you;
|
||||
}
|
||||
33
src/Sim/InitializeData/InitialBuildingData.js
Normal file
33
src/Sim/InitializeData/InitialBuildingData.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import SimGetTieredCpsMult from '../ReplacedGameFunctions/SimGetTieredCpsMult';
|
||||
|
||||
/**
|
||||
* This function constructs an object with the static properties of a building,
|
||||
* but with a 'cps' method changed to check sim data
|
||||
*
|
||||
* @param {string} buildingName Name of the building
|
||||
* @returns {Object} you The static object
|
||||
*/
|
||||
export default function InitialBuildingData(buildingName) {
|
||||
const me = Game.Objects[buildingName];
|
||||
const you = {};
|
||||
you.cps = function (it) {
|
||||
let mult = 1;
|
||||
mult *= SimGetTieredCpsMult(it);
|
||||
mult *= Game.magicCpS(it.name);
|
||||
if (typeof it.baseCps === 'function') {
|
||||
return it.baseCps(it) * mult;
|
||||
}
|
||||
return it.baseCPS * mult;
|
||||
};
|
||||
// Below is needed for above eval, specifically for the GetTieredCpsMult function
|
||||
you.baseCps = me.baseCps;
|
||||
you.name = me.name;
|
||||
you.tieredUpgrades = me.tieredUpgrades;
|
||||
you.synergies = me.synergies;
|
||||
you.fortune = me.fortune;
|
||||
you.grandma = me.grandma;
|
||||
you.baseCPS = me.baseCps;
|
||||
you.id = me.id;
|
||||
you.vanilla = me.vanilla;
|
||||
return you;
|
||||
}
|
||||
Reference in New Issue
Block a user