Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: チームが片方しかいない試合が表示できるように修正 #460

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions packages/config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,40 +120,40 @@ export const config = createConfig(
// visible: (state) => !state.matchInfo, // エキシビションモードでのみ表示
// changeable: (state) =>
// !state.matchInfo && // エキシビションモードでのみマニュアル変更可能
// !state.matchState[state.side].getPointState().finish,
// !state.matchState[state.side]?.getPointState().finish,
// scorable: (state) =>
// !state.matchInfo || // エキシビションモードでは通常通り加算可能
// state.matchInfo.teams[state.side].robotType == "leg", // 通常の試合では歩行型のときのみ加算可能
// state.matchInfo.teams[state.side]?.robotType == "leg", // 通常の試合では歩行型のときのみ加算可能
// },
leaveBase: {
changeable: (state) =>
!state.matchState[state.side].getPointState().finish,
!state.matchState[state.side]?.getPointState().finish,
},
overMiddle: {
changeable: (state) =>
!state.matchState[state.side].getPointState().finish,
!state.matchState[state.side]?.getPointState().finish,
},
enterDestination: {
changeable: (state) =>
!state.matchState[state.side].getPointState().finish,
!state.matchState[state.side]?.getPointState().finish,
},
placeBall: {
changeable: (state) =>
!state.matchState[state.side].getPointState().finish,
!state.matchState[state.side]?.getPointState().finish,
},
returnBase: {
changeable: (state) =>
!state.matchState[state.side].getPointState().finish,
!state.matchState[state.side]?.getPointState().finish,
},
goal: {
changeable: (state) =>
!state.matchState[state.side].getPointState().finish,
!state.matchState[state.side]?.getPointState().finish,
scorable: (state) => {
if (state.matchInfo?.matchType !== "main") return false; // 本戦以外では先ゴールに得点を与えない

const selfTime = state.matchState[state.side].getGoalTimeSeconds(); // 自分のゴールタイム
const selfTime = state.matchState[state.side]?.getGoalTimeSeconds(); // 自分のゴールタイム
const otherTime =
state.matchState[against(state.side)].getGoalTimeSeconds();
state.matchState[against(state.side)]?.getGoalTimeSeconds();

if (selfTime == null) return false; // 自分がゴールしていないなら先ゴールでない
if (otherTime == null) return true; // 自分がゴールしていて、相手がゴールしていないなら先ゴール
Expand All @@ -162,18 +162,19 @@ export const config = createConfig(
},
bringBall: {
changeable: (state) =>
!state.matchState[state.side].getPointState().finish,
!state.matchState[state.side]?.getPointState().finish,
},
bringRareBall: {
visible: (state) =>
!state.matchInfo || state.matchInfo.matchType === "main", // 本戦以外では激レアどじょうを表示しない
changeable: (state) =>
!state.matchState[state.side].getPointState().finish,
!state.matchState[state.side]?.getPointState().finish,
scorable: (state) =>
!state.matchInfo || state.matchInfo.matchType === "main", // 本戦以外では激レアどじょうに得点を与えない
},
finish: {
changeable: (state) => !state.matchState[state.side].getPointState().goal,
changeable: (state) =>
!state.matchState[state.side]?.getPointState().goal,
},
}
);
2 changes: 1 addition & 1 deletion packages/config/src/types/matchInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type DerivedMatchInfo<
> = {
id: string;
teams: {
[S in Side]: DerivedTeamInfo<RobotType, DepartmentType>;
[S in Side]?: DerivedTeamInfo<RobotType, DepartmentType>;
};
matchType: MatchType;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/types/premise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type DerivedDynamicPremiseState<
PointState extends Record<string, unknown> = Record<string, unknown>,
> = {
matchState: {
[S in Side]: {
[S in Side]?: {
getPointState: () => PointState;
getGoalTimeSeconds: () => number | undefined;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/utility/createConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ describe("正しい設定を生成できる", () => {
const visible = (state: PremiseState) =>
state.matchInfo?.matchType == "pre";
const scorable = (state: PremiseState) =>
state.matchState[state.side].getGoalTimeSeconds() != undefined;
state.matchState[state.side]?.getGoalTimeSeconds() != undefined;
const changeable = (state: PremiseState) =>
state.matchInfo?.teams[state.side].robotType == "wheel";
state.matchInfo?.teams[state.side]?.robotType == "wheel";

const config = createConfig(
{
Expand Down
3 changes: 3 additions & 0 deletions packages/kcmsf/src/components/match/PointControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Props {
rule: Rule;
onChange: (value: Parameters<Rule["point"]>[0]) => void;
children: React.ReactNode;
disabled?: boolean;
}

export const PointControl = (props: Props) => (
Expand All @@ -25,6 +26,7 @@ export const PointControl = (props: Props) => (
props.onChange(active);
}}
disabled={
props.disabled ||
!(props.rule.changeable?.(props.team.point.premiseState) ?? true)
}
>
Expand All @@ -43,6 +45,7 @@ export const PointControl = (props: Props) => (
props.onChange(count);
}}
disabled={
props.disabled ||
!(props.rule.changeable?.(props.team.point.premiseState) ?? true)
}
>
Expand Down
2 changes: 2 additions & 0 deletions packages/kcmsf/src/components/match/PointControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const PointControls = (props: {
team: Team;
onChange: () => void;
onGoal: (done: boolean) => void;
disabled?: boolean;
}) => {
return (
<Flex direction="column" gap="xs">
Expand All @@ -27,6 +28,7 @@ export const PointControls = (props: {
props.onGoal(value);
}}
key={`${props.team.point.premiseState.side}-${rule.name}`}
disabled={props.disabled}
>
{rule.label}
{rule.name === "goal" && props.team.goalTimeSeconds != null
Expand Down
49 changes: 28 additions & 21 deletions packages/kcmsf/src/components/match/matchSubmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,39 @@ type APIPostRunResults = {
finishState: "goal" | "finished";
}[];

export const MatchSubmit = (props: {
export const MatchSubmit = ({
matchInfo,
available,
result,
}: {
matchInfo: MatchInfo;
available: boolean;
result: {
left: Omit<TeamResult, "id">;
right: Omit<TeamResult, "id">;
left?: Omit<TeamResult, "id">;
right?: Omit<TeamResult, "id">;
};
}) => {
const submit = async () => {
const runResults: APIPostRunResults = [
{
teamID: props.matchInfo.teams.left.id,
points: props.result.left.points,
goalTimeSeconds: props.result.left.time ?? null,
finishState: props.result.left.time != null ? "goal" : "finished",
},
{
teamID: props.matchInfo.teams.right.id,
points: props.result.right.points,
goalTimeSeconds: props.result.right.time ?? null,
finishState: props.result.right.time != null ? "goal" : "finished",
},
];
const runResults: APIPostRunResults = [];
if (matchInfo.teams.left && result.left) {
runResults.push({
teamID: matchInfo.teams.left.id,
points: result.left.points,
goalTimeSeconds: result.left.time ?? null,
finishState: result.left.time != null ? "goal" : "finished",
});
}
if (matchInfo.teams.right && result.right) {
runResults.push({
teamID: matchInfo.teams.right.id,
points: result.right.points,
goalTimeSeconds: result.right.time ?? null,
finishState: result.right.time != null ? "goal" : "finished",
});
}

const result = await fetch(
`${import.meta.env.VITE_API_URL}/match/${props.matchInfo.matchType}/${props.matchInfo.id}/run_result`,
const res = await fetch(
`${import.meta.env.VITE_API_URL}/match/${matchInfo.matchType}/${matchInfo.id}/run_result`,
{
method: "post",
body: JSON.stringify(runResults),
Expand All @@ -52,7 +59,7 @@ export const MatchSubmit = (props: {
).catch(() => undefined);

notifications.show(
result?.ok
res?.ok
? {
title: "送信成功",
message: "結果が正常に送信されました",
Expand All @@ -73,7 +80,7 @@ export const MatchSubmit = (props: {
px="xl"
py="sm"
color="teal"
disabled={!props.available}
disabled={!available}
onClick={submit}
>
<Flex gap="xs">
Expand Down
Loading