Skip to content

Commit

Permalink
Weapon追加
Browse files Browse the repository at this point in the history
  • Loading branch information
DekoKiyo committed Aug 30, 2024
1 parent d3b5db2 commit 64e140a
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 101 deletions.
2 changes: 2 additions & 0 deletions JsonGenerator/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import PacificBankHeistGen from './generators/Callouts/PacificBankHeist';
import { VehicleGen } from './generators/Objects/Vehicle';
import { Toaster } from './components/ui/toaster';
import { PedGen } from './generators/Objects/Ped';
import { WeaponGen } from './generators/Objects/Weapon';

function App() {
return (
Expand All @@ -40,6 +41,7 @@ function App() {
/>
<Route path="/generators/vehicles" Component={VehicleGen} />
<Route path="/generators/peds" Component={PedGen} />
<Route path="/generators/weapons" Component={WeaponGen} />

{/* CALLOUTS */}
<Route path="/callouts" Component={Callouts} />
Expand Down
24 changes: 24 additions & 0 deletions JsonGenerator/src/components/ui/textarea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from "react"

import { cn } from "../../lib/utils"

export interface TextareaProps
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}

const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
({ className, ...props }, ref) => {
return (
<textarea
className={cn(
"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={ref}
{...props}
/>
)
}
)
Textarea.displayName = "Textarea"

export { Textarea }
57 changes: 5 additions & 52 deletions JsonGenerator/src/generators/Objects/Ped.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ import {
} from '../../components/ui/form';
import { Input } from '../../components/ui/input';
import { toast } from '../../components/ui/use-toast';
import { Trans, useTranslation } from 'react-i18next';
import format from '../../format';
import { useTranslation } from 'react-i18next';
import { ID_PEDS } from '../../store/keys';
import { createElement, ReactElement, useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { Switch } from '../../components/ui/switch';

export interface Ped {
name: string;
chance: number;
random_props: boolean;
health: number;
armor: number;
Expand All @@ -48,10 +45,6 @@ export const PedGen = () => {
function resetForm() {
const nameInput = document.getElementById('name-input') as HTMLInputElement;
nameInput.value = '';
const chanceInput = document.getElementById(
'chance-input'
) as HTMLInputElement;
chanceInput.value = '';
const randomPropsInput = document.getElementById(
'random_props-input'
) as HTMLInputElement;
Expand Down Expand Up @@ -90,17 +83,6 @@ export const PedGen = () => {
name: z.string({
required_error: t('generators.common.require')
}),
chance: z.coerce
.number({
message: t('generators.common.require'),
required_error: t('generators.common.require')
})
.min(0, {
message: t('generators.common.higher-than-0')
})
.max(1000, {
message: format(t('generators.common.lower-than-x'), '1000')
}),
random_props: z.coerce.boolean({
message: t('generators.common.require'),
required_error: t('generators.common.require')
Expand Down Expand Up @@ -142,7 +124,6 @@ export const PedGen = () => {
resolver: zodResolver(formSchema),
defaultValues: {
name: undefined,
chance: 100,
random_props: false,
health: 200,
armor: 200,
Expand All @@ -169,12 +150,11 @@ export const PedGen = () => {
const previous: string | null = localStorage.getItem(ID_PEDS);
if (previous) {
const local: Ped[] = JSON.parse(previous) as Ped[];
const veh: Ped | undefined = local.find(
(x) => (x.name = ped.name)
const ped: Ped | undefined = local.find(
(x) => x.name === ped?.name
);
if (veh) {
if (ped) {
form.setValue('name', ped.name);
form.setValue('chance', ped.chance);
form.setValue('random_props', ped.random_props);
form.setValue('health', ped.health);
form.setValue('armor', ped.armor);
Expand Down Expand Up @@ -202,7 +182,7 @@ export const PedGen = () => {
const previous: string | null = localStorage.getItem(ID_PEDS);
if (previous) {
const local: Ped[] = JSON.parse(previous);
if (local.filter((veh) => veh.name == data.name).length > 0) {
if (local.filter((ped) => ped.name == data.name).length > 0) {
toast({
variant: 'destructive',
title: t('generators.common.warn.exist-name'),
Expand Down Expand Up @@ -291,32 +271,6 @@ export const PedGen = () => {
</FormItem>
)}
/>
<FormField
control={form.control}
name="chance"
render={({ field }) => (
<FormItem>
<FormLabel>Chance</FormLabel>
<FormControl>
<Input id="chance-input" type="number" {...field} />
</FormControl>
<FormDescription>
<Trans
i18nKey="configurations.descriptions.chance"
components={{
l: (
<Link to="/weighted-randomization-algorithm">
{t('main.weighted-randomization-algorithm')}
</Link>
)
}}>
DESC
</Trans>
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="random_props"
Expand Down Expand Up @@ -470,7 +424,6 @@ export const PedGen = () => {
onClick={() => {
const data: Ped = {
name: form.getValues('name'),
chance: Number(form.getValues('chance')),
random_props: Boolean(form.getValues('random_props')),
health: Number(form.getValues('health')),
armor: Number(form.getValues('armor')),
Expand Down
49 changes: 1 addition & 48 deletions JsonGenerator/src/generators/Objects/Vehicle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ import {
} from '../../components/ui/form';
import { Input } from '../../components/ui/input';
import { toast } from '../../components/ui/use-toast';
import { Trans, useTranslation } from 'react-i18next';
import format from '../../format';
import { useTranslation } from 'react-i18next';
import { ID_VEHICLES } from '../../store/keys';
import { createElement, ReactElement, useEffect, useState } from 'react';
import { Link } from 'react-router-dom';

export interface Vehicle {
name: string;
chance: number;
livery: number;
color: string;
model: string;
Expand All @@ -43,10 +40,6 @@ export const VehicleGen = () => {
function resetForm() {
const nameInput = document.getElementById('name-input') as HTMLInputElement;
nameInput.value = '';
const chanceInput = document.getElementById(
'chance-input'
) as HTMLInputElement;
chanceInput.value = '';
const liveryInput = document.getElementById(
'livery-input'
) as HTMLInputElement;
Expand All @@ -65,17 +58,6 @@ export const VehicleGen = () => {
name: z.string({
required_error: t('generators.common.require')
}),
chance: z.coerce
.number({
message: t('generators.common.require'),
required_error: t('generators.common.require')
})
.min(0, {
message: t('generators.common.higher-than-0')
})
.max(1000, {
message: format(t('generators.common.lower-than-x'), '1000')
}),
livery: z.coerce
.number({
message: t('generators.common.require'),
Expand All @@ -94,7 +76,6 @@ export const VehicleGen = () => {
resolver: zodResolver(formSchema),
defaultValues: {
name: undefined,
chance: 100,
livery: 0,
color: '#FFFFFF',
model: undefined
Expand Down Expand Up @@ -123,7 +104,6 @@ export const VehicleGen = () => {
);
if (veh) {
form.setValue('name', vehicle.name);
form.setValue('chance', vehicle.chance);
form.setValue('livery', vehicle.livery);
form.setValue('color', vehicle.color);
form.setValue('model', vehicle.model);
Expand Down Expand Up @@ -236,32 +216,6 @@ export const VehicleGen = () => {
</FormItem>
)}
/>
<FormField
control={form.control}
name="chance"
render={({ field }) => (
<FormItem>
<FormLabel>Chance</FormLabel>
<FormControl>
<Input id="chance-input" type="number" {...field} />
</FormControl>
<FormDescription>
<Trans
i18nKey="configurations.descriptions.chance"
components={{
l: (
<Link to="/weighted-randomization-algorithm">
{t('main.weighted-randomization-algorithm')}
</Link>
)
}}>
DESC
</Trans>
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="livery"
Expand Down Expand Up @@ -327,7 +281,6 @@ export const VehicleGen = () => {
onClick={() => {
const data: Vehicle = {
name: form.getValues('name'),
chance: Number(form.getValues('chance')),
livery: Number(form.getValues('livery')),
color: form.getValues('color'),
model: form.getValues('model')
Expand Down
Loading

0 comments on commit 64e140a

Please sign in to comment.