104 lines
4.2 KiB
C#
104 lines
4.2 KiB
C#
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<string, int>(SetStoryVariable));
|
|
FunctionInterpreter.SetFunction("GetVariable", new Func<string, int>(GetStoryVariable));
|
|
FunctionInterpreter.SetFunction("GenerateDialogBlock", new Action<string>(GenerateDialogBlock));
|
|
FunctionInterpreter.SetFunction("GenerateSongBlock", new Action<string>(GenerateSongBlock));
|
|
FunctionInterpreter.SetFunction("SetUnlockKey", new Action<string>(SetUnlockKey));
|
|
}
|
|
|
|
static void SetConditionInterpreter()
|
|
{
|
|
ConditionInterpreter.SetFunction("GetVariable", new Func<string, int>(GetStoryVariable));
|
|
}
|
|
}
|
|
|
|
public static partial class StoryInterpreters
|
|
{
|
|
/// <summary>
|
|
/// 设置全局变量的值
|
|
/// </summary>
|
|
static void SetStoryVariable(string variableName, int value)
|
|
{
|
|
GameSaveManager.instance.StorySaveModule.storyVariables[variableName] = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取全局变量的值
|
|
/// </summary>
|
|
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<string> 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));
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
} |