sa2kit 1.6.0 → 1.6.1

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.
@@ -2827,6 +2827,7 @@ var MMDVisualNovel = forwardRef(
2827
2827
  const [pendingNodeIndex, setPendingNodeIndex] = useState(null);
2828
2828
  const [showChoices, setShowChoices] = useState(false);
2829
2829
  const [isCameraManual, setIsCameraManual] = useState(false);
2830
+ const [variables, setVariables] = useState({});
2830
2831
  const playerRef = useRef(null);
2831
2832
  const containerRef = useRef(null);
2832
2833
  const autoTimerRef = useRef(null);
@@ -2848,32 +2849,6 @@ var MMDVisualNovel = forwardRef(
2848
2849
  }
2849
2850
  ]);
2850
2851
  }, []);
2851
- const goToNextDialogue = useCallback(() => {
2852
- if (!currentNode) return;
2853
- if (autoTimerRef.current) {
2854
- clearTimeout(autoTimerRef.current);
2855
- autoTimerRef.current = null;
2856
- }
2857
- const nextDialogueIndex = currentDialogueIndex + 1;
2858
- if (nextDialogueIndex < currentNode.dialogues.length && currentNode?.dialogues[nextDialogueIndex] !== void 0) {
2859
- const nextDialogue = currentNode.dialogues[nextDialogueIndex];
2860
- setCurrentDialogueIndex(nextDialogueIndex);
2861
- addToHistory(nextDialogue, currentNodeIndex, nextDialogueIndex);
2862
- onDialogueChange?.(nextDialogue, nextDialogueIndex, currentNodeIndex);
2863
- typingCompleteRef.current = false;
2864
- } else if (currentNode.choices && currentNode.choices.length > 0) {
2865
- setShowChoices(true);
2866
- } else {
2867
- const nextNodeIndex = currentNodeIndex + 1;
2868
- if (nextNodeIndex < nodes.length) {
2869
- goToNode(nextNodeIndex);
2870
- } else if (loop) {
2871
- goToNode(0);
2872
- } else {
2873
- onScriptComplete?.();
2874
- }
2875
- }
2876
- }, [currentNode, currentDialogueIndex, currentNodeIndex, nodes.length, loop, addToHistory, onDialogueChange, onScriptComplete]);
2877
2852
  const goToNode = useCallback(
2878
2853
  (nodeIndex, force = false) => {
2879
2854
  if (nodeIndex < 0 || nodeIndex >= nodes.length) return;
@@ -2912,8 +2887,52 @@ var MMDVisualNovel = forwardRef(
2912
2887
  }, 100);
2913
2888
  }, 300);
2914
2889
  },
2915
- [nodes, isTransitioning, addToHistory, onNodeChange, onDialogueChange, currentNodeIndex, isVmdFinished]
2890
+ [nodes, isTransitioning, addToHistory, onNodeChange, onDialogueChange, currentNodeIndex]
2916
2891
  );
