Skip to content

Commit

Permalink
Use same form for creating and editing matches
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Nov 15, 2023
1 parent 435d1d2 commit 7f58627
Show file tree
Hide file tree
Showing 16 changed files with 1,189 additions and 902 deletions.
5 changes: 2 additions & 3 deletions backend/src/configController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Controller, Get, NoSecurity, Route, Security } from '@tsoa/runtime';
import { TMT_LOG_ADDRESS } from '.';
import { IConfig } from '../../common/types/config';

@Route('/api/config')
@Security('bearer_token')
Expand All @@ -9,9 +10,7 @@ export class ConfigController extends Controller {
*/
@Get()
@NoSecurity()
async getConfig(): Promise<{
tmtLogAddress: string | null;
}> {
async getConfig(): Promise<IConfig> {
return {
tmtLogAddress: TMT_LOG_ADDRESS,
};
Expand Down
2 changes: 1 addition & 1 deletion backend/src/election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const create = (
/**
* @throws if configuration is invalid
*/
const checkValidConfiguration = (
export const checkValidConfiguration = (
mapPool: string[],
steps: Array<IElectionStepAdd | IElectionStepSkip>
) => {
Expand Down
1 change: 1 addition & 0 deletions backend/src/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ export const update = async (match: Match, dto: IMatchUpdateDto) => {
}

if (dto.electionSteps) {
Election.checkValidConfiguration(match.data.mapPool, dto.electionSteps);
match.data.electionSteps = dto.electionSteps;
}

Expand Down
157 changes: 156 additions & 1 deletion backend/src/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,169 @@ import { IPreset, IPresetCreateDto, IPresetUpdateDto } from '../../common/types/
import * as Storage from './storage';

const FILE_NAME = 'presets.json';
const DEFAULT_PRESETS: IPreset[] = [
{
id: 'rUqWHsdPuA1pCqEfseVpRn',
name: '5on5 Competitive',
data: {
teamA: {
name: 'Team A',
advantage: 0,
},
teamB: {
name: 'Team B',
advantage: 0,
},
gameServer: null,
mapPool: [
'de_ancient',
'de_anubis',
'de_inferno',
'de_mirage',
'de_nuke',
'de_overpass',
'de_vertigo',
],
electionSteps: [
{
map: {
mode: 'BAN',
who: 'TEAM_A',
},
},
{
map: {
mode: 'BAN',
who: 'TEAM_B',
},
},
{
map: {
mode: 'BAN',
who: 'TEAM_A',
},
},
{
map: {
mode: 'BAN',
who: 'TEAM_B',
},
},
{
map: {
mode: 'BAN',
who: 'TEAM_A',
},
},
{
map: {
mode: 'BAN',
who: 'TEAM_B',
},
},
{
map: {
mode: 'RANDOM_PICK',
},
side: {
mode: 'KNIFE',
},
},
],
rconCommands: {
init: [
'game_type 0; game_mode 1; sv_game_mode_flags 0; sv_skirmish_id 0',
'say > RCON INIT LOADED <',
],
knife: [
'mp_give_player_c4 0; mp_startmoney 0; mp_ct_default_secondary ""; mp_t_default_secondary ""',
'say > SPECIAL KNIFE CONFIG LOADED <',
],
match: [
'mp_give_player_c4 1; mp_startmoney 800; mp_ct_default_secondary "weapon_hkp2000"; mp_t_default_secondary "weapon_glock"',
'mp_overtime_enable 1',
'say > MATCH CONFIG LOADED <',
],
end: ['say > MATCH END RCON LOADED <'],
},
matchEndAction: 'NONE',
mode: 'SINGLE',
canClinch: true,
},
},
{
id: '5yNVDnvcFHzVRaMnpjLYMv',
name: '2on2 Wingman',
data: {
teamA: {
name: 'Team A',
advantage: 0,
},
teamB: {
name: 'Team B',
advantage: 0,
},
gameServer: null,
mapPool: ['de_inferno', 'de_nuke', 'de_overpass', 'de_vertigo'],
electionSteps: [
{
map: {
mode: 'BAN',
who: 'TEAM_A',
},
},
{
map: {
mode: 'BAN',
who: 'TEAM_B',
},
},
{
map: {
mode: 'BAN',
who: 'TEAM_A',
},
},
{
map: {
mode: 'RANDOM_PICK',
},
side: {
mode: 'PICK',
who: 'TEAM_B',
},
},
],
rconCommands: {
init: [
'game_type 0; game_mode 1; sv_game_mode_flags 0; sv_skirmish_id 0',
'say > RCON INIT LOADED <',
],
knife: [
'mp_give_player_c4 0; mp_startmoney 0; mp_ct_default_secondary ""; mp_t_default_secondary ""',
'say > SPECIAL KNIFE CONFIG LOADED <',
],
match: [
'mp_give_player_c4 1; mp_startmoney 800; mp_ct_default_secondary "weapon_hkp2000"; mp_t_default_secondary "weapon_glock"',
'mp_overtime_enable 1',
'say > MATCH CONFIG LOADED <',
],
end: ['say > MATCH END RCON LOADED <'],
},
matchEndAction: 'NONE',
mode: 'SINGLE',
canClinch: true,
},
},
];
const presets = new Map<string, IPreset>();

const write = async () => {
await Storage.write(FILE_NAME, Array.from(presets.values()));
};

export const setup = async () => {
const data = await Storage.read(FILE_NAME, [] as IPreset[]);
const data = await Storage.read(FILE_NAME, DEFAULT_PRESETS);
data.forEach((preset) => presets.set(preset.id, preset));
};

Expand Down
12 changes: 12 additions & 0 deletions backend/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,18 @@ const models: TsoaRoute.Models = {
additionalProperties: false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
IConfig: {
dataType: 'refObject',
properties: {
tmtLogAddress: {
dataType: 'union',
subSchemas: [{ dataType: 'string' }, { dataType: 'enum', enums: [null] }],
required: true,
},
},
additionalProperties: false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
};
const validationService = new ValidationService(models);

Expand Down
24 changes: 14 additions & 10 deletions backend/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,19 @@
],
"type": "object",
"additionalProperties": false
},
"IConfig": {
"properties": {
"tmtLogAddress": {
"type": "string",
"nullable": true
}
},
"required": [
"tmtLogAddress"
],
"type": "object",
"additionalProperties": false
}
},
"securitySchemes": {
Expand Down Expand Up @@ -3104,16 +3117,7 @@
"content": {
"application/json": {
"schema": {
"properties": {
"tmtLogAddress": {
"type": "string",
"nullable": true
}
},
"required": [
"tmtLogAddress"
],
"type": "object"
"$ref": "#/components/schemas/IConfig"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions common/types/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IConfig {
tmtLogAddress: string | null;
}
28 changes: 28 additions & 0 deletions frontend/src/assets/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,31 @@ export const SvgSettings: Component<ComponentProps<'svg'>> = (props) => (
<path d="M19.43 12.98c.04-.32.07-.64.07-.98 0-.34-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.09-.16-.26-.25-.44-.25-.06 0-.12.01-.17.03l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.06-.02-.12-.03-.18-.03-.17 0-.34.09-.43.25l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98 0 .33.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.09.16.26.25.44.25.06 0 .12-.01.17-.03l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.06.02.12.03.18.03.17 0 .34-.09.43-.25l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zm-1.98-1.71c.04.31.05.52.05.73 0 .21-.02.43-.05.73l-.14 1.13.89.7 1.08.84-.7 1.21-1.27-.51-1.04-.42-.9.68c-.43.32-.84.56-1.25.73l-1.06.43-.16 1.13-.2 1.35h-1.4l-.19-1.35-.16-1.13-1.06-.43c-.43-.18-.83-.41-1.23-.71l-.91-.7-1.06.43-1.27.51-.7-1.21 1.08-.84.89-.7-.14-1.13c-.03-.31-.05-.54-.05-.74s.02-.43.05-.73l.14-1.13-.89-.7-1.08-.84.7-1.21 1.27.51 1.04.42.9-.68c.43-.32.84-.56 1.25-.73l1.06-.43.16-1.13.2-1.35h1.39l.19 1.35.16 1.13 1.06.43c.43.18.83.41 1.23.71l.91.7 1.06-.43 1.27-.51.7 1.21-1.07.85-.89.7.14 1.13zM12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm0 6c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2z" />
</svg>
);

export const SvgVisiblityOff: Component<ComponentProps<'svg'>> = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
height="24px"
viewBox="0 0 24 24"
width="24px"
fill="currentColor"
{...props}
>
<path d="M0 0h24v24H0V0zm0 0h24v24H0V0zm0 0h24v24H0V0zm0 0h24v24H0V0z" fill="none" />
<path d="M12 6c3.79 0 7.17 2.13 8.82 5.5-.59 1.22-1.42 2.27-2.41 3.12l1.41 1.41c1.39-1.23 2.49-2.77 3.18-4.53C21.27 7.11 17 4 12 4c-1.27 0-2.49.2-3.64.57l1.65 1.65C10.66 6.09 11.32 6 12 6zm-1.07 1.14L13 9.21c.57.25 1.03.71 1.28 1.28l2.07 2.07c.08-.34.14-.7.14-1.07C16.5 9.01 14.48 7 12 7c-.37 0-.72.05-1.07.14zM2.01 3.87l2.68 2.68C3.06 7.83 1.77 9.53 1 11.5 2.73 15.89 7 19 12 19c1.52 0 2.98-.29 4.32-.82l3.42 3.42 1.41-1.41L3.42 2.45 2.01 3.87zm7.5 7.5l2.61 2.61c-.04.01-.08.02-.12.02-1.38 0-2.5-1.12-2.5-2.5 0-.05.01-.08.01-.13zm-3.4-3.4l1.75 1.75c-.23.55-.36 1.15-.36 1.78 0 2.48 2.02 4.5 4.5 4.5.63 0 1.23-.13 1.77-.36l.98.98c-.88.24-1.8.38-2.75.38-3.79 0-7.17-2.13-8.82-5.5.7-1.43 1.72-2.61 2.93-3.53z" />
</svg>
);

export const SvgVisiblity: Component<ComponentProps<'svg'>> = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
height="24px"
viewBox="0 0 24 24"
width="24px"
fill="currentColor"
{...props}
>
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M12 6c3.79 0 7.17 2.13 8.82 5.5C19.17 14.87 15.79 17 12 17s-7.17-2.13-8.82-5.5C4.83 8.13 8.21 6 12 6m0-2C7 4 2.73 7.11 1 11.5 2.73 15.89 7 19 12 19s9.27-3.11 11-7.5C21.27 7.11 17 4 12 4zm0 5c1.38 0 2.5 1.12 2.5 2.5S13.38 14 12 14s-2.5-1.12-2.5-2.5S10.62 9 12 9m0-2c-2.48 0-4.5 2.02-4.5 4.5S9.52 16 12 16s4.5-2.02 4.5-4.5S14.48 7 12 7z" />
</svg>
);
Loading

0 comments on commit 7f58627

Please sign in to comment.