Start bindings and interface implementation for the IC10Editor mod
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Assets.Scripts.Objects.Motherboards;
|
||||
using HarmonyLib;
|
||||
|
||||
@@ -29,6 +30,10 @@ namespace Slang
|
||||
return;
|
||||
}
|
||||
|
||||
var newUuid = Guid.NewGuid().ToString();
|
||||
|
||||
SlangPlugin.CopySourceToFile(result);
|
||||
|
||||
// Set the result to be the compiled source so the rest of the function can continue as normal
|
||||
result = compiled;
|
||||
}
|
||||
|
||||
12
csharp_mod/SlangFormatter.cs
Normal file
12
csharp_mod/SlangFormatter.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using StationeersIC10Editor;
|
||||
|
||||
namespace Slang
|
||||
{
|
||||
public class SlangFormatter : ICodeFormatter
|
||||
{
|
||||
public override Line ParseLine(string line)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using BepInEx;
|
||||
using HarmonyLib;
|
||||
|
||||
@@ -9,7 +10,7 @@ namespace Slang
|
||||
{
|
||||
class L
|
||||
{
|
||||
private static BepInEx.Logging.ManualLogSource _logger;
|
||||
private static BepInEx.Logging.ManualLogSource? _logger;
|
||||
|
||||
public static void SetLogger(BepInEx.Logging.ManualLogSource logger)
|
||||
{
|
||||
@@ -18,34 +19,32 @@ namespace Slang
|
||||
|
||||
public static void Debug(string message)
|
||||
{
|
||||
_logger.LogDebug(message);
|
||||
_logger?.LogDebug(message);
|
||||
}
|
||||
|
||||
public static void Info(string message)
|
||||
{
|
||||
_logger.LogInfo(message);
|
||||
_logger?.LogInfo(message);
|
||||
}
|
||||
|
||||
public static void Error(string message)
|
||||
{
|
||||
_logger.LogError(message);
|
||||
_logger?.LogError(message);
|
||||
}
|
||||
|
||||
public static void Warning(string message)
|
||||
{
|
||||
_logger.LogWarning(message);
|
||||
_logger?.LogWarning(message);
|
||||
}
|
||||
}
|
||||
|
||||
[BepInPlugin(PluginGuid, PluginName, "0.1.0")]
|
||||
public class SlangPlugin : BaseUnityPlugin
|
||||
{
|
||||
public const string PluginGuid = "com.dbidwell94.slang";
|
||||
public const string PluginGuid = "com.biddydev.slang";
|
||||
public const string PluginName = "Slang";
|
||||
|
||||
const string RUST_DLL_NAME = "slang.dll";
|
||||
|
||||
private readonly string[] SLANG_KEYWORDS = { "let ", "fn " };
|
||||
const string RUST_DLL_NAME = "slang.compiler.dll";
|
||||
|
||||
/// <summary>Takes raw `Slang` source code and compiles it into IC10</summary>
|
||||
[DllImport(RUST_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
@@ -55,6 +54,21 @@ namespace Slang
|
||||
[DllImport(RUST_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern void free_slang_string(IntPtr ptr);
|
||||
|
||||
private static Regex? _slangSourceCheck = null;
|
||||
|
||||
private static Regex SlangSourceCheck
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_slangSourceCheck is null)
|
||||
{
|
||||
_slangSourceCheck = new Regex(@"[;{}()]|\b(let|fn|device)\b|\/\/");
|
||||
}
|
||||
|
||||
return _slangSourceCheck;
|
||||
}
|
||||
}
|
||||
|
||||
public static string Compile(string source)
|
||||
{
|
||||
if (string.IsNullOrEmpty(source))
|
||||
@@ -71,11 +85,19 @@ namespace Slang
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsSlangSource(ref string input)
|
||||
/// <summary>Take original slang source code and copies it to a file
|
||||
/// for use in restoring later.
|
||||
/// </summary>
|
||||
public static bool CopySourceToFile(string source)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsSlangSource(ref string input)
|
||||
{
|
||||
return SlangSourceCheck.IsMatch(input);
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
L.SetLogger(Logger);
|
||||
@@ -94,7 +116,7 @@ namespace Slang
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
Logger.LogError(
|
||||
L.Error(
|
||||
$"{RUST_DLL_NAME} compiler not found. This means it was not embedded in the mod. Please contact the mod author!"
|
||||
);
|
||||
return;
|
||||
@@ -109,9 +131,7 @@ namespace Slang
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Logger.LogWarning(
|
||||
$"Could not overwrite {fileName} (it might be in use): {e.Message}"
|
||||
);
|
||||
L.Warning($"Could not overwrite {fileName} (it might be in use): {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
22
csharp_mod/StationpediaDocumentation.cs
Normal file
22
csharp_mod/StationpediaDocumentation.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Assets.Scripts.UI;
|
||||
|
||||
namespace Slang
|
||||
{
|
||||
public static class SlangDocs
|
||||
{
|
||||
public static StationpediaPage[] Pages
|
||||
{
|
||||
get
|
||||
{
|
||||
return
|
||||
[
|
||||
new StationpediaPage(
|
||||
"slang-init",
|
||||
"Slang",
|
||||
"Slang is a new high level language built specifically for Stationeers"
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,11 +46,15 @@
|
||||
<HintPath>$(ManagedDir)/Assembly-CSharp-firstpass.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="IC10Editor.dll">
|
||||
<HintPath>./ref/IC10Editor.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="../rust_compiler/target/x86_64-pc-windows-gnu/release/slang.dll">
|
||||
<LogicalName>slang.dll</LogicalName>
|
||||
<LogicalName>slang.compiler.dll</LogicalName>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user