Skip to content

Commit

Permalink
Project creation now use the Unity specific tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
McJones committed Nov 14, 2023
1 parent c3f3dbe commit 36a5c2e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Editor/Utility/YarnEditorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 21 additions & 6 deletions Editor/Utility/YarnProjectUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -56,6 +52,25 @@ internal static string CreateYarnProject(YarnImporter initialSourceAsset)
return destinationPath;
}

/// <summary>
/// Creates a Unity tweaked default Yarn Project.
/// </summary>
/// <remarks>
/// This is just a default Yarn Project with the exclusion file pattern set up to ignore ~ folders.
/// </remarks>
/// <returns>A Unity default Yarn Project</returns>
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;
}

/// <summary>
/// Updates every localization .CSV file associated with this
/// .yarnproject file.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Tests/Editor/YarnImporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 36a5c2e

Please sign in to comment.