Wrap MinecraftVersion in its own object.
This commit is contained in:
30
src/util/MinecraftVersion.ts
Normal file
30
src/util/MinecraftVersion.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export class MinecraftVersion {
|
||||
|
||||
private static readonly MINECRAFT_VERSION_REGEX = /(\d+).(\d+).(\d+)/
|
||||
|
||||
private readonly major: number
|
||||
private readonly minor: number
|
||||
private readonly revision: number
|
||||
|
||||
constructor(version: string) {
|
||||
const res = MinecraftVersion.MINECRAFT_VERSION_REGEX.exec(version)
|
||||
if(res != null) {
|
||||
this.major = Number(res[1])
|
||||
this.minor = Number(res[2])
|
||||
this.revision = Number(res[3])
|
||||
} else {
|
||||
throw new Error(`${version} is not a valid minecraft version!`)
|
||||
}
|
||||
}
|
||||
|
||||
public static isMinecraftVersion(version: string): boolean {
|
||||
return MinecraftVersion.MINECRAFT_VERSION_REGEX.test(version)
|
||||
}
|
||||
|
||||
public getMajor(): number { return this.major }
|
||||
public getMinor(): number { return this.minor }
|
||||
public getRevision(): number { return this.revision }
|
||||
|
||||
public toString(): string { return `${this.major}.${this.minor}.${this.revision}`}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { MinecraftVersion } from './MinecraftVersion'
|
||||
|
||||
export interface VersionSegmented {
|
||||
|
||||
isForVersion(version: string): boolean
|
||||
isForVersion(version: MinecraftVersion): boolean
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { ForgeModStructure113 } from '../model/struct/model/module/forgemod/forgemod113.struct'
|
||||
import { ForgeModStructure17 } from '../model/struct/model/module/forgemod/forgemod17.struct'
|
||||
import { Forge113Adapter } from '../resolver/forge/adapter/forge113.resolver'
|
||||
import { Forge17Adapter } from '../resolver/forge/adapter/forge17.resolver'
|
||||
import { ForgeGradle3Adapter } from '../resolver/forge/adapter/ForgeGradle3.resolver'
|
||||
import { ForgeGradle2Adapter } from '../resolver/forge/adapter/ForgeGradle2.resolver'
|
||||
import { ForgeResolver } from '../resolver/forge/forge.resolver'
|
||||
import { BaseForgeModStructure } from '../model/struct/model/module/forgemod.struct'
|
||||
import { MinecraftVersion } from './MinecraftVersion'
|
||||
|
||||
export class VersionSegmentedRegistry {
|
||||
|
||||
public static readonly FORGE_ADAPTER_IMPL = [
|
||||
Forge17Adapter,
|
||||
Forge113Adapter
|
||||
ForgeGradle2Adapter,
|
||||
ForgeGradle3Adapter
|
||||
]
|
||||
|
||||
public static readonly FORGEMOD_STRUCT_IML = [
|
||||
@@ -18,7 +19,7 @@ export class VersionSegmentedRegistry {
|
||||
]
|
||||
|
||||
public static getForgeResolver(
|
||||
minecraftVersion: string,
|
||||
minecraftVersion: MinecraftVersion,
|
||||
forgeVersion: string,
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
@@ -33,7 +34,7 @@ export class VersionSegmentedRegistry {
|
||||
}
|
||||
|
||||
public static getForgeModStruct(
|
||||
minecraftVersion: string,
|
||||
minecraftVersion: MinecraftVersion,
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
baseUrl: string
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Axios from 'axios'
|
||||
import { PromotionsSlim } from '../model/forge/promotionsslim'
|
||||
import { MinecraftVersion } from './MinecraftVersion'
|
||||
|
||||
export class VersionUtil {
|
||||
|
||||
@@ -10,28 +11,9 @@ export class VersionUtil {
|
||||
|
||||
public static readonly MINECRAFT_VERSION_REGEX = /(\d+).(\d+).(\d+)/
|
||||
|
||||
public static isMinecraftVersion(version: string): boolean {
|
||||
return VersionUtil.MINECRAFT_VERSION_REGEX.test(version)
|
||||
}
|
||||
|
||||
public static getMinecraftVersionComponents(version: string): { major: number, minor: number, revision: number } {
|
||||
if (VersionUtil.isMinecraftVersion(version)) {
|
||||
const result = VersionUtil.MINECRAFT_VERSION_REGEX.exec(version)
|
||||
if (result != null) {
|
||||
return {
|
||||
major: Number(result[1]),
|
||||
minor: Number(result[2]),
|
||||
revision: Number(result[3])
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error(`${version} is not a valid minecraft version!`)
|
||||
}
|
||||
|
||||
public static isVersionAcceptable(version: string, acceptable: number[]): boolean {
|
||||
const versionComponents = VersionUtil.getMinecraftVersionComponents(version)
|
||||
if (versionComponents != null && versionComponents.major === 1) {
|
||||
return acceptable.find((element) => versionComponents.minor === element) != null
|
||||
public static isVersionAcceptable(version: MinecraftVersion, acceptable: number[]): boolean {
|
||||
if (version.getMajor() === 1) {
|
||||
return acceptable.find((element) => version.getMinor() === element) != null
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -49,12 +31,12 @@ export class VersionUtil {
|
||||
return response.data as PromotionsSlim
|
||||
}
|
||||
|
||||
public static getPromotedVersionStrict(index: PromotionsSlim, minecraftVersion: string, promotion: string): string {
|
||||
public static getPromotedVersionStrict(index: PromotionsSlim, minecraftVersion: MinecraftVersion, promotion: string): string {
|
||||
const workingPromotion = promotion.toLowerCase()
|
||||
return index.promos[`${minecraftVersion}-${workingPromotion}`]
|
||||
}
|
||||
|
||||
public static async getPromotedForgeVersion(minecraftVersion: string, promotion: string): Promise<string> {
|
||||
public static async getPromotedForgeVersion(minecraftVersion: MinecraftVersion, promotion: string): Promise<string> {
|
||||
const workingPromotion = promotion.toLowerCase()
|
||||
const res = await VersionUtil.getPromotionIndex()
|
||||
let version = res.promos[`${minecraftVersion}-${workingPromotion}`]
|
||||
|
||||
Reference in New Issue
Block a user