Add support for checking sdsh scripts during build with an MSBuild task

This commit is contained in:
Ritchie Frodomar 2024-07-11 16:32:28 -04:00
parent ad83b00da5
commit 77570ed25b
88 changed files with 305 additions and 191 deletions

View file

@ -0,0 +1,101 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using SociallyDistant.Core.Core.Scripting;
namespace SociallyDistant.Core.BuildTasks;
public class SdshScriptCheckTask : Microsoft.Build.Utilities.Task
{
[Required]
public string ScriptsSource { get; set; } = string.Empty;
[Required]
public string ScriptsOutput { get; set; } = string.Empty;
[Output]
public ITaskItem[] Results { get; set; }
public override bool Execute()
{
var collectedScripts = new List<string>();
var results = new List<ITaskItem>();
var result = true;
foreach (string shFile in Directory.EnumerateFiles(ScriptsSource, "*.sh", SearchOption.AllDirectories))
{
var parseResult = CheckScriptSyntax(shFile);
result &= parseResult;
results.Add(new TaskItem(shFile, new Dictionary<string, string> { { "IsValid", parseResult.ToString() } }));
collectedScripts.Add(shFile.Substring(ScriptsSource.Length));
}
Results = results.ToArray();
if (!result)
{
this.Log.LogError("Some sdsh scripts failed to parse.");
return false;
}
if (!Directory.Exists(ScriptsOutput))
Directory.CreateDirectory(ScriptsOutput);
Log.LogMessage("Cleaning the script output directory...");
foreach (string shFile in Directory.EnumerateFiles(ScriptsOutput, "*.sh", SearchOption.AllDirectories))
{
string relative = shFile.Substring(ScriptsOutput.Length);
if (collectedScripts.Contains(relative))
continue;
Log.LogMessage($"Deleting: {shFile}");
File.Delete(shFile);
}
foreach (string relative in collectedScripts)
{
string source = ScriptsSource + relative;
string destination = ScriptsOutput + relative;
string? outputDirectory = Path.GetDirectoryName(destination);
if (string.IsNullOrEmpty(outputDirectory))
continue;
if (!Directory.Exists(outputDirectory))
{
Log.LogMessage($"creating: {outputDirectory}");
Directory.CreateDirectory(outputDirectory);
}
Log.LogMessage($"Copying: {source} -> {destination}");
File.Copy(source, destination);
}
return true;
}
private bool CheckScriptSyntax(string path)
{
using var stream = File.OpenRead(path);
using var streamReader = new StreamReader(stream);
var text = streamReader.ReadToEnd();
var context = new UserScriptExecutionContext();
var parser = new InteractiveShell(context);
try
{
parser.ParseScript(text).GetAwaiter().GetResult();
return true;
}
catch (Exception ex)
{
Log.LogError($"{path}: parse error: {ex}");
return false;
}
}
}

View file

