Skip to content

Commit 49ef98d

Browse files
committed
improve gm param
* adds support for match groups * verifies gamemode existence
1 parent 075698b commit 49ef98d

File tree

3 files changed

+92
-70
lines changed

3 files changed

+92
-70
lines changed

src/components/quickplay/MatchGroupSelector.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useCallback, useEffect, useState } from "react";
33
import useQuickplayStore from "@store/quickplay";
44

55
import ServerFinder from "./ServerFinder";
6+
import { baseGamemodeSet } from "@ssg/quickplayStaticData";
67

78
export function MatchGroupSelector({ hash }) {
89
const quickplayStore = useQuickplayStore((state) => state);
@@ -38,6 +39,13 @@ export function MatchGroupSelector({ hash }) {
3839
[quickplayStore.searching],
3940
);
4041

42+
useEffect(() => {
43+
if (!quickplayStore.carousel) {
44+
return;
45+
}
46+
quickplayStore.carousel.to(index);
47+
}, [index, quickplayStore.carousel])
48+
4149
// Handle available match groups shifting
4250
useEffect(() => {
4351
const newIndex = quickplayStore.availableMatchGroups.findIndex(
@@ -68,9 +76,20 @@ export function MatchGroupSelector({ hash }) {
6876
"payload_race",
6977
];
7078
} else {
71-
gamemodes = gm.split(",").filter((mode) => mode);
79+
const userGmList = gm.split(",").filter((mode) => mode);
80+
gamemodes = userGmList.filter((mode) => baseGamemodeSet.has(mode));
81+
if (gamemodes.length === 0) {
82+
const activeMatchGroupSet = new Set(quickplayStore.availableMatchGroups.filter((mg) => mg.active).map((mg) => mg.code));
83+
const selectedMatchGroups = userGmList.filter((mode) => activeMatchGroupSet.has(mode));
84+
if (selectedMatchGroups.length > 0) {
85+
handleSelect(quickplayStore.availableMatchGroups.findIndex((mg) => mg.code === selectedMatchGroups[0]));
86+
gamemodes = [];
87+
}
88+
}
89+
}
90+
if (gamemodes && gamemodes.length > 0) {
91+
quickplayStore.setGamemodes(gamemodes);
7292
}
73-
quickplayStore.setGamemodes(gamemodes);
7493
}
7594
if (urlparms.get("autostart") === "1") {
7695
startSearching(1);

src/components/quickplay/ServerFinder.tsx

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import adImg from "@img/gamemodes/ad.webp";
2-
import arenaImg from "@img/gamemodes/arena.webp";
3-
import cpImg from "@img/gamemodes/cp.webp";
4-
import ctfImg from "@img/gamemodes/ctf.webp";
5-
import kothImg from "@img/gamemodes/koth.webp";
6-
import payloadImg from "@img/gamemodes/pl.webp";
7-
import plrImg from "@img/gamemodes/plr.webp";
8-
import miscImg from "@img/gamemodes/sd.webp";
91
import xMarkImg from "@img/xmark.webp";
102
import {
3+
baseGamemodes,
114
getDefaultMatchGroups,
125
getSpecialEventDesc,
136
} from "@ssg/quickplayStaticData";
@@ -66,65 +59,6 @@ const gamemodeToPrefix = {
6659
const SERVER_HEADROOM = 1;
6760
const FULL_PLAYERS = 24;
6861

69-
const gamemodes = {
70-
payload: {
71-
name: "Payload",
72-
code: "payload",
73-
description: "BLU pushes the cart down the track. RED need to stop them.",
74-
skill: 0,
75-
img: payloadImg,
76-
},
77-
koth: {
78-
name: "King of the Hill",
79-
code: "koth",
80-
description: "One team must control a single point until time runs out.",
81-
skill: 0,
82-
img: kothImg,
83-
},
84-
attack_defense: {
85-
name: "Attack / Defense",
86-
code: "attack_defense",
87-
description: "BLU wins by capturing all points. RED wins by stopping them.",
88-
skill: 1,
89-
img: adImg,
90-
},
91-
ctf: {
92-
name: "Capture the Flag",
93-
code: "ctf",
94-
description: "And by flag we mean a glowing briefcase.",
95-
skill: 1,
96-
img: ctfImg,
97-
},
98-
capture_point: {
99-
name: "Capture Points",
100-
code: "capture_point",
101-
description: "Capture all points to win.",
102-
skill: 1,
103-
img: cpImg,
104-
},
105-
payload_race: {
106-
name: "Payload Race",
107-
code: "payload_race",
108-
description: "Two teams. Two bombs. Two tracks. Hilarity ensues.",
109-
skill: 1,
110-
img: plrImg,
111-
},
112-
alternative: {
113-
name: "Misc",
114-
code: "alternative",
115-
description: "Game modes that don't fit into one of the other categories.",
116-
skill: 2,
117-
img: miscImg,
118-
},
119-
arena: {
120-
name: "Arena",
121-
code: "arena",
122-
description: "Quick rounds. No respawns. It's like Counter-Strike!",
123-
skill: 2,
124-
img: arenaImg,
125-
},
126-
};
127-
12862
const MISC_GAMEMODES = ["arena", "pass", "pd", "rd", "sd", "tc", "vsh", "zi"];
12963

13064
const REGIONS = {
@@ -1679,7 +1613,7 @@ export default function ServerFinder({ hash }: { hash: string }) {
16791613
<div>
16801614
<h4 style={{ fontWeight: 500 }}>Game Modes</h4>
16811615
<div className="row g-4">
1682-
{Object.values(gamemodes).map((gm) => {
1616+
{Object.values(baseGamemodes).map((gm) => {
16831617
return (
16841618
<div
16851619
key={gm.code}

src/ssg/quickplayStaticData.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import adImg from "@img/gamemodes/ad.webp";
2+
import arenaImg from "@img/gamemodes/arena.webp";
3+
import cpImg from "@img/gamemodes/cp.webp";
4+
import ctfImg from "@img/gamemodes/ctf.webp";
5+
import kothImg from "@img/gamemodes/koth.webp";
6+
import payloadImg from "@img/gamemodes/pl.webp";
7+
import plrImg from "@img/gamemodes/plr.webp";
8+
import miscImg from "@img/gamemodes/sd.webp";
19
import halloweenImg from "@img/gamemodes/halloween.webp";
210
import jumpImg from "@img/gamemodes/jump.webp";
311
import mvmImg from "@img/gamemodes/mvm.webp";
@@ -6,6 +14,67 @@ import smissmasImg from "@img/gamemodes/smissmas.webp";
614
import summerImg from "@img/gamemodes/summer.webp";
715
import workshopImg from "@img/gamemodes/workshop.webp";
816

17+
export const baseGamemodes = {
18+
payload: {
19+
name: "Payload",
20+
code: "payload",
21+
description: "BLU pushes the cart down the track. RED need to stop them.",
22+
skill: 0,
23+
img: payloadImg,
24+
},
25+
koth: {
26+
name: "King of the Hill",
27+
code: "koth",
28+
description: "One team must control a single point until time runs out.",
29+
skill: 0,
30+
img: kothImg,
31+
},
32+
attack_defense: {
33+
name: "Attack / Defense",
34+
code: "attack_defense",
35+
description: "BLU wins by capturing all points. RED wins by stopping them.",
36+
skill: 1,
37+
img: adImg,
38+
},
39+
ctf: {
40+
name: "Capture the Flag",
41+
code: "ctf",
42+
description: "And by flag we mean a glowing briefcase.",
43+
skill: 1,
44+
img: ctfImg,
45+
},
46+
capture_point: {
47+
name: "Capture Points",
48+
code: "capture_point",
49+
description: "Capture all points to win.",
50+
skill: 1,
51+
img: cpImg,
52+
},
53+
payload_race: {
54+
name: "Payload Race",
55+
code: "payload_race",
56+
description: "Two teams. Two bombs. Two tracks. Hilarity ensues.",
57+
skill: 1,
58+
img: plrImg,
59+
},
60+
alternative: {
61+
name: "Misc",
62+
code: "alternative",
63+
description: "Game modes that don't fit into one of the other categories.",
64+
skill: 2,
65+
img: miscImg,
66+
},
67+
arena: {
68+
name: "Arena",
69+
code: "arena",
70+
description: "Quick rounds. No respawns. It's like Counter-Strike!",
71+
skill: 2,
72+
img: arenaImg,
73+
},
74+
};
75+
76+
export const baseGamemodeSet = new Set(Object.keys(baseGamemodes));
77+
978
const holidayToImg = {
1079
summer: summerImg,
1180
halloween: halloweenImg,

0 commit comments

Comments
 (0)