Commit bee6e416 authored by Chunchi Che's avatar Chunchi Che

optimize

parent a38b43bd
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit"; import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { RootState } from "../../store"; import { RootState } from "../../store";
import { DuelState } from "./mod"; import { DuelState } from "./mod";
import { judgeSelf } from "./util";
export const newTurnImpl: CaseReducer<DuelState, PayloadAction<number>> = ( export const newTurnImpl: CaseReducer<DuelState, PayloadAction<number>> = (
state, state,
...@@ -9,5 +10,5 @@ export const newTurnImpl: CaseReducer<DuelState, PayloadAction<number>> = ( ...@@ -9,5 +10,5 @@ export const newTurnImpl: CaseReducer<DuelState, PayloadAction<number>> = (
state.currentPlayer = action.payload; state.currentPlayer = action.payload;
}; };
export const selectCurrentPlayer = (state: RootState) => export const selectCurrentPlayerIsMe = (state: RootState) =>
state.duel.currentPlayer; judgeSelf(state.duel.currentPlayer!, state.duel);
...@@ -8,18 +8,23 @@ import { ...@@ -8,18 +8,23 @@ import {
selectMeInitInfo, selectMeInitInfo,
selectOpInitInfo, selectOpInitInfo,
} from "../../reducers/duel/initInfoSlice"; } from "../../reducers/duel/initInfoSlice";
import { selectCurrentPlayerIsMe } from "../../reducers/duel/turnSlice";
const Config = NeosConfig.ui.status; const Config = NeosConfig.ui.status;
const avatarSize = 40; const avatarSize = 40;
const ME_VALUE = "myself";
const OP_VALUE = "opponent";
const PlayerStatus = () => { const PlayerStatus = () => {
const meInfo = useAppSelector(selectMeInitInfo); const meInfo = useAppSelector(selectMeInitInfo);
const opInfo = useAppSelector(selectOpInitInfo); const opInfo = useAppSelector(selectOpInitInfo);
const myTurn = useAppSelector(selectCurrentPlayerIsMe);
return ( return (
<CheckCard.Group <CheckCard.Group
bordered bordered
style={{ height: `${NeosConfig.ui.layout.header.height}` }} style={{ height: `${NeosConfig.ui.layout.header.height}` }}
value={myTurn ? ME_VALUE : OP_VALUE}
> >
<CheckCard <CheckCard
avatar={ avatar={
...@@ -29,9 +34,9 @@ const PlayerStatus = () => { ...@@ -29,9 +34,9 @@ const PlayerStatus = () => {
icon={<UserOutlined />} icon={<UserOutlined />}
/> />
} }
title={`opponent`} title={OP_VALUE}
description={`Hp: ${opInfo?.life || 0}`} description={`Lp: ${opInfo?.life || 0}`}
value="opponent" value={OP_VALUE}
style={{ style={{
position: "absolute", position: "absolute",
left: `${NeosConfig.ui.layout.sider.width}px`, left: `${NeosConfig.ui.layout.sider.width}px`,
...@@ -45,9 +50,9 @@ const PlayerStatus = () => { ...@@ -45,9 +50,9 @@ const PlayerStatus = () => {
icon={<UserOutlined />} icon={<UserOutlined />}
/> />
} }
title={`myself`} title={ME_VALUE}
description={`Hp: ${meInfo?.life || 0}`} description={`Lp: ${meInfo?.life || 0}`}
value="myself" value={ME_VALUE}
style={{ style={{
position: "absolute", position: "absolute",
right: "0px", right: "0px",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment