Skip to content

Commit

Permalink
Fix#versions: Use MinecraftVersionRange
Browse files Browse the repository at this point in the history
  • Loading branch information
MMK21Hub committed Aug 20, 2023
1 parent 7109cbf commit 736c915
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ async function generateTranslationStrings(

// Remove fixes that aren't for the target version
fixes = await filter(fixes, async (fix) => {
if (!fix.versions) return true
const versions = await resolveMinecraftVersionSpecifier(fix.versions)
if (fix.versions.isUnconstrained()) return true
const versions = await fix.versions.getVersionIds()
return versions.includes(targetVersion)
})

Expand Down Expand Up @@ -472,9 +472,9 @@ export async function generateStats(
) {
async function checkVersion(fix: Fix) {
if (!versions) return true
if (!fix.versions) return true
if (fix.versions.isUnconstrained()) return true

const fixVersions = await resolveMinecraftVersionSpecifier(fix.versions)
const fixVersions = await fix.versions.getVersionIds()
return fixVersions.some((version) => versions.includes(version))
}

Expand Down
22 changes: 13 additions & 9 deletions src/classes/Fix.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
findVersionIndex,
MinecraftLanguage,
MinecraftVersionSpecifier,
resolveMinecraftVersionSpecifier,
} from "../helpers/minecraftHelpers.js"
import {
MinecraftVersionRange,
MinecraftVersionSimpleRangeTemplate,
} from "./minecraftVersions.js"
import { MultiTransformer } from "../transformers/MultiTransformer.js"
import { Transformer } from "../builder.js"
import {
Expand All @@ -21,7 +23,7 @@ export interface FixOptions {
/** A "transformer" that declares the edits that need to be made to the specified translation string. Providing an array of transformers automatically uses a {@link MultiTransformer} */
transformer: Transformer | Transformer[]
/** Specifies the versions of Minecraft that the fix should be applied to (defaults to all versions) */
versions?: MinecraftVersionSpecifier
versions?: MinecraftVersionSimpleRangeTemplate | MinecraftVersionRange
/** Specifies the languages that the fix should be applied to (defaults to all languages) */
languages?: MinecraftLanguage[]
/** References the Mojira bug report for the bug that the fix fixes */
Expand All @@ -35,7 +37,7 @@ export interface FixData extends FixOptions {
export default class Fix {
key
transformer
versions
versions: MinecraftVersionRange
languages
bug

Expand All @@ -51,15 +53,14 @@ export default class Fix {
)

// TODO: Deduplicate warnings that come from the same bug
if (!this.versions)
if (this.versions.isUnconstrained())
return console.warn(
`${this.bug} has been fixed upstream, but its fix(es) don't have version constraints.`
)

const fixVersion = fixVersions.at(-1)!
const applicableVersions = await resolveMinecraftVersionSpecifier(
this.versions
)
const applicableVersions = await this.versions.getVersionIds()

const lastApplicableVersion = applicableVersions.at(-1)
if (!lastApplicableVersion)
return new Error(`Fix#versions didn't return anything when resolved!`)
Expand Down Expand Up @@ -143,7 +144,10 @@ export default class Fix {

this.bug = options.bug
this.key = options.key
this.versions = options.versions
this.versions =
options.versions instanceof MinecraftVersionRange
? options.versions
: new MinecraftVersionRange(options.versions || [null, null])
this.languages = options.languages
}
}
8 changes: 8 additions & 0 deletions src/classes/minecraftVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export class MinecraftVersionRange {
return processedRange
}

isConstrained() {
return this.end || this.start || this.excludeRanges.length !== 0
}

isUnconstrained() {
return !this.isConstrained()
}

constructor(template: MinecraftVersionRangeTemplate) {
template = toFancyTemplate(template)
this.start = template.start
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const commandLineArg = process.argv[2]
const targetVersions: MinecraftVersionFancyRange = {
start: "23w06a",
// start: "1.19.2",
end: "23w32a",
}
// const targetVersions = "1.19.3"
// const targetVersions: StartAndEnd<string> = ["1.19.1-pre1", null]
Expand Down

0 comments on commit 736c915

Please sign in to comment.