This commit is contained in:
rex
2025-10-23 20:06:31 +08:00
parent 4fb4d5fd69
commit 2c34c157f1
7 changed files with 30 additions and 89 deletions

View File

@@ -1,10 +1,26 @@
--- ---
description: description: 工程全局规则
globs:
alwaysApply: true 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 中文 - Always respond in 中文
- 只能新增、修改和删除 src 目录里的文件或者文件夹,严禁修改其他文件或者文件夹! - 只能新增、修改和删除 src 目录里的文件或者文件夹,严禁修改其他文件或者文件夹!
-

View File

@@ -3,5 +3,4 @@ biome.json
index.html index.html
pnpm-lock.yaml pnpm-lock.yaml
.trae/ .trae/
!src/
.cursor/ .cursor/

View File

@@ -4,11 +4,10 @@ globs: ["**/*.ts", "**/*.tsx"]
alwaysApply: Auto Attached alwaysApply: Auto Attached
--- ---
本规则为前端组件制定规范 # 本规则为前端公共组件规范
在 components 目录工作时: - 非公共组件不要放在本目录下
- 样式统一使用 Tailwind
样式统一使用 Tailwind - 如果需要动画,使用 Motion 库
动画使用 Framer Motion - 遵循组件命名约定
遵循组件命名约定 - export 的时候采用 命名导出,不要使用 默认导出
本规则同时对 API 端点实施校验:

View File

@@ -1 +1 @@
export * from './Example'; export * from './Example';

View File

@@ -1,40 +1,16 @@
import { useGlobalStore } from '@/store/global'; import { useGlobalStore } from '@/store/global';
import './index.css'; import './index.css';
import { isEmpty } from 'lodash-es'; import { isEmpty } from 'lodash-es';
import { EVENT, useMujian } from '@/providers/MujianProvider'; import { Button } from '@/components';
function Home() { function Home() {
const { count, increment } = useGlobalStore((state) => state);
const mujian = useMujian();
console.log('count', count);
console.log('isEmpty', isEmpty(count));
return ( return (
<> <>
<div> <div>
<div className="text-3xl font-bold underline">Hello World2</div> <div className="text-3xl font-bold underline">Hello World2</div>
</div> </div>
<h1>Vite + React</h1> <Button>Click me</Button>
<button type="button" onClick={increment}>
Increment
</button>
<p>Count: {count}</p>
<br />
<button
type="button"
onClick={async () => {
mujian.emit(EVENT.MUJIAN_AI_CHAT_SEND_MESSAGE, {
message: 'Hello, World!',
});
}}
>
Hello
</button>
</> </>
); );
} }

View File

@@ -3,3 +3,5 @@ description: Provider 模版
globs: ["**/*.ts", "**/*.tsx"] globs: ["**/*.ts", "**/*.tsx"]
alwaysApply: Auto Attached alwaysApply: Auto Attached
--- ---
- RouterProvider 为 react-router 路由配置文件

View File

@@ -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<MujianSdk | null>(null);
export interface MujianProviderProps {
children: ReactNode;
loadingPage?: ReactNode;
}
export const MujianProvider = ({
children,
loadingPage,
}: MujianProviderProps) => {
const [mujian, setMujian] = useState<MujianSdk | null>(null);
useEffect(() => {
(async () => {
const mujian = new MujianSdk();
await mujian.init();
setMujian(mujian);
})();
}, []);
return (
<MujianContext.Provider value={mujian}>
{mujian ? children : (loadingPage ?? 'Mujian is loading')}
</MujianContext.Provider>
);
};
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;
};