Skip to content

Commit

Permalink
project editor no longer erroneously suggests upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
McJones committed Nov 13, 2023
1 parent 98a85f8 commit c3f3dbe
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- If you don't use pauses you won't need to change anything
- `Effects.Typewriter` now is a wrapper into the `PausableTypewriter` effect
- If you don't use pauses nothing will change
- Yarn Projects that have no import data will no longer suggest to upgrade the project file
- this solves an uncommon but *very* hard to debug error
- `YarnProjectImporterEditor.CreateUpgradeUI` is now private
- Yarn Project editor upgrade help link now correctly links to the upgrade page on the docs

### Removed

Expand Down
80 changes: 76 additions & 4 deletions Editor/Editors/YarnProjectImporterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class YarnProjectImporterEditor : ScriptedImporterEditor
// YarnProjectImporter. Used during Inspector GUI drawing.
internal static SerializedProperty CurrentProjectDefaultLanguageProperty;

const string ProjectUpgradeHelpURL = "https://docs.yarnspinner.dev";
const string ProjectUpgradeHelpURL = "https://docs.yarnspinner.dev/using-yarnspinner-with-unity/importing-yarn-files/yarn-projects#upgrading-yarn-projects";
const string CreateNewIssueURL = "https://github.com/YarnSpinnerTool/YarnSpinner-Unity/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=Project Import Error";

private SerializedProperty compileErrorsProperty;
private SerializedProperty serializedDeclarationsProperty;
Expand Down Expand Up @@ -207,11 +208,31 @@ public override VisualElement CreateInspectorGUI()

ui.styleSheets.Add(yarnProjectStyleSheet);

if (importData == null || importData.ImportStatus == ProjectImportData.ImportStatusCode.NeedsUpgradeFromV1) {
ui.Add(CreateUpgradeUI(yarnProjectImporter));
// if the import data is null it means import has crashed
// we need to let the user know and perhaps ask them to file an issue
if (importData == null)
{
ui.Add(CreateCriticalErrorUI());
return ui;
}

// next we need to handle the two edge cases
// either the importData is for the older format
// or it's completely unknown (most likely a error)
// in both cases we show the respective custom UI and return
switch (importData.ImportStatus)
{
case ProjectImportData.ImportStatusCode.NeedsUpgradeFromV1:
{
ui.Add(CreateUpgradeUI(yarnProjectImporter));
return ui;
}
case ProjectImportData.ImportStatusCode.Unknown:
{
ui.Add(CreateUnknownErrorUI());
return ui;
}
}

var importDataSO = new SerializedObject(importData);
var diagnosticsProperty = importDataSO.FindProperty(nameof(ProjectImportData.diagnostics));
Expand Down Expand Up @@ -510,7 +531,8 @@ public override bool HasModified()
return base.HasModified() || AnyModifications;
}

public VisualElement CreateUpgradeUI(YarnProjectImporter importer) {
private VisualElement CreateUpgradeUI(YarnProjectImporter importer)
{
var ui = new VisualElement();

var box = new VisualElement();
Expand Down Expand Up @@ -547,5 +569,55 @@ public VisualElement CreateUpgradeUI(YarnProjectImporter importer) {

return ui;
}

private VisualElement CreateErrorUI(string headerText, string[] labels, string linkLabel, string link)
{
var ui = new VisualElement();
var box = new VisualElement();
box.AddToClassList("help-box");

Label header = new Label(headerText);
header.style.unityFontStyleAndWeight = FontStyle.Bold;
box.Add(header);

foreach (var label in labels)
{
box.Add(new Label(label));
}

var learnMoreLink = new Label(linkLabel);
learnMoreLink.RegisterCallback<MouseDownEvent>(evt =>
{
Application.OpenURL(link);
});
learnMoreLink.AddToClassList("link");
box.Add(learnMoreLink);

ui.Add(box);

ui.Add(new IMGUIContainer(ApplyRevertGUI));

return ui;
}

private VisualElement CreateCriticalErrorUI()
{
string[] labels = {
"This is likely due to a bug on our end, and not in your project.",
"Try recreating the project and see if this resolves the issue."
};

return CreateErrorUI("This project has failed to import due to an internal error.", labels, "If the issue persists, please open an issue.", CreateNewIssueURL);
}

private VisualElement CreateUnknownErrorUI()
{
string[] labels = {
"The type of this Yarn Project is unknown.",
"Try recreating the project and see if this resolves the issue."
};

return CreateErrorUI("This project has failed to import correctly.", labels, "If the issue persists, please open an issue.", CreateNewIssueURL);
}
}
}

0 comments on commit c3f3dbe

Please sign in to comment.