Skip to content

Commit e30a8f7

Browse files
authored
Merge pull request #3 from HeZeBang/dev/danmaku
Dev/danmaku
2 parents deb963b + 0b88243 commit e30a8f7

11 files changed

Lines changed: 2272 additions & 3657 deletions

.env.example

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,11 @@ META_DESCRIPTION=Welcome to DrawPlace! Collaborate with art enthusiasts to creat
1717
DRAW_DELAY_MS=5000
1818
DRAW_MAX_POINTS=24
1919
CANVAS_WIDTH=1534
20-
CANVAS_HEIGHT=1009
20+
CANVAS_HEIGHT=1009
21+
22+
# Danmaku
23+
DANMAKU_ACTIVITY_ID=your_activity
24+
DANMAKU_TOKEN_NAME=your_token_name
25+
DANMAKU_TOKEN=your_custom_token
26+
DANMAKU_ROOT_PATH=https://danmaku.geekpie.club
27+
DANMAKU_SOCKET_PATH=/socket.io

components/Board.tsx

Lines changed: 111 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { Button } from "./ui/button";
3030
import { cn } from "@/lib/utils";
3131
import AnnounceModal from "./AnnounceModal";
3232
import { parseInitData } from "@/lib/binary-parser";
33+
import DanmakuPlayer from "./Danmaku";
3334

