diff --git a/.cursor/rules/general.mdc b/.cursor/rules/general.mdc index e736d0d..f5343f3 100644 --- a/.cursor/rules/general.mdc +++ b/.cursor/rules/general.mdc @@ -1,10 +1,26 @@ --- -description: -globs: +description: 工程全局规则 alwaysApply: true --- +你是一个游戏开发Agent,需要在本工程中,协助我开发一个 HTML 游戏。 + +## 本工程介绍 + +- 这是一个模版工程,开发者会基于这个工程进行拓展开发 +- 本工程采用 Vite + React 框架,是一个React SPA架构的游戏/应用 +- 本工程强烈建议使用如下前端NPM包: + - react-router: 用于管理页面和路由 + - zustand: 用于React状态管理 + - TailwindCSS: 用于编写样式和管理主题 + - axios:用于发起http请求。包括上传和SSE场景。 + - dayjs: 用于处理日期 + - localforage: 用于管理Storage + - react-icons: 用于使用图标 + - motion: 动效库 + - loadsh-es: 用于提供一些常用的utils函数 + +## 你需要遵循的规则 - Always respond in 中文 - 只能新增、修改和删除 src 目录里的文件或者文件夹,严禁修改其他文件或者文件夹! -- \ No newline at end of file diff --git a/.cursorignore b/.cursorignore index 4ed5891..dc58d54 100644 --- a/.cursorignore +++ b/.cursorignore @@ -3,5 +3,4 @@ biome.json index.html pnpm-lock.yaml .trae/ -!src/ .cursor/ \ No newline at end of file diff --git a/src/components/.cursor/rules/components_rules.mdc b/src/components/.cursor/rules/components_rules.mdc index 9e43cae..bff46f7 100644 --- a/src/components/.cursor/rules/components_rules.mdc +++ b/src/components/.cursor/rules/components_rules.mdc @@ -4,11 +4,10 @@ globs: ["**/*.ts", "**/*.tsx"] alwaysApply: Auto Attached --- -本规则为前端组件制定规范: +# 本规则为前端公共组件规范 -在 components 目录工作时: - -样式统一使用 Tailwind -动画使用 Framer Motion -遵循组件命名约定 -本规则同时对 API 端点实施校验: \ No newline at end of file +- 非公共组件不要放在本目录下 +- 样式统一使用 Tailwind +- 如果需要动画,使用 Motion 库 +- 遵循组件命名约定 +- export 的时候采用 命名导出,不要使用 默认导出 diff --git a/src/components/index.ts b/src/components/index.ts index 65c511b..99e3012 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1 +1 @@ -export * from './Example'; \ No newline at end of file +export * from './Example'; diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index 3d9d52b..3c055ac 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -1,40 +1,16 @@ import { useGlobalStore } from '@/store/global'; import './index.css'; import { isEmpty } from 'lodash-es'; -import { EVENT, useMujian } from '@/providers/MujianProvider'; +import { Button } from '@/components'; function Home() { - const { count, increment } = useGlobalStore((state) => state); - const mujian = useMujian(); - - console.log('count', count); - - console.log('isEmpty', isEmpty(count)); return ( <>
Hello World2
-

Vite + React

- - -

Count: {count}

- -
- - + ); } diff --git a/src/providers/.cursor/rules/providers_rules.mdc b/src/providers/.cursor/rules/providers_rules.mdc index ca17b3f..1c3de5a 100644 --- a/src/providers/.cursor/rules/providers_rules.mdc +++ b/src/providers/.cursor/rules/providers_rules.mdc @@ -3,3 +3,5 @@ description: Provider 模版 globs: ["**/*.ts", "**/*.tsx"] alwaysApply: Auto Attached --- + +- RouterProvider 为 react-router 路由配置文件 diff --git a/src/providers/MujianProvider.tsx b/src/providers/MujianProvider.tsx deleted file mode 100644 index d69e6af..0000000 --- a/src/providers/MujianProvider.tsx +++ /dev/null @@ -1,51 +0,0 @@ -// @rule: do not modify this file - -import { MujianSdk } from '@mujian/js-sdk'; -import { - createContext, - type ReactNode, - useContext, - useEffect, - useState, -} from 'react'; - -export { EVENT } from '@mujian/js-sdk'; - -const MujianContext = createContext(null); - -export interface MujianProviderProps { - children: ReactNode; - loadingPage?: ReactNode; -} - -export const MujianProvider = ({ - children, - loadingPage, -}: MujianProviderProps) => { - const [mujian, setMujian] = useState(null); - - useEffect(() => { - (async () => { - const mujian = new MujianSdk(); - await mujian.init(); - setMujian(mujian); - })(); - }, []); - - return ( - - {mujian ? children : (loadingPage ?? 'Mujian is loading')} - - ); -}; - -export const useMujian = () => { - const mujian = useContext(MujianContext); - if (!mujian) { - const message = - 'Mujian is not initialized. Please check that useMujian is called inside MujianProvider'; - console.error(message); - throw new Error(message); - } - return mujian; -};