YarnSpinnerTool / YarnSpinner

Yarn Spinner is a tool for building interactive dialogue in games!
https://yarnspinner.dev
MIT License
2.31k stars 201 forks source link

yarn spinner for godot #24

Closed blurymind closed 8 months ago

blurymind commented 8 years ago

Godot is a great open source alternative to unity! It has a json parser and uses gdscript - which is similar to python.

It would be amazing if someone ports yarn spinner to godot - so godot users can use yarn on godot games!

some links: https://www.facebook.com/groups/godotengine/permalink/735320436604553/

http://www.godotengine.org/

http://docs.godotengine.org/en/latest/classes/class_dictionary.html?highlight=dictionary http://docs.godotengine.org/en/latest/tutorials/engine/saving_games.html?highlight=json

desplesda commented 8 years ago

Oh, nice! I hadn’t heard of Godot before. Looks awesome!

So, the biggest thing that would hold back a port of Yarn Spinner to Godot is the language. Godot appears to use its own, custom, Python-like language, while Yarn Spinner is written in C# and compiles to a .NET assembly (because that’s what Unity uses.) Porting all of Yarn Spinner would mean doing one of two things:

Because I’m a much better C#/Unity developer than I am a Godot programmer at the moment, I (@desplesda) would prefer to keep my attention focused on the core Yarn Spinner project for the moment; however, If there’s some awesome person (maybe you!) who wants to take on either of these tasks, let me know, and I’ll provide as much help as I can!

On 25 Feb 2016, at 11:56 AM, Todor Imreorov notifications@github.com wrote:

Godot is a great open source alternative to unity! It has a json parser and uses gdscript - whic is similar to python.

It would be amazing if someone ports yarn spinner to godot - so godot users can use yarn on godot games!

some links: https://www.facebook.com/groups/godotengine/permalink/735320436604553/ https://www.facebook.com/groups/godotengine/permalink/735320436604553/ http://www.godotengine.org/ http://www.godotengine.org/ http://docs.godotengine.org/en/latest/classes/class_dictionary.html?highlight=dictionary http://docs.godotengine.org/en/latest/classes/class_dictionary.html?highlight=dictionary http://docs.godotengine.org/en/latest/tutorials/engine/saving_games.html?highlight=json http://docs.godotengine.org/en/latest/tutorials/engine/saving_games.html?highlight=json — Reply to this email directly or view it on GitHub https://github.com/thesecretlab/YarnSpinner/issues/24.

desplesda commented 8 years ago

Also: @blurymind, thank you very much for opening this issue!! It's awesome to see people wanting Yarn Spinner to be more available!

blurymind commented 8 years ago

I have limited coding skills, so i was able to make something really basic so far. My interpreter can load the right yarn node into godot and go to the right next node based on user input. There is still quite a lot of ground to cover, but due to my limited ability i cant rewrite yarn spinner as i dont fully understand how it works.

techtonik commented 8 years ago

@blurymind do you code available somewhere?

techtonik commented 8 years ago

Composing a checklist of features that needs to be covered will also help a lot. It can be interesting as challenges for people learning Godot.

Zedjones commented 6 years ago

Now that Godot has native C# support, is there any consideration for pursuing development for the engine? My team and I would love for something like this to come to fruition.

naturally-intelligent commented 6 years ago

Related: built a basic Yarn importer for Godot:

https://github.com/naturally-intelligent/godot-yarn-importer

giulianob commented 5 years ago

Since C# support is getting better and better, it's possible now to use Yarn as it is with Godot. I have a POC working successfully without much trouble. I did also write an importer plugin to compile the .yarn.txt files into bytecode but I'm running into some issues running the pre-compiled bytecode. Anyways, it's possible to do it in C# with Godot. It just won't work on mobile until C# is fully supported there.

frojo commented 5 years ago

@giulianob do you have a link to that importer you wrote? or the source for it :)

I started working on a GDScript yarnspinner runner: https://github.com/frojo/yarnspinnergd It takes .yarn.txt files and compiles them into bytecode but ONLY for straight-up lines. No options/commands etc. But it does have some sort of DialogueRunner too in GDscript. I haven't worked on it in a bit, but I might want to add the other Yarnspinner functionality soon.

giulianob commented 5 years ago

I just used C# to compile. I had issues getting Yarn to run the bytecode though and opened an issue to try and get help. The C# importer looks like the following, it's called by GD and returns the bytes then GD saves the resource. Also, it imports all txt files since GD doesn't have a way to recognize an extension like .yarn.txt sadly

using System;
using Godot;
using Yarn;

