@luna-editor/engine 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/Player.d.ts +3 -0
  2. package/dist/Player.js +336 -0
  3. package/dist/atoms/screen-size.d.ts +22 -0
  4. package/dist/atoms/screen-size.js +8 -0
  5. package/dist/components/BacklogUI.d.ts +2 -0
  6. package/dist/components/BacklogUI.js +115 -0
  7. package/dist/components/ConversationLogUI.d.ts +2 -0
  8. package/dist/components/ConversationLogUI.js +115 -0
  9. package/dist/components/DebugControls.d.ts +12 -0
  10. package/dist/components/DebugControls.js +5 -0
  11. package/dist/components/DialogueBox.d.ts +2 -0
  12. package/dist/components/DialogueBox.js +28 -0
  13. package/dist/components/EndScreen.d.ts +8 -0
  14. package/dist/components/EndScreen.js +5 -0
  15. package/dist/components/GameScreen.d.ts +9 -0
  16. package/dist/components/GameScreen.js +111 -0
  17. package/dist/components/OverlayUI.d.ts +13 -0
  18. package/dist/components/OverlayUI.js +21 -0
  19. package/dist/components/PluginComponentProvider.d.ts +14 -0
  20. package/dist/components/PluginComponentProvider.js +24 -0
  21. package/dist/constants/screen-size.d.ts +3 -0
  22. package/dist/constants/screen-size.js +6 -0
  23. package/dist/contexts/DataContext.d.ts +24 -0
  24. package/dist/contexts/DataContext.js +101 -0
  25. package/dist/hooks/useBacklog.d.ts +14 -0
  26. package/dist/hooks/useBacklog.js +82 -0
  27. package/dist/hooks/useConversationLog.d.ts +14 -0
  28. package/dist/hooks/useConversationLog.js +82 -0
  29. package/dist/hooks/usePlayerLogic.d.ts +21 -0
  30. package/dist/hooks/usePlayerLogic.js +145 -0
  31. package/dist/hooks/usePluginAPI.d.ts +19 -0
  32. package/dist/hooks/usePluginAPI.js +42 -0
  33. package/dist/hooks/usePluginEvents.d.ts +14 -0
  34. package/dist/hooks/usePluginEvents.js +197 -0
  35. package/dist/hooks/usePreloadImages.d.ts +2 -0
  36. package/dist/hooks/usePreloadImages.js +56 -0
  37. package/dist/hooks/useScreenSize.d.ts +89 -0
  38. package/dist/hooks/useScreenSize.js +87 -0
  39. package/dist/hooks/useTypewriter.d.ts +11 -0
  40. package/dist/hooks/useTypewriter.js +56 -0
  41. package/dist/hooks/useUIVisibility.d.ts +9 -0
  42. package/dist/hooks/useUIVisibility.js +19 -0
  43. package/dist/hooks/useVoice.d.ts +4 -0
  44. package/dist/hooks/useVoice.js +21 -0
  45. package/dist/index.d.ts +10 -0
  46. package/dist/index.js +9 -0
  47. package/dist/plugin/PluginManager.d.ts +108 -0
  48. package/dist/plugin/PluginManager.js +851 -0
  49. package/dist/plugin/luna-react.d.ts +41 -0
  50. package/dist/plugin/luna-react.js +99 -0
  51. package/dist/sdk.d.ts +512 -0
  52. package/dist/sdk.js +64 -0
  53. package/dist/types.d.ts +186 -0
  54. package/dist/types.js +2 -0
  55. package/dist/utils/attributeNormalizer.d.ts +5 -0
  56. package/dist/utils/attributeNormalizer.js +53 -0
  57. package/dist/utils/facePositionCalculator.d.ts +29 -0
  58. package/dist/utils/facePositionCalculator.js +127 -0
  59. package/package.json +55 -0
