chore: change class names

This commit is contained in:
2025-11-29 23:00:44 +09:00
parent 1528cc3202
commit e30b81c440
12 changed files with 92 additions and 92 deletions

View File

@@ -1,13 +1,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class Script public class Command
{ {
private List<ScriptAction> _actions; private List<CommandSet> _actions;
private int _currentIndex = -1; private int _currentIndex = -1;
private Dictionary<string, int> _labelMap = new(); 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; _actions = actions;
_labelMap = labelMap; _labelMap = labelMap;
@@ -19,25 +19,25 @@ public class Script
return _currentIndex < _actions.Count - 1; return _currentIndex < _actions.Count - 1;
} }
public ScriptAction Continue() public CommandSet Continue()
{ {
if (!HasNextAction()) if (!HasNextAction())
return null; return null;
_currentIndex++; _currentIndex++;
ScriptAction currentAction = _actions[_currentIndex]; CommandSet currentAction = _actions[_currentIndex];
return currentAction; return currentAction;
} }
public ScriptAction GetCurrent() public CommandSet GetCurrent()
{ {
if (_currentIndex >= 0 && _currentIndex < _actions.Count) if (_currentIndex >= 0 && _currentIndex < _actions.Count)
return _actions[_currentIndex]; return _actions[_currentIndex];
return null; return null;
} }
public ScriptAction PeekNext() public CommandSet PeekNext()
{ {
if (_currentIndex < _actions.Count - 1) if (_currentIndex < _actions.Count - 1)
return _actions[_currentIndex + 1]; return _actions[_currentIndex + 1];

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
public class ScriptAction public class CommandSet
{ {
public string Type { get; set; } public string Type { get; set; }
public Dictionary<string, object> Params { get; set; } = new(); public Dictionary<string, object> Params { get; set; } = new();

View File

@@ -1,18 +1,18 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
public class ScriptParser public class Parser
{ {
private static readonly Regex TagRegex = new(@"^\[(\w+)(?:\s+(.*))?\]$"); private static readonly Regex TagRegex = new(@"^\[(\w+)(?:\s+(.*))?\]$");
private static readonly Regex AttrRegex = new(@"(\w+)=(""[^""]*""|'[^']*'|[^ \t\]]+)"); 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(); Dictionary<string, int> labelMap = new();
ScriptAction lastChoice = null; CommandSet lastChoice = null;
text = Regex.Replace(text, "<shake>", "<link=shake>"); text = Regex.Replace(text, "<shake>", "<link=shake>");
text = Regex.Replace(text, "</shake>", "</link>"); text = Regex.Replace(text, "</shake>", "</link>");
@@ -32,7 +32,7 @@ public class ScriptParser
string tagName = tagMatch.Groups[1].Value; string tagName = tagMatch.Groups[1].Value;
string attrString = tagMatch.Groups[2].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; if (!attrString.Contains("=")) scriptAction.Params["content"] = attrString;
else ParseAttributes(attrString, scriptAction.Params); else ParseAttributes(attrString, scriptAction.Params);
@@ -42,7 +42,7 @@ public class ScriptParser
string label = scriptAction.GetParam("content"); string label = scriptAction.GetParam("content");
if (!string.IsNullOrEmpty(label) && !labelMap.ContainsKey(label)) if (!string.IsNullOrEmpty(label) && !labelMap.ContainsKey(label))
{ {
labelMap[label] = actions.Count; labelMap[label] = commands.Count;
} }
} }
@@ -52,11 +52,11 @@ public class ScriptParser
lastChoice = scriptAction; lastChoice = scriptAction;
} }
actions.Add(scriptAction); commands.Add(scriptAction);
continue; continue;
} }
Match choiceMatch = ChoiceOptionRegex.Match(line); Match choiceMatch = ChoiceRegex.Match(line);
if (choiceMatch.Success && lastChoice != null) if (choiceMatch.Success && lastChoice != null)
{ {
lastChoice.Choices.Add( lastChoice.Choices.Add(
@@ -70,10 +70,10 @@ public class ScriptParser
continue; 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) private static void ParseAttributes(string attrString, Dictionary<string, object> paramDict)

View File

@@ -1,10 +1,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class VariableManager public class Store
{ {
private static VariableManager _instance; private static Store _instance;
public static VariableManager Instance => _instance ??= new VariableManager(); public static Store Instance => _instance ??= new Store();
private Dictionary<string, object> _variables = new(); private Dictionary<string, object> _variables = new();

View File

@@ -4,7 +4,7 @@ using PrimeTween;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
public class VisualNovelLayoutDirector : MonoBehaviour public class VNDirector : MonoBehaviour
{ {
// ========================= [Enums] ========================= // ========================= [Enums] =========================
public enum EntranceType { Left, Right, BottomLeft, BottomRight, Center, Top, LeftRun, RightRun } public enum EntranceType { Left, Right, BottomLeft, BottomRight, Center, Top, LeftRun, RightRun }

View File

@@ -6,7 +6,7 @@ using UnityEngine.EventSystems;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
public class ScriptManager : MonoBehaviour public class VNManager : MonoBehaviour
{ {
[SerializeField] [SerializeField]
TextAsset scriptFile; TextAsset scriptFile;
@@ -25,11 +25,11 @@ public class ScriptManager : MonoBehaviour
[SerializeField] [SerializeField]
float charsPerSecond = 45f; float charsPerSecond = 45f;
public VisualNovelLayoutDirector director; public VNDirector director;
private readonly float shakeAmount = 1.1f; private readonly float shakeAmount = 1.1f;
private bool isChoiceAvailable = false; private bool isChoiceAvailable = false;
private Tween dialogueTween; private Tween dialogueTween;
private Script _currentScript; private Command _currentScript;
public static string NextScriptPath = ""; public static string NextScriptPath = "";
@@ -45,18 +45,18 @@ public class ScriptManager : MonoBehaviour
TextAsset loadedScript = Resources.Load<TextAsset>($"NovelScripts/{NextScriptPath}"); TextAsset loadedScript = Resources.Load<TextAsset>($"NovelScripts/{NextScriptPath}");
if (loadedScript != null) if (loadedScript != null)
{ {
_currentScript = ScriptParser.Parse(loadedScript.text); _currentScript = Parser.Parse(loadedScript.text);
NextScriptPath = ""; NextScriptPath = "";
} }
else else
{ {
Debug.LogError($"ScriptManager :: Cannot find script: {NextScriptPath}"); Debug.LogError($"ScriptManager :: Cannot find script: {NextScriptPath}");
_currentScript = ScriptParser.Parse(scriptFile.text); _currentScript = Parser.Parse(scriptFile.text);
} }
} }
else else
{ {
_currentScript = ScriptParser.Parse(scriptFile.text); _currentScript = Parser.Parse(scriptFile.text);
} }
NextStep(); NextStep();
@@ -84,114 +84,114 @@ public class ScriptManager : MonoBehaviour
{ {
if (_currentScript.HasNextAction()) if (_currentScript.HasNextAction())
{ {
ScriptAction action = _currentScript.Continue(); CommandSet command = _currentScript.Continue();
ExecuteAction(action); Execute(command);
return; return;
} }
Debug.Log("ScriptManager :: End of Script"); 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}"); Debug.Log($"ScriptManager :: Change Label: {labelName}");
NextStep(); NextStep();
return; 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}"); Debug.Log($"ScriptManager :: Change Background: {bgFile}");
NextStep(); NextStep();
return; return;
} }
if (action.Type == "char") if (command.Type == "char")
{ {
string charFile = action.GetParam("img"); string charFile = command.GetParam("img");
if (string.IsNullOrEmpty(charFile)) 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 == "") charEntrance = "center";
if (charEntrance.ToLower() == "center") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.Center); if (charEntrance.ToLower() == "center") director.AddCharacter(charFile, VNDirector.EntranceType.Center);
if (charEntrance.ToLower() == "top") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.Top); if (charEntrance.ToLower() == "top") director.AddCharacter(charFile, VNDirector.EntranceType.Top);
if (charEntrance.ToLower() == "left") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.Left); if (charEntrance.ToLower() == "left") director.AddCharacter(charFile, VNDirector.EntranceType.Left);
if (charEntrance.ToLower() == "right") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.Right); if (charEntrance.ToLower() == "right") director.AddCharacter(charFile, VNDirector.EntranceType.Right);
if (charEntrance.ToLower() == "bottomleft") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.BottomLeft); if (charEntrance.ToLower() == "bottomleft") director.AddCharacter(charFile, VNDirector.EntranceType.BottomLeft);
if (charEntrance.ToLower() == "bottomright") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.BottomRight); if (charEntrance.ToLower() == "bottomright") director.AddCharacter(charFile, VNDirector.EntranceType.BottomRight);
if (charEntrance.ToLower() == "leftrun") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.LeftRun); if (charEntrance.ToLower() == "leftrun") director.AddCharacter(charFile, VNDirector.EntranceType.LeftRun);
if (charEntrance.ToLower() == "rightrun") director.AddCharacter(charFile, VisualNovelLayoutDirector.EntranceType.RightRun); if (charEntrance.ToLower() == "rightrun") director.AddCharacter(charFile, VNDirector.EntranceType.RightRun);
Debug.Log($"ScriptManager :: Character: {charFile}"); Debug.Log($"ScriptManager :: Character: {charFile}");
NextStep(); NextStep();
return; return;
} }
if (action.Type == "remove") if (command.Type == "remove")
{ {
string charName = action.GetParam("target"); string charName = command.GetParam("target");
string exitType = action.GetParam("exit"); string exitType = command.GetParam("exit");
if (exitType == "") exitType = "center"; if (exitType == "") exitType = "center";
VisualNovelLayoutDirector.EntranceType type = new(); VNDirector.EntranceType type = new();
if (exitType.ToLower() == "center") type = VisualNovelLayoutDirector.EntranceType.Center; if (exitType.ToLower() == "center") type = VNDirector.EntranceType.Center;
if (exitType.ToLower() == "left") type = VisualNovelLayoutDirector.EntranceType.Left; if (exitType.ToLower() == "left") type = VNDirector.EntranceType.Left;
if (exitType.ToLower() == "right") type = VisualNovelLayoutDirector.EntranceType.Right; if (exitType.ToLower() == "right") type = VNDirector.EntranceType.Right;
if (exitType.ToLower() == "bottomleft") type = VisualNovelLayoutDirector.EntranceType.BottomLeft; if (exitType.ToLower() == "bottomleft") type = VNDirector.EntranceType.BottomLeft;
if (exitType.ToLower() == "bottomright") type = VisualNovelLayoutDirector.EntranceType.BottomRight; if (exitType.ToLower() == "bottomright") type = VNDirector.EntranceType.BottomRight;
if (exitType.ToLower() == "top") type = VisualNovelLayoutDirector.EntranceType.Top; if (exitType.ToLower() == "top") type = VNDirector.EntranceType.Top;
if (exitType.ToLower() == "leftrun") type = VisualNovelLayoutDirector.EntranceType.LeftRun; if (exitType.ToLower() == "leftrun") type = VNDirector.EntranceType.LeftRun;
if (exitType.ToLower() == "rightrun") type = VisualNovelLayoutDirector.EntranceType.RightRun; if (exitType.ToLower() == "rightrun") type = VNDirector.EntranceType.RightRun;
director.RemoveCharacter(charName, type); director.RemoveCharacter(charName, type);
Debug.Log($"ScriptManager :: Remove Character: {charName} to {exitType}"); Debug.Log($"ScriptManager :: Remove Character: {charName} to {exitType}");
NextStep(); NextStep();
return; return;
} }
if (action.Type == "action") if (command.Type == "action")
{ {
string charName = action.GetParam("target"); string charName = command.GetParam("target");
string charAnim = action.GetParam("anim"); string charAnim = command.GetParam("anim");
if (charAnim == "") charAnim = "center"; if (charAnim == "") charAnim = "center";
if (charAnim.ToLower() == "jump") director.PlayAction(charName, VisualNovelLayoutDirector.ActionType.Jump); if (charAnim.ToLower() == "jump") director.PlayAction(charName, VNDirector.ActionType.Jump);
if (charAnim.ToLower() == "shake") director.PlayAction(charName, VisualNovelLayoutDirector.ActionType.Shake); if (charAnim.ToLower() == "shake") director.PlayAction(charName, VNDirector.ActionType.Shake);
if (charAnim.ToLower() == "run") director.PlayAction(charName, VisualNovelLayoutDirector.ActionType.Run); if (charAnim.ToLower() == "run") director.PlayAction(charName, VNDirector.ActionType.Run);
if (charAnim.ToLower() == "nod") director.PlayAction(charName, VisualNovelLayoutDirector.ActionType.Nod); if (charAnim.ToLower() == "nod") director.PlayAction(charName, VNDirector.ActionType.Nod);
if (charAnim.ToLower() == "punch") director.PlayAction(charName, VisualNovelLayoutDirector.ActionType.Punch); if (charAnim.ToLower() == "punch") director.PlayAction(charName, VNDirector.ActionType.Punch);
Debug.Log($"ScriptManager :: Action: {charName} {charAnim}"); Debug.Log($"ScriptManager :: Action: {charName} {charAnim}");
NextStep(); NextStep();
return; return;
} }
if (action.Type == "expr") if (command.Type == "expr")
{ {
string charName = action.GetParam("target"); string charName = command.GetParam("target");
string charExpr = action.GetParam("expr"); string charExpr = command.GetParam("expr");
director.ChangeExpression(charName, charExpr); director.ChangeExpression(charName, charExpr);
Debug.Log($"ScriptManager :: Expression: {charName} {charExpr}"); Debug.Log($"ScriptManager :: Expression: {charName} {charExpr}");
NextStep(); NextStep();
return; return;
} }
if (action.Type == "spk") if (command.Type == "spk")
{ {
string speaker = action.GetParam("name"); string speaker = command.GetParam("name");
if (speakerSprite.activeSelf == false) if (speakerSprite.activeSelf == false)
speakerSprite.SetActive(true); speakerSprite.SetActive(true);
if (speaker == "") if (speaker == "")
speakerSprite.SetActive(false); speakerSprite.SetActive(false);
speaker = VariableManager.Instance.ReplaceVariables(speaker); speaker = Store.Instance.ReplaceVariables(speaker);
Debug.Log($"ScriptManager :: Speaker: {speaker}"); Debug.Log($"ScriptManager :: Speaker: {speaker}");
speakerText.SetText(speaker); speakerText.SetText(speaker);
speakerText.ForceMeshUpdate(true); speakerText.ForceMeshUpdate(true);
NextStep(); NextStep();
return; return;
} }
if (action.Type == "msg") if (command.Type == "msg")
{ {
string dialogue = action.GetParam("content"); string dialogue = command.GetParam("content");
dialogue = VariableManager.Instance.ReplaceVariables(dialogue); dialogue = Store.Instance.ReplaceVariables(dialogue);
DisplayDialogue(dialogue); DisplayDialogue(dialogue);
@@ -202,14 +202,14 @@ public class ScriptManager : MonoBehaviour
} }
return; return;
} }
if (action.Type == "goto") if (command.Type == "goto")
{ {
string targetLabel = action.GetParam("content"); string targetLabel = command.GetParam("content");
_currentScript.JumpTo(targetLabel); _currentScript.JumpTo(targetLabel);
NextStep(); NextStep();
return; return;
} }
if (action.Type == "choices") if (command.Type == "choices")
{ {
Debug.Log("ScriptManager :: Show Choices"); Debug.Log("ScriptManager :: Show Choices");
isChoiceAvailable = true; isChoiceAvailable = true;
@@ -219,9 +219,9 @@ public class ScriptManager : MonoBehaviour
tempColor.a = 0.8f; tempColor.a = 0.8f;
choiceBackground.color = tempColor; 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"]; string target = choice["goto"];
GameObject buttonObj = Instantiate(choiceButtonPrefab, choiceButtonContainer); GameObject buttonObj = Instantiate(choiceButtonPrefab, choiceButtonContainer);
buttonObj.GetComponentInChildren<TextMeshProUGUI>().text = text; buttonObj.GetComponentInChildren<TextMeshProUGUI>().text = text;
@@ -243,28 +243,28 @@ public class ScriptManager : MonoBehaviour
} }
return; 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(); NextStep();
return; 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(); NextStep();
return; return;
} }
if (action.Type == "scene") if (command.Type == "scene")
{ {
string sceneName = action.GetParam("file"); string sceneName = command.GetParam("file");
string nextScript = action.GetParam("script"); string nextScript = command.GetParam("script");
Debug.Log($"ScriptManager :: Load Scene: {sceneName}, Next Script: {nextScript}"); Debug.Log($"ScriptManager :: Load Scene: {sceneName}, Next Script: {nextScript}");
NextScriptPath = nextScript; NextScriptPath = nextScript;
@@ -280,7 +280,7 @@ public class ScriptManager : MonoBehaviour
dialogueText.SetText(" "); dialogueText.SetText(" ");
dialogueText.ForceMeshUpdate(true); dialogueText.ForceMeshUpdate(true);
_currentScript = ScriptParser.Parse(scriptFile.text); _currentScript = Parser.Parse(scriptFile.text);
} }
private bool IsPointerOverInteractiveUI() private bool IsPointerOverInteractiveUI()