mirror of
https://ghproxy.com/https://github.com/StreakingMan/solvable-sheep-game
synced 2025-05-25 06:48:14 +08:00
feat: 关卡进度缓存
This commit is contained in:
parent
e7ae319ecf
commit
0afeac0f87
33
src/App.tsx
33
src/App.tsx
|
@ -183,18 +183,26 @@ const Symbol: FC<SymbolProps> = ({ x, y, icon, isCover, status, onClick }) => {
|
||||||
const themeFromPath: string = parsePathThemeName(location.href);
|
const themeFromPath: string = parsePathThemeName(location.href);
|
||||||
const customThemeIdFromPath = parsePathCustomThemeId(location.href);
|
const customThemeIdFromPath = parsePathCustomThemeId(location.href);
|
||||||
const CUSTOM_THEME_FAIL_TIP = '查询配置失败';
|
const CUSTOM_THEME_FAIL_TIP = '查询配置失败';
|
||||||
|
const initTheme = customThemeIdFromPath
|
||||||
|
? { title: '', icons: [], sounds: [], name: '' }
|
||||||
|
: themeFromPath
|
||||||
|
? builtInThemes.find((theme) => theme.name === themeFromPath) ??
|
||||||
|
defaultTheme
|
||||||
|
: defaultTheme;
|
||||||
|
|
||||||
|
// 读取缓存关卡数
|
||||||
|
const LAST_LEVEL_STORAGE_KEY = 'lastLevel';
|
||||||
|
const initLevel = Number(localStorage.getItem(LAST_LEVEL_STORAGE_KEY) || '1');
|
||||||
|
|
||||||
const App: FC = () => {
|
const App: FC = () => {
|
||||||
const [curTheme, setCurTheme] = useState<Theme<any>>(
|
const [curTheme, setCurTheme] = useState<Theme<any>>(initTheme);
|
||||||
customThemeIdFromPath
|
|
||||||
? { title: '', icons: [], sounds: [], name: '' }
|
|
||||||
: defaultTheme
|
|
||||||
);
|
|
||||||
const [themes, setThemes] = useState<Theme<any>[]>(builtInThemes);
|
const [themes, setThemes] = useState<Theme<any>[]>(builtInThemes);
|
||||||
const [pureMode, setPureMode] = useState<boolean>(!!customThemeIdFromPath);
|
const [pureMode, setPureMode] = useState<boolean>(!!customThemeIdFromPath);
|
||||||
|
|
||||||
const [scene, setScene] = useState<Scene>(makeScene(1, curTheme.icons));
|
const [scene, setScene] = useState<Scene>(
|
||||||
const [level, setLevel] = useState<number>(1);
|
makeScene(initLevel, curTheme.icons)
|
||||||
|
);
|
||||||
|
const [level, setLevel] = useState<number>(initLevel);
|
||||||
const [queue, setQueue] = useState<MySymbol[]>([]);
|
const [queue, setQueue] = useState<MySymbol[]>([]);
|
||||||
const [sortedQueue, setSortedQueue] = useState<
|
const [sortedQueue, setSortedQueue] = useState<
|
||||||
Record<MySymbol['id'], number>
|
Record<MySymbol['id'], number>
|
||||||
|
@ -221,6 +229,11 @@ const App: FC = () => {
|
||||||
}
|
}
|
||||||
}, [bgmOn]);
|
}, [bgmOn]);
|
||||||
|
|
||||||
|
// 关卡缓存
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem(LAST_LEVEL_STORAGE_KEY, level.toString());
|
||||||
|
}, [level]);
|
||||||
|
|
||||||
// 初始化主题
|
// 初始化主题
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (customThemeIdFromPath) {
|
if (customThemeIdFromPath) {
|
||||||
|
@ -245,12 +258,6 @@ const App: FC = () => {
|
||||||
setCurTheme({ ...curTheme, title: CUSTOM_THEME_FAIL_TIP });
|
setCurTheme({ ...curTheme, title: CUSTOM_THEME_FAIL_TIP });
|
||||||
console.log(e);
|
console.log(e);
|
||||||
});
|
});
|
||||||
} else if (themeFromPath) {
|
|
||||||
// 内置主题
|
|
||||||
setCurTheme(
|
|
||||||
themes.find((theme) => theme.name === themeFromPath) ??
|
|
||||||
defaultTheme
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user