diff --git a/data/seasons/d2-season-info.ts b/data/seasons/d2-season-info.ts index e8058e80..045e919e 100644 --- a/data/seasons/d2-season-info.ts +++ b/data/seasons/d2-season-info.ts @@ -1,4 +1,35 @@ -export default { +export enum D2SeasonEnum { + DEBUG = 0, + RED_WAR, + CURSE_OF_OSIRIS, + WARMIND, + FORSAKEN, + BLACK_ARMORY, + JOKERS_WILD, + PENUMBRA, + SHADOWKEEP, + DAWN, + WORTHY, + + __LENGTH, // This always needs to be last +} + +export const D2CurrentSeason: number = D2SeasonEnum.__LENGTH - 1; + +export const D2SeasonInfo = { + 0: { + DLCName: 'Debug', + seasonName: 'Debug', + seasonTag: 'debug', + season: 0, + year: 0, + maxLevel: 0, + maxPower: 0, + softCap: 0, + releaseDate: '2017-09-06', + resetTime: '09:00:00Z', + numWeeks: 0, + }, 1: { DLCName: 'Red War', seasonName: 'Red War', @@ -10,6 +41,7 @@ export default { softCap: 285, releaseDate: '2017-09-06', resetTime: '09:00:00Z', + numWeeks: 13, }, 2: { DLCName: 'Curse of Osiris', @@ -22,6 +54,7 @@ export default { softCap: 320, releaseDate: '2017-12-05', resetTime: '17:00:00Z', + numWeeks: 22, }, 3: { DLCName: 'Warmind', @@ -34,6 +67,7 @@ export default { softCap: 340, releaseDate: '2018-05-08', resetTime: '18:00:00Z', + numWeeks: 17, }, 4: { DLCName: 'Forsaken', @@ -46,6 +80,7 @@ export default { softCap: 500, releaseDate: '2018-09-04', resetTime: '17:00:00Z', + numWeeks: 13, }, 5: { DLCName: 'Black Armory', @@ -58,6 +93,7 @@ export default { softCap: 500, releaseDate: '2018-11-27', resetTime: '17:00:00Z', + numWeeks: 12, }, 6: { DLCName: "Joker's Wild", @@ -70,6 +106,7 @@ export default { softCap: 500, releaseDate: '2019-03-05', resetTime: '17:00:00Z', + numWeeks: 14, }, 7: { DLCName: 'Penumbra', @@ -82,6 +119,7 @@ export default { softCap: 500, releaseDate: '2019-06-04', resetTime: '17:00:00Z', + numWeeks: 13, }, 8: { DLCName: 'Shadowkeep', @@ -94,6 +132,7 @@ export default { softCap: 900, releaseDate: '2019-10-01', resetTime: '17:00:00Z', + numWeeks: 10, }, 9: { DLCName: '', @@ -106,6 +145,7 @@ export default { softCap: 900, releaseDate: '2019-12-10', resetTime: '17:00:00Z', + numWeeks: 13, }, 10: { DLCName: '', @@ -118,6 +158,7 @@ export default { softCap: 950, releaseDate: '2020-03-10', resetTime: '17:00:00Z', + numWeeks: 13, }, } as Record< number, @@ -132,5 +173,20 @@ export default { softCap: number; releaseDate: string; resetTime: string; + numWeeks: number; } >; + +function getCurrentSeason(): number { + let seasonDate: Date; + const today = new Date(); + for (let i = D2SeasonEnum.__LENGTH - 1; i > 0; i--) { + seasonDate = new Date(`${D2SeasonInfo[i].releaseDate}T${D2SeasonInfo[i].resetTime}`); + if (today >= seasonDate) { + return D2SeasonInfo[i].season; + } + } + return 0; +} + +export const D2CalculatedSeason: number = getCurrentSeason(); diff --git a/output/d2-season-info.ts b/output/d2-season-info.ts new file mode 100644 index 00000000..045e919e --- /dev/null +++ b/output/d2-season-info.ts @@ -0,0 +1,192 @@ +export enum D2SeasonEnum { + DEBUG = 0, + RED_WAR, + CURSE_OF_OSIRIS, + WARMIND, + FORSAKEN, + BLACK_ARMORY, + JOKERS_WILD, + PENUMBRA, + SHADOWKEEP, + DAWN, + WORTHY, + + __LENGTH, // This always needs to be last +} + +export const D2CurrentSeason: number = D2SeasonEnum.__LENGTH - 1; + +export const D2SeasonInfo = { + 0: { + DLCName: 'Debug', + seasonName: 'Debug', + seasonTag: 'debug', + season: 0, + year: 0, + maxLevel: 0, + maxPower: 0, + softCap: 0, + releaseDate: '2017-09-06', + resetTime: '09:00:00Z', + numWeeks: 0, + }, + 1: { + DLCName: 'Red War', + seasonName: 'Red War', + seasonTag: 'redwar', + season: 1, + year: 1, + maxLevel: 20, + maxPower: 300, + softCap: 285, + releaseDate: '2017-09-06', + resetTime: '09:00:00Z', + numWeeks: 13, + }, + 2: { + DLCName: 'Curse of Osiris', + seasonName: 'Curse of Osiris', + seasonTag: 'osiris', + season: 2, + year: 1, + maxLevel: 25, + maxPower: 330, + softCap: 320, + releaseDate: '2017-12-05', + resetTime: '17:00:00Z', + numWeeks: 22, + }, + 3: { + DLCName: 'Warmind', + seasonName: 'Warmind', + seasonTag: 'warmind', + season: 3, + year: 1, + maxLevel: 30, + maxPower: 380, + softCap: 340, + releaseDate: '2018-05-08', + resetTime: '18:00:00Z', + numWeeks: 17, + }, + 4: { + DLCName: 'Forsaken', + seasonName: 'Season of the Outlaw', + seasonTag: 'outlaw', + season: 4, + year: 2, + maxLevel: 50, + maxPower: 600, + softCap: 500, + releaseDate: '2018-09-04', + resetTime: '17:00:00Z', + numWeeks: 13, + }, + 5: { + DLCName: 'Black Armory', + seasonName: 'Season of the Forge', + seasonTag: 'forge', + season: 5, + year: 2, + maxLevel: 50, + maxPower: 650, + softCap: 500, + releaseDate: '2018-11-27', + resetTime: '17:00:00Z', + numWeeks: 12, + }, + 6: { + DLCName: "Joker's Wild", + seasonName: 'Season of the Drifter', + seasonTag: 'drifter', + season: 6, + year: 2, + maxLevel: 50, + maxPower: 700, + softCap: 500, + releaseDate: '2019-03-05', + resetTime: '17:00:00Z', + numWeeks: 14, + }, + 7: { + DLCName: 'Penumbra', + seasonName: 'Season of Opulence', + seasonTag: 'opulence', + season: 7, + year: 2, + maxLevel: 50, + maxPower: 750, + softCap: 500, + releaseDate: '2019-06-04', + resetTime: '17:00:00Z', + numWeeks: 13, + }, + 8: { + DLCName: 'Shadowkeep', + seasonName: 'Season of the Undying', + seasonTag: 'undying', + season: 8, + year: 3, + maxLevel: 50, + maxPower: 960, + softCap: 900, + releaseDate: '2019-10-01', + resetTime: '17:00:00Z', + numWeeks: 10, + }, + 9: { + DLCName: '', + seasonName: 'Season of Dawn', + seasonTag: 'dawn', + season: 9, + year: 3, + maxLevel: 50, + maxPower: 970, + softCap: 900, + releaseDate: '2019-12-10', + resetTime: '17:00:00Z', + numWeeks: 13, + }, + 10: { + DLCName: '', + seasonName: 'Season of the Worthy', + seasonTag: 'worthy', + season: 10, + year: 3, + maxLevel: 50, + maxPower: 1010, + softCap: 950, + releaseDate: '2020-03-10', + resetTime: '17:00:00Z', + numWeeks: 13, + }, +} as Record< + number, + { + DLCName: string; + seasonName: string; + seasonTag: string; + season: number; + year: number; + maxLevel: number; + maxPower: number; + softCap: number; + releaseDate: string; + resetTime: string; + numWeeks: number; + } +>; + +function getCurrentSeason(): number { + let seasonDate: Date; + const today = new Date(); + for (let i = D2SeasonEnum.__LENGTH - 1; i > 0; i--) { + seasonDate = new Date(`${D2SeasonInfo[i].releaseDate}T${D2SeasonInfo[i].resetTime}`); + if (today >= seasonDate) { + return D2SeasonInfo[i].season; + } + } + return 0; +} + +export const D2CalculatedSeason: number = getCurrentSeason(); diff --git a/package.json b/package.json index 9200eff0..a4f1f379 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ }, "dependencies": { "@types/btoa": "^1.2.3", + "@types/fs-extra": "^9.0.1", "@types/node": "^14.0.1", "@types/stringify-object": "^3.3.0", "@typescript-eslint/eslint-plugin": "^2.34.0", @@ -44,7 +45,7 @@ "cross-fetch": "^3.0.4", "destiny2-manifest": "^2.2.4", "destiny2-utils": "^2.0.3", - "fs": "^0.0.1-security", + "fs-extra": "^9.0.0", "gist-client": "^1.1.1", "npm-run-all": "^4.1.5", "stringify-object": "^3.3.0", diff --git a/src/generate-season-info.ts b/src/generate-season-info.ts index 50ed1f7b..6a8269d8 100644 --- a/src/generate-season-info.ts +++ b/src/generate-season-info.ts @@ -1,8 +1,8 @@ import { getAll, loadLocal } from 'destiny2-manifest/node'; -import { getCurrentSeason, writeFile } from './helpers'; +import { getCurrentSeason, writeFile, copyFile } from './helpers'; import seasons from '../data/seasons/seasons_master.json'; -import seasonsInfo from '../data/seasons/d2-season-info'; +import { D2SeasonInfo } from '../data/seasons/d2-season-info'; loadLocal(); const inventoryItems = getAll('DestinyInventoryItemDefinition'); @@ -20,9 +20,10 @@ inventoryItems.forEach((inventoryItem) => { writeFile('./data/seasons/seasons_master.json', seasons); -const seasonTags = Object.values(seasonsInfo) - .filter((seasonInfo) => seasonInfo.season <= calculatedSeason) +const seasonTags = Object.values(D2SeasonInfo) + .filter((seasonInfo) => seasonInfo.season > 0 && seasonInfo.season <= calculatedSeason) .map((seasonInfo) => [seasonInfo.seasonTag, seasonInfo.season] as const) .reduce((acc: Record, [tag, num]) => ((acc[tag] = num), acc), {}); writeFile('./output/season-tags.json', seasonTags); +copyFile('./data/seasons/d2-season-info.ts', './output/d2-season-info.ts'); diff --git a/src/helpers.ts b/src/helpers.ts index b6f86f75..1080a260 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -7,20 +7,21 @@ import { get, loadLocal } from 'destiny2-manifest/node'; || \*================================================================================================================================*/ import { execSync } from 'child_process'; -import seasonInfo from '../data/seasons/d2-season-info.js'; -import { writeFileSync } from 'fs'; +import { D2SeasonInfo, D2SeasonEnum } from '../data/seasons/d2-season-info.js'; +import fse from 'fs-extra'; + +const { writeFileSync, copyFileSync } = fse; loadLocal(); export function getCurrentSeason() { let seasonDate: Date; - const maxSeasons = Object.keys(seasonInfo).length; const today = new Date(Date.now()); - for (let i = maxSeasons; i > 0; i--) { - seasonDate = new Date(`${seasonInfo[i].releaseDate}T${seasonInfo[i].resetTime}`); + for (let i = D2SeasonEnum.__LENGTH - 1; i > 0; i--) { + seasonDate = new Date(`${D2SeasonInfo[i].releaseDate}T${D2SeasonInfo[i].resetTime}`); seasonDate.setDate(seasonDate.getDate() - 1); if (today >= seasonDate) { - return seasonInfo[i].season; + return D2SeasonInfo[i].season; } } return 0; @@ -40,6 +41,11 @@ export function writeFile(filename: string, data: any, pretty = true) { console.log(`${filename} saved.`); } +export function copyFile(filename: string, filename2: string) { + copyFileSync(filename, filename2); + console.log(`${filename} copied to ${filename2} .`); +} + export function uniqAndSortArray(array: T[]): T[] { const uniq = [...new Set(array)]; return uniq.every(isNumberlike) ? uniq.sort((a, b) => Number(a) - Number(b)) : uniq.sort(); diff --git a/yarn.lock b/yarn.lock index 589f74d3..8c418411 100644 --- a/yarn.lock +++ b/yarn.lock @@ -259,6 +259,13 @@ resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== +"@types/fs-extra@^9.0.1": + version "9.0.1" + resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.1.tgz#91c8fc4c51f6d5dbe44c2ca9ab09310bd00c7918" + integrity sha512-B42Sxuaz09MhC3DDeW5kubRcQ5by4iuVQ0cRRWM2lggLzAa/KVom0Aft/208NgMvNQQZ86s5rVcqDdn/SH0/mg== + dependencies: + "@types/node" "*" + "@types/hosted-git-info@^2.7.0": version "2.7.0" resolved "https://registry.yarnpkg.com/@types/hosted-git-info/-/hosted-git-info-2.7.0.tgz#5199b4df62d53f51d60520d61513eaa4b2dd3d3d" @@ -545,6 +552,11 @@ asynckit@^0.4.0: resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= +at-least-node@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" + integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== + aws-sign2@~0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8" @@ -1404,16 +1416,21 @@ fs-constants@^1.0.0: resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow== +fs-extra@^9.0.0: + version "9.0.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.0.tgz#b6afc31036e247b2466dc99c29ae797d5d4580a3" + integrity sha512-pmEYSk3vYsG/bF651KPUXZ+hvjpgWYw/Gc7W9NFUe3ZVLczKKWIij3IKpOrQcdw4TILtibFslZ0UmR8Vvzig4g== + dependencies: + at-least-node "^1.0.0" + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^1.0.0" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= -fs@^0.0.1-security: - version "0.0.1-security" - resolved "https://registry.yarnpkg.com/fs/-/fs-0.0.1-security.tgz#8a7bd37186b6dddf3813f23858b57ecaaf5e41d4" - integrity sha1-invTcYa23d84E/I4WLV+yq9eQdQ= - ftp@~0.3.10: version "0.3.10" resolved "https://registry.yarnpkg.com/ftp/-/ftp-0.3.10.tgz#9197d861ad8142f3e63d5a83bfe4c59f7330885d" @@ -1549,7 +1566,7 @@ got@^6.7.1: unzip-response "^2.0.1" url-parse-lax "^1.0.0" -graceful-fs@^4.1.11, graceful-fs@^4.1.2: +graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0: version "4.2.4" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb" integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw== @@ -1970,6 +1987,15 @@ json-stringify-safe@~5.0.1: resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus= +jsonfile@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.0.1.tgz#98966cba214378c8c84b82e085907b40bf614179" + integrity sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg== + dependencies: + universalify "^1.0.0" + optionalDependencies: + graceful-fs "^4.1.6" + jsprim@^1.2.2: version "1.4.1" resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2" @@ -3858,6 +3884,11 @@ unique-string@^1.0.0: dependencies: crypto-random-string "^1.0.0" +universalify@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d" + integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug== + unpipe@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"