using System; using System.Collections.Generic; using DynamicExpresso; using Ichni.Menu; using Ichni.Story; using Ichni.Story.UI; using UnityEngine; namespace Ichni.Story { public static partial class StoryInterpreters { public static readonly Interpreter FunctionInterpreter; public static readonly Interpreter ConditionInterpreter; static StoryInterpreters() { FunctionInterpreter = new Interpreter(); ConditionInterpreter = new Interpreter(); SetFunctionInterpreter(); SetConditionInterpreter(); } static void SetFunctionInterpreter() { FunctionInterpreter.SetFunction("SetVariable", new Action(SetStoryVariable)); FunctionInterpreter.SetFunction("GetVariable", new Func(GetStoryVariable)); FunctionInterpreter.SetFunction("GenerateDialogBlock", new Action(GenerateDialogBlock)); FunctionInterpreter.SetFunction("GenerateSongBlock", new Action(GenerateSongBlock)); FunctionInterpreter.SetFunction("SetUnlockKey", new Action(SetUnlockKey)); } static void SetConditionInterpreter() { ConditionInterpreter.SetFunction("GetVariable", new Func(GetStoryVariable)); } } public static partial class StoryInterpreters { /// /// 设置全局变量的值 /// static void SetStoryVariable(string variableName, int value) { GameSaveManager.instance.StorySaveModule.storyVariables[variableName] = value; } /// /// 获取全局变量的值 /// static int GetStoryVariable(string variableName) { if (GameSaveManager.instance.StorySaveModule.storyVariables.TryGetValue(variableName, out int value)) { return value; } throw new ArgumentException($"Global variable '{variableName}' not found."); } } public static partial class StoryInterpreters { static void GenerateDialogBlock(string blockName) { StoryBlockUIBase currentBlock = StoryManager.instance.storyline.currentBlock; Vector2 positionOffset = new Vector2(500, 0); DialogBlockUI newBlock = StoryManager.instance.storyline.GenerateDialogBlock(blockName, currentBlock.blockPosition + positionOffset, StoryBlockState.Current); StoryManager.instance.storyline.GenerateConnector(currentBlock, newBlock); StoryManager.instance.storyline.SetUpBackground(); StoryManager.instance.storyline.connectors.ForEach(c => c.SetCurve()); } static void GenerateSongBlock(string blockName) { StoryBlockUIBase currentBlock = StoryManager.instance.storyline.currentBlock; Vector2 positionOffset = new Vector2(500, 0); SongBlockUI newBlock = StoryManager.instance.storyline.GenerateSongBlock(blockName, currentBlock.blockPosition + positionOffset, StoryBlockState.Current); StoryManager.instance.storyline.GenerateConnector(currentBlock, newBlock); } static void SetUnlockKey(string key) { if (GameSaveManager.instance.SongSaveModule.storyUnlockKeys.Add(key)) { GameSaveManager.instance.SongSaveModule.SaveStoryUnlockKeys(); DialogManager.instance.dialogEndActions.Add(() => { ChapterSelectionUnit currentChapter = ChapterSelectionManager.instance.currentChapter; List unlockedSongs = currentChapter.GetRelatedSongNamesOfUnlockKey(key); foreach (string songName in unlockedSongs) { StoryManager.instance.storyUIPage.messageBox.AddInfo( "Message/Unlock_Song_Title", "Message/Unlock_Song", () => StoryManager.instance.storyUIPage.messageBox.SetParameter("SongName", songName)); } }); } } } }