public class YarnImporterPlugin : Node
{
    public Godot.Collections.Dictionary Compile(string sourceFile)
    {
        var dict = new Godot.Collections.Dictionary();
        try
        {
            var dialogue = new Dialogue(null);
            dialogue.LogDebugMessage = (message) => GD.Print($"Yarn Debug: {message}");
            dialogue.LogErrorMessage = (message) => GD.PushError($"Yarn Error: {message}");
            dialogue.LoadFile(ProjectSettings.GlobalizePath(sourceFile));
            var byteCode = dialogue.GetCompiledProgram(Dialogue.CompiledFormat.V1);

            dict.Add("bytes", byteCode);
            return dict;
        }
        catch (Exception e)
        {
            GD.PushError($"Error compiling yarn file {sourceFile} {e}");
            dict.Add("error", Error.ParseError);
            return dict;
        }
    }
}
frojo commented 5 years ago

Ah okay cool. Hm maybe it's possible to use this, and then write a GDScript runner/dialogueUI thing that takes that bytecode...

Technohacker commented 4 years ago

Soo I was looking at Yarn and I was wondering, would it make sense to parse Yarn into Godot's scene tree somehow, which would allow making it a specific node attached to the scene when needed? I'm kinda drawing inspiration from Finite State Machine plugins for Godot that make use of the Godot Scene Tree to represent states :)

realkotob commented 4 years ago

@Technohacker It might make more sense to make it an autoload if there's no need to have multiple copies running.

If you want multiple copies, a script class would be a better idea than a new node-- so basically you instance the gd script and use it locally where needed -- since there's no need for it to be actually a node in the scene tree if its only parsing and not showing anything to the screen.

Technohacker commented 4 years ago

@asheraryam Thanks for the suggestions. Yeah that makes sense :)

Taking some inspiration from @naturally-intelligent's plugin, I've made a parser for Yarn that converts a .yarn file into a GDScript file directly instead of an intermediary bytecode so I could let the GDScript runtime handle execution flow. Would be glad to get some opinions/critique about it :)

realkotob commented 4 years ago

@Technohacker Clever implementation! I went through the importer scripts and it looks pretty good.

I don't have any immediate feedback about the structure but it looks pretty solid, I'll have to try it to get a feel for it to get more specific.

My only comment is that this approach would lead to a lot of code duplication for big yarn stories, so you'll probably want to add more resources and less code injection in the future -- if the injected code becomes bigger than the new runtime we'd need to create.

Technohacker commented 4 years ago

Thank you! Yeah the resources are actually because my initial implementation was to save the Yarn Story as a pseudo-AST of sorts as a resource file and have that parsed at runtime, then I just went through the parse to GDScript method instead :D

My ideology was that considering the story is largely static, converting it into GDScript would reduce runtime parsing overhead since Godot can compile down the script into a more efficient form for release. The generated code isn't meant to be human readable but I understand that it's a possible storage overhead :sweat_smile:

realkotob commented 4 years ago

@Technohacker Yeah that's fine, there will always be a trade-off between storage and runtime, that's just how things are :b

With the upcoming godot 4.0, gdscript is being rewritten so it will definitely be more compact when stored as bytecode for release.

I'm not working with yarn at this current moment so it might be a while before I try this, but it is definitely my favorite yarn plugin and I intend to use it.

JoshLee0915 commented 3 years ago

I have been working on a port of Yarn Spinner for Godot. I have not had a ton of time to test it yet but at least the basic function seem to be working.

https://github.com/JoshLee0915/YarnSpinner-Godot

It only works with the Mono versions of Godot though as I made use of the existing runtime and compiler for it. If I get the time I would like to rewrite the compiler and runtime in C++ so it could be implemented using GDNative or as a legit module so the mono runtime would not be needed to use it.

blurymind commented 3 years ago

This is really cool. Do you think it could be exported to wasm in the future? That would allow us to bundle it with yarn editor and replace bondagejs.

Either way its very cool to see it in godot, which is arguably the most popular open source engine out there atm

On Mon, 5 Apr 2021, 03:13 JoshLee0915, @.***> wrote:

I have been working on a port of Yarn Spinner for Godot. I have not had a ton of time to test it yet but at least the basic function seem to be working.

https://github.com/JoshLee0915/YarnSpinner-Godot

It only works with the Mono versions of Godot though as I made use of the existing runtime and compiler for it. If I get the time I would like to rewrite the compiler and runtime in C++ so it could be implemented using GDNative or as a legit module so the mono runtime would not be needed to use it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/YarnSpinnerTool/YarnSpinner/issues/24#issuecomment-813144829, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRRWVII4Z7J42D5ZLVMUOLTHEMF5ANCNFSM4B4JF3WQ .

blurymind commented 3 years ago

