Skip to content

Commit

Permalink
-- complete Event, fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ichirukyn committed Jan 13, 2024
1 parent a5147b7 commit 0393a16
Show file tree
Hide file tree
Showing 25 changed files with 667 additions and 42 deletions.
7 changes: 7 additions & 0 deletions src/app/router/RouterPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const pathBase = {
hero: '/hero',
item: '/item',
map: '/map',
event: '/event',
}

export const pathRoutes = {
Expand Down Expand Up @@ -38,4 +39,10 @@ export const pathRoutes = {
create: `${ pathBase.map }/create`,
application: `${ pathBase.map }/application`,
},
event: {
base: `${ pathBase.event }`,
edit: `${ pathBase.event }/edit`,
create: `${ pathBase.event }/create`,
application: `${ pathBase.event }/application`,
},
}
20 changes: 20 additions & 0 deletions src/app/router/Routers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import ItemCreate from "@/pages/item/ItemCreate";
import ItemEdit from "@/pages/item/ItemEdit";
import EnemyCreate from "@/pages/enemy/EnemyCreate";
import EnemyEdit from "@/pages/enemy/EnemyEdit";
import EventEdit from "@/pages/event/EventEdit";
import EventCreate from "@/pages/event/EventCreate";
import EventList from "@/pages/event/EventList";


export const Routers = [
Expand Down Expand Up @@ -81,6 +84,23 @@ export const Routers = [
Layout: Default,
},

// Event
{
path: pathRoutes.event.base,
Component: EventList,
Layout: Default,
},
{
path: pathRoutes.event.create,
Component: EventCreate,
Layout: Default,
},
{
path: `${ pathRoutes.event.edit }/:id`,
Component: EventEdit,
Layout: Default,
},

// Map
{
path: pathRoutes.map.base,
Expand Down
14 changes: 14 additions & 0 deletions src/pages/event/EventCreate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FC } from 'react';
import EventForm from "@/widgets/Event/EventForm";

const EventCreate: FC = () => {
return (
<div className='main__block block_column p_40 w_100p'>
<h3 className='mb_30'>Создания события</h3>

<EventForm/>
</div>
);
};

export default EventCreate;
17 changes: 17 additions & 0 deletions src/pages/event/EventEdit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FC } from 'react';
import EventForm from "@/widgets/Event/EventForm";
import { useParams } from "react-router-dom";

const EventEdit: FC = () => {
const { id } = useParams()

return (
<div className='main__block block_column p_40 w_100p'>
<h3 className='mb_30'>Редактирование события</h3>

<EventForm id={ id ? Number(id) : undefined }/>
</div>
);
};

export default EventEdit;
32 changes: 32 additions & 0 deletions src/pages/event/EventList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { FC, useEffect, useState } from 'react';
import Table from "@/shared/ui/Table/Table";
import { EventColumn } from "@/widgets";
import { Link } from "react-router-dom";
import { pathRoutes } from "@/app";
import { EventType } from "@/shared/types";
import { fetchAllEvent } from "@/shared/api/event";

const EventList: FC = () => {
const [eventList, setEventList] = useState<EventType[] | []>([])

useEffect(() => {
fetchAllEvent().then((res) => {
setEventList(res.data)
})
}, []);

return (
<div className='main__block block_column p_40 w_100p'>
<h3 className='mb_30'>Список событий</h3>
<Table rows={ eventList } columns={ EventColumn } style={ { isHeader: true } }/>

<div className="block_row justify-end w_100p mt_10">
<Link to={ pathRoutes.event.create }>
<button className='button'>Создать</button>
</Link>
</div>
</div>
);
};

