Merge pull request #769 from DanielNoord/tests

Tests
This commit is contained in:
Daniël van Noord
2021-04-12 21:30:32 +02:00
committed by GitHub
38 changed files with 8840 additions and 10855 deletions

View File

@@ -1,46 +0,0 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
globals: {
Game: 'writable',
l: 'readonly',
b64_to_utf8: 'readonly',
utf8_to_b64: 'readonly',
BeautifyAll: 'readonly',
PlaySound: 'readonly',
},
extends: ['airbnb-base', 'plugin:prettier/recommended'],
parserOptions: {
ecmaVersion: 12,
},
plugins: ['@typescript-eslint'],
overrides: [
{
files: ['src/**/*.{ts,tsx}'],
extends: ['plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
rules: {
'import/extensions': 'off', // To allow importing .ts without errors
'import/no-unresolved': 'off', // To allow importing .ts without errors
},
},
],
ignorePatterns: ['*CookieMonster*.js', 'dist/*', 'node_modules/*'],
rules: {
'import/no-mutable-exports': 'off', // We need to this throughout Cookie Monster
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'func-names': 'off', // To allow unnamed arrow functions
'prefer-destructuring': ['error', { object: true, array: false }], // Importing arrays and then destructuring them seems to fail
'max-len': [
1,
{
code: 100,
ignoreComments: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
},
};

70
.eslintrc.json Normal file
View File

@@ -0,0 +1,70 @@
{
"env": {
"browser": true,
"es2021": true
},
"globals": {
"Game": "writable",
"l": "readonly",
"b64_to_utf8": "readonly",
"utf8_to_b64": "readonly",
"BeautifyAll": "readonly",
"PlaySound": "readonly"
},
"extends": [
"airbnb-base",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 12
},
"plugins": [
"@typescript-eslint"
],
"overrides": [
{
"files": [
"src/**/*.{ts,tsx}"
],
"extends": [
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"rules": {
"import/extensions": "off", // To allow importing .ts without errors
"import/no-unresolved": "off" // To allow importing .ts without errors
}
}
],
"ignorePatterns": [
"*CookieMonster*.js",
"dist/*",
"node_modules/*"
],
"rules": {
"import/no-mutable-exports": "off", // We need to this throughout Cookie Monster
"no-plusplus": [
"error",
{
"allowForLoopAfterthoughts": true
}
],
"func-names": "off", // To allow unnamed arrow functions
"prefer-destructuring": [
"error",
{
"object": true,
"array": false
}
], // Importing arrays and then destructuring them seems to fail
"max-len": [
1,
{
"code": 100,
"ignoreComments": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true
}
]
}
}

View File

@@ -1,31 +1,29 @@
name: CI name: CI
on: pull_request on: pull_request
jobs: jobs:
Check_ESLint: Check_linting_test_and_build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - name: Check out repository code
uses: actions/checkout@v2
- name: Install dependencies
run: npm ci
- name: Run ESLint - name: Run ESLint
run: | run: npx eslint src
npm install - name: Run Mocha tests
npx eslint src run: npx mocha
Check_main_file:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check if CookieMonster.js is built correctly - name: Check if CookieMonster.js is built correctly
run: | run: |
npm install npx webpack -o ./tmp --env production
npx webpack -o ./test --env production if cmp <(head -n 2 dist/CookieMonster.js) <(head -n 2 tmp/CookieMonster.js); then
if cmp <(head -n 2 dist/CookieMonster.js) <(head -n 2 test/CookieMonster.js); then
echo '### SUCCESS: CookieMonster is correctly built! ###' echo '### SUCCESS: CookieMonster is correctly built! ###'
else else
echo '### WARNING: CookieMonster.js does not seem to be correct. Make sure to run "npm run build" after saving all your changes! ###' echo '### WARNING: CookieMonster.js does not seem to be correct. Make sure to run "npm run build" after saving all your changes! ###'
exit 1 exit 1
fi fi
if cmp <(head -n 2 CookieMonster.js) <(head -n 2 test/CookieMonster.js); then if cmp <(head -n 2 CookieMonster.js) <(head -n 2 tmp/CookieMonster.js); then
echo '### SUCCESS: CookieMonster is correctly built! ###' echo '### SUCCESS: CookieMonster is correctly built! ###'
else else
echo '### WARNING: Make sure to move the file from the /dist folder to the main folder. Otherwise Github Pages won't notice it ###' echo '### WARNING: CookieMonster.js does not seem to be correct. Make sure to run "npm run build" after saving all your changes! ###'
exit 1 exit 1
fi fi

4
.mocharc.json Normal file
View File

@@ -0,0 +1,4 @@
{
"recursive": true,
"require": "esm"
}

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

15651
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,71 +1,76 @@
{ {
"name": "cookiemonster-mod", "name": "cookiemonster-mod",
"version": "2.031.7", "version": "2.031.7",
"description": "Cookie Monster is an add-on that you can load into Cookie Clicker which offers a wide range of tools and statistics to enhance the game. It is not a cheat interface although it does offer helpers for golden cookies and such, everything can be toggled off at will to only leave how much information you want. This is a helper and everything is an option.", "description": "Cookie Monster is an add-on that you can load into Cookie Clicker which offers a wide range of tools and statistics to enhance the game. It is not a cheat interface although it does offer helpers for golden cookies and such, everything can be toggled off at will to only leave how much information you want. This is a helper and everything is an option.",
"main": "CookieMonster.js", "main": "CookieMonster.js",
"keywords": [ "keywords": [
"Cookie Clicker", "Cookie Clicker",
"javascript", "javascript",
"mod", "mod",
"Dashnet", "Dashnet",
"Orteil" "Orteil"
], ],
"scripts": { "scripts": {
"copy-file": "cp dist/CookieMonster.js CookieMonster.js", "copy-file": "cp dist/CookieMonster.js CookieMonster.js",
"eslint-src": "eslint src", "eslint-src": "eslint src",
"build": "run-s eslint-src pack-prod remove-comment copy-file", "build": "run-s eslint-src pack-prod remove-comment copy-file test",
"build-test": "run-s pack-dev", "build-test": "run-s pack-dev",
"pack-prod": "webpack --env production", "pack-prod": "webpack --env production",
"pack-dev": "webpack", "pack-dev": "webpack",
"remove-comment": "sed -i '' -e '/\\/\\/# sourceMappingURL.*/d' dist/CookieMonster.js" "remove-comment": "sed -i '' -e '/\\/\\/# sourceMappingURL.*/d' dist/CookieMonster.js",
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Aktanusa/CookieMonster.git"
},
"license": "MIT",
"author": {
"name": "Aktanusa",
"email": "chanam.geo@yahoo.com"
},
"contributors": [
{
"name": "Daniël van Noord",
"email": "13665637+DanielNoord@users.noreply.github.com"
}, },
"repository": { {
"type": "git", "name": "Aran Leite",
"url": "git+https://github.com/Aktanusa/CookieMonster.git" "email": "hyoretsu@gmail.com",
}, "url": "https://www.linkedin.com/in/aranleite"
"license": "MIT",
"author": {
"name": "Aktanusa",
"email": "chanam.geo@yahoo.com"
},
"contributors": [
{
"name": "Daniël van Noord",
"email": "13665637+DanielNoord@users.noreply.github.com"
},
{
"name": "Aran Leite",
"email": "hyoretsu@gmail.com",
"url": "https://www.linkedin.com/in/aranleite"
}
],
"bugs": {
"url": "https://github.com/Aktanusa/CookieMonster/issues"
},
"homepage": "https://github.com/Aktanusa/CookieMonster#readme",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.23.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"npm-run-all": "^4.1.5",
"prettier": "2.2.1",
"ts-loader": "^8.1.0",
"typescript": "^4.2.3",
"webpack": "^5.24.4",
"webpack-cli": "^4.5.0"
},
"ccrepo": {
"icon": [
10,
0
],
"name": "Cookie Monster"
},
"dependencies": {
"@eastdesire/jscolor": "^2.4.5"
} }
],
"bugs": {
"url": "https://github.com/Aktanusa/CookieMonster/issues"
},
"homepage": "https://github.com/Aktanusa/CookieMonster#readme",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"chai": "^4.3.4",
"eslint": "^7.23.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"esm": "^3.2.25",
"mocha": "^8.3.2",
"npm-run-all": "^4.1.5",
"prettier": "2.2.1",
"sinon": "^10.0.0",
"ts-loader": "^8.1.0",
"typescript": "^4.2.3",
"webpack": "^5.24.4",
"webpack-cli": "^4.5.0"
},
"ccrepo": {
"icon": [
10,
0
],
"name": "Cookie Monster"
},
"dependencies": {
"@eastdesire/jscolor": "^2.4.5"
}
} }

View File

@@ -15,6 +15,7 @@ import {
CacheGoldenAndWrathCookiesMults, CacheGoldenAndWrathCookiesMults,
CacheStatsCookies, CacheStatsCookies,
} from './Stats/Stats'; } from './Stats/Stats';
import AllAmountTillNextAchievement from './TillNextAchievement/AllAmountTillNextAchievement';
import { import {
CacheAverageCookiesFromClicks, CacheAverageCookiesFromClicks,
HeavenlyChipsDiff, HeavenlyChipsDiff,
@@ -39,6 +40,7 @@ export default function InitCache() {
ClickTimes[ClickTimes.length - 1] * 20, ClickTimes[ClickTimes.length - 1] * 20,
); );
CacheHeavenlyChipsPS(); CacheHeavenlyChipsPS();
AllAmountTillNextAchievement();
CacheAvgCPS(); CacheAvgCPS();
CacheIncome(); CacheIncome();
CacheBuildingsPrices(); CacheBuildingsPrices();

View File

@@ -1,4 +1,4 @@
import { FormatTime } from '../Disp/BeautifyAndFormatting/BeautifyFormatting'; import FormatTime from '../Disp/BeautifyAndFormatting/FormatTime';
import GetCPS from '../Disp/HelperFunctions/GetCPS'; import GetCPS from '../Disp/HelperFunctions/GetCPS';
import CacheAvgCPS from './CPS/CPS'; import CacheAvgCPS from './CPS/CPS';
import CacheCurrWrinklerCPS from './CPS/CurrWrinklerCPS'; import CacheCurrWrinklerCPS from './CPS/CurrWrinklerCPS';

View File

@@ -1,6 +1,6 @@
/** Functions related to the Dragon */ /** Functions related to the Dragon */
import { Beautify } from '../../Disp/BeautifyAndFormatting/BeautifyFormatting'; import Beautify from '../../Disp/BeautifyAndFormatting/Beautify';
import CopyData from '../../Sim/SimulationData/CopyData'; import CopyData from '../../Sim/SimulationData/CopyData';
import { SimDoSims, SimObjects } from '../../Sim/VariablesAndData'; import { SimDoSims, SimObjects } from '../../Sim/VariablesAndData';
import { import {

View File

@@ -12,6 +12,7 @@ import {
CacheObjects1, CacheObjects1,
CacheObjects10, CacheObjects10,
CacheObjects100, CacheObjects100,
CacheObjectsNextAchievement,
CacheUpgrades, CacheUpgrades,
} from '../VariablesAndData'; } from '../VariablesAndData';
@@ -82,6 +83,13 @@ export function CacheBuildingsPrices() {
Game.Objects[i].free, Game.Objects[i].free,
100, 100,
); );
CacheObjectsNextAchievement[i].price = BuildingGetPrice(
Game.Objects[i],
Game.Objects[i].basePrice,
Game.Objects[i].amount,
Game.Objects[i].free,
CacheObjectsNextAchievement[i].AmountNeeded,
);
}); });
} }

