From 36a5c2e8f22de01b5d7f33d079d67c0d5c9f4dc9 Mon Sep 17 00:00:00 2001 From: Tim Nugent Date: Tue, 14 Nov 2023 11:04:26 +1100 Subject: [PATCH] Project creation now use the Unity specific tweaks --- Editor/Utility/YarnEditorUtility.cs | 2 +- Editor/Utility/YarnProjectUtility.cs | 27 +++++++++++++++++++++------ Tests/Editor/YarnImporterTests.cs | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Editor/Utility/YarnEditorUtility.cs b/Editor/Utility/YarnEditorUtility.cs index 2725c793..c93a263e 100644 --- a/Editor/Utility/YarnEditorUtility.cs +++ b/Editor/Utility/YarnEditorUtility.cs @@ -217,7 +217,7 @@ private class DoCreateYarnProjectAsset : UnityEditor.ProjectWindowCallback.EndNa public override void Action(int instanceId, string pathName, string resourceFile) { // Produce the asset. - var project = new Yarn.Compiler.Project(); + var project = YarnProjectUtility.CreateDefaultYarnProject(); var json = project.GetJson(); // Write it all out to disk as UTF-8 diff --git a/Editor/Utility/YarnProjectUtility.cs b/Editor/Utility/YarnProjectUtility.cs index d13367b6..f1e84c3a 100644 --- a/Editor/Utility/YarnProjectUtility.cs +++ b/Editor/Utility/YarnProjectUtility.cs @@ -42,11 +42,7 @@ internal static string CreateYarnProject(YarnImporter initialSourceAsset) destinationPath = AssetDatabase.GenerateUniqueAssetPath(destinationPath); // Create the program - var newProject = new Yarn.Compiler.Project(); - - // Follow Unity's behaviour - exclude any content in a folder whose - // name ends with a tilde - newProject.ExcludeFilePatterns = new[] { "**/*~/*" }; + var newProject = YarnProjectUtility.CreateDefaultYarnProject(); newProject.SaveToFile(destinationPath); @@ -56,6 +52,25 @@ internal static string CreateYarnProject(YarnImporter initialSourceAsset) return destinationPath; } + /// + /// Creates a Unity tweaked default Yarn Project. + /// + /// + /// This is just a default Yarn Project with the exclusion file pattern set up to ignore ~ folders. + /// + /// A Unity default Yarn Project + internal static Yarn.Compiler.Project CreateDefaultYarnProject() + { + // Create the program + var newProject = new Yarn.Compiler.Project(); + + // Follow Unity's behaviour - exclude any content in a folder whose + // name ends with a tilde + newProject.ExcludeFilePatterns = new[] { "**/*~/*" }; + + return newProject; + } + /// /// Updates every localization .CSV file associated with this /// .yarnproject file. @@ -640,7 +655,7 @@ internal static void UpgradeYarnProject(YarnProjectImporter importer) } // Next, replace the existing project with a new one! - var newProject = new Yarn.Compiler.Project(); + var newProject = YarnProjectUtility.CreateDefaultYarnProject(); File.WriteAllText(importer.assetPath, newProject.GetJson()); // Finally, import the assets we've touched. diff --git a/Tests/Editor/YarnImporterTests.cs b/Tests/Editor/YarnImporterTests.cs index 7c43a0d9..51a01d4c 100644 --- a/Tests/Editor/YarnImporterTests.cs +++ b/Tests/Editor/YarnImporterTests.cs @@ -584,7 +584,7 @@ public void YarnImporter_CanCreateProjectAndScriptSimultaneously() string yarnProjectPath = $"{YarnTestUtility.TestFilesDirectoryPath}/Project.yarnproject"; string yarnScriptPath = $"{YarnTestUtility.TestFilesDirectoryPath}/Script.yarn"; - var projectText = new Yarn.Compiler.Project().GetJson(); + var projectText = YarnProjectUtility.CreateDefaultYarnProject().GetJson(); var scriptText = "title: Start\n---\n===\n"; File.WriteAllText(yarnProjectPath, projectText);