@ -1,6 +1,6 @@
#nullable enable
namespace SociallyDistant.Architecture
namespace SociallyDistant.Core.Core.Scripting
{
public class ArrayView<TElementType>
{

View file

@ -1,5 +1,5 @@
#nullable enable
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public static class CommonScriptHooks
{

View file

@ -1,7 +1,7 @@
#nullable enable
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Consoles
namespace SociallyDistant.Core.Core.Scripting.Consoles
{
public class FileOutputConsole :
ITextConsole,

View file

@ -1,7 +1,7 @@
using System.Text;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Consoles
namespace SociallyDistant.Core.Core.Scripting.Consoles
{
public class LineListConsole : ITextConsole
{

View file

@ -1,6 +1,6 @@
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Consoles
namespace SociallyDistant.Core.Core.Scripting.Consoles
{
public class RedirectedConsole : ITextConsole
{

View file

@ -1,9 +1,9 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.GlobalCommands
namespace SociallyDistant.Core.Core.Scripting.GlobalCommands
{
public class ExecuteHookCommand : IScriptCommand
{
@ -15,7 +15,7 @@ namespace SociallyDistant.Core.Scripting.GlobalCommands
string hookName = args[0];
await SystemModule.GetSystemModule().Context.ScriptSystem.RunHookAsync(hookName);
await Application.Instance.Context.ScriptSystem.RunHookAsync(hookName);
}
}
}

View file

@ -1,9 +1,8 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.GlobalCommands
namespace SociallyDistant.Core.Core.Scripting.GlobalCommands
{
public class SaveGameCommand : IScriptCommand
{

View file

@ -1,9 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.GlobalCommands
namespace SociallyDistant.Core.Core.Scripting.GlobalCommands
{
public class WorldFlagCommand : IScriptCommand
{
@ -15,7 +13,7 @@ namespace SociallyDistant.Core.Scripting.GlobalCommands
worldflag get <flag> - Sets the specified world flag in the current world.
worldflag run-if-set <flag> <command> [args...] - Runs the specified command with the given arguments if the given world flag is set.
worldflag run-if-unset <flag> <command> [args...] - Runs the specified command with the given arguments if the given world flag isn't set.";
internal WorldFlagCommand(IWorldManager worldManager)
public WorldFlagCommand(IWorldManager worldManager)
{
this.worldManager = worldManager;
}

View file

@ -2,15 +2,16 @@
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.FileSystems;
using SociallyDistant.Core.OS.Network;
using SociallyDistant.OS.FileSystems;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public sealed class HypervisorComputer : IComputer
{
private readonly IUser user;
private readonly IFileSystem hypervisorFileSystem = new HypervisorFileSystem();
public bool IsPlayer => true;
/// <inheritdoc />
public string Name => "socially-distant";

View file

@ -1,9 +1,8 @@
#nullable enable
using SociallyDistant.Core.OS.FileSystems;
using SociallyDistant.OS.FileSystems;
using SociallyDistant.OS.FileSystems.Immutable;
using SociallyDistant.Core.OS.FileSystems.Immutable;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public sealed class HypervisorFileSystem : IFileSystem
{

View file

@ -1,16 +1,16 @@
#nullable enable
using System.Runtime.CompilerServices;
using SociallyDistant.Architecture;
using SociallyDistant.Core.Core.Systems;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public sealed class HypervisorProcess : ISystemProcess
{
private readonly int id;
private readonly IEnvironmentVariableProvider environment = new SimpleEnvironmentVariableProvider();
private readonly UniqueIntGenerator idGenerator;
private readonly ISystemProcess? parent;
private readonly List<ISystemProcess> children = new List<ISystemProcess>();
private readonly IUser user;

View file

@ -1,7 +1,7 @@
#nullable enable
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public sealed class HypervisorUser : IUser
{

View file

@ -1,5 +1,5 @@
#nullable enable
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public interface ICommandShell
{

View file

@ -1,7 +1,7 @@
#nullable enable
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public interface ITerminalProcessController
{

View file

@ -1,7 +1,6 @@
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public class AssignmentInstruction : ShellInstruction
{

View file

@ -1,8 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class BranchEvaluator : ShellInstruction
{

View file

@ -1,8 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class BranchInstruction : ShellInstruction
{

View file

@ -1,8 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public class CommandData
{

View file

@ -1,8 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class CommandExpansion : IArgumentEvaluator
{

View file

@ -2,7 +2,7 @@
using System.Text;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class CommandExpansionConsole : ITextConsole
{

View file

@ -1,8 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class EmptyShellInstruction : ShellInstruction
{

View file

@ -1,9 +1,8 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.Parsing;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.Scripting.Parsing;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class FunctionDeclaration : ShellInstruction
{

View file

@ -1,10 +1,9 @@
#nullable enable
using System.Text;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public interface IArgumentEvaluator
{

View file

@ -1,8 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class LogicalAndInstruction : ShellInstruction
{

View file

@ -1,8 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class LogicalOrInstruction : ShellInstruction
{

View file

@ -1,7 +1,6 @@
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class ParallelInstruction : ShellInstruction
{

View file

@ -1,8 +1,7 @@
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.Consoles;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.Scripting.Consoles;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class PipeInstruction : ShellInstruction
{

View file

@ -1,7 +1,6 @@
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class SequentialInstruction : ShellInstruction
{

View file

@ -1,9 +1,8 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public abstract class ShellInstruction
{

View file

@ -1,9 +1,8 @@
#nullable enable
using System.Text.RegularExpressions;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class ShellPattern : ShellInstruction
{

View file

@ -1,7 +1,6 @@
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class SingleInstruction : ShellInstruction
{

View file

@ -1,8 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public class VariableAccessEvaluator : IArgumentEvaluator
{

View file

@ -1,8 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Instructions
namespace SociallyDistant.Core.Core.Scripting.Instructions
{
public sealed class WhileLoop : ShellInstruction
{

View file

@ -3,15 +3,11 @@
using System.Diagnostics;
using System.Text;
using Serilog;
using SociallyDistant.Architecture;
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.Instructions;
using SociallyDistant.Core.Core.Scripting.Parsing;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.Scripting.Instructions;
using SociallyDistant.Core.Scripting.Parsing;
using SociallyDistant.GamePlatform;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public class InteractiveShell :
ITerminalProcessController,
@ -184,7 +180,7 @@ namespace SociallyDistant.Core.Scripting
{
try
{
return await scriptTree.RunAsync(this.consoleDevice ?? new UnityTextConsole(), this);
return await scriptTree.RunAsync(this.consoleDevice ?? new HostConsole(), this);
}
catch (ScriptEndException endException)
{

View file

@ -1,14 +1,12 @@
#nullable enable
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.Consoles;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.FileSystems;
using SociallyDistant.Core.Scripting.Consoles;
using SociallyDistant.Core.OS.FileSystems.Host;
using SociallyDistant.Core.Shell.Commands;
using SociallyDistant.OS.Devices;
using SociallyDistant.OS.FileSystems.Host;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public class OperatingSystemExecutionContext : IInteractiveShellContext
{
@ -45,8 +43,7 @@ namespace SociallyDistant.Core.Scripting
if (HandleBuiltin(name, args, console, callSite ?? this))
return 0;
var sys = SystemModule.GetSystemModule();
CustomCommandAsset? customCommand = sys.Context.ContentManager.GetContentOfType<CustomCommandAsset>()
CustomCommandAsset? customCommand = Application.Instance.Context.ContentManager.GetContentOfType<CustomCommandAsset>()
.FirstOrDefault(x => x.Name == name);
if (customCommand != null)
@ -136,7 +133,7 @@ namespace SociallyDistant.Core.Scripting
private async Task<int?> HandleCustomCommand(CustomCommandAsset command, string name, string[] args, ITextConsole console)
{
if (command.IsPlayerOnly && process.User.Computer is not PlayerComputer)
if (command.IsPlayerOnly && process.User.Computer.IsPlayer)
return null;
var consoleWrapper = new ConsoleWrapper(console);
@ -208,8 +205,7 @@ namespace SociallyDistant.Core.Scripting
private DateTime GetCurrentTime()
{
var system = SystemModule.GetSystemModule();
IWorld world = system.Context.WorldManager.World;
IWorld world = Application.Instance.Context.WorldManager.World;
return world.GlobalWorldState.Value.Now;
}

View file

@ -2,7 +2,7 @@
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.Tasks;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public sealed class OperatingSystemScript : IShellScript
{

View file

@ -1,8 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.Parsing
namespace SociallyDistant.Core.Core.Scripting.Parsing
{
public class LocalScriptExecutionContext : IScriptExecutionContext
{

View file

@ -1,9 +1,8 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.Instructions;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.Scripting.Instructions;
namespace SociallyDistant.Core.Scripting.Parsing
namespace SociallyDistant.Core.Core.Scripting.Parsing
{
public class ScriptFunction : IScriptFunction
{

View file

@ -1,12 +1,10 @@
#nullable enable
using System.Text;
using SociallyDistant.Architecture;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Scripting.Instructions;
using SociallyDistant.Core.Core.Scripting.Instructions;
// hello world
namespace SociallyDistant.Core.Scripting.Parsing
namespace SociallyDistant.Core.Core.Scripting.Parsing
{
public class ScriptParser
{

View file

@ -1,9 +1,8 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.Instructions;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.Scripting.Instructions;
namespace SociallyDistant.Core.Scripting.Parsing
namespace SociallyDistant.Core.Core.Scripting.Parsing
{
public class TextArgumentEvaluator : IArgumentEvaluator
{

View file

@ -1,5 +1,5 @@
#nullable enable
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public abstract class ScriptCommandProvider
{

View file

@ -1,7 +1,5 @@
#nullable enable
using SociallyDistant.Core.Core.Scripting;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public class ScriptContextCommand
{

View file

@ -1,6 +1,6 @@
#nullable enable
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public sealed class ScriptEndException : Exception
{

View file

@ -1,12 +1,10 @@
#nullable enable
using System.Diagnostics;
using Serilog;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.Parsing;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.Scripting.Parsing;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public class ScriptExecutionContext : IScriptExecutionContext
{
@ -40,8 +38,7 @@ namespace SociallyDistant.Core.Scripting
if (functionResult != null)
return functionResult;
var system = SystemModule.GetSystemModule();
IGameContext gameContext = system.Context;
IGameContext gameContext = Application.Instance.Context;
// Search for global commands first
IScriptCommand? globalCommand = gameContext.ScriptSystem.GetGlobalCommand(name);

View file

@ -1,13 +1,10 @@
#nullable enable
using System.Diagnostics;
using Serilog;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.GamePlatform;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public class ScriptSystem : IScriptSystem
{
@ -15,7 +12,7 @@ namespace SociallyDistant.Core.Scripting
private readonly Dictionary<string, IScriptCommand> globalCommands = new Dictionary<string, IScriptCommand>();
private readonly IGameContext game;
internal ScriptSystem(IGameContext game)
public ScriptSystem(IGameContext game)
{
this.game = game;
}
@ -29,7 +26,7 @@ namespace SociallyDistant.Core.Scripting
if (command == null)
return;
await command.ExecuteAsync(context, console ?? new UnityTextConsole(), name, args);
await command.ExecuteAsync(context, console ?? new HostConsole(), name, args);
}
/// <inheritdoc />

View file

@ -2,7 +2,7 @@
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public class ShellScriptAsset
{

View file

@ -2,7 +2,7 @@
using System.Text.RegularExpressions;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public class ShellTester
{

View file

@ -1,8 +1,6 @@
using System.Text;
using SociallyDistant.Architecture;
using SociallyDistant.Core.Core;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public static class ShellUtility
{

View file

@ -1,7 +1,7 @@
#nullable enable
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Architecture
namespace SociallyDistant.Core.Core.Scripting
{
public class SimpleEnvironmentVariableProvider : IEnvironmentVariableProvider
{

View file

@ -1,9 +1,7 @@
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.WorldData.Data;
using SociallyDistant.Core.Core.WorldData.Data;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.WorldCommands
namespace SociallyDistant.Core.Core.Scripting.WorldCommands
{
public class SetPlayerIspCommand : WorldCommand
{

View file

@ -1,8 +1,6 @@
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.WorldCommands
namespace SociallyDistant.Core.Core.Scripting.WorldCommands
{
public class SpawnIspCommand : WorldCommand
{

View file

@ -1,20 +1,16 @@
#nullable enable
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Core.Scripting.WorldCommands
namespace SociallyDistant.Core.Core.Scripting.WorldCommands
{
public abstract class WorldCommand : IScriptCommand
{
/// <inheritdoc />
public async Task ExecuteAsync(IScriptExecutionContext context, ITextConsole console, string name, string[] args)
{
var systemModule = SystemModule.GetSystemModule();
IGameContext game = systemModule.Context;
IGameContext game = Application.Instance.Context;
IWorldManager worldManager = game.WorldManager;
await OnExecute(worldManager, context, console, name, args);

View file

@ -1,7 +1,7 @@
#nullable enable
using SociallyDistant.Core.Scripting.WorldCommands;
using SociallyDistant.Core.Core.Scripting.WorldCommands;
namespace SociallyDistant.Core.Scripting
namespace SociallyDistant.Core.Core.Scripting
{
public sealed class WorldScriptCommandProvider : ScriptCommandProvider
{

View file

@ -0,0 +1,22 @@
using Serilog;
namespace SociallyDistant.Core.OS.Devices;
public class HostConsole : ITextConsole
{
public string WindowTitle { get; set; } = string.Empty;
public bool IsInteractive { get; } = false;
public void ClearScreen()
{
}
public void WriteText(string text)
{
Log.Information(text);
}
public ConsoleInputData? ReadInput()
{
return null;
}
}

View file

@ -5,21 +5,10 @@ using SociallyDistant.Core.OS.Network;
namespace SociallyDistant.Core.OS.Devices
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class NetworkServiceAttribute : Attribute
{
private readonly string id;
public string Id => id;
public NetworkServiceAttribute(string id)
{
this.id = id;
}
}
public interface IComputer
{
bool IsPlayer { get; }
string Name { get; }
bool FindUserById(int id, out IUser? user);
bool FindUserByName(string username, out IUser? user);

View file

@ -0,0 +1,14 @@
namespace SociallyDistant.Core.OS.Devices;
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class NetworkServiceAttribute : Attribute
{
private readonly string id;
public string Id => id;
public NetworkServiceAttribute(string id)
{
this.id = id;
}
}

View file

@ -1,7 +1,7 @@
#nullable enable
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.OS.FileSystems.Host
namespace SociallyDistant.Core.OS.FileSystems.Host
{
public class FileInputConsole :
ITextConsole,

View file

@ -1,9 +1,8 @@
#nullable enable
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.FileSystems;
namespace SociallyDistant.OS.FileSystems.Immutable
namespace SociallyDistant.Core.OS.FileSystems.Immutable
{
public class ImmutableDirectoryEntry : IDirectoryEntry
{

View file

@ -1,8 +1,6 @@
#nullable enable
using SociallyDistant.Core.OS.FileSystems;
namespace SociallyDistant.OS.FileSystems.Immutable
namespace SociallyDistant.Core.OS.FileSystems.Immutable
{
public class ImmutableDirectoryTree
{

View file

@ -1,9 +1,8 @@
#nullable enable
using SociallyDistant.Core.Core;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.FileSystems;
namespace SociallyDistant.OS.FileSystems
namespace SociallyDistant.Core.OS.FileSystems
{
public class VirtualFileSystem : IVirtualFileSystem
{

View file

@ -9,6 +9,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="17.10.4" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.10.4" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.1" />

View file

@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Serilog;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Systems;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.Tasks;

View file

@ -1,6 +1,7 @@
#nullable enable
using System.Collections;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.OS.Devices;
namespace SociallyDistant.Architecture

View file

@ -0,0 +1,44 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
* This UsingTask element declares a custom MSBuild task named "ScriptValidatorTask".
* It specifies the assembly file where the task is defined from the current file's directory
-->
<UsingTask
TaskName="SdshScriptCheckTask"
AssemblyFile="$(OutDir)/SociallyDistant.Framework.dll" />
<!--
* This defines a new MSBuild Target named "ValidateScripts".
* The BeforeTargets attribute specifies that this target should run before the "Build" target, so we can validate
before a build is performed
-->
<Target Name="ValidateScripts" AfterTargets="Build">
<!--
* This executes the custom ScriptValidatorTask that is in the SociallyDistant.Framework.dll assembly
* It passes the ShellScripts above as the ScriptPaths parameter.
* ContinueOnError="false" means the build will stop if this task fails at any point
* The Output element captures the task's ValidationResults output into an MSBuild property named ScriptValidationResults.
-->
<SdshScriptCheckTask
ScriptsSource="$(MSBuildProjectDirectory)/Content"
ScriptsOutput="$(OutDir)Content/"
ContinueOnError="false">
<Output TaskParameter="Results" PropertyName="ScriptValidationResults" />
</SdshScriptCheckTask>
<!--
This Error task will cause the build to fail if any script validation failed.
It checks the IsValid metadata of each ScriptValidationResults item.
If IsValid is false for any item, it displays an error message with the script's identity (path).
-->
<Error
Text="Script validation failed for: %(ScriptValidationResults.Identity)"
Condition="'%(ScriptValidationResults.IsValid)' == 'false'" />
</Target>
</Project>

View file

@ -1,9 +1,9 @@
#nullable enable
using SociallyDistant.Architecture;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.Tasks;
using SociallyDistant.Core.Scripting;
using SociallyDistant.OS.Devices;
namespace SociallyDistant.Commands.CoreUtils

View file

@ -3,8 +3,8 @@
using System.Diagnostics;
using System.Net.Mime;
using SociallyDistant.Core.ContentManagement;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.Scripting;
namespace SociallyDistant.GamePlatform.ContentManagement
{

View file

@ -3,8 +3,7 @@
using SociallyDistant.Core.Chat;
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Scripting.Instructions;
using SociallyDistant.Core.Core.Scripting.Instructions;
using SociallyDistant.Core.Social;
using SociallyDistant.GamePlatform;

View file

@ -7,7 +7,6 @@ using SociallyDistant.Core.Chat;
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Social;
using SociallyDistant.Core.WorldData;

View file

@ -2,11 +2,10 @@
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.Instructions;
using SociallyDistant.Core.Core.Scripting.Parsing;
using SociallyDistant.Core.Core.WorldData.Data;
using SociallyDistant.Core.OS.Network;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Scripting.Instructions;
using SociallyDistant.Core.Scripting.Parsing;
using SociallyDistant.GamePlatform;
namespace SociallyDistant.GameplaySystems.Hacking.Assets

View file

@ -5,7 +5,6 @@ using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.FileSystems;
using SociallyDistant.Core.OS.Network;
using SociallyDistant.Core.Scripting;
using SociallyDistant.GameplaySystems.NonPlayerComputers;
using SociallyDistant.Player;

View file

@ -6,7 +6,6 @@ using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.WorldData.Data;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Social;
using SociallyDistant.Core.WorldData;
using SociallyDistant.GameplaySystems.Social;

View file

@ -8,7 +8,6 @@ using SociallyDistant.Core.Core.WorldData.Data;
using SociallyDistant.Core.Missions;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Social;
using SociallyDistant.Core.WorldData;
using SociallyDistant.GameplaySystems.Social;

View file

@ -2,10 +2,9 @@
using SociallyDistant.Architecture;
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.Instructions;
using SociallyDistant.Core.Core.Scripting.Parsing;
using SociallyDistant.Core.Missions;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Scripting.Instructions;
using SociallyDistant.Core.Scripting.Parsing;
using SociallyDistant.Core.Social;
using SociallyDistant.GamePlatform;

View file

@ -2,10 +2,10 @@
using System.Diagnostics;
using Serilog;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.GlobalCommands;
using SociallyDistant.Core.Core.Scripting.StandardModules;
using SociallyDistant.Core.Missions;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.Scripting.GlobalCommands;
namespace SociallyDistant.GameplaySystems.Missions
{

View file

@ -30,7 +30,9 @@ namespace SociallyDistant.GameplaySystems.NonPlayerComputers
private ISystemProcess systemd;
private IWorldManager world = null!;
private ServiceManager? serviceManager;
public bool IsPlayer => false;
/// <inheritdoc />
public string Name => worldData.HostName;

View file

@ -1,8 +1,8 @@
#nullable enable
using SociallyDistant.Core.Core;
using SociallyDistant.Core.OS.FileSystems;
using SociallyDistant.Core.OS.FileSystems.Immutable;
using SociallyDistant.OS.FileSystems;
using SociallyDistant.OS.FileSystems.Immutable;
namespace SociallyDistant.GameplaySystems.NonPlayerComputers
{

View file

@ -1,9 +1,8 @@
#nullable enable
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Scripting.Instructions;
using SociallyDistant.Core.Scripting.Parsing;
using SociallyDistant.Core.Core.Scripting.Instructions;
using SociallyDistant.Core.Core.Scripting.Parsing;
using SociallyDistant.Core.Social;
using SociallyDistant.GamePlatform;

View file

@ -4,7 +4,6 @@ using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.WorldData.Data;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Social;
using SociallyDistant.Player;

View file

@ -1,10 +1,10 @@
#nullable enable
using System.Text;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Serialization;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.Network;
using SociallyDistant.Core.OS.Network.MessageTransport;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Serialization.Binary;
namespace SociallyDistant.NetworkServices.Ssh

View file

@ -1,16 +1,15 @@
#nullable enable
using SociallyDistant.Architecture;
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.FileSystems;
using SociallyDistant.Core.OS.FileSystems.Host;
using SociallyDistant.Core.OS.Network;
using SociallyDistant.Core.Scripting;
using SociallyDistant.GamePlatform;
using SociallyDistant.GameplaySystems.Networld;
using SociallyDistant.OS.FileSystems;
using SociallyDistant.OS.FileSystems.Host;
using SociallyDistant.Player;
namespace SociallyDistant.OS.Devices
@ -32,6 +31,8 @@ namespace SociallyDistant.OS.Devices
private ISystemProcess? systemd;
private PlayerInfo playerInfo;
public bool IsPlayer => true;
/// <inheritdoc />
public string Name { get; private set; } = "localhost";
public PlayerUser PlayerUser => playerUser;

View file

@ -2,8 +2,8 @@
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.FileSystems;
using SociallyDistant.Core.OS.FileSystems.Host;
using SociallyDistant.Core.OS.FileSystems.Immutable;
using SociallyDistant.OS.FileSystems;
using SociallyDistant.OS.FileSystems.Immutable;
namespace SociallyDistant.OS.Devices
{

View file

@ -11,6 +11,7 @@
<!-- Asset importer overrides -->
<Import Project=".\Content\ContentOverrides.targets" />
<Import Project=".\CheckSdshScripts.targets" />
<ItemGroup>
<ProjectReference Include="..\..\vendor\MonoGame.ImGuiNet\MonoGame.ImGuiNet\Monogame.ImGuiNet.csproj" />
@ -94,4 +95,8 @@
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Content\Scripts\" />
</ItemGroup>
</Project>

View file

@ -17,7 +17,6 @@ using SociallyDistant.Core.Core.WorldData.Data;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS;
using SociallyDistant.Core.OS.Network.MessageTransport;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Serialization.Binary;
using SociallyDistant.Core.Shell;
using SociallyDistant.Core.Shell.Common;

View file

@ -10,11 +10,10 @@ using SociallyDistant.Core.ContentManagement;
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Config;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Core.Scripting.GlobalCommands;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.OS.Devices;
using SociallyDistant.Core.OS.Tasks;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Scripting.GlobalCommands;
using SociallyDistant.Core.Shell;
using SociallyDistant.GamePlatform;
using SociallyDistant.GameplaySystems.Chat;

View file

@ -1,8 +1,8 @@
using AcidicGUI.Layout;
using AcidicGUI.Widgets;
using Microsoft.Xna.Framework;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Programs;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.Shell.Windowing;
using SociallyDistant.Core.UI.Terminal;

View file

@ -3,7 +3,6 @@ using System.Reactive.Subjects;
using SociallyDistant.Core.Core;
using SociallyDistant.Core.Core.Scripting;
using SociallyDistant.Core.Modules;
using SociallyDistant.Core.Scripting;
using SociallyDistant.Core.UI.Shell;
namespace SociallyDistant.UI;

View file

@ -1,7 +1,7 @@
#nullable enable
using SociallyDistant.Core.Core;
using SociallyDistant.Core.OS.FileSystems;
using SociallyDistant.OS.FileSystems.Immutable;
using SociallyDistant.Core.OS.FileSystems.Immutable;
using SociallyDistant.Player;
namespace SociallyDistant.VfsMapping