View File

@@ -7,12 +7,6 @@ import {
shortScaleAbbreviated, shortScaleAbbreviated,
} from '../../Data/Scales.ts'; } from '../../Data/Scales.ts';
import { BackupFunctions } from '../../Main/VariablesAndData'; import { BackupFunctions } from '../../Main/VariablesAndData';
import {
ColourGreen,
ColourOrange,
ColourRed,
ColourYellow,
} from '../VariablesAndData';
/** /**
* This function returns formats number based on the Scale setting * This function returns formats number based on the Scale setting
@@ -21,7 +15,7 @@ import {
* @param {number} forced Used to force (type 3) in certains cases * @param {number} forced Used to force (type 3) in certains cases
* @returns {string} Formatted number * @returns {string} Formatted number
*/ */
export function Beautify(num, floats, forced) { export default function Beautify(num, floats, forced) {
const decimals = CMOptions.ScaleDecimals + 1; const decimals = CMOptions.ScaleDecimals + 1;
if (num === Infinity) { if (num === Infinity) {
return 'Infinity'; return 'Infinity';
@@ -93,66 +87,3 @@ export function Beautify(num, floats, forced) {
console.log(`Could not beautify number with Cookie Monster Beautify: ${num}`); // eslint-disable-line no-console console.log(`Could not beautify number with Cookie Monster Beautify: ${num}`); // eslint-disable-line no-console
return BackupFunctions.Beautify(num, floats); return BackupFunctions.Beautify(num, floats);
} }
/**
* This function returns time as a string depending on TimeFormat setting
* @param {number} time Time to be formatted
* @param {number} longFormat 1 or 0
* @returns {string} Formatted time
*/
export function FormatTime(time, longFormat) {
let formattedTime = time;
if (time === Infinity) return time;
if (time < 0) return 'Negative time period';
formattedTime = Math.ceil(time);
const y = Math.floor(formattedTime / 31557600);
const d = Math.floor((formattedTime % 31557600) / 86400);
const h = Math.floor((formattedTime % 86400) / 3600);
const m = Math.floor((formattedTime % 3600) / 60);
const s = Math.floor(formattedTime % 60);
let str = '';
if (CMOptions.TimeFormat) {
if (formattedTime > 3155760000) return 'XX:XX:XX:XX:XX';
str += `${(y < 10 ? '0' : '') + y}:`;
str += `${(d < 10 ? '0' : '') + d}:`;
str += `${(h < 10 ? '0' : '') + h}:`;
str += `${(m < 10 ? '0' : '') + m}:`;
str += (s < 10 ? '0' : '') + s;
} else {
if (formattedTime > 777600000)
return longFormat ? 'Over 9000 days!' : '>9000d';
str +=
y > 0
? `${y + (longFormat ? (y === 1 ? ' year' : ' years') : 'y')}, ` // eslint-disable-line no-nested-ternary
: '';
str +=
d > 0 ? `${d + (longFormat ? (d === 1 ? ' day' : ' days') : 'd')}, ` : ''; // eslint-disable-line no-nested-ternary
if (str.length > 0 || h > 0)
str += `${h + (longFormat ? (h === 1 ? ' hour' : ' hours') : 'h')}, `; // eslint-disable-line no-nested-ternary
if (str.length > 0 || m > 0)
str += `${m + (longFormat ? (m === 1 ? ' minute' : ' minutes') : 'm')}, `; // eslint-disable-line no-nested-ternary
str += s + (longFormat ? (s === 1 ? ' second' : ' seconds') : 's'); // eslint-disable-line no-nested-ternary
}
return str;
}
/**
* This function returns the color to be used for time-strings
* @param {number} time Time to be coloured
* @returns {{string, string}} {text, color} Both the formatted time and color as strings in an array
*/
export function GetTimeColour(time) {
let color;
let text;
if (time <= 0) {
if (CMOptions.TimeFormat) text = '00:00:00:00:00';
else text = 'Done!';
color = ColourGreen;
} else {
text = FormatTime(time);
if (time > 300) color = ColourRed;
else if (time > 60) color = ColourOrange;
else color = ColourYellow;
}
return { text, color };
}

View File

@@ -0,0 +1,43 @@
import { CMOptions } from '../../Config/VariablesAndData';
/**
* This function returns time as a string depending on TimeFormat setting
* @param {number} time Time to be formatted
* @param {number} longFormat 1 or 0
* @returns {string} Formatted time
*/
export default function FormatTime(time, longFormat) {
let formattedTime = time;
if (time === Infinity) return time;
if (time < 0) return 'Negative time period';
formattedTime = Math.ceil(time);
const y = Math.floor(formattedTime / 31536000);
const d = Math.floor((formattedTime % 31536000) / 86400);
const h = Math.floor(((formattedTime % 31536000) % 86400) / 3600);
const m = Math.floor((((formattedTime % 31536000) % 86400) % 3600) / 60);
const s = Math.floor((((formattedTime % 31536000) % 86400) % 3600) % 60);
let str = '';
if (CMOptions.TimeFormat) {
if (formattedTime > 3155760000) return 'XX:XX:XX:XX:XX';
str += `${(y < 10 ? '0' : '') + y}:`;
str += `${(d < 10 ? '0' : '') + d}:`;
str += `${(h < 10 ? '0' : '') + h}:`;
str += `${(m < 10 ? '0' : '') + m}:`;
str += (s < 10 ? '0' : '') + s;
} else {
if (formattedTime > 777600000)
return longFormat ? 'Over 9000 days!' : '>9000d';
str +=
y > 0
? `${y + (longFormat ? (y === 1 ? ' year' : ' years') : 'y')}, ` // eslint-disable-line no-nested-ternary
: '';
if (str.length > 0 || d > 0)
str += `${d + (longFormat ? (d === 1 ? ' day' : ' days') : 'd')}, `; // eslint-disable-line no-nested-ternary
if (str.length > 0 || h > 0)
str += `${h + (longFormat ? (h === 1 ? ' hour' : ' hours') : 'h')}, `; // eslint-disable-line no-nested-ternary
if (str.length > 0 || m > 0)
str += `${m + (longFormat ? (m === 1 ? ' minute' : ' minutes') : 'm')}, `; // eslint-disable-line no-nested-ternary
str += s + (longFormat ? (s === 1 ? ' second' : ' seconds') : 's'); // eslint-disable-line no-nested-ternary
}
return str;
}

View File

@@ -0,0 +1,29 @@
import { CMOptions } from '../../Config/VariablesAndData';
import {
ColourGreen,
ColourOrange,
ColourRed,
ColourYellow,
} from '../VariablesAndData';
import FormatTime from './FormatTime';
/**
* This function returns the color to be used for time-strings
* @param {number} time Time to be coloured
* @returns {{string, string}} {text, color} Both the formatted time and color as strings in an array
*/
export default function GetTimeColour(time) {
let color;
let text;
if (time <= 0) {
if (CMOptions.TimeFormat) text = '00:00:00:00:00';
else text = 'Done!';
color = ColourGreen;
} else {
text = FormatTime(time);
if (time > 300) color = ColourRed;
else if (time > 60) color = ColourOrange;
else color = ColourYellow;
}
return { text, color };
}

View File

@@ -5,7 +5,7 @@ import {
} from '../../Cache/VariablesAndData'; } from '../../Cache/VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData'; import { CMOptions } from '../../Config/VariablesAndData';
import BuildingSell from '../../Sim/SimulationEvents/SellBuilding'; import BuildingSell from '../../Sim/SimulationEvents/SellBuilding';
import { Beautify } from '../BeautifyAndFormatting/BeautifyFormatting'; import Beautify from '../BeautifyAndFormatting/Beautify';
import { ColoursOrdering, LastTargetBuildings } from '../VariablesAndData'; import { ColoursOrdering, LastTargetBuildings } from '../VariablesAndData';
/** /**

View File

@@ -4,10 +4,8 @@ import CacheDragonCost from '../../Cache/Dragon/Dragon';
import { CacheCostDragonUpgrade } from '../../Cache/VariablesAndData'; import { CacheCostDragonUpgrade } from '../../Cache/VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData'; import { CMOptions } from '../../Config/VariablesAndData';
import CalculateChangeAura from '../../Sim/SimulationEvents/AuraChange'; import CalculateChangeAura from '../../Sim/SimulationEvents/AuraChange';
import { import Beautify from '../BeautifyAndFormatting/Beautify';
Beautify, import FormatTime from '../BeautifyAndFormatting/FormatTime';
FormatTime,
} from '../BeautifyAndFormatting/BeautifyFormatting';
/** /**
* This functions adds the two extra lines about CPS and time to recover to the aura picker infoscreen * This functions adds the two extra lines about CPS and time to recover to the aura picker infoscreen

View File

@@ -1,6 +1,6 @@
import ToggleWrinklerButtons from '../Config/Toggles/ToggleWrinklerButtons'; import ToggleWrinklerButtons from '../Config/Toggles/ToggleWrinklerButtons';
import { CMOptions } from '../Config/VariablesAndData'; import { CMOptions } from '../Config/VariablesAndData';
import { Beautify } from './BeautifyAndFormatting/BeautifyFormatting'; import Beautify from './BeautifyAndFormatting/Beautify';
import UpdateBuildings from './BuildingsUpgrades/Buildings'; import UpdateBuildings from './BuildingsUpgrades/Buildings';
import UpdateUpgrades from './BuildingsUpgrades/Upgrades'; import UpdateUpgrades from './BuildingsUpgrades/Upgrades';
import { UpdateBotBar } from './InfoBars/BottomBar'; import { UpdateBotBar } from './InfoBars/BottomBar';

View File

@@ -7,11 +7,10 @@ import {
} from '../../Cache/VariablesAndData'; } from '../../Cache/VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData'; import { CMOptions } from '../../Config/VariablesAndData';
import { VersionMajor, VersionMinor } from '../../Data/Moddata.ts'; import { VersionMajor, VersionMinor } from '../../Data/Moddata.ts';
import { import Beautify from '../BeautifyAndFormatting/Beautify';
Beautify, import FormatTime from '../BeautifyAndFormatting/FormatTime';
FormatTime, import GetTimeColour from '../BeautifyAndFormatting/GetTimeColour';
GetTimeColour,
} from '../BeautifyAndFormatting/BeautifyFormatting';
import GetCPS from '../HelperFunctions/GetCPS'; import GetCPS from '../HelperFunctions/GetCPS';
import GetWrinkConfigBank from '../HelperFunctions/GetWrinkConfigBank'; import GetWrinkConfigBank from '../HelperFunctions/GetWrinkConfigBank';
import { import {

View File

@@ -16,7 +16,7 @@ import {
import PopAllNormalWrinklers from '../../HelperFunctions/PopWrinklers'; import PopAllNormalWrinklers from '../../HelperFunctions/PopWrinklers';
import { ClickTimes, CookieTimes } from '../../VariablesAndData'; import { ClickTimes, CookieTimes } from '../../VariablesAndData';
import GetCPS from '../../HelperFunctions/GetCPS'; import GetCPS from '../../HelperFunctions/GetCPS';
import { Beautify } from '../../BeautifyAndFormatting/BeautifyFormatting'; import Beautify from '../../BeautifyAndFormatting/Beautify';
import AddMissingAchievements from './CreateMissingAchievements'; import AddMissingAchievements from './CreateMissingAchievements';
/** /**

View File

@@ -38,15 +38,12 @@ import {
} from '../../../Cache/VariablesAndData'; } from '../../../Cache/VariablesAndData';
import { CMOptions } from '../../../Config/VariablesAndData'; import { CMOptions } from '../../../Config/VariablesAndData';
import ResetBonus from '../../../Sim/SimulationEvents/ResetAscension'; import ResetBonus from '../../../Sim/SimulationEvents/ResetAscension';
import {
Beautify,
FormatTime,
} from '../../BeautifyAndFormatting/BeautifyFormatting';
import GetCPS from '../../HelperFunctions/GetCPS'; import GetCPS from '../../HelperFunctions/GetCPS';
import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank'; import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank';
import { ColourGreen, ColourRed, ColourTextPre } from '../../VariablesAndData'; import { ColourGreen, ColourRed, ColourTextPre } from '../../VariablesAndData';
import { StatsListing, StatsHeader, StatsMissDisp } from './CreateDOMElements'; import { StatsListing, StatsHeader, StatsMissDisp } from './CreateDOMElements';
import Beautify from '../../BeautifyAndFormatting/Beautify';
import FormatTime from '../../BeautifyAndFormatting/FormatTime';
/** /**
* This function creates the "Lucky" section of the stats page * This function creates the "Lucky" section of the stats page

View File

@@ -4,7 +4,7 @@ import {
CacheTimeTillNextPrestige, CacheTimeTillNextPrestige,
} from '../../Cache/VariablesAndData'; } from '../../Cache/VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData'; import { CMOptions } from '../../Config/VariablesAndData';
import { Beautify } from '../BeautifyAndFormatting/BeautifyFormatting'; import Beautify from '../BeautifyAndFormatting/Beautify';
/** /**
* This function creates a header object for tooltips. * This function creates a header object for tooltips.

View File

@@ -192,7 +192,7 @@ export function TooltipCreateCalculationSection(tooltip) {
} }
if (TooltipType === 'b') { if (TooltipType === 'b') {
tooltip.appendChild( tooltip.appendChild(
TooltipCreateHeader('Buildings left till next additional achievement'), TooltipCreateHeader('Buildings (price / PP) left till next achievement'),
); );
tooltip.lastChild.id = 'CMTooltipNextAchievementHeader'; // eslint-disable-line no-param-reassign tooltip.lastChild.id = 'CMTooltipNextAchievementHeader'; // eslint-disable-line no-param-reassign
const production = document.createElement('div'); const production = document.createElement('div');

View File

@@ -1,8 +1,4 @@
import UpdateTooltips from './UpdateTooltips'; import UpdateTooltips from './UpdateTooltips';
import {
Beautify,
GetTimeColour,
} from '../BeautifyAndFormatting/BeautifyFormatting';
import { import {
SimpleTooltipElements, SimpleTooltipElements,
TooltipName, TooltipName,
@@ -10,6 +6,8 @@ import {
} from '../VariablesAndData'; } from '../VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData'; import { CMOptions } from '../../Config/VariablesAndData';
import BuildingGetPrice from '../../Sim/SimulationEvents/BuyBuilding'; import BuildingGetPrice from '../../Sim/SimulationEvents/BuyBuilding';
import GetTimeColour from '../BeautifyAndFormatting/GetTimeColour';
import Beautify from '../BeautifyAndFormatting/Beautify';
/** All general functions related to creating and updating tooltips */ /** All general functions related to creating and updating tooltips */

View File

@@ -1,3 +1,4 @@
import ColourOfPP from '../../../Cache/PP/ColourOfPP';
import { import {
CacheObjects1, CacheObjects1,
CacheObjects10, CacheObjects10,
@@ -5,12 +6,11 @@ import {
CacheObjectsNextAchievement, CacheObjectsNextAchievement,
} from '../../../Cache/VariablesAndData'; } from '../../../Cache/VariablesAndData';
import { CMOptions } from '../../../Config/VariablesAndData'; import { CMOptions } from '../../../Config/VariablesAndData';
import BuyBuildingsBonusIncome from '../../../Sim/SimulationEvents/BuyBuildingBonusIncome';
import { SimObjects } from '../../../Sim/VariablesAndData'; import { SimObjects } from '../../../Sim/VariablesAndData';
import { import Beautify from '../../BeautifyAndFormatting/Beautify';
Beautify, import FormatTime from '../../BeautifyAndFormatting/FormatTime';
FormatTime, import GetTimeColour from '../../BeautifyAndFormatting/GetTimeColour';
GetTimeColour,
} from '../../BeautifyAndFormatting/BeautifyFormatting';
import GetCPS from '../../HelperFunctions/GetCPS'; import GetCPS from '../../HelperFunctions/GetCPS';
import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank'; import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank';
import { import {
@@ -101,13 +101,36 @@ export default function Building() {
} }
} }
if (CacheObjectsNextAchievement[TooltipName].AmountNeeded < 101) { const ObjectsTillNext = CacheObjectsNextAchievement[TooltipName];
if (ObjectsTillNext.AmountNeeded < 101) {
l('CMTooltipProductionLeft').style.marginBottom = '4px'; l('CMTooltipProductionLeft').style.marginBottom = '4px';
l('CMTooltipNextAchievementHeader').style.display = ''; l('CMTooltipNextAchievementHeader').style.display = '';
l('CMTooltipNextAchievement').textContent = Beautify(
CacheObjectsNextAchievement[TooltipName].AmountNeeded, let PPOfAmount;
); if (Game.cookiesPs) {
PPOfAmount =
Math.max(
ObjectsTillNext.price - (Game.cookies + GetWrinkConfigBank()),
0,
) /
Game.cookiesPs +
ObjectsTillNext.price /
BuyBuildingsBonusIncome(TooltipName, ObjectsTillNext.AmountNeeded);
} else
PPOfAmount =
ObjectsTillNext.price /
BuyBuildingsBonusIncome(TooltipName, ObjectsTillNext.AmountNeeded);
l('CMTooltipNextAchievement').textContent = `${Beautify(
ObjectsTillNext.AmountNeeded,
)} / ${Beautify(ObjectsTillNext.price)} / `;
l('CMTooltipNextAchievement').style.color = 'white'; l('CMTooltipNextAchievement').style.color = 'white';
const PPFrag = document.createElement('span');
if (CMOptions.PPDisplayTime) PPFrag.textContent = FormatTime(PPOfAmount);
else PPFrag.textContent = Beautify(PPOfAmount);
PPFrag.className =
ColourTextPre + ColourOfPP({ pp: PPOfAmount }, ObjectsTillNext.price);
l('CMTooltipNextAchievement').appendChild(PPFrag);
} else { } else {
l('CMTooltipNextAchievementHeader').style.display = 'none'; l('CMTooltipNextAchievementHeader').style.display = 'none';
l('CMTooltipProductionLeft').style.marginBottom = '0px'; l('CMTooltipProductionLeft').style.marginBottom = '0px';

View File

@@ -1,5 +1,5 @@
import { CMOptions } from '../../../Config/VariablesAndData'; import { CMOptions } from '../../../Config/VariablesAndData';
import { Beautify } from '../../BeautifyAndFormatting/BeautifyFormatting'; import Beautify from '../../BeautifyAndFormatting/Beautify';
import { TooltipName } from '../../VariablesAndData'; import { TooltipName } from '../../VariablesAndData';
import * as Create from '../CreateTooltip'; import * as Create from '../CreateTooltip';

View File

@@ -1,9 +1,7 @@
import { CacheNoGoldSwitchCookiesPS } from '../../../Cache/VariablesAndData'; import { CacheNoGoldSwitchCookiesPS } from '../../../Cache/VariablesAndData';
import { CMOptions } from '../../../Config/VariablesAndData'; import { CMOptions } from '../../../Config/VariablesAndData';
import { import Beautify from '../../BeautifyAndFormatting/Beautify';
Beautify, import GetTimeColour from '../../BeautifyAndFormatting/GetTimeColour';
GetTimeColour,
} from '../../BeautifyAndFormatting/BeautifyFormatting';
import CalculateGrimoireRefillTime from '../../HelperFunctions/CalculateGrimoireRefillTime'; import CalculateGrimoireRefillTime from '../../HelperFunctions/CalculateGrimoireRefillTime';
import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank'; import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank';
import { ColourTextPre, TooltipName } from '../../VariablesAndData'; import { ColourTextPre, TooltipName } from '../../VariablesAndData';

View File

@@ -1,5 +1,5 @@
import { CMOptions } from '../../../Config/VariablesAndData'; import { CMOptions } from '../../../Config/VariablesAndData';
import { Beautify } from '../../BeautifyAndFormatting/BeautifyFormatting'; import Beautify from '../../BeautifyAndFormatting/Beautify';
import * as Create from '../CreateTooltip'; import * as Create from '../CreateTooltip';
/** /**

View File

@@ -1,6 +1,6 @@
import { CacheGods } from '../../../Cache/VariablesAndData'; import { CacheGods } from '../../../Cache/VariablesAndData';
import { CMOptions } from '../../../Config/VariablesAndData'; import { CMOptions } from '../../../Config/VariablesAndData';
import { Beautify } from '../../BeautifyAndFormatting/BeautifyFormatting'; import Beautify from '../../BeautifyAndFormatting/Beautify';
import { TooltipName, TooltipType } from '../../VariablesAndData'; import { TooltipName, TooltipType } from '../../VariablesAndData';
import * as Create from '../CreateTooltip'; import * as Create from '../CreateTooltip';

View File

@@ -3,11 +3,9 @@ import {
CacheUpgrades, CacheUpgrades,
} from '../../../Cache/VariablesAndData'; } from '../../../Cache/VariablesAndData';
import { CMOptions } from '../../../Config/VariablesAndData'; import { CMOptions } from '../../../Config/VariablesAndData';
import { import Beautify from '../../BeautifyAndFormatting/Beautify';
Beautify, import FormatTime from '../../BeautifyAndFormatting/FormatTime';
FormatTime, import GetTimeColour from '../../BeautifyAndFormatting/GetTimeColour';
GetTimeColour,
} from '../../BeautifyAndFormatting/BeautifyFormatting';
import GetCPS from '../../HelperFunctions/GetCPS'; import GetCPS from '../../HelperFunctions/GetCPS';
import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank'; import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank';
import { import {

View File

@@ -2,11 +2,8 @@ import GetCPSBuffMult from '../../../Cache/CPS/GetCPSBuffMult';
import { CacheEdifice, CacheLucky } from '../../../Cache/VariablesAndData'; import { CacheEdifice, CacheLucky } from '../../../Cache/VariablesAndData';
import ToggleToolWarnPos from '../../../Config/Toggles/ToggleToolWarnPos'; import ToggleToolWarnPos from '../../../Config/Toggles/ToggleToolWarnPos';
import { CMOptions } from '../../../Config/VariablesAndData'; import { CMOptions } from '../../../Config/VariablesAndData';
import Beautify from '../../BeautifyAndFormatting/Beautify';
import { import FormatTime from '../../BeautifyAndFormatting/FormatTime';
Beautify,
FormatTime,
} from '../../BeautifyAndFormatting/BeautifyFormatting';
import GetCPS from '../../HelperFunctions/GetCPS'; import GetCPS from '../../HelperFunctions/GetCPS';
import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank'; import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank';
import { import {

View File

@@ -2,7 +2,7 @@ import {
CacheWrinklersFattest, CacheWrinklersFattest,
CacheWrinklersTotal, CacheWrinklersTotal,
} from '../../../Cache/VariablesAndData'; } from '../../../Cache/VariablesAndData';
import { Beautify } from '../../BeautifyAndFormatting/BeautifyFormatting'; import Beautify from '../../BeautifyAndFormatting/Beautify';
import { TooltipName } from '../../VariablesAndData'; import { TooltipName } from '../../VariablesAndData';
import * as Create from '../CreateTooltip'; import * as Create from '../CreateTooltip';

View File

@@ -1,6 +1,6 @@
import { CMOptions } from '../../Config/VariablesAndData'; import { CMOptions } from '../../Config/VariablesAndData';
import { SimObjects } from '../../Sim/VariablesAndData'; import { SimObjects } from '../../Sim/VariablesAndData';
import { Beautify } from '../BeautifyAndFormatting/BeautifyFormatting'; import Beautify from '../BeautifyAndFormatting/Beautify';
import { import {
TooltipWrinkler, TooltipWrinkler,
TooltipWrinklerArea, TooltipWrinklerArea,

View File

@@ -1,6 +1,5 @@
import { CMOptions } from '../../Config/VariablesAndData'; import { CMOptions } from '../../Config/VariablesAndData';
import { FormatTime } from '../../Disp/BeautifyAndFormatting/BeautifyFormatting'; import FormatTime from '../../Disp/BeautifyAndFormatting/FormatTime';
import CalculateGrimoireRefillTime from '../../Disp/HelperFunctions/CalculateGrimoireRefillTime'; import CalculateGrimoireRefillTime from '../../Disp/HelperFunctions/CalculateGrimoireRefillTime';
import { import {
BackupGrimoireDraw, BackupGrimoireDraw,

View File

@@ -1,9 +1,7 @@
import jscolor from '@eastdesire/jscolor'; import jscolor from '@eastdesire/jscolor';
import { CMOptions } from '../../Config/VariablesAndData'; import { CMOptions } from '../../Config/VariablesAndData';
import { import Beautify from '../../Disp/BeautifyAndFormatting/Beautify';
Beautify as CMBeautify, import FormatTime from '../../Disp/BeautifyAndFormatting/FormatTime';
FormatTime,
} from '../../Disp/BeautifyAndFormatting/BeautifyFormatting';
import { AddAuraInfo, AddDragonLevelUpTooltip } from '../../Disp/Dragon/Dragon'; import { AddAuraInfo, AddDragonLevelUpTooltip } from '../../Disp/Dragon/Dragon';
import AddMenu from '../../Disp/MenuSections/AddMenus'; import AddMenu from '../../Disp/MenuSections/AddMenus';
import UpdateTitle from '../../Disp/TabTitle/TabTitle'; import UpdateTitle from '../../Disp/TabTitle/TabTitle';
@@ -146,7 +144,7 @@ export default function ReplaceNative() {
let title = 'Cookie Clicker'; let title = 'Cookie Clicker';
if (Game.season === 'fools') title = 'Cookie Baker'; if (Game.season === 'fools') title = 'Cookie Baker';
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
Title = `${Game.OnAscend ? 'Ascending! ' : ''}${CMBeautify(Game.cookies)} ${ Title = `${Game.OnAscend ? 'Ascending! ' : ''}${Beautify(Game.cookies)} ${
Game.cookies === 1 ? 'cookie' : 'cookies' Game.cookies === 1 ? 'cookie' : 'cookies'
} - ${title}`; } - ${title}`;
UpdateTitle(); UpdateTitle();

View File

@@ -0,0 +1,106 @@
import { before, describe, it } from 'mocha';
import { assert } from 'chai';
import FormatTime from '../../src/Disp/BeautifyAndFormatting/FormatTime';
import { CMOptions } from '../../src/Config/VariablesAndData';
describe('FormatTime', function () {
it('Format when time is Infinity', function () {
assert.equal(FormatTime(Infinity, 0), Infinity);
});
it('Format when time is negative', function () {
assert.equal(FormatTime(-1, 0), 'Negative time period');
});
describe('TimeFormat = 0', function () {
before(function () {
CMOptions.TimeFormat = 0;
});
describe('Longformat = 0', function () {
it('Format when time is 0', function () {
assert.equal(FormatTime(0, 0), '0s');
});
it('Format when time is 1 second', function () {
assert.equal(FormatTime(1, 0), '1s');
});
it('Format when time is over 1 minute', function () {
assert.equal(FormatTime(61, 0), '1m, 1s');
});
it('Format when time is over 1 hour', function () {
assert.equal(FormatTime(3601, 0), '1h, 0m, 1s');
});
it('Format when time is over 1 day', function () {
assert.equal(FormatTime(86401, 0), '1d, 0h, 0m, 1s');
});
it('Format when time is over 1 year', function () {
assert.equal(FormatTime(31536001, 0), '1y, 0d, 0h, 0m, 1s');
});
it('Format when time is over >9000 days', function () {
assert.equal(FormatTime(777600001, 0), '>9000d');
});
it('Format when time is over >99.9 years', function () {
assert.equal(FormatTime(3155760001, 0), '>9000d');
});
});
describe('Longformat = 1', function () {
it('Format when time is 0', function () {
assert.equal(FormatTime(0, 1), '0 seconds');
});
it('Format when time is 1 second', function () {
assert.equal(FormatTime(1, 1), '1 second');
});
it('Format when time is over 1 minute', function () {
assert.equal(FormatTime(61, 1), '1 minute, 1 second');
});
it('Format when time is over 1 hour', function () {
assert.equal(FormatTime(3601, 1), '1 hour, 0 minutes, 1 second');
});
it('Format when time is over 1 day', function () {
assert.equal(
FormatTime(86401, 1),
'1 day, 0 hours, 0 minutes, 1 second',
);
});
it('Format when time is over 1 year', function () {
assert.equal(
FormatTime(31536001, 1),
'1 year, 0 days, 0 hours, 0 minutes, 1 second',
);
});
it('Format when time is over >9000 days', function () {
assert.equal(FormatTime(777600001, 1), 'Over 9000 days!');
});
it('Format when time is over >99.9 years', function () {
assert.equal(FormatTime(3155760001, 1), 'Over 9000 days!');
});
});
});
describe('TimeFormat = 1', function () {
before(function () {
CMOptions.TimeFormat = 1;
});
it('Format when time is 0', function () {
assert.equal(FormatTime(0, 0), '00:00:00:00:00');
});
it('Format when time is 1 second', function () {
assert.equal(FormatTime(1, 0), '00:00:00:00:01');
});
it('Format when time is over 1 minute', function () {
assert.equal(FormatTime(61, 0), '00:00:00:01:01');
});
it('Format when time is over 1 hour', function () {
assert.equal(FormatTime(3601, 0), '00:00:01:00:01');
});
it('Format when time is over 1 day', function () {
assert.equal(FormatTime(86401, 0), '00:01:00:00:01');
});
it('Format when time is over 1 year', function () {
assert.equal(FormatTime(31536001, 0), '01:00:00:00:01');
});
it('Format when time is over >9000 days', function () {
assert.equal(FormatTime(777600001, 0), '24:240:00:00:01');
});
it('Format when time is over >99.9 years', function () {
assert.equal(FormatTime(3155760001, 0), 'XX:XX:XX:XX:XX');
});
});
});