Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed minecraft flavour types #162

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/bindings/FabricInstallerVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type FabricInstallerVersion = string;
3 changes: 3 additions & 0 deletions src/bindings/FabricLoaderVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type FabricLoaderVersion = string;
3 changes: 3 additions & 0 deletions src/bindings/ForgeBuildVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type ForgeBuildVersion = string;
16 changes: 15 additions & 1 deletion src/bindings/MinecraftFlavour.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { FabricInstallerVersion } from './FabricInstallerVersion';
import type { FabricLoaderVersion } from './FabricLoaderVersion';
import type { ForgeBuildVersion } from './ForgeBuildVersion';
import type { PaperBuildVersion } from './PaperBuildVersion';

export type MinecraftFlavour = 'vanilla' | 'fabric' | 'paper' | 'spigot';
export type MinecraftFlavour =
| 'vanilla'
| {
fabric: {
loader_version: FabricLoaderVersion | null;
installer_version: FabricInstallerVersion | null;
};
}
| { paper: { build_version: PaperBuildVersion | null } }
| 'spigot'
| { forge: { build_version: ForgeBuildVersion | null } };
3 changes: 3 additions & 0 deletions src/bindings/PaperBuildVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type PaperBuildVersion = bigint;
19 changes: 19 additions & 0 deletions src/bindings/impl/FlavourStringToMinecraftFlavour.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MinecraftFlavour } from 'bindings/MinecraftFlavour';

export function flavourStringToMinecraftFlavour(
flavour: string
): MinecraftFlavour {
switch (flavour.toLowerCase()) {
case 'vanilla':
return 'vanilla';
case 'fabric':
return { fabric: { loader_version: null, installer_version: null } };
case 'paper':
return { paper: { build_version: null } };
case 'spigot':
return 'spigot';
case 'forge':
return { forge: { build_version: null } };
}
throw new Error(`Unknown flavour: ${flavour}`);
}
10 changes: 3 additions & 7 deletions src/components/Minecraft/Create/MinecraftBasicForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { MinecraftFlavour } from 'bindings/MinecraftFlavour';
import { MinecraftVersions } from 'bindings/MinecraftVersions';
import ComboField from 'components/Atoms/Form/ComboField';
import InputField from 'components/Atoms/Form/InputField';
Expand All @@ -10,12 +9,9 @@ import { MinecraftSetupConfigPrimitiveForm } from './form';

export default function MinecraftBasicForm() {
const { data: minecraftFlavours, isLoading: minecraftFlavoursLoading } =
useQuery<MinecraftFlavour[]>(['minecraft', 'flavours'], () =>
axios.get('/games/minecraft/flavours').then((res) => {
// sort by name
return res.data.sort((a: MinecraftFlavour, b: MinecraftFlavour) => {
return a.localeCompare(b);
});
useQuery<string[]>(['minecraft', 'flavours'], () =>
axios.get<Array<string>>('/games/minecraft/flavours').then((res) => {
return res.data;
})
);

Expand Down
3 changes: 2 additions & 1 deletion src/components/Minecraft/MinecraftCreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import MinecraftAdvancedForm from './Create/MinecraftAdvancedForm';
import MinecraftBasicForm from './Create/MinecraftBasicForm';
import MinecraftNameForm from './Create/MinecraftNameForm';
import { flavourStringToMinecraftFlavour } from 'bindings/impl/FlavourStringToMinecraftFlavour';

function _renderStepContent(step: number) {
switch (step) {
Expand Down Expand Up @@ -61,7 +62,7 @@ export default function CreateMinecraftInstance({
) {
const parsedValues: MinecraftSetupConfigPrimitive = {
...values,
flavour: values.flavour as MinecraftFlavour,
flavour: flavourStringToMinecraftFlavour(values.flavour),
cmd_args: values.cmd_args.split(' ').filter((item) => item !== ''),
auto_start: values.auto_start === 'true',
restart_on_crash: values.restart_on_crash === 'true',
Expand Down