mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-25 01:41:05 -05:00
Made enum for Minecraft version types
This commit is contained in:
parent
40ffa003d6
commit
59e9693705
1 changed files with 95 additions and 0 deletions
95
src/games/minecraft/minecraft-version-type.ts
Normal file
95
src/games/minecraft/minecraft-version-type.ts
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
import { VersionType } from "@/utils/versioning";
|
||||||
|
import { Enum, EnumOptions } from "@/utils/enum";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents Minecraft version types.
|
||||||
|
*
|
||||||
|
* @partial
|
||||||
|
*/
|
||||||
|
enum MinecraftVersionTypeValues {
|
||||||
|
/**
|
||||||
|
* Represents the release version type of Minecraft.
|
||||||
|
*/
|
||||||
|
RELEASE = "release",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the snapshot version type of Minecraft.
|
||||||
|
*/
|
||||||
|
SNAPSHOT = "snapshot",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the old beta version type of Minecraft.
|
||||||
|
*/
|
||||||
|
OLD_BETA = "old_beta",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the old alpha version type of Minecraft.
|
||||||
|
*/
|
||||||
|
OLD_ALPHA = "old_alpha",
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for configuring the behavior of the MinecraftVersionType enum.
|
||||||
|
*
|
||||||
|
* @partial
|
||||||
|
*/
|
||||||
|
const MinecraftVersionTypeOptions: EnumOptions = {
|
||||||
|
/**
|
||||||
|
* The case should be ignored while parsing the version type.
|
||||||
|
*/
|
||||||
|
ignoreCase: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non-word characters should be ignored while parsing the version type.
|
||||||
|
*/
|
||||||
|
ignoreNonWordCharacters: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a `MinecraftVersionType` value to a corresponding `VersionType` value.
|
||||||
|
*
|
||||||
|
* @param type - The Minecraft version type to convert.
|
||||||
|
* @param version - The Minecraft version string, used for additional checks when the type is `Snapshot`.
|
||||||
|
*
|
||||||
|
* @returns The corresponding `VersionType` value.
|
||||||
|
*/
|
||||||
|
function toVersionType(type: MinecraftVersionType, version?: string): VersionType {
|
||||||
|
switch (type) {
|
||||||
|
case MinecraftVersionType.SNAPSHOT:
|
||||||
|
return version?.match(/-pre|-rc|-beta|Pre-[Rr]elease|[Rr]elease Candidate/)
|
||||||
|
? VersionType.BETA
|
||||||
|
: VersionType.ALPHA;
|
||||||
|
|
||||||
|
case MinecraftVersionType.OLD_BETA:
|
||||||
|
return VersionType.BETA;
|
||||||
|
|
||||||
|
case MinecraftVersionType.OLD_ALPHA:
|
||||||
|
return VersionType.ALPHA;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return VersionType.RELEASE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collection of methods to work with MinecraftVersionType.
|
||||||
|
*
|
||||||
|
* @partial
|
||||||
|
*/
|
||||||
|
const MinecraftVersionTypeMethods = {
|
||||||
|
toVersionType,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents Minecraft version types.
|
||||||
|
*/
|
||||||
|
export const MinecraftVersionType = Enum.create(
|
||||||
|
MinecraftVersionTypeValues,
|
||||||
|
MinecraftVersionTypeOptions,
|
||||||
|
MinecraftVersionTypeMethods,
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents Minecraft version types.
|
||||||
|
*/
|
||||||
|
export type MinecraftVersionType = Enum<typeof MinecraftVersionTypeValues>;
|
Loading…
Reference in a new issue