export default EventList;
3 changes: 3 additions & 0 deletions src/pages/event/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './EventCreate'
export * from './EventEdit'
export * from './EventList'
2 changes: 2 additions & 0 deletions src/pages/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const Home: FC = () => {
<Link to={ pathRoutes.hero.base } className='td_underline tab_active text_title'>Игроки</Link>
<Link to={ pathRoutes.enemy.base } className='td_underline tab_active text_title'>Противники</Link>
<Link to={ pathRoutes.item.base } className='td_underline tab_active text_title'>Предметы</Link>
<Link to={ pathRoutes.event.base } className='td_underline tab_active text_title'>События</Link>

<br/>
<p className='text_title'>(Ниже в разработке)</p>
<Link to={ pathRoutes.map.base } className='td_underline tab_active text_title'>Карта</Link>
Expand Down
1 change: 1 addition & 0 deletions src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './enemy'
export * from './event'
export * from './hero'
export * from './home'
export * from './item'
Expand Down
37 changes: 37 additions & 0 deletions src/shared/api/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AxiosResponse } from "axios";
import { EventType } from "@/shared/types";
import axiosInstance from "@/shared/api/axios";

export const fetchAllEvent = async () => {
const response: AxiosResponse<EventType[]> = await axiosInstance.get(
`/event`,
)

return response
}

export const fetchOneEvent = async (event_id: number) => {
const response: AxiosResponse<EventType> = await axiosInstance.get(
`/event/${ event_id }`,
)

return response
}

export const createEvent = async (event: EventType) => {
const response: AxiosResponse<EventType> = await axiosInstance.post(
`/event`,
{ ...event },
)

return response
}

export const updateEvent = async (event: EventType, event_id: number) => {
const response: AxiosResponse<EventType> = await axiosInstance.put(
`/event/${ event_id }`,
{ ...event },
)

return response
}
46 changes: 45 additions & 1 deletion src/shared/api/item.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AxiosResponse } from "axios";
import { ItemType } from "@/shared/types";
import { EventTriggerType, ItemType } from "@/shared/types";
import axiosInstance from "@/shared/api/axios";