The mono version of godot is well funded by Microsoft, but a lot of godot users prefer gdscript over c# as it has optional type and cleaner syntax.

Wouldnt rewriting in c++ leave you with also having to maintain it? I though yarnspinner could also build to c++. It would be needed to get it to work in unreal and other game engines

On Mon, 5 Apr 2021, 10:56 Todor Imreorov, @.***> wrote:

This is really cool. Do you think it could be exported to wasm in the future? That would allow us to bundle it with yarn editor and replace bondagejs.

Either way its very cool to see it in godot, which is arguably the most popular open source engine out there atm

On Mon, 5 Apr 2021, 03:13 JoshLee0915, @.***> wrote:

I have been working on a port of Yarn Spinner for Godot. I have not had a ton of time to test it yet but at least the basic function seem to be working.

https://github.com/JoshLee0915/YarnSpinner-Godot

It only works with the Mono versions of Godot though as I made use of the existing runtime and compiler for it. If I get the time I would like to rewrite the compiler and runtime in C++ so it could be implemented using GDNative or as a legit module so the mono runtime would not be needed to use it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/YarnSpinnerTool/YarnSpinner/issues/24#issuecomment-813144829, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRRWVII4Z7J42D5ZLVMUOLTHEMF5ANCNFSM4B4JF3WQ .

JoshLee0915 commented 3 years ago

This is really cool. Do you think it could be exported to wasm in the future? That would allow us to bundle it with yarn editor and replace bondagejs.

Not with the current .net based setup. To my knowledge there have been a few people trying to setup a wasm compiler for C# but to my knowledge no one has made a functional one yet. I hear you could hack something together with Blazor but it sounds like it would not work for this situation and may still need to be run server side.

The mono version of godot is well funded by Microsoft, but a lot of godot users prefer gdscript over c# as it has optional type and cleaner syntax.

I should have been a bit clearer, it actually works with GDScript, it just requires you to use the mono enabled version of the engine since the back end plugin is in C#. I made special wrappers that allow GDScripts to be used for the variable store and dialogue runner as long as they implement the required methods and I adjusted the callbacks I could to use Godots event system to further help with the plugins flexibility.

While I have not tested everything yet, you should be able to do everything you would normally do in C# in GDScript and the only downside is the fact that the mono build still has some issues (though not as bad as it used to be) and will result in a larger binary.

Wouldnt rewriting in c++ leave you with also having to maintain it?

That is a possibility but tbh if I did it I would hope to be able to hand it off to Secret Lab so the Yarn community as a whole could help out with the maintenance. The larger question though is maintaining bother a C++ and .net version or going with just one. I personally think it would be better to try to move the compiler and runtimes into C++, Rust, or another language that can compile to native and wasm since that would allow the tool to be used more easily in other engines since most usually allow for binding of native binaries in some manner. That is a bit outside of this topic though.

blurymind commented 3 years ago

I think so too, if we could get yarnspinner to compile to c++, that would give us a clean path to getting it to work on unreal/other engines, but also getting it to run via wasm in js.

Thanks for working on this. I think yarnSpinner uses antlr with the goal of being portable, but I havent seen it run on anything but unity with c# yet

On Mon, Apr 5, 2021 at 11:51 PM JoshLee0915 @.***> wrote:

This is really cool. Do you think it could be exported to wasm in the future? That would allow us to bundle it with yarn editor and replace bondagejs.

Not with the current .net based setup. To my knowledge there have been a few people trying to setup a wasm compiler for C# but to my knowledge no one has made a functional one yet. I hear you could hack something together with Blazor but it sounds like it would not work for this situation and may still need to be run server side.

The mono version of godot is well funded by Microsoft, but a lot of godot users prefer gdscript over c# as it has optional type and cleaner syntax.

I should have been a bit clearer, it actually works with GDScript, it just requires you to use the mono enabled version of the engine since the back end plugin is in C#. I made special wrappers that allow GDScripts to be used for the variable store and dialogue runner as long as they implement the required methods and I adjusted the callbacks I could to use Godots event system to further help with the plugins flexibility.

While I have not tested everything yet, you should be able to do everything you would normally do in C# in GDScript and the only downside is the fact that the mono build still has some issues (though not as bad as it used to be) and will result in a larger binary.

Wouldnt rewriting in c++ leave you with also having to maintain it?

That is a possibility but tbh if I did it I would hope to be able to hand it off to Secret Lab so the Yarn community as a whole could help out with the maintenance. The larger question though is maintaining bother a C++ and .net version or going with just one. I personally think it would be better to try to move the compiler and runtimes into C++, Rust, or another language that can compile to native and wasm since that would allow the tool to be used more easily in other engines since most usually allow for binding of native binaries in some manner. That is a bit outside of this topic though.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/YarnSpinnerTool/YarnSpinner/issues/24#issuecomment-813694885, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRRWVMRN2TQ4ICDWF3RHVLTHI5GRANCNFSM4B4JF3WQ .

