mirror of
https://ghproxy.com/https://github.com/StreakingMan/solvable-sheep-game
synced 2026-07-29 19:51:48 +08:00
fix: 分数缓存逻辑调整
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
LAST_SCORE_STORAGE_KEY,
|
||||
LAST_TIME_STORAGE_KEY,
|
||||
randomString,
|
||||
resetScoreStorage,
|
||||
timestampToUsedTimeString,
|
||||
waitTimeout,
|
||||
} from '../utils';
|
||||
@@ -170,7 +171,6 @@ const Game: FC<{
|
||||
Record<MySymbol['id'], number>
|
||||
>({});
|
||||
const [finished, setFinished] = useState<boolean>(false);
|
||||
const [tipText, setTipText] = useState<string>('');
|
||||
const [animating, setAnimating] = useState<boolean>(false);
|
||||
|
||||
// 音效
|
||||
@@ -394,14 +394,12 @@ const Game: FC<{
|
||||
|
||||
// 输了
|
||||
if (updateQueue.length === 7) {
|
||||
setTipText('失败了');
|
||||
setFinished(true);
|
||||
}
|
||||
|
||||
if (!updateScene.find((s) => s.status !== 2)) {
|
||||
// 胜利
|
||||
if (level === maxLevel) {
|
||||
setTipText('完成挑战');
|
||||
setFinished(true);
|
||||
return;
|
||||
}
|
||||
@@ -428,9 +426,7 @@ const Game: FC<{
|
||||
useEffect(() => {
|
||||
if (finished) {
|
||||
intervalRef.current && clearInterval(intervalRef.current);
|
||||
localStorage.setItem(LAST_LEVEL_STORAGE_KEY, '1');
|
||||
localStorage.setItem(LAST_SCORE_STORAGE_KEY, '0');
|
||||
localStorage.setItem(LAST_TIME_STORAGE_KEY, '0');
|
||||
resetScoreStorage();
|
||||
}
|
||||
}, [finished]);
|
||||
// 更新使用时间
|
||||
|
||||
@@ -52,7 +52,7 @@ const Score: FC<{
|
||||
// 综合评分
|
||||
const rating = Math.max(0, score) * 100 - Math.round(time / 1000);
|
||||
// 分主题排行
|
||||
const themeId = sessionStorage.getItem(PLAYING_THEME_ID_STORAGE_KEY);
|
||||
const themeId = localStorage.getItem(PLAYING_THEME_ID_STORAGE_KEY);
|
||||
|
||||
const uploadRankInfo = (id?: string) => {
|
||||
const _userId = localStorage.getItem(USER_ID_STORAGE_KEY);
|
||||
@@ -93,6 +93,13 @@ const Score: FC<{
|
||||
.then((res) => {
|
||||
setRankList(res as any);
|
||||
cb && cb(res as any);
|
||||
const _userId = localStorage.getItem(USER_ID_STORAGE_KEY);
|
||||
if (_userId) {
|
||||
setTimeout(() => {
|
||||
const rankEl = document.getElementById(_userId + 'el');
|
||||
rankEl?.scrollIntoView({ behavior: 'smooth' });
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
@@ -219,7 +226,7 @@ const Score: FC<{
|
||||
<tr>
|
||||
<th>名次</th>
|
||||
<th>名称</th>
|
||||
{/*<th>通关数</th>*/}
|
||||
<th>通关数</th>
|
||||
{/*<th>用时</th>*/}
|
||||
{/*<th>得分</th>*/}
|
||||
<th>综合评分</th>
|
||||
@@ -227,14 +234,23 @@ const Score: FC<{
|
||||
</thead>
|
||||
<tbody>
|
||||
{rankList.map((rank, idx) => (
|
||||
<tr key={idx}>
|
||||
<tr
|
||||
key={idx}
|
||||
id={rank.userId}
|
||||
style={{
|
||||
background:
|
||||
rank.userId === userId
|
||||
? 'rgb(0 0 0 / 20%)'
|
||||
: '',
|
||||
}}
|
||||
>
|
||||
<td>{idx + 1}</td>
|
||||
<td>
|
||||
{rank.username}
|
||||
{rank.userId === userId &&
|
||||
'(你)'}
|
||||
</td>
|
||||
{/*<td>{rank.level}</td>*/}
|
||||
<td>{rank.level}</td>
|
||||
{/*<td>*/}
|
||||
{/* {timestampToUsedTimeString(*/}
|
||||
{/* rank.time*/}
|
||||
|
||||
Reference in New Issue
Block a user