Skip to content

Commit

Permalink
完成
Browse files Browse the repository at this point in the history
  • Loading branch information
DekoKiyo committed Aug 25, 2024
1 parent db9f743 commit 8e891ae
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
58 changes: 50 additions & 8 deletions JsonGenerator/src/generators/Objects/Vehicle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {
} from '../../components/ui/form';
import { Input } from '../../components/ui/input';
import { toast } from '../../components/ui/use-toast';
import { useTranslation } from 'react-i18next';
import { Trans, useTranslation } from 'react-i18next';
import format from '../../format';
import { ID_VEHICLES } from '../../store/keys';
import { createElement, ReactElement, useEffect, useState } from 'react';
import { Link } from 'react-router-dom';

export interface Vehicle {
name: string;
Expand All @@ -32,11 +33,24 @@ export const VehicleGen = () => {
const { t } = useTranslation();
const [list, setList] = useState([] as ReactElement[]);
const [index, setIndex] = useState(0);
const [updateBtnEnabled, setUpdateBtnEnabled] = useState(false);
const [deleteBtnEnabled, setDeleteBtnEnabled] = useState(false);

useEffect(() => {
updateList();
}, []);

function resetForm() {
form.resetField('name');
form.setValue('chance', 100);
form.setValue('livery', 0);
form.setValue('color', '#FFFFFF');
form.resetField('model');

setUpdateBtnEnabled(false);
setDeleteBtnEnabled(false);
}

const formSchema = z.object({
name: z.string({
required_error: t('generators.common.require')
Expand Down Expand Up @@ -101,6 +115,9 @@ export const VehicleGen = () => {
form.setValue('color', vehicle.color);
form.setValue('model', vehicle.model);
setIndex(i);

setUpdateBtnEnabled(true);
setDeleteBtnEnabled(true);
}
}
}
Expand Down Expand Up @@ -131,6 +148,7 @@ export const VehicleGen = () => {
localStorage.setItem(ID_VEHICLES, JSON.stringify([data]));
}

resetForm();
updateList();

toast({
Expand All @@ -150,6 +168,9 @@ export const VehicleGen = () => {
local[index] = data;

localStorage.setItem(ID_VEHICLES, JSON.stringify(local));

resetForm();

toast({
variant: 'default',
title: t('generators.common.saved'),
Expand Down Expand Up @@ -196,7 +217,7 @@ export const VehicleGen = () => {
<Input id="name" type="text" {...field} />
</FormControl>
<FormDescription>
This is your public display name.
{t('configurations.descriptions.preset-name')}
</FormDescription>
<FormMessage />
</FormItem>
Expand All @@ -212,7 +233,17 @@ export const VehicleGen = () => {
<Input id="chance" type="number" {...field} />
</FormControl>
<FormDescription>
This is your public display name.
<Trans
i18nKey="configurations.descriptions.chance"
components={{
l: (
<Link to="/weighted-randomization-algorithm">
{t('main.weighted-randomization-algorithm')}
</Link>
)
}}>
DESC
</Trans>
</FormDescription>
<FormMessage />
</FormItem>
Expand All @@ -228,7 +259,7 @@ export const VehicleGen = () => {
<Input id="livery" type="number" {...field} />
</FormControl>
<FormDescription>
This is your public display name.
{t('configurations.descriptions.livery')}
</FormDescription>
<FormMessage />
</FormItem>
Expand All @@ -244,7 +275,7 @@ export const VehicleGen = () => {
<Input id="color" type="color" {...field} />
</FormControl>
<FormDescription>
This is your public display name.
{t('configurations.descriptions.color')}
</FormDescription>
<FormMessage />
</FormItem>
Expand All @@ -260,7 +291,7 @@ export const VehicleGen = () => {
<Input id="model" type="text" {...field} />
</FormControl>
<FormDescription>
This is your public display name.
{t('configurations.descriptions.model')}
</FormDescription>
<FormMessage />
</FormItem>
Expand All @@ -269,6 +300,15 @@ export const VehicleGen = () => {
<Button id="submit-btn" type="submit">
Submit
</Button>
<Button
id="new-btn"
onClick={() => {
resetForm();
updateList();
}}
type="button">
New
</Button>
<Button
id="update-btn"
onClick={() => {
Expand All @@ -283,7 +323,8 @@ export const VehicleGen = () => {
onUpdate(data);
updateList();
}}
type="button">
type="button"
disabled={!updateBtnEnabled}>
Update
</Button>
<Button
Expand All @@ -292,7 +333,8 @@ export const VehicleGen = () => {
onDelete();
updateList();
}}
type="button">
type="button"
disabled={!deleteBtnEnabled}>
Delete
</Button>
</form>
Expand Down
8 changes: 7 additions & 1 deletion JsonGenerator/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"localization-status": "Localization Status",
"localization-info": "More Information",
"page-list": "Page List",
"404": "This is not the web page you are looking for."
"404": "This is not the web page you are looking for.",
"weighted-randomization-algorithm": "Weighted Randomization Algorithm"
},
"languages": {
"language": "Language",
Expand Down Expand Up @@ -111,6 +112,11 @@
"type": "Type",
"initValue": "Init value",
"descriptions": {
"preset-name": "Used to determine the preset.",
"chance": "The probability that the preset will be used. For more information: <l>Weighted Randomization Algorithm</l>",
"livery": "The vehicle's livery index. This config will be used in if it has any livery.",
"color": "The vehicle's color hash. This config will be used in if it has no livery.",
"model": "The vehicle's model name.",
"officerName": "It used in some callouts' dialogue.",
"language": "Check <l>here</l>.",
"enableAutoUpdate": "If true, the plugin updates automatically without asking.",
Expand Down
4 changes: 2 additions & 2 deletions JsonGenerator/src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@
vertical-align: top;
}

.mainContent a {
a {
text-decoration: underline;
}

.mainContent a:hover {
a:hover {
color: var(--ring);
}

Expand Down

0 comments on commit 8e891ae

Please sign in to comment.