Skip to content

Commit

Permalink
1.2.7
Browse files Browse the repository at this point in the history
- Update to resource pack format `8`
- Fix maximum snapshot output from `getVersions()`
  • Loading branch information
Nixinova committed Oct 3, 2021
1 parent ee0b858 commit 1b002f2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Changelog

## 1.2.7
*2021-10-03*
- Fixed snapshots appearing malformed when using `getVersions()`.
- Fixed incorrect maximum snapshot data being listed when using `getVersions()`.
- Updated resource pack format to `8`.

## 1.2.6
*2021-09-23*
- Fixed `getVersions()` returning invalid snapshots.
- Fixed 1.18 resource pack version being `8` instead of `7`.
- Fixed 1.18 snapshot resource pack versions being `8` instead of `7`.

## 1.2.5
*2021-09-16*
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pack-format",
"version": "1.2.6",
"version": "1.2.7",
"description": "Returns the pack_format of any Minecraft version, including snapshots",
"scripts": {
"prepublish": "tsc",
Expand All @@ -20,8 +20,7 @@
},
"files": [
"bin/",
"dist/",
"!dist/test/"
"dist/src/"
],
"engines": {
"node": ">=12"
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPackFormat, getVersions, LATEST } from './index'
import { version as VERSION } from '../package.json'
const VERSION = require('../package.json').version;

const indent = (n: number): string => ' '.repeat(n * 4)
const log = function (arg: string, desc: string[], example: string): void {
Expand Down
26 changes: 20 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { VersionName, SnapshotName, PackType, FormatResult, VersionsResult } fro

// Data sets //

const LATEST = { resource: 7, data: 8 }
const LATEST = { resource: 8, data: 8 }

const START_RELEASES: Record<VersionName, Record<PackType, FormatResult>> = {
'1.6.x': { resource: 1, data: undefined },
Expand All @@ -12,7 +12,7 @@ const START_RELEASES: Record<VersionName, Record<PackType, FormatResult>> = {
'1.15.x': { resource: 5, data: 5 },
'1.16.2': { resource: 6, data: 6 },
'1.17.x': { resource: 7, data: 7 },
'1.18.x': { resource: 7, data: 8 },
'1.18.x': { resource: 8, data: 8 },
'1.19.x': { resource: undefined, data: undefined },
}

Expand All @@ -27,6 +27,7 @@ const START_SNAPSHOTS: Record<string, Record<PackType, FormatResult>> = {
'20w45a': { resource: 7, data: 6 },
'20w46a': { resource: 7, data: 7 },
'21w37a': { resource: 7, data: 8 },
'21w39a': { resource: 8, data: 8 },
[fauxCurrentSnapshot]: { resource: undefined, data: undefined },
}

Expand All @@ -36,6 +37,11 @@ const SPECIAL: Record<number, string[]> = {
6: ['combat6', 'combat7a', 'combat7b', 'combat8a', 'combat8b', 'combat8c'],
}

/**
* @param version the version to look up
* @param type the pack format type to return; either 'resource' or 'data'
* @returns the pack format for a given version
*/
function getPackFormat(version: string, type: PackType = 'resource'): FormatResult {
if (!version) return undefined
version = version.toString().toLowerCase().trim()
Expand Down Expand Up @@ -84,6 +90,12 @@ function getPackFormat(version: string, type: PackType = 'resource'): FormatResu
return undefined
}

/**
* Retrieve a list of applicable versions for a given pack format
* @param format the pack format to look up
* @param type the pack format type to return; either 'resource' or 'data'
* @returns an object containing minimum and maximum applicable release and snapshot versions
*/
function getVersions(format: number, type: PackType = 'resource'): VersionsResult {
let output: VersionsResult = {
'releases': { 'min': '', 'max': '' },
Expand All @@ -103,10 +115,12 @@ function getVersions(format: number, type: PackType = 'resource'): VersionsResul

// Min and max snapshots
const startSnaps = Object.entries(START_SNAPSHOTS)
const snapIndex = startSnaps.findIndex(([, data]) => data[type] === format)
if (snapIndex >= 0) {
const maxSnap = startSnaps[snapIndex][0]
const minSnap = startSnaps[snapIndex + 1][0].replace(/(\d)\w$/, (_, n) => `${n - 1}a`)
const snapIndices = startSnaps.flatMap((item) => item[1][type] === format ? startSnaps.indexOf(item) : [])
if (snapIndices.length) {
const minIndex = snapIndices[0]
const maxIndex = snapIndices[snapIndices.length - 1]
const maxSnap = startSnaps[minIndex][0]
const minSnap = startSnaps[maxIndex + 1][0].replace(/(\d+)\w$/, (_, n) => `${n - 1}a`)
output.snapshots.min = maxSnap as SnapshotName
output.snapshots.max = minSnap as SnapshotName
}
Expand Down
3 changes: 3 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ testPackFormat(['1.16.2 pre1'], 5)
testPackFormat(['1.16.2 pre-release 1'], 5)
testPackFormat(['1.30'], undefined)
testPackFormat(['1.16.3'], 6)
testPackFormat(['1.18'], 8)
testPackFormat(['11w50a'], undefined)
testPackFormat(['13w23a'], undefined)
testPackFormat(['13w24a'], 1)
Expand All @@ -56,6 +57,7 @@ testPackFormat(['20w46a', 'data'], 7)
testPackFormat(['21w37a'], 7)
testPackFormat(['21w37a', 'resource'], 7)
testPackFormat(['21w37a', 'data'], 8)
testPackFormat(['21w39a', 'resource'], 8)
testPackFormat(['combat3'], 4)
testPackFormat(['1.18-exp1'], 7)
testPackFormat(['1.18-es2'], 7)
Expand All @@ -64,5 +66,6 @@ testPackFormat(['1.18 experimental snapshot 3'], 7)
testVersions([3, 'data'], { 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' } })

console.log(`\nRan ${total} tests | ${passed} passed | ${failed} failed`)

0 comments on commit 1b002f2

Please sign in to comment.