-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ink Scripted Importer #205
base: master
Are you sure you want to change the base?
Conversation
Oh wow thanks for looking into this! I'll take a look this week if I find time. At a glance it looks lovely (so much less code!!) |
Totally! I see your message in #ink-unity-integration-dev. I'll keep watch for questions/comments there too. Thanks! |
…ince ink files aren't constucted at runtime anymore
@tomkail Okay I'm moving this out of draft as I've cleaned up the known things I needed to do, but I suspect there may be things I've missed since this was such a huge change. Feel free to tag me on any changes you want after doing a review. I'll loop back when I have the time 🤘 |
Amazing! Annoyingly nobody has checked this out. How about we stick it on a
beta branch and publish it there? Maybe that’ll encourage people.
…On Mon, Oct 7, 2024 at 00:49 Alex Larioza ***@***.***> wrote:
@tomkail <https://github.com/tomkail> Okay I'm moving this out of draft
as I've cleaned up the known things I needed to do, but I suspect there may
be things I've missed since this was such a huge change. Feel free to tag
me on any changes you want after doing a review. I'll loop back when I have
the time 🤘
—
Reply to this email directly, view it on GitHub
<#205 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJR3UED36NFMMKTA7MLXJDZ2HD67AVCNFSM6AAAAABNPMJ5EWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJVGY2TKOJTGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Sounds good to me! I'd rather give more people more time to test it out before its merged into main 😅 I don't appear to have the option to change the base branch to a new (non-existing) branch tho. If you make a beta branch I can update the PR! |
I forgot to update the docs, so I snuck another commit in 👍 |
DefaultAsset asset = AssetDatabase.LoadAssetAtPath<DefaultAsset>(path); | ||
DrawInkFile(InkLibrary.GetInkFileWithFile(asset), rect); | ||
InkFile asset = AssetDatabase.LoadAssetAtPath<InkFile>(path); | ||
DrawInkFile(asset, rect); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InkFile is now a Scriptable Object.
No OnDrawProjectWindowItem
would be needed if we assign a custom icon to InkFile.cs from the inspector
|
||
|
||
|
||
public class InkFile : ScriptableObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with the way the project is maintained but this is a breaking change so it would be nice to bump the major version in the package manifest.
{
"name": "com.inkle.ink-unity-integration",
"version": "2.0.0",
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some general comments, moving to scripted importers is a natural step forward for the library but it looks like it will require breaking changes.
This could be a chance for some cleanups and other breaking changes around the codebase.
Let me know if you want more feedback, I'm interested in closer collaboration.
/// Automatically compiles .ink assets each time they are imported, and creates an InkFile asset. | ||
/// </summary> | ||
[ScriptedImporter(1, "ink")] | ||
public class InkImporter : ScriptedImporter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing namespace: Ink.UnityIntegration
var compiler = new Compiler(inputString, new Compiler.Options | ||
{ | ||
countAllVisits = true, | ||
fileHandler = new UnityInkFileHandler(Path.GetDirectoryName(absolutePath)), | ||
errorHandler = (string message, ErrorType type) => { | ||
InkCompilerLog log; | ||
if(InkCompilerLog.TryParse(message, out log)) { | ||
if(string.IsNullOrEmpty(log.relativeFilePath)) log.relativeFilePath = Path.GetFileName(absolutePath); | ||
switch (log.type) | ||
{ | ||
case ErrorType.Error: | ||
inkFile.errors.Add(log); | ||
Debug.LogError("Ink "+log.type+" for "+Path.GetFileName(absolutePath)+": "+log.content + " (at "+log.relativeFilePath+":"+log.lineNumber+")", inkFile); | ||
break; | ||
case ErrorType.Warning: | ||
inkFile.warnings.Add(log); | ||
Debug.LogWarning("Ink "+log.type+" for "+Path.GetFileName(absolutePath)+": "+log.content + " (at "+log.relativeFilePath+" "+log.lineNumber+")", inkFile); | ||
break; | ||
case ErrorType.Author: | ||
inkFile.todos.Add(log); | ||
if (InkSettings.instance.printInkLogsInConsoleOnCompile) | ||
{ | ||
Debug.Log("Ink Log for "+Path.GetFileName(absolutePath)+": "+log.content + " (at "+log.relativeFilePath+" "+log.lineNumber+")", inkFile); | ||
} | ||
break; | ||
} | ||
|
||
} else { | ||
Debug.LogWarning("Couldn't parse log "+message); | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be extracted to a new method for readability, same with errorHandler
inside it
var compiler = new Compiler(inputString, new Compiler.Options | |
{ | |
countAllVisits = true, | |
fileHandler = new UnityInkFileHandler(Path.GetDirectoryName(absolutePath)), | |
errorHandler = (string message, ErrorType type) => { | |
InkCompilerLog log; | |
if(InkCompilerLog.TryParse(message, out log)) { | |
if(string.IsNullOrEmpty(log.relativeFilePath)) log.relativeFilePath = Path.GetFileName(absolutePath); | |
switch (log.type) | |
{ | |
case ErrorType.Error: | |
inkFile.errors.Add(log); | |
Debug.LogError("Ink "+log.type+" for "+Path.GetFileName(absolutePath)+": "+log.content + " (at "+log.relativeFilePath+":"+log.lineNumber+")", inkFile); | |
break; | |
case ErrorType.Warning: | |
inkFile.warnings.Add(log); | |
Debug.LogWarning("Ink "+log.type+" for "+Path.GetFileName(absolutePath)+": "+log.content + " (at "+log.relativeFilePath+" "+log.lineNumber+")", inkFile); | |
break; | |
case ErrorType.Author: | |
inkFile.todos.Add(log); | |
if (InkSettings.instance.printInkLogsInConsoleOnCompile) | |
{ | |
Debug.Log("Ink Log for "+Path.GetFileName(absolutePath)+": "+log.content + " (at "+log.relativeFilePath+" "+log.lineNumber+")", inkFile); | |
} | |
break; | |
} | |
} else { | |
Debug.LogWarning("Couldn't parse log "+message); | |
} | |
} | |
}); | |
var compiler = CreateCompiler(inputString, absolutePath, inkFile); |
Debug.LogError("Ink "+log.type+" for "+Path.GetFileName(absolutePath)+": "+log.content + " (at "+log.relativeFilePath+":"+log.lineNumber+")", inkFile); | ||
break; | ||
case ErrorType.Warning: | ||
inkFile.warnings.Add(log); | ||
Debug.LogWarning("Ink "+log.type+" for "+Path.GetFileName(absolutePath)+": "+log.content + " (at "+log.relativeFilePath+" "+log.lineNumber+")", inkFile); | ||
break; | ||
case ErrorType.Author: | ||
inkFile.todos.Add(log); | ||
if (InkSettings.instance.printInkLogsInConsoleOnCompile) | ||
{ | ||
Debug.Log("Ink Log for "+Path.GetFileName(absolutePath)+": "+log.content + " (at "+log.relativeFilePath+" "+log.lineNumber+")", inkFile); | ||
} | ||
break; | ||
} | ||
|
||
} else { | ||
Debug.LogWarning("Couldn't parse log "+message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For The AssetImportContext.LogImportError()
could be used for handling all of the importer errors.
Unity handles UI for displaying errors logged this way in the importer header. This in turn could eliminate the need for custom error UI in the Ink File Editor
@@ -68,17 +68,6 @@ public string templateFilePath { | |||
else return AssetDatabase.GetAssetPath(templateFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the templateFile
should probably change type to the ScriptableObject imported by the InkImporter
public static System.Version inkVersionCurrent = new System.Version(1,2,0); | ||
public static System.Version unityIntegrationVersionCurrent = new System.Version(1,2,1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be best to put it somewhere else
// Helper class for ink files that maintains INCLUDE connections between ink files | ||
/// <summary> | ||
/// ScriptableObject that serves as the imported version of .ink files. | ||
/// </summary> | ||
[Serializable] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Serializable is redundant on a scriptable object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the static nested class InkIncludeParser
is still inside the type but its not used (could be removed).
[ScriptedImporter(1, "ink")] | ||
public class InkImporter : ScriptedImporter | ||
{ | ||
public override void OnImportAsset(AssetImportContext ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If compiling output of one ink file depends on another ink file then the AssetImportContext.DependsOnSourceAsset
should be used for proper importer behavior.
/// Automatically compiles .ink assets each time they are imported, and creates an InkFile asset. | ||
/// </summary> | ||
[ScriptedImporter(1, "ink")] | ||
public class InkImporter : ScriptedImporter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A complimentary InkImporterEditor : ScriptedImporterEditor
could be created for better UX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest writing new UI code with UI Toolkit.
it's impossible given that the package manifest says unity 2018 is still supported.
That's a separate topic, but maybe a poll on discord could be useful to see if users really need a support for very old editor versions.
IMO bumping minimal version to 2021.3+ would be a sensible decision.
This aims to implement #53, which IMO, has some huge benefits:
InkFile
references instead of genericTextAsset
references in game code.This PR is currently in a proof of concept stage: it hasn't been fully tested, but loading and running ink files at runtime and in the Editor is working.
The original implementation was written before Unity supported custom scripted importers, so many of the systems are now obsolete. Since this is a pretty big change, I wanted to open a PR to get an initial review to get some initial thoughts from the maintainers.
Interested in all feedback, but the question at the top of my mind: Do we need to expose includes and master files in the editor? While Ink at a language level still has these concepts, I'm not sure how important it is to expose these in Unity if its no longer important for compilation?