Skip to content
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

added live scripting stuff #216

Merged
merged 1 commit into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion UniTAS/Patcher/Implementations/GUI/MainMenuTabs/TestTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ public class TestTab : IMainMenuTab
private readonly ISceneWrapper _sceneWrapper;
private readonly IMonoBehaviourController _monoBehaviourController;
private readonly IRuntimeTestAndLog _runtimeTestAndLog;
private readonly ILiveScripting _liveScripting;

public TestTab(IGameRender gameRender, IGameRestart gameRestart, ISceneWrapper sceneWrapper,
IMonoBehaviourController monoBehaviourController, IRuntimeTestAndLog runtimeTestAndLog)
IMonoBehaviourController monoBehaviourController, IRuntimeTestAndLog runtimeTestAndLog,
ILiveScripting liveScripting)
{
_gameRender = gameRender;
_gameRestart = gameRestart;
_sceneWrapper = sceneWrapper;
_monoBehaviourController = monoBehaviourController;
_runtimeTestAndLog = runtimeTestAndLog;
_liveScripting = liveScripting;
}

public void Render(int windowID)
Expand Down Expand Up @@ -68,6 +71,11 @@ public void Render(int windowID)
_runtimeTestAndLog.Test();
}

if (GUILayout.Button("test scripting"))
{
_liveScripting.Evaluate("print('hello world')");
}

GUILayout.EndVertical();
}

Expand Down
32 changes: 32 additions & 0 deletions UniTAS/Patcher/Implementations/LiveScripting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Loaders;
using UniTAS.Patcher.Interfaces.DependencyInjection;
using UniTAS.Patcher.Services;
using UniTAS.Patcher.Services.Logging;

namespace UniTAS.Patcher.Implementations;

[Singleton]
public class LiveScripting : ILiveScripting
{
private readonly Script _script;

public LiveScripting(ILogger logger)
{
_script = new(CoreModules.Preset_Complete)
{
Options =
{
// do NOT use unity loader
ScriptLoader = new FileSystemScriptLoader(),
DebugInput = _ => null,
DebugPrint = logger.LogInfo
}
};
}

public void Evaluate(string code)
{
_script.DoString(code);
}
}
10 changes: 10 additions & 0 deletions UniTAS/Patcher/Services/ILiveScripting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace UniTAS.Patcher.Services;

public interface ILiveScripting
{
/// <summary>
/// Evaluates the given code.
/// </summary>
/// <param name="code"></param>
void Evaluate(string code);
}