diff --git a/changelog.md b/changelog.md index bff8cb9..285c2e5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## Next +- Changed output of `getVersions` to replace '`.x`' with the actual game version. + ## 1.3.16 - Updated resource pack format to `36`. - Updated data pack format to `50`. diff --git a/src/index.ts b/src/index.ts index a99f889..0c913d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,12 @@ import { VersionName, SnapshotName, PackType, FormatResult, VersionsResult } fro // Data sets // +const HIGHEST_MINORS: number[] = [ + /*1.0*/0, /*1.1*/0, /*1.2*/5, /*1.3*/2, /*1.4*/7, /*1.5*/2, /*1.6*/4, /*1.7*/10, /*1.8*/9, /*1.9*/4, + /*1.10*/2, /*1.11*/2, /*1.12*/2, /*1.13*/2, /*1.14*/4, /*1.15*/2, /*1.16*/5, /*1.17*/1, /*1.18*/2, /*1.19*/2, + /*1.20*/6, /*1.21*/2 +] + const START_RELEASES: Record> = { '1.0.x': { resource: null, data: null }, '1.6.x': { resource: 1, data: null }, @@ -182,7 +188,11 @@ function getVersions(format: number, type: PackType = 'resource'): VersionsResul if (!format || format > LATEST[type] || (type === 'data' && format < 4)) return output const getVersionBelow = function (ver: VersionName, minVer: VersionName): VersionName { - const formatVer = ([x, y, z]: Array) => [x, y, z].join('.') as VersionName + const toHighestMinor = (ver: VersionName): VersionName => { + const major = ver.split('.')[1] + return ver.replace('.x', '.' + HIGHEST_MINORS[+major]) as VersionName + } + const formatVer = ([x, y, z]: Array) => toHighestMinor([x, y, z].join('.') as VersionName) const [minX, minY, minZ] = minVer.split('.') const [x, y, z] = ver.split('.') // (1.X.a) vs 1.X.b @@ -202,9 +212,9 @@ function getVersions(format: number, type: PackType = 'resource'): VersionsResul const relIndex = startReleases.findIndex(([, data]) => data[type] === format) if (relIndex >= 0) { const lastWithFormat = startReleases.find(([, obj]) => (obj[type] ?? 0) > format) ?? [] - const minRelease = startReleases[relIndex][0] as VersionName + const minRelease = startReleases[relIndex][0].replace('.x', '') as VersionName const maxRelease = getVersionBelow(lastWithFormat[0] as VersionName, minRelease) - output.releases.min = minRelease + output.releases.min = minRelease as VersionName output.releases.max = maxRelease } diff --git a/src/types.ts b/src/types.ts index 411f166..9043cae 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -export type VersionName = `1.${number}.${number | 'x'}` +export type VersionName = `1.${number}` | `1.${number}.${number | 'x'}` export type SnapshotName = `${number}w${string}${Lowercase}` export type PackType = 'resource' | 'data' diff --git a/test/test.js b/test/test.js index b348cfd..e638039 100644 --- a/test/test.js +++ b/test/test.js @@ -49,11 +49,11 @@ testPackFormats() testVersions([3, 'data'], { releases: { min: '', max: '' }, snapshots: { min: '', max: '' } }) testVersions([10, 'resource'], { releases: { min: '', max: '' }, snapshots: { min: '', max: '' } }) -testVersions([6, 'resource'], { releases: { min: '1.16.x', max: '1.16.x' }, snapshots: { min: '', max: '' } }) -testVersions([6, 'data'], { releases: { min: '1.16.x', max: '1.16.x' }, snapshots: { min: '20w45a', max: '20w45a' } }) -testVersions([7, 'resource'], { releases: { min: '1.17.x', max: '1.17.x' }, snapshots: { min: '20w45a', max: '21w38a' } }) -testVersions([10, 'data'], { releases: { min: '1.19.x', max: '1.19.3' }, snapshots: { min: '22w11a', max: '23w02a' } }) +testVersions([6, 'resource'], { releases: { min: '1.16.2', max: '1.16.5' }, snapshots: { min: '', max: '' } }) +testVersions([6, 'data'], { releases: { min: '1.16.2', max: '1.16.5' }, snapshots: { min: '20w45a', max: '20w45a' } }) +testVersions([7, 'resource'], { releases: { min: '1.17', max: '1.17.1' }, snapshots: { min: '20w45a', max: '21w38a' } }) +testVersions([10, 'data'], { releases: { min: '1.19', max: '1.19.3' }, snapshots: { min: '22w11a', max: '23w02a' } }) testVersions([11, 'resource'], { releases: { min: '', max: '' }, snapshots: { min: '22w42a', max: '22w44a' } }) -testVersions([15, 'data'], { releases: { min: '1.20.x', max: '1.20.1' }, snapshots: { min: '23w18a', max: '23w30a' } }) +testVersions([15, 'data'], { releases: { min: '1.20', max: '1.20.1' }, snapshots: { min: '23w18a', max: '23w30a' } }) console.log(`\nRan ${total} tests | ${passed} passed | ${failed} failed`)