mirror of
https://github.com/HoonTB/Project-AS.git
synced 2025-12-26 11:51:21 +09:00
chore: change class names
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Script
|
||||
public class Command
|
||||
{
|
||||
private List<ScriptAction> _actions;
|
||||
private List<CommandSet> _actions;
|
||||
private int _currentIndex = -1;
|
||||
private Dictionary<string, int> _labelMap = new();
|
||||
|
||||
public Script(List<ScriptAction> actions, Dictionary<string, int> labelMap)
|
||||
public Command(List<CommandSet> actions, Dictionary<string, int> labelMap)
|
||||
{
|
||||
_actions = actions;
|
||||
_labelMap = labelMap;
|
||||
@@ -19,25 +19,25 @@ public class Script
|
||||
return _currentIndex < _actions.Count - 1;
|
||||
}
|
||||
|
||||
public ScriptAction Continue()
|
||||
public CommandSet Continue()
|
||||
{
|
||||
if (!HasNextAction())
|
||||
return null;
|
||||
|
||||
_currentIndex++;
|
||||
ScriptAction currentAction = _actions[_currentIndex];
|
||||
CommandSet currentAction = _actions[_currentIndex];
|
||||
|
||||
return currentAction;
|
||||
}
|
||||
|
||||
public ScriptAction GetCurrent()
|
||||
public CommandSet GetCurrent()
|
||||
{
|
||||
if (_currentIndex >= 0 && _currentIndex < _actions.Count)
|
||||
return _actions[_currentIndex];
|
||||
return null;
|
||||
}
|
||||
|
||||
public ScriptAction PeekNext()
|
||||
public CommandSet PeekNext()
|
||||
{
|
||||
if (_currentIndex < _actions.Count - 1)
|
||||
return _actions[_currentIndex + 1];
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ScriptAction
|
||||
public class CommandSet
|
||||
{
|
||||
public string Type { get; set; }
|
||||
public Dictionary<string, object> Params { get; set; } = new();
|
||||
@@ -1,18 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public class ScriptParser
|
||||
public class Parser
|
||||
{
|
||||
private static readonly Regex TagRegex = new(@"^\[(\w+)(?:\s+(.*))?\]$");
|
||||
private static readonly Regex AttrRegex = new(@"(\w+)=(""[^""]*""|'[^']*'|[^ \t\]]+)");
|
||||
private static readonly Regex ChoiceOptionRegex = new(@"^\*\s*(.+?)\s*>\s*(.+)$");
|
||||
private static readonly Regex ChoiceRegex = new(@"^\*\s*(.+?)\s*>\s*(.+)$");
|
||||
|
||||
public static Script Parse(string text)
|
||||
public static Command Parse(string text)
|
||||
{
|
||||
List<ScriptAction> actions = new();
|
||||
List<CommandSet> commands = new();
|
||||
Dictionary<string, int> labelMap = new();
|
||||
|
||||
ScriptAction lastChoice = null;
|
||||
CommandSet lastChoice = null;
|
||||
|
||||
text = Regex.Replace(text, "<shake>", "<link=shake>");
|
||||
text = Regex.Replace(text, "</shake>", "</link>");
|
||||
@@ -32,7 +32,7 @@ public class ScriptParser
|
||||
string tagName = tagMatch.Groups[1].Value;
|
||||
string attrString = tagMatch.Groups[2].Value;
|
||||
|
||||
var scriptAction = new ScriptAction { Type = tagName };
|
||||
var scriptAction = new CommandSet { Type = tagName };
|
||||
|
||||
if (!attrString.Contains("=")) scriptAction.Params["content"] = attrString;
|
||||
else ParseAttributes(attrString, scriptAction.Params);
|
||||
@@ -42,7 +42,7 @@ public class ScriptParser
|
||||
string label = scriptAction.GetParam("content");
|
||||
if (!string.IsNullOrEmpty(label) && !labelMap.ContainsKey(label))
|
||||
{
|
||||
labelMap[label] = actions.Count;
|
||||
labelMap[label] = commands.Count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,11 +52,11 @@ public class ScriptParser
|
||||
lastChoice = scriptAction;
|
||||
}
|
||||
|
||||
actions.Add(scriptAction);
|
||||
commands.Add(scriptAction);
|
||||
continue;
|
||||
}
|
||||
|
||||
Match choiceMatch = ChoiceOptionRegex.Match(line);
|
||||
Match choiceMatch = ChoiceRegex.Match(line);
|
||||
if (choiceMatch.Success && lastChoice != null)
|
||||
{
|
||||
lastChoice.Choices.Add(
|
||||
@@ -70,10 +70,10 @@ public class ScriptParser
|
||||
continue;
|
||||
}
|
||||
|
||||
actions.Add(new ScriptAction { Type = "msg", Params = { { "content", line } } });
|
||||
commands.Add(new CommandSet { Type = "msg", Params = { { "content", line } } });
|
||||
}
|
||||
|
||||
return new Script(actions, labelMap);
|
||||
return new Command(commands, labelMap);
|
||||
}
|
||||
|
||||
private static void ParseAttributes(string attrString, Dictionary<string, object> paramDict)
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class VariableManager
|
||||
public class Store
|
||||
{
|
||||
private static VariableManager _instance;
|
||||
public static VariableManager Instance => _instance ??= new VariableManager();
|
||||
private static Store _instance;
|
||||
public static Store Instance => _instance ??= new Store();
|
||||
|
||||
private Dictionary<string, object> _variables = new();
|
||||
|
||||
@@ -4,7 +4,7 @@ using PrimeTween;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class VisualNovelLayoutDirector : MonoBehaviour
|
||||
public class VNDirector : MonoBehaviour
|
||||
{
|
||||
// ========================= [Enums] =========================
|
||||
public enum EntranceType { Left, Right, BottomLeft, BottomRight, Center, Top, LeftRun, RightRun }
|
||||
@@ -6,7 +6,7 @@ using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ScriptManager : MonoBehaviour
|
||||
public class VNManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
TextAsset scriptFile;
|
||||
@@ -25,11 +25,11 @@ public class ScriptManager : MonoBehaviour
|
||||
[SerializeField]
|
||||
float charsPerSecond = 45f;
|
||||
|
||||
public VisualNovelLayoutDirector director;
|
||||
public VNDirector director;
|
||||
private readonly float shakeAmount = 1.1f;
|
||||
private bool isChoiceAvailable = false;
|
||||
private Tween dialogueTween;
|
||||
private Script _currentScript;
|
||||
private Command _currentScript;
|
||||
|
||||
public static string NextScriptPath = "";
|
||||
|
||||
@@ -45,18 +45,18 @@ public class ScriptManager : MonoBehaviour
|
||||
TextAsset loadedScript = Resources.Load<TextAsset>($"NovelScripts/{NextScriptPath}");
|
||||
if (loadedScript != null)
|
||||
{
|
||||
_currentScript = ScriptParser.Parse(loadedScript.text);
|
||||
_currentScript = Parser.Parse(loadedScript.text);
|
||||
NextScriptPath = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"ScriptManager :: Cannot find script: {NextScriptPath}");
|
||||
_currentScript = ScriptParser.Parse(scriptFile.text);
|
||||
_currentScript = Parser.Parse(scriptFile.text);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentScript = ScriptParser.Parse(scriptFile.text);
|
||||
_currentScript = Parser.Parse(scriptFile.text);
|
||||
}
|
||||
|
||||
NextStep();
|
||||
@@ -84,114 +84,114 @@ public class ScriptManager : MonoBehaviour
|
||||
{
|
||||
if (_currentScript.HasNextAction())
|
||||
{
|
||||
ScriptAction action = _currentScript.Continue();
|
||||
ExecuteAction(action);
|
||||
CommandSet command = _currentScript.Continue();
|
||||
Execute(command);
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log("ScriptManager :: End of Script");
|
||||
}
|
||||
|
||||
private void ExecuteAction(ScriptAction action)
|
||||
private void Execute(CommandSet command)
|
||||
{
|
||||
if (action.Type == "label")
|
||||
if (command.Type == "label")
|
||||
{
|
||||
string labelName = action.GetParam("content");
|
||||
string labelName = command.GetParam("content");
|
||||
Debug.Log($"ScriptManager :: Change Label: {labelName}");
|
||||
NextStep();
|
||||
return;
|
||||
}
|
||||
if (action.Type == "bg")
|
||||
if (command.Type == "bg")
|
||||
{
|
||||
string bgFile = action.GetParam("file");
|
||||
string bgFile = command.GetParam("file");
|
||||
Debug.Log($"ScriptManager :: Change Background: {bgFile}");
|
||||
NextStep();
|
||||
return;
|
||||
}
|
||||
if (action.Type == "char")
|
||||
if (command.Type == "char")
|
||||
{
|
||||
string charFile = action.GetParam("img");
|
||||
string charFile = command.GetParam("img");
|
||||
if (string.IsNullOrEmpty(charFile))
|
||||
{
|
||||
charFile = action.GetParam("target");
|
||||
charFile = command.GetParam("target");
|
||||
}
|
||||
string charEntrance = action.GetParam("enter");
|
||||
string charEntrance = command.GetParam("enter");
|
||||
if (charEntrance == "") charEntrance = "center";
|
||||
if (charEntrance.ToLower() == "center") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.Center);
|
||||
if (charEntrance.ToLower() == "top") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.Top);
|
||||
if (charEntrance.ToLower() == "left") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.Left);
|
||||
if (charEntrance.ToLower() == "right") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.Right);
|
||||
if (charEntrance.ToLower() == "bottomleft") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.BottomLeft);
|
||||
if (charEntrance.ToLower() == "bottomright") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.BottomRight);
|
||||
if (charEntrance.ToLower() == "leftrun") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.LeftRun);
|
||||
if (charEntrance.ToLower() == "rightrun") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.RightRun);
|
||||
if (charEntrance.ToLower() == "center") director.AddCharacter(charFile, VNDirector.EntranceType.Center);
|
||||
if (charEntrance.ToLower() == "top") director.AddCharacter(charFile, VNDirector.EntranceType.Top);
|
||||
if (charEntrance.ToLower() == "left") director.AddCharacter(charFile, VNDirector.EntranceType.Left);
|
||||
if (charEntrance.ToLower() == "right") director.AddCharacter(charFile, VNDirector.EntranceType.Right);
|
||||
if (charEntrance.ToLower() == "bottomleft") director.AddCharacter(charFile, VNDirector.EntranceType.BottomLeft);
|
||||
if (charEntrance.ToLower() == "bottomright") director.AddCharacter(charFile, VNDirector.EntranceType.BottomRight);
|
||||
if (charEntrance.ToLower() == "leftrun") director.AddCharacter(charFile, VNDirector.EntranceType.LeftRun);
|
||||
if (charEntrance.ToLower() == "rightrun") director.AddCharacter(charFile, VNDirector.EntranceType.RightRun);
|
||||
Debug.Log($"ScriptManager :: Character: {charFile}");
|
||||
NextStep();
|
||||
return;
|
||||
}
|
||||
if (action.Type == "remove")
|
||||
if (command.Type == "remove")
|
||||
{
|
||||
string charName = action.GetParam("target");
|
||||
string exitType = action.GetParam("exit");
|
||||
string charName = command.GetParam("target");
|
||||
string exitType = command.GetParam("exit");
|
||||
if (exitType == "") exitType = "center";
|
||||
|
||||
VisualNovelLayoutDirector.EntranceType type = new();
|
||||
if (exitType.ToLower() == "center") type = VisualNovelLayoutDirector.EntranceType.Center;
|
||||
if (exitType.ToLower() == "left") type = VisualNovelLayoutDirector.EntranceType.Left;
|
||||
if (exitType.ToLower() == "right") type = VisualNovelLayoutDirector.EntranceType.Right;
|
||||
if (exitType.ToLower() == "bottomleft") type = VisualNovelLayoutDirector.EntranceType.BottomLeft;
|
||||
if (exitType.ToLower() == "bottomright") type = VisualNovelLayoutDirector.EntranceType.BottomRight;
|
||||
if (exitType.ToLower() == "top") type = VisualNovelLayoutDirector.EntranceType.Top;
|
||||
if (exitType.ToLower() == "leftrun") type = VisualNovelLayoutDirector.EntranceType.LeftRun;
|
||||
if (exitType.ToLower() == "rightrun") type = VisualNovelLayoutDirector.EntranceType.RightRun;
|
||||
VNDirector.EntranceType type = new();
|
||||
if (exitType.ToLower() == "center") type = VNDirector.EntranceType.Center;
|
||||
if (exitType.ToLower() == "left") type = VNDirector.EntranceType.Left;
|
||||
if (exitType.ToLower() == "right") type = VNDirector.EntranceType.Right;
|
||||
if (exitType.ToLower() == "bottomleft") type = VNDirector.EntranceType.BottomLeft;
|
||||
if (exitType.ToLower() == "bottomright") type = VNDirector.EntranceType.BottomRight;
|
||||
if (exitType.ToLower() == "top") type = VNDirector.EntranceType.Top;
|
||||
if (exitType.ToLower() == "leftrun") type = VNDirector.EntranceType.LeftRun;
|
||||
if (exitType.ToLower() == "rightrun") type = VNDirector.EntranceType.RightRun;
|
||||
|
||||
director.RemoveCharacter(charName, type);
|
||||
Debug.Log($"ScriptManager :: Remove Character: {charName} to {exitType}");
|
||||
NextStep();
|
||||
return;
|
||||
}
|
||||
if (action.Type == "action")
|
||||
if (command.Type == "action")
|
||||
{
|
||||
string charName = action.GetParam("target");
|
||||
string charAnim = action.GetParam("anim");
|
||||
string charName = command.GetParam("target");
|
||||
string charAnim = command.GetParam("anim");
|
||||
if (charAnim == "") charAnim = "center";
|
||||
if (charAnim.ToLower() == "jump") director.PlayAction(charName, VisualNovelLayoutDirector.ActionType.Jump);
|
||||
if (charAnim.ToLower() == "shake") director.PlayAction(charName, VisualNovelLayoutDirector.ActionType.Shake);
|
||||
if (charAnim.ToLower() == "run") director.PlayAction(charName, VisualNovelLayoutDirector.ActionType.Run);
|
||||
if (charAnim.ToLower() == "nod") director.PlayAction(charName, VisualNovelLayoutDirector.ActionType.Nod);
|
||||
if (charAnim.ToLower() == "punch") director.PlayAction(charName, VisualNovelLayoutDirector.ActionType.Punch);
|
||||
if (charAnim.ToLower() == "jump") director.PlayAction(charName, VNDirector.ActionType.Jump);
|
||||
if (charAnim.ToLower() == "shake") director.PlayAction(charName, VNDirector.ActionType.Shake);
|
||||
if (charAnim.ToLower() == "run") director.PlayAction(charName, VNDirector.ActionType.Run);
|
||||
if (charAnim.ToLower() == "nod") director.PlayAction(charName, VNDirector.ActionType.Nod);
|
||||
if (charAnim.ToLower() == "punch") director.PlayAction(charName, VNDirector.ActionType.Punch);
|
||||
Debug.Log($"ScriptManager :: Action: {charName} {charAnim}");
|
||||
NextStep();
|
||||
return;
|
||||
}
|
||||
if (action.Type == "expr")
|
||||
if (command.Type == "expr")
|
||||
{
|
||||
string charName = action.GetParam("target");
|
||||
string charExpr = action.GetParam("expr");
|
||||
string charName = command.GetParam("target");
|
||||
string charExpr = command.GetParam("expr");
|
||||
director.ChangeExpression(charName, charExpr);
|
||||
Debug.Log($"ScriptManager :: Expression: {charName} {charExpr}");
|
||||
NextStep();
|
||||
return;
|
||||
}
|
||||
if (action.Type == "spk")
|
||||
if (command.Type == "spk")
|
||||
{
|
||||
string speaker = action.GetParam("name");
|
||||
string speaker = command.GetParam("name");
|
||||
if (speakerSprite.activeSelf == false)
|
||||
speakerSprite.SetActive(true);
|
||||
if (speaker == "")
|
||||
speakerSprite.SetActive(false);
|
||||
|
||||
speaker = VariableManager.Instance.ReplaceVariables(speaker);
|
||||
speaker = Store.Instance.ReplaceVariables(speaker);
|
||||
Debug.Log($"ScriptManager :: Speaker: {speaker}");
|
||||
speakerText.SetText(speaker);
|
||||
speakerText.ForceMeshUpdate(true);
|
||||
NextStep();
|
||||
return;
|
||||
}
|
||||
if (action.Type == "msg")
|
||||
if (command.Type == "msg")
|
||||
{
|
||||
string dialogue = action.GetParam("content");
|
||||
dialogue = VariableManager.Instance.ReplaceVariables(dialogue);
|
||||
string dialogue = command.GetParam("content");
|
||||
dialogue = Store.Instance.ReplaceVariables(dialogue);
|
||||
|
||||
|
||||
DisplayDialogue(dialogue);
|
||||
@@ -202,14 +202,14 @@ public class ScriptManager : MonoBehaviour
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (action.Type == "goto")
|
||||
if (command.Type == "goto")
|
||||
{
|
||||
string targetLabel = action.GetParam("content");
|
||||
string targetLabel = command.GetParam("content");
|
||||
_currentScript.JumpTo(targetLabel);
|
||||
NextStep();
|
||||
return;
|
||||
}
|
||||
if (action.Type == "choices")
|
||||
if (command.Type == "choices")
|
||||
{
|
||||
Debug.Log("ScriptManager :: Show Choices");
|
||||
isChoiceAvailable = true;
|
||||
@@ -219,9 +219,9 @@ public class ScriptManager : MonoBehaviour
|
||||
tempColor.a = 0.8f;
|
||||
choiceBackground.color = tempColor;
|
||||
|
||||
foreach (var choice in action.Choices)
|
||||
foreach (var choice in command.Choices)
|
||||
{
|
||||
string text = VariableManager.Instance.ReplaceVariables(choice["content"]);
|
||||
string text = Store.Instance.ReplaceVariables(choice["content"]);
|
||||
string target = choice["goto"];
|
||||
GameObject buttonObj = Instantiate(choiceButtonPrefab, choiceButtonContainer);
|
||||
buttonObj.GetComponentInChildren<TextMeshProUGUI>().text = text;
|
||||
@@ -243,28 +243,28 @@ public class ScriptManager : MonoBehaviour
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (action.Type == "var")
|
||||
if (command.Type == "var")
|
||||
{
|
||||
foreach (var entry in action.Params)
|
||||
foreach (var entry in command.Params)
|
||||
{
|
||||
VariableManager.Instance.SetVariable(entry.Key, entry.Value.ToString());
|
||||
Store.Instance.SetVariable(entry.Key, entry.Value.ToString());
|
||||
}
|
||||
NextStep();
|
||||
return;
|
||||
}
|
||||
if (action.Type == "add")
|
||||
if (command.Type == "add")
|
||||
{
|
||||
foreach (var entry in action.Params)
|
||||
foreach (var entry in command.Params)
|
||||
{
|
||||
VariableManager.Instance.AddVariable(entry.Key, entry.Value.ToString());
|
||||
Store.Instance.AddVariable(entry.Key, entry.Value.ToString());
|
||||
}
|
||||
NextStep();
|
||||
return;
|
||||
}
|
||||
if (action.Type == "scene")
|
||||
if (command.Type == "scene")
|
||||
{
|
||||
string sceneName = action.GetParam("file");
|
||||
string nextScript = action.GetParam("script");
|
||||
string sceneName = command.GetParam("file");
|
||||
string nextScript = command.GetParam("script");
|
||||
Debug.Log($"ScriptManager :: Load Scene: {sceneName}, Next Script: {nextScript}");
|
||||
|
||||
NextScriptPath = nextScript;
|
||||
@@ -280,7 +280,7 @@ public class ScriptManager : MonoBehaviour
|
||||
dialogueText.SetText(" ");
|
||||
dialogueText.ForceMeshUpdate(true);
|
||||
|
||||
_currentScript = ScriptParser.Parse(scriptFile.text);
|
||||
_currentScript = Parser.Parse(scriptFile.text);
|
||||
}
|
||||
|
||||
private bool IsPointerOverInteractiveUI()
|
||||
Reference in New Issue
Block a user