3435
const Board = () => {
3536
const { config } = useRuntimeConfigContext();
@@ -496,118 +497,120 @@ const Board = () => {
496497
</div>
497498

498499
{/* Canvas Area - Flexible */}
499-
<div className="flex-1 overflow-hidden relative bg-muted/20 flex items-center justify-center">
500-
<TransformWrapper
501-
initialScale={1}
502-
minScale={0.3}
503-
maxScale={20}
504-
centerOnInit={true}
505-
smooth={false}
506-
wheel={{ step: ratio * 0.1, touchPadDisabled: false }}
507-
panning={{
508-
allowLeftClickPan: editable ? false : true,
509-
allowMiddleClickPan: true,
510-
allowRightClickPan: true,
511-
}} // Middle or Right click to pan
512-
onTransformed={(e) => setRatio(e.state.scale)}
513-
doubleClick={{ disabled: true }}
514-
>
515-
<TransformComponent wrapperStyle={{ width: "100%", height: "100%" }}>
516-
<div
517-
className="bg-background shadow-2xl border border-border"
518-
style={{
519-
backgroundImage:
520-
statusConfig.currentViewMode !== ViewMode.CanvasOnly
521-
? `url(/map.png)`
522-
: undefined,
523-
imageRendering: ratio > 1 ? "pixelated" : "auto",
500+
<DanmakuPlayer>
501+
<div className="h-full w-full overflow-hidden relative bg-muted/20 flex items-center justify-center">
502+
<TransformWrapper
503+
initialScale={1}
504+
minScale={0.3}
505+
maxScale={20}
506+
centerOnInit={true}
507+
smooth={false}
508+
wheel={{ step: ratio * 0.1, touchPadDisabled: false }}
509+
panning={{
510+
allowLeftClickPan: editable ? false : true,
511+
allowMiddleClickPan: true,
512+
allowRightClickPan: true,
513+
}} // Middle or Right click to pan
514+
onTransformed={(e) => setRatio(e.state.scale)}
515+
doubleClick={{ disabled: true }}
516+
>
517+
<TransformComponent wrapperStyle={{ width: "100%", height: "100%" }}>
518+
<div
519+
className="bg-background shadow-2xl border border-border"
520+
style={{
521+
backgroundImage:
522+
statusConfig.currentViewMode !== ViewMode.CanvasOnly
523+
? `url(/map.png)`
524+
: undefined,
525+
imageRendering: ratio > 1 ? "pixelated" : "auto",
526+
}}
527+
>
528+
<Canvas
529+
ref={canvasRef}
530+
color={selectedColor}
531+
onMove={handleMove}
532+
onDraw={handleDraw}
533+
editable={pointsLeft > 0 && editable}
534+
opacity={
535+
statusConfig.currentViewMode !== ViewMode.MapOnly ? "1" : "0"
536+
}
537+
/>
538+
{settingsConfig.useOverlay && (
539+
<rect
540+
className={cn(
541+
"h-[1px] w-[1px] pointer-events-none z-10 absolute ring-[0.1px] ring-black ring-offset-[0.1px]",
542+
editable ? "animate-pulse" : "opacity-50",
543+
)}
544+
style={{
545+
left: location.x + 1,
546+
top: location.y + 1,
547+
backgroundColor:
548+
(editable && selectedColor) || "transparent",
549+
shapeRendering: "crispEdges",
550+
}}
551+
/>
552+
)}
553+
</div>
554+
</TransformComponent>
555+
</TransformWrapper>
556+
<LoginModal
557+
isOpen={showLoginModal}
558+
onClickBtn={handleLogin}
559+
onClose={() => setShowLoginModal(false)}
560+
/>
561+
<GuideModal
562+
isOpen={showGuideModal}
563+
onClickBtn={() => {
564+
updateSettingsConfig({ showGuideOnLoad: false });
565+
setShowGuideModal(false);
566+
}}
567+
onClose={() => {
568+
updateSettingsConfig({ showGuideOnLoad: false });
569+
setShowGuideModal(false);
570+
}}
571+
/>
572+
<AnnounceModal
573+
isOpen={showAnnounce}
574+
onClickBtn={() => {
575+
updateSettingsConfig({
576+
announcementVersion: process.env.NEXT_PUBLIC_APP_VERSION || "",
577+
});
578+
setShowAnnounce(false);
579+
}}
580+
onClose={() => {
581+
updateSettingsConfig({
582+
announcementVersion: process.env.NEXT_PUBLIC_APP_VERSION || "",
583+
});
584+
setShowAnnounce(false);
585+
}}
586+
/>
587+
<div className="absolute bottom-4 mx-auto flex gap-3">
588+
<Button
589+
variant="outline"
590+
size="sm"
591+
className={cn(
592+
"w-fit h-8 rounded-full px-3 border-none transition-all duration-500",
593+
editable ? "" : "opacity-30",
594+
"hover:opacity-100 delay-1000 hover:delay-0",
595+
)}
596+
onClick={() => {
597+
setEditable((val) => !val);
524598
}}
525599
>
526-
<Canvas
527-
ref={canvasRef}
528-
color={selectedColor}
529-
onMove={handleMove}
530-
onDraw={handleDraw}
531-
editable={pointsLeft > 0 && editable}
532-
opacity={
533-
statusConfig.currentViewMode !== ViewMode.MapOnly ? "1" : "0"
534-
}
535-
/>
536-
{settingsConfig.useOverlay && (
537-
<rect
538-
className={cn(
539-
"h-[1px] w-[1px] pointer-events-none z-10 absolute ring-[0.1px] ring-black ring-offset-[0.1px]",
540-
editable ? "animate-pulse" : "opacity-50",
541-
)}
542-
style={{
543-
left: location.x + 1,
544-
top: location.y + 1,
545-
backgroundColor:
546-
(editable && selectedColor) || "transparent",
547-
shapeRendering: "crispEdges",
548-
}}
549-
/>
600+
{editable ? (
601+
<Brush className="h-4 w-4" />
602+
) : (
603+
<View className="h-4 w-4" />
550604
)}
551-
</div>
552-
</TransformComponent>
553-
</TransformWrapper>
554-
<LoginModal
555-
isOpen={showLoginModal}
556-
onClickBtn={handleLogin}
557-
onClose={() => setShowLoginModal(false)}
558-
/>
559-
<GuideModal
560-
isOpen={showGuideModal}
561-
onClickBtn={() => {
562-
updateSettingsConfig({ showGuideOnLoad: false });
563-
setShowGuideModal(false);
564-
}}
565-
onClose={() => {
566-
updateSettingsConfig({ showGuideOnLoad: false });
567-
setShowGuideModal(false);
568-
}}
569-
/>
570-
<AnnounceModal
571-
isOpen={showAnnounce}
572-
onClickBtn={() => {
573-
updateSettingsConfig({
574-
announcementVersion: process.env.NEXT_PUBLIC_APP_VERSION || "",
575-
});
576-
setShowAnnounce(false);
577-
}}
578-
onClose={() => {
579-
updateSettingsConfig({
580-
announcementVersion: process.env.NEXT_PUBLIC_APP_VERSION || "",
581-
});
582-
setShowAnnounce(false);
583-
}}
584-
/>
585-
<div className="absolute bottom-4 mx-auto flex gap-3">
586-
<Button
587-
variant="outline"
588-
size="sm"
589-
className={cn(
590-
"w-fit h-8 rounded-full px-3 border-none transition-all duration-500",
591-
editable ? "" : "opacity-30",
592-
"hover:opacity-100 delay-1000 hover:delay-0",
593-
)}
594-
onClick={() => {
595-
setEditable((val) => !val);
596-
}}
597-
>
598-
{editable ? (
599-
<Brush className="h-4 w-4" />
600-
) : (
601-
<View className="h-4 w-4" />
602-
)}
603-
{editable ? (
604-
<span className="">绘制模式</span>
605-
) : (
606-
<span className="">浏览模式</span>
607-
)}
608-
</Button>
605+
{editable ? (
606+
<span className="">绘制模式</span>
607+
) : (
608+
<span className="">浏览模式</span>
609+
)}
610+
</Button>
611+
</div>
609612
</div>
610-
</div>
613+
</DanmakuPlayer>
611614

612615
{/* Bottom Control Area */}
613616
<div className="bg-card border-t p-4 z-10 shrink-0">

0 commit comments

Comments
 (0)