Skip to content

Commit

Permalink
Replace .x with actual game version
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Aug 24, 2024
1 parent 5334192 commit b312a81
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
16 changes: 13 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<VersionName, Record<PackType, FormatResult>> = {
'1.0.x': { resource: null, data: null },
'1.6.x': { resource: 1, data: null },
Expand Down Expand Up @@ -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<string | number>) => [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<string | number>) => 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
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -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<string>}`

export type PackType = 'resource' | 'data'
Expand Down
10 changes: 5 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

0 comments on commit b312a81

Please sign in to comment.