Polyphase Game Engine
Loading...
Searching...
No Matches
CSharpManager.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include <string>
6
7// Drives the PolyphaseSharp C# -> Lua transpiler (Tools/PolyphaseSharp).
8// The .NET SDK is an authoring-time dependency only: pure-Lua projects never
9// touch any of this, and shipped games run the generated Lua with no .NET.
10class CSharpManager
11{
12public:
13 static CSharpManager* Get();
14
15 // True when the loaded project has CSharpScripting=1 in Config.ini.
16 bool IsEnabledForProject() const;
17
18 // <Project>/Scripts/CSharp (empty string when no project is loaded).
19 std::string GetProjectCSharpDir() const;
20
21 // Any .cs source under Scripts/CSharp (cheap disk probe).
22 bool ProjectHasCSharpSources() const;
23
24 // Probe `dotnet --version`. Result is cached; pass forceReprobe after an
25 // install. Requires major version >= 8.
26 bool CheckDotnet(std::string* outVersion = nullptr, bool forceReprobe = false);
27
28 // Build the transpiler tool if its sources are newer than the built dll
29 // (or it was never built). Blocking; returns the dll path or "" on failure.
30 std::string EnsureToolBuilt(std::string* outLog = nullptr);
31
32 // Transpile <Project>/Scripts/CSharp. Blocking. Diagnostics are pushed to
33 // the log (file(line,col): error CS/PS... format) and appended to outLog.
34 // Returns false on compile/validation errors or missing prerequisites.
35 bool Transpile(bool checkOnly = false, std::string* outLog = nullptr);
36
37 // Open the project's C# workspace in the IDE chosen in
38 // Preferences > External > Editors (default Visual Studio). Creates any
39 // missing workspace files first, so projects enabled by older builds
40 // pick up Game.sln retroactively.
41 void OpenIde();
42
43 // Create Game.csproj / Game.sln under Scripts/CSharp if absent.
44 // Idempotent; called from EnableForProject and OpenIde.
45 void EnsureWorkspaceFiles();
46
47 // Turn C# scripting on for the loaded project: sets CSharpScripting=1 in
48 // Config.ini, scaffolds Scripts/CSharp/ (Game.csproj + sample Rotator.cs),
49 // appends Intermediate/CSharp/ to the project .gitignore, and probes dotnet
50 // (logging install guidance when missing). Safe to call repeatedly.
51 bool EnableForProject();
52
53 // The winget/apt command (or download URL) offered when dotnet is missing.
54 static const char* GetDotnetInstallCommand();
55 static const char* GetDotnetInstallUrl();
56
57private:
58 bool mDotnetProbed = false;
59 bool mDotnetOk = false;
60 std::string mDotnetVersion;
61 std::string mToolDllPath;
62};
63
64#endif