bram-dingelstad commented 2 years ago

Hey y'all, i've been following this thread along since the beginning to see if something would come out. I've been using YarnSpinner in combination with Godot for some time in some of consultancy / professional work. Its implementation is based on the work of another programmer, but I refactored it for my needs and made it more error resistant & compatible with Godot.

The aim is to have it 100% be in spec with Yarn Spinner while also providing a tool in Godot to do the actual writing. I've been working a lot on stability and developer / writing experience (helpful error messages and stuff). I've also done a lot of work in documentation and tutorials (and making them inline with YarnSpinner). Y'all can help me out over here.

I could definitely use the outcome of the C++ compiler / virtual machine @JoshLee0915, would love to hear your thoughts on maybe combining our efforts!

JoshLee0915 commented 2 years ago

Good day @bram-dingelstad! I would be interested in seeing if we could combine our efforts. After chatting about it on issue #299 there seems to be enough interest from the secret lab team that doing a C++ port is something I want to try at some point here.

bram-dingelstad commented 2 years ago

Cool! Feel free to contact me through my git email or contact information you can find on my website. Would love to chat and find out what we can do!

On 8 Dec 2021, at 3:05 PM, JoshLee0915 @.***> wrote:

Good day @.***(https://github.com/bram-dingelstad)! I would be interested in seeing if we could combine our efforts. After chatting about it on issue #299 there seems to be enough interest from the secret lab team that doing a C++ port is something I want to try at some point here.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

JSchrepp commented 1 year ago

Oh dear. Catching up on this thread in 2023, it looks like all the community solutions to this are likely incompatible with Godot 4, as it introduces a breaking GDScript 2 and the linked solutions haven't been updated in years. Many of them use yield which has been removed in favor of await.

I definitely understand the pressures of supporting a custom language, especially one that is willing to break like this, regardless of it being in an engine gaining significant ground. Perhaps the more robust solution for Godot integration would be to use a more widely-usable (perhaps already existing?) C++ implementation, which could then be integrated through GDExtension APIs and surfaced with a thin GDScript interface. However, the C++ proposal hasn't been updated in a year at this point, so it's not clear if that's actually less work than porting all the Godot 3.x work.

JoshLee0915 commented 1 year ago

The main issue is just the fact that the run times for Yarn are all in C#. To make a GDExtension you would have to either make an interop layer (which sucks to maintain) or port it to C++. I have been working on a C++ port slowly but 2022 got really busy for me due to being brought on for a major project so did not have as much time as I may have liked.

My port for Godot 3.x Mono could actually be migrated to 4.0 without to much work I think since most of it is in C# and there where less changes there then in GDScript 2.0, but not sure if I would want to spend some time porting that or focus on the C++ port so I can try to move forward with using GDExtension when/if I can

naturally-intelligent commented 1 year ago

@JSchrepp

There is a Godot 4 version of the "godot-yarn-importer" base lib

https://github.com/naturally-intelligent/godot-yarn-importer/issues/2

janhohenheim commented 1 year ago

The main issue is just the fact that the run times for Yarn are all in C#. To make a GDExtension you would have to either make an interop layer (which sucks to maintain) or port it to C++. I have been working on a C++ port slowly but 2022 got really busy for me due to being brought on for a major project so did not have as much time as I may have liked.

My port for Godot 3.x Mono could actually be migrated to 4.0 without to much work I think since most of it is in C# and there where less changes there then in GDScript 2.0, but not sure if I would want to spend some time porting that or focus on the C++ port so I can try to move forward with using GDExtension when/if I can

We just finished porting the entire compiler and runtime to Rust (see our crate yarn_slinger), so one could use that instead of C++ :)

dogboydog commented 10 months ago

Just dropping this link here for anyone interested. I have been working on this port, initially for use in my own game project, but sharing it back with the YS community. It's designed to have a similar experience to the Unity plugin, and a lot of the features are working. It is still in a pre-release phase though.

https://docs.yarnspinner.dev/beginners-guide/making-a-game/yarn-spinner-for-godot

This version is for Godot 4, but it still requires the C# enabled version of the engine. A C++ or Rust based plugin would have to be a different project.

https://github.com/YarnSpinnerTool/YarnSpinner-Godot

desplesda commented 8 months ago

Because we've now officially adopted Yarn Spinner for Godot as a Yarn Spinner project, all future work and discussions on this port can happen in its own repo.

Thanks for the discussion in this thread, everyone!