export const fetchAllItem = async () => {
Expand Down Expand Up @@ -35,3 +35,47 @@ export const updateItem = async (item: ItemType, item_id: number) => {

return response
}


// Trigger
export const fetchAllEventTrigger = async (event_id: number) => {
const response: AxiosResponse<EventTriggerType[]> = await axiosInstance.get(
`/event/${ event_id }/trigger`,
)

return response
}

export const fetchOneEventTrigger = async (event_id: number, trigger_id: number) => {
const response: AxiosResponse<EventTriggerType> = await axiosInstance.get(
`/event/${ event_id }/trigger/${ trigger_id }`,
)

return response
}

export const createEventTrigger = async (event: EventTriggerType, event_id: number) => {
const response: AxiosResponse<EventTriggerType> = await axiosInstance.post(
`/event/${ event_id }/trigger`,
{ ...event },
)

return response
}

export const updateEventTrigger = async (event: EventTriggerType, event_id: number, trigger_id: number) => {
const response: AxiosResponse<EventTriggerType> = await axiosInstance.put(
`/event/${ event_id }/trigger/${ trigger_id }`,
{ ...event },
)

return response
}

export const deleteEventTrigger = async (event_id: number, trigger_id: number) => {
const response: AxiosResponse<boolean> = await axiosInstance.delete(
`/event/${ event_id }/trigger/${ trigger_id }`
)

return response
}
26 changes: 26 additions & 0 deletions src/shared/types/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export type EventType = {
id?: number;
name: string;
desc: string;
text?: string;
keyboard?: string;
state?: string;
type: string;
}

export type EventTriggerType = {
id?: number;
event_id?: number;
name: string;
desc?: string;
condition_attr?: string;
condition?: string;
condition_value?: number;
condition_item?: number;
chance?: number;
trigger_type?: string;
text?: string;
reward?: string;
mandatory?: boolean;
hidden?: boolean;
}
1 change: 1 addition & 0 deletions src/shared/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './class'
export * from './enemy'
export * from './event'
export * from './item'
export * from './hero'
export * from './race'
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/Effect/Effect.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export const EffectConstants = {
{ value: 'prev_view', label: 'Разное:', disabled: true },
{ value: 'prev', label: 'Прошлое значение' },
{ value: 'prev_percent', label: 'Прошлый процент' },
{ value: 'total_stats', label: 'Всего ОС' },
{ value: 'lvl', label: 'Уровень' },
],
condition: [
{ value: '>', label: 'Больше' },
Expand Down
27 changes: 11 additions & 16 deletions src/widgets/Effect/EffectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,17 @@ const EffectForm: FC<IEffectCreateProps> = ({ update_data, index, defaultData, e
<MenuItem key={ value } value={ value } disabled={ disabled || false }>{ label }</MenuItem>
))
)
: (
EffectConstants.attribute.map(({ label, value, disabled }) => (
<MenuItem key={ value } value={ value } disabled={ disabled || false }>{ label }</MenuItem>
))
)
}
{ type === 'control'
? (
EffectConstants.control.map(({ label, value, disabled }) => (
<MenuItem key={ value } value={ value } disabled={ disabled || false }>{ label }</MenuItem>
))
) : (
EffectConstants.attribute.map(({ label, value, disabled }) => (
<MenuItem key={ value } value={ value } disabled={ disabled || false }>{ label }</MenuItem>
))
)
:
type === 'control'
? (
EffectConstants.control.map(({ label, value, disabled }) => (
<MenuItem key={ value } value={ value } disabled={ disabled || false }>{ label }</MenuItem>
))
) : (
EffectConstants.attribute.map(({ label, value, disabled }) => (
<MenuItem key={ value } value={ value } disabled={ disabled || false }>{ label }</MenuItem>
))
)
}
</Select>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/widgets/Enemy/EnemyWeaponForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const EnemyWeaponForm: FC<IEnemyWeaponFormProps> = ({ weapon, updateWeapon }) =>
<Controller control={ control } name='weapon_id' defaultValue={ 1 } render={ ({ field }) => (
<div className="block_row align-start justify-between gap_15 w_100p mt_10">
<Select className='w_100p' value={ field.value } onChange={ field.onChange }>
<MenuItem value={ 0 } disabled>Любой класс</MenuItem>
{ weaponList.map(({ id, name }) => (
<MenuItem value={ id } key={ id }>{ name }</MenuItem>
)) }
Expand Down
15 changes: 15 additions & 0 deletions src/widgets/Event/Event.column.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { GridColDef } from "@mui/x-data-grid";
import { Link } from "react-router-dom";
import { pathRoutes } from "@/app";

export const EventColumn: GridColDef[] = [
{ field: 'id', minWidth: 60, maxWidth: 60 },
{
field: 'name', minWidth: 180, flex: 1, renderCell: ({ row, formattedValue }) => {
return <Link to={ `${ pathRoutes.event.edit }/${ row.id }` } className='td_underline'>{ formattedValue }</Link>
}
},
{ field: 'desc', minWidth: 180, flex: 1 },
{ field: 'text', minWidth: 180, flex: 1 },
{ field: 'type', minWidth: 120 },
]
20 changes: 20 additions & 0 deletions src/widgets/Event/Event.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { EffectConstants } from "@/widgets";

export const EventConstants = {
type: [
{ value: 'quest', label: 'Квест' },
{ value: 'battle', label: 'Сражение' },
{ value: 'boss', label: 'Босс' },
],
trigger_type: [
{ value: 'start', label: 'Условие начала' },
{ value: 'condition', label: 'Условие выполнения' },
],
attribute: [
{ value: 'race_id', label: 'Раса (По id)' },
{ value: 'class_id', label: 'Класс (По id)' },

{ value: 'mana_view', label: 'Мана:', disabled: true },
...EffectConstants.attribute,
],
}
25 changes: 25 additions & 0 deletions src/widgets/Event/Event.schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { boolean, number, object, string } from "yup";

export const EventCreateScheme = object().shape({
name: string().required('Введите название'),
desc: string().required('Введите описание'),
text: string().optional(),
keyboard: string().nullable(),
state: string().nullable(),
type: string().required('Выберите тип'),
})

export const EventTriggerCreateScheme = object().shape({
name: string().required('Введите название'),
desc: string().required('Введите описание'),
condition_attr: string().optional(),
condition: string().optional(),
condition_value: number().optional(),
condition_item: number().optional(),
chance: number().optional(),
trigger_type: string().required('Выберите тип'),
text: string().optional(),
reward: string().optional(),
mandatory: boolean().default(false),
hidden: boolean().default(false),
})
Loading

0 comments on commit 0393a16

Please sign in to comment.