2892
+ const triggerNodeTransition = useCallback(() => {
2893
+ if (!currentNode) return;
2894
+ let nextNodeIndex = currentNodeIndex + 1;
2895
+ if (currentNode.nextCondition) {
2896
+ const { key, map, defaultIndex } = currentNode.nextCondition;
2897
+ const val = variables[key];
2898
+ if (val !== void 0 && map[val] !== void 0) {
2899
+ nextNodeIndex = map[val];
2900
+ console.log(`[MMDVisualNovel] Branching: ${key}=${val} -> node ${nextNodeIndex}`);
2901
+ } else {
2902
+ nextNodeIndex = defaultIndex;
2903
+ }
2904
+ }
2905
+ if (nextNodeIndex < nodes.length && nextNodeIndex >= 0) {
2906
+ goToNode(nextNodeIndex);
2907
+ } else if (loop) {
2908
+ goToNode(0);
2909
+ } else {
2910
+ onScriptComplete?.();
2911
+ }
2912
+ }, [currentNode, currentNodeIndex, nodes.length, loop, variables, goToNode, onScriptComplete]);
2913
+ const goToNextDialogue = useCallback(() => {
2914
+ if (!currentNode) return;
2915
+ if (currentDialogue?.choices && currentDialogue.choices.length > 0 && !showChoices) {
2916
+ setShowChoices(true);
2917
+ return;
2918
+ }
2919
+ if (autoTimerRef.current) {
2920
+ clearTimeout(autoTimerRef.current);
2921
+ autoTimerRef.current = null;
2922
+ }
2923
+ const nextDialogueIndex = currentDialogueIndex + 1;
2924
+ if (nextDialogueIndex < currentNode.dialogues.length && currentNode?.dialogues[nextDialogueIndex] !== void 0) {
2925
+ const nextDialogue = currentNode.dialogues[nextDialogueIndex];
2926
+ setCurrentDialogueIndex(nextDialogueIndex);
2927
+ addToHistory(nextDialogue, currentNodeIndex, nextDialogueIndex);
2928
+ onDialogueChange?.(nextDialogue, nextDialogueIndex, currentNodeIndex);
2929
+ typingCompleteRef.current = false;
2930
+ } else if (currentNode.choices && currentNode.choices.length > 0) {
2931
+ setShowChoices(true);
2932
+ } else {
2933
+ triggerNodeTransition();
2934
+ }
2935
+ }, [currentNode, currentDialogue, currentDialogueIndex, currentNodeIndex, nodes.length, loop, addToHistory, onDialogueChange, onScriptComplete, showChoices, variables, goToNode, triggerNodeTransition]);
2917
2936
  const goToDialogue = useCallback(
2918
2937
  (dialogueIndex) => {
2919
2938
  if (!currentNode) return;
@@ -2992,6 +3011,10 @@ var MMDVisualNovel = forwardRef(
2992
3011
  getCurrentNodeIndex: () => currentNodeIndex,
2993
3012
  getCurrentDialogueIndex: () => currentDialogueIndex,
2994
3013
  getHistory: () => history,
3014
+ getVariables: () => variables,
3015
+ setVariable: (key, value) => {
3016
+ setVariables((prev) => ({ ...prev, [key]: value }));
3017
+ },
2995
3018
  setAutoMode: setIsAutoMode,
2996
3019
  skipTyping: () => {
2997
3020
  typingCompleteRef.current = true;
@@ -3152,18 +3175,38 @@ var MMDVisualNovel = forwardRef(
3152
3175
  }
3153
3176
  }
3154
3177
  ),
3155
- showChoices && currentNode.choices && /* @__PURE__ */ React6.createElement(
3178
+ showChoices && (currentDialogue?.choices || currentNode.choices) && /* @__PURE__ */ React6.createElement(
3156
3179
  ChoiceMenu,
3157
3180
  {
3158
- choices: currentNode.choices,
3181
+ choices: currentDialogue?.choices || currentNode.choices,
3159
3182
  theme: dialogueTheme,
3160
3183
  onSelect: (choice) => {
3184
+ if (choice.setVariable) {
3185
+ const { key, value } = choice.setVariable;
3186
+ setVariables((prev) => ({ ...prev, [key]: value }));
3187
+ console.log(`[MMDVisualNovel] Variable set: ${key} = ${value}`);
3188
+ }
3161
3189
  choice.onSelect?.();
3162
- if (choice.nextNodeIndex === currentNodeIndex) {
3163
- goToDialogue(choice.nextDialogueIndex || 0);
3164
- setShowChoices(false);
3165
- } else {
3166
- goToNode(choice.nextNodeIndex, true);
3190
+ setShowChoices(false);
3191
+ if (choice.nextNodeIndex !== void 0) {
3192
+ if (choice.nextNodeIndex === currentNodeIndex) {
3193
+ goToDialogue(choice.nextDialogueIndex || 0);
3194
+ } else {
3195
+ goToNode(choice.nextNodeIndex, true);
3196
+ }
3197
+ } else if (currentDialogue?.choices) {
3198
+ const nextIdx = currentDialogueIndex + 1;
3199
+ if (currentNode && nextIdx < currentNode.dialogues.length) {
3200
+ const nextDialogue = currentNode.dialogues[nextIdx];
3201
+ if (nextDialogue) {
3202
+ setCurrentDialogueIndex(nextIdx);
3203
+ addToHistory(nextDialogue, currentNodeIndex, nextIdx);
3204
+ onDialogueChange?.(nextDialogue, nextIdx, currentNodeIndex);
3205
+ typingCompleteRef.current = false;
3206
+ }
3207
+ } else {
3208
+ triggerNodeTransition();
3209
+ }
3167
3210
  }
3168
3211
  }
3169
3212
  }
@@ -3582,6 +3625,6 @@ var MMDMusicPlayer = forwardRef(
3582
3625
  );
3583
3626
  MMDMusicPlayer.displayName = "MMDMusicPlayer";
3584
3627
 
3585
- export { DialogueBox, HistoryPanel, LoadingOverlay, LoadingScreen, MMDMusicPlayer, MMDPlayerBase, MMDPlayerEnhanced, MMDPlayerEnhancedDebugInfo, MMDPlaylist, MMDPlaylistDebugInfo, MMDVisualNovel, MusicControls, PlaylistPanel, StartScreen, TrackInfo, loadAmmo };
3628
+ export { ChoiceMenu, DialogueBox, HistoryPanel, LoadingOverlay, LoadingScreen, MMDMusicPlayer, MMDPlayerBase, MMDPlayerEnhanced, MMDPlayerEnhancedDebugInfo, MMDPlaylist, MMDPlaylistDebugInfo, MMDVisualNovel, MusicControls, PlaylistPanel, StartScreen, TrackInfo, loadAmmo };
3586
3629
  //# sourceMappingURL=index.mjs.map
3587
3630
  //# sourceMappingURL=index.mjs.map