@@ -0,0 +1,56 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ export const useTypewriter = (options = {}) => {
3
+ const { speed = 50, onComplete } = options;
4
+ const [displayText, setDisplayText] = useState("");
5
+ const [isTyping, setIsTyping] = useState(false);
6
+ const typingTimeoutRef = useRef(null);
7
+ const startTyping = useCallback((text) => {
8
+ setDisplayText("");
9
+ setIsTyping(true);
10
+ if (typingTimeoutRef.current) {
11
+ clearTimeout(typingTimeoutRef.current);
12
+ }
13
+ let index = 0;
14
+ const typeChar = () => {
15
+ if (index < text.length) {
16
+ setDisplayText(text.slice(0, index + 1));
17
+ index++;
18
+ typingTimeoutRef.current = setTimeout(typeChar, speed);
19
+ }
20
+ else {
21
+ setIsTyping(false);
22
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete();
23
+ }
24
+ };
25
+ typeChar();
26
+ }, [speed, onComplete]);
27
+ const skipTyping = useCallback((text) => {
28
+ if (typingTimeoutRef.current) {
29
+ clearTimeout(typingTimeoutRef.current);
30
+ }
31
+ setDisplayText(text);
32
+ setIsTyping(false);
33
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete();
34
+ }, [onComplete]);
35
+ const reset = useCallback(() => {
36
+ if (typingTimeoutRef.current) {
37
+ clearTimeout(typingTimeoutRef.current);
38
+ }
39
+ setDisplayText("");
40
+ setIsTyping(false);
41
+ }, []);
42
+ useEffect(() => {
43
+ return () => {
44
+ if (typingTimeoutRef.current) {
45
+ clearTimeout(typingTimeoutRef.current);
46
+ }
47
+ };
48
+ }, []);
49
+ return {
50
+ displayText,
51
+ isTyping,
52
+ startTyping,
53
+ skipTyping,
54
+ reset,
55
+ };
56
+ };
@@ -0,0 +1,9 @@
1
+ import type { PluginManager } from "../plugin/PluginManager";
2
+ import type { ComponentType } from "../sdk";
3
+ /**
4
+ * UI コンポーネントの表示状態を管理するフック
5
+ * @param pluginManager - PluginManager インスタンス
6
+ * @param type - コンポーネントタイプ
7
+ * @returns [isVisible, show, hide, toggle]
8
+ */
9
+ export declare function useUIVisibility(pluginManager: PluginManager, type: ComponentType): [boolean, () => void, () => void, () => void];
@@ -0,0 +1,19 @@
1
+ import { useEffect, useState } from "react";
2
+ /**
3
+ * UI コンポーネントの表示状態を管理するフック
4
+ * @param pluginManager - PluginManager インスタンス
5
+ * @param type - コンポーネントタイプ
6
+ * @returns [isVisible, show, hide, toggle]
7
+ */
8
+ export function useUIVisibility(pluginManager, type) {
9
+ const [isVisible, setIsVisible] = useState(() => pluginManager.getUIVisibility(type));
10
+ useEffect(() => {
11
+ // UI 状態の変更を監視
12
+ const unsubscribe = pluginManager.subscribeUIVisibility(type, setIsVisible);
13
+ return unsubscribe;
14
+ }, [pluginManager, type]);
15
+ const show = () => pluginManager.showUI(type);
16
+ const hide = () => pluginManager.hideUI(type);
17
+ const toggle = () => pluginManager.toggleUIVisibility(type);
18
+ return [isVisible, show, hide, toggle];
19
+ }
@@ -0,0 +1,4 @@
1
+ export declare const useVoice: () => {
2
+ playVoice: (voiceUrl: string) => void;
3
+ stopVoice: () => void;
4
+ };
@@ -0,0 +1,21 @@
1
+ import { useCallback, useRef } from "react";
2
+ export const useVoice = () => {
3
+ const audioRef = useRef(null);
4
+ const playVoice = useCallback((voiceUrl) => {
5
+ if (!audioRef.current) {
6
+ audioRef.current = new Audio();
7
+ }
8
+ audioRef.current.src = voiceUrl;
9
+ audioRef.current.play().catch(console.error);
10
+ }, []);
11
+ const stopVoice = useCallback(() => {
12
+ if (audioRef.current) {
13
+ audioRef.current.pause();
14
+ audioRef.current.currentTime = 0;
15
+ }
16
+ }, []);
17
+ return {
18
+ playVoice,
19
+ stopVoice,
20
+ };
21
+ };
@@ -0,0 +1,10 @@
1
+ export { useScreenSizeAtom } from "./atoms/screen-size";
2
+ export { OverlayUI } from "./components/OverlayUI";
3
+ export { aspectRatio, BasisHeight, BasisWidth } from "./constants/screen-size";
4
+ export { useDataAPI } from "./contexts/DataContext";
5
+ export { setGlobalUIAPI, usePluginAPI, useUIVisibility, } from "./hooks/usePluginAPI";
6
+ export { useScreenScale, useScreenSize, useToPixel, } from "./hooks/useScreenSize";
7
+ export { Player } from "./Player";
8
+ export type { BacklogData, DataAPI, DataContext, PlayerSettingsData, ScenarioPlaybackData, } from "./sdk";
9
+ export { ComponentType } from "./sdk";
10
+ export type { ActionNode, BacklogEntry, Character, DisplayedCharacter, EntityState, PlayerProps, PlayerSettings, PlayerState, PluginConfig, PublishedScenario, ScenarioBlock, ScenarioBlockAttributeValue, ScenarioBlockCharacter, ScenarioBlockEntityAttributeValue, ScenarioBlockType, } from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ // Screen size system
2
+ export { useScreenSizeAtom } from "./atoms/screen-size";
3
+ export { OverlayUI } from "./components/OverlayUI";
4
+ export { aspectRatio, BasisHeight, BasisWidth } from "./constants/screen-size";
5
+ export { useDataAPI } from "./contexts/DataContext";
6
+ export { setGlobalUIAPI, usePluginAPI, useUIVisibility, } from "./hooks/usePluginAPI";
7
+ export { useScreenScale, useScreenSize, useToPixel, } from "./hooks/useScreenSize";
8
+ export { Player } from "./Player";
9
+ export { ComponentType } from "./sdk";
@@ -0,0 +1,108 @@
1
+ import React from "react";
2
+ import { type ActionExecutionContext, type ActionNodeDefinition, type BlockChangeContext, type CharacterContext, type CharacterSpeakContext, ComponentType, type DialogueContext, type LunaPlugin, type ScenarioContext, type ScenarioReadyContext, type UIAPI } from "../sdk";
3
+ export interface LoadedPlugin {
4
+ plugin: LunaPlugin;
5
+ instance: PluginInstance;
6
+ enabled: boolean;
7
+ config: unknown;
8
+ }
9
+ interface PluginHooksImpl {
10
+ onInit?: () => void;
11
+ onScenarioReady?: (context: ScenarioReadyContext) => void;
12
+ onBlockChange?: (context: BlockChangeContext) => void;
13
+ onCharacterEnter?: (context: CharacterContext) => void;
14
+ onCharacterExit?: (context: CharacterContext) => void;
15
+ onDialogueShow?: (context: DialogueContext) => void;
16
+ characterSpeakHandler?: (context: CharacterSpeakContext) => void;
17
+ onActionExecute?: (context: ActionExecutionContext) => void;
18
+ onScenarioStart?: (context: ScenarioContext) => void;
19
+ onScenarioEnd?: (context: ScenarioContext) => void;
20
+ }
21
+ export interface PluginInstance {
22
+ actionNodes: Map<string, ActionNodeDefinition>;
23
+ hooks: PluginHooksImpl;
24
+ styles: Map<string, string[]>;
25
+ effects: Map<string, HTMLElement>;
26
+ overlays: Map<string, HTMLElement>;
27
+ components: Map<ComponentType, React.ComponentType<any>>;
28
+ assetUrls: Map<string, string>;
29
+ }
30
+ export declare class PluginManager {
31
+ private plugins;
32
+ private styleElements;
33
+ private injectedStyles;
34
+ private storage;
35
+ private componentRegistry;
36
+ private uiVisibilityState;
37
+ private uiVisibilityListeners;
38
+ constructor();
39
+ /**
40
+ * グローバルReactランタイムを初期化(クライアントサイドのみ)
41
+ */
42
+ private initializeReactRuntime;
43
+ loadPlugin(packageName: string, bundleUrl: string, config?: unknown): Promise<void>;
44
+ private loadPluginScript;
45
+ private createPluginAPI;
46
+ private applyStyles;
47
+ private hideEffect;
48
+ private removeOverlay;
49
+ registerStyleElement(name: string, element: HTMLElement): void;
50
+ callHook(hookName: keyof PluginHooksImpl, ...args: unknown[]): void;
51
+ executeActionNode(nodeType: string, context: unknown): Promise<void>;
52
+ setPluginEnabled(packageName: string, enabled: boolean): void;
53
+ cleanup(): void;
54
+ private findPluginByComponentType;
55
+ getComponent(type: ComponentType): React.ComponentType | null;
56
+ hasComponent(type: ComponentType): boolean;
57
+ getRegisteredComponents(): ComponentType[];
58
+ /**
59
+ * Get ActionNode definition by type
60
+ */
61
+ getActionNodeDefinition(type: string): ActionNodeDefinition | undefined;
62
+ /**
63
+ * プラグインのアセットURLを取得
64
+ * @param packageName - プラグインのパッケージ名
65
+ * @param filename - アセットファイル名
66
+ * @returns アセットのURL(見つからない場合は空文字列)
67
+ */
68
+ getPluginAssetUrl(packageName: string, filename: string): string;
69
+ /**
70
+ * UI コンポーネントの表示状態を設定
71
+ * @param type - コンポーネントタイプ
72
+ * @param visible - 表示状態
73
+ */
74
+ private setUIVisibility;
75
+ /**
76
+ * UI コンポーネントの表示状態を取得
77
+ * @param type - コンポーネントタイプ
78
+ * @returns 表示状態
79
+ */
80
+ getUIVisibility(type: ComponentType): boolean;
81
+ /**
82
+ * UI コンポーネントの表示状態変更を監視
83
+ * @param type - コンポーネントタイプ
84
+ * @param listener - コールバック関数
85
+ * @returns リスナーを削除する関数
86
+ */
87
+ subscribeUIVisibility(type: ComponentType, listener: (visible: boolean) => void): () => void;
88
+ /**
89
+ * UIAPIを取得する(プラグインコンポーネントで使用可能にするため)
90
+ */
91
+ getUIAPI(): UIAPI;
92
+ /**
93
+ * UI コンポーネントの表示/非表示を切り替え
94
+ * @param type - コンポーネントタイプ
95
+ */
96
+ toggleUIVisibility(type: ComponentType): void;
97
+ /**
98
+ * UI コンポーネントを表示
99
+ * @param type - コンポーネントタイプ
100
+ */
101
+ showUI(type: ComponentType): void;
102
+ /**
103
+ * UI コンポーネントを非表示
104
+ * @param type - コンポーネントタイプ
105
+ */
106
+ hideUI(type: ComponentType): void;
107
+ }
108
+ export {};