Skip to content

Commit

Permalink
Merge branch 'master' into RightType
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss authored Oct 20, 2023
2 parents fca26bc + 8413b93 commit aafa19f
Show file tree
Hide file tree
Showing 25 changed files with 766 additions and 212 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
release/
x64/
x86/
bld/
Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/DMStandard/Types/World.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

var/name = "OpenDream World"
var/time
var/timezone = 0 as opendream_unimplemented
var/timezone = 0
var/timeofday
var/realtime
var/tick_lag = 1
Expand Down
13 changes: 13 additions & 0 deletions OpenDream.sln
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDreamPackaging", "OpenD
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robust.Serialization.Generator", "RobustToolbox\Robust.Serialization.Generator\Robust.Serialization.Generator.csproj", "{366AA569-0889-491B-AB00-F038EAEC5221}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDreamPackageTool", "OpenDreamPackageTool\OpenDreamPackageTool.csproj", "{351729DE-F70D-4136-AD48-1E08A715C1B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -428,6 +430,16 @@ Global
{366AA569-0889-491B-AB00-F038EAEC5221}.Release|x64.Build.0 = Release|Any CPU
{366AA569-0889-491B-AB00-F038EAEC5221}.Tools|Any CPU.ActiveCfg = Debug|Any CPU
{366AA569-0889-491B-AB00-F038EAEC5221}.Tools|Any CPU.Build.0 = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|x64.ActiveCfg = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|x64.Build.0 = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|Any CPU.Build.0 = Release|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|x64.ActiveCfg = Release|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|x64.Build.0 = Release|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Tools|Any CPU.ActiveCfg = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Tools|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -459,6 +471,7 @@ Global
{CBF4EBB8-A6A0-446F-82D4-B1D24FF5B3FF} = {534AFACE-24AF-4F54-B7B0-951C5D62DF34}
{F3735A7F-44A2-4BEE-ADD6-952577D4DC33} = {DBFD7471-84E2-4AAB-86E9-F8DFF917ED5B}
{D080D3FA-CE53-40D2-AC9A-940FD9EB5055} = {DBFD7471-84E2-4AAB-86E9-F8DFF917ED5B}
{366AA569-0889-491B-AB00-F038EAEC5221} = {DBFD7471-84E2-4AAB-86E9-F8DFF917ED5B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {970174FD-D22D-44D9-A410-F82A015E6F74}
Expand Down
19 changes: 12 additions & 7 deletions OpenDreamClient/Interface/InterfaceElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ protected InterfaceElement(ElementDescriptor elementDescriptor) {
}

public void PopulateElementDescriptor(MappingDataNode node, ISerializationManager serializationManager) {
MappingDataNode original = (MappingDataNode)serializationManager.WriteValue(ElementDescriptor.GetType(), ElementDescriptor);
foreach (var key in node.Keys) {
original.Remove(key);
try {
MappingDataNode original =
(MappingDataNode)serializationManager.WriteValue(ElementDescriptor.GetType(), ElementDescriptor);
foreach (var key in node.Keys) {
original.Remove(key);
}

MappingDataNode newNode = original.Merge(node);
ElementDescriptor = (ElementDescriptor)serializationManager.Read(ElementDescriptor.GetType(), newNode);
UpdateElementDescriptor();
} catch (Exception e) {
Logger.GetSawmill("opendream.interface").Error($"Error while populating values of \"{Id}\": {e}");
}

MappingDataNode newNode = original.Merge(node);
ElementDescriptor = (ElementDescriptor)serializationManager.Read(ElementDescriptor.GetType(), newNode);
UpdateElementDescriptor();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamClient/States/MainMenu/MainMenuControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
SeparationOverride="4">
<Label Text="Address: " FontColorOverride="#FFFFFF"/>
<LineEdit Name="AddressBoxProtected"
PlaceHolder="127.0.0.1:25566"
PlaceHolder="127.0.0.1:1212"
HorizontalExpand="True" />
</BoxContainer>
<Control MinSize="0 2" />
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamClient/States/MainMenu/MainMenuControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public MainMenuControl(IResourceCache resCache, IConfigurationManager configMan)
var currentUserName = configMan.GetCVar(CVars.PlayerName);
UserNameBox.Text = currentUserName;

AddressBoxProtected.Text = "127.0.0.1:25566";
AddressBoxProtected.Text = "127.0.0.1:1212";

#if DEBUG
DebugWarningLabel.Visible = true;
Expand Down
94 changes: 94 additions & 0 deletions OpenDreamPackageTool/ClientPackaging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System.Diagnostics;
using Robust.Packaging.Utility;

namespace OpenDreamPackageTool;

/// <summary>
/// Packages the client's resources & assemblies in a format ready to be downloaded by connecting clients
/// </summary>
public static class ClientPackaging {
private static readonly string[] ClientIgnoredResources = {
"Maps",
"emotes.xml",
"Groups",
"engineCommandPerms.yml",
"clientCommandPerms.yml"
};

private static readonly string[] ClientContentAssemblies = {
"OpenDreamClient",
"OpenDreamShared"
};

public static void Package(Program.ClientOptions options) {
Directory.CreateDirectory(options.OutputDir);

if (!options.SkipBuild)
WipeBin();

Build(options);
}

private static void WipeBin() {
Console.WriteLine("Clearing old build artifacts (if any)...");

if (Directory.Exists("bin"))
Directory.Delete("bin", true);
}

private static void Build(Program.ClientOptions options) {
Console.WriteLine("Building project...");

if (!options.SkipBuild) {
ProcessHelpers.RunCheck(new ProcessStartInfo {
FileName = "dotnet",
ArgumentList = {
"build",
"OpenDreamClient/OpenDreamClient.csproj",
"-c", "Release",
"--nologo",
"/v:m",
"/t:Rebuild",
"/p:FullRelease=True",
"/m"
}
}).Wait();
}

DirectoryInfo releaseDir = new DirectoryInfo(Path.Combine(options.OutputDir, "OpenDreamClient"));

Console.WriteLine("Packaging client...");
releaseDir.Create();
CopyResources(releaseDir.FullName);
CopyContentAssemblies(Path.Combine(releaseDir.FullName, "Assemblies"));
}

private static void CopyResources(string dest) {
var ignoreSet = Program.SharedIgnoredResources.Union(ClientIgnoredResources).ToArray();

Program.CopyDirectory("Resources", dest, ignoreSet);
}

private static void CopyContentAssemblies(string dest) {
List<string> files = new();
string sourceDir = Path.Combine("bin", "Content.Client");
string[] baseAssemblies = ClientContentAssemblies;

// Include content assemblies.
foreach (var assembly in baseAssemblies) {
files.Add(assembly + ".dll");

// If PDB available, include it as well.
var pdbPath = assembly + ".pdb";
if (File.Exists(Path.Combine(sourceDir, pdbPath)))
files.Add(pdbPath);
}

// Create assemblies dir if necessary.
Directory.CreateDirectory(dest);

foreach (var file in files) {
File.Copy(Path.Combine(sourceDir, file), Path.Combine(dest, file));
}
}
}
14 changes: 14 additions & 0 deletions OpenDreamPackageTool/OpenDreamPackageTool.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\RobustToolbox\Robust.Packaging\Robust.Packaging.csproj" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions OpenDreamPackageTool/PlatformReg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenDreamPackageTool;

public record PlatformReg(string RId, string TargetOs, bool BuildByDefault) {
public string RId = RId;
public string TargetOs = TargetOs;
public bool BuildByDefault = BuildByDefault;
}
172 changes: 172 additions & 0 deletions OpenDreamPackageTool/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
using System.Diagnostics.CodeAnalysis;

namespace OpenDreamPackageTool;

public static class Program {
public class Options {
public string OutputDir = "release/";
public bool SkipBuild;
}

public class ServerOptions : Options {
public string? Platform;
public bool HybridAcz;
public bool InPlatformSubDir = true;
public bool TgsEngineBuild;
}

public class ClientOptions : Options {

}

public class TgsOptions : Options {
// Avoid adding arguments for TGS, to give us more flexibility while keeping compatibility
}

public static readonly string[] SharedIgnoredResources = {
".gitignore",
".directory",
".DS_Store"
};

public static int Main(string[] args) {
if (!TryParseArgs(args, out var options))
return 1;

if (!File.Exists("OpenDream.sln")) {
Console.Error.WriteLine(
"You must run this tool from the root of the OpenDream repo. OpenDream.sln was not found.");
return 1;
}

switch (options) {
case ServerOptions serverOptions:
ServerPackaging.Package(serverOptions);
break;
case ClientOptions clientOptions:
ClientPackaging.Package(clientOptions);
break;
case TgsOptions tgsOptions:
TgsPackaging.Package(tgsOptions);
break;
}

return 0;
}

public static void CopyDirectory(string src, string dest, string[]? skip = null) {
skip ??= Array.Empty<string>();

var srcDir = new DirectoryInfo(src);
if (!srcDir.Exists)
throw new Exception($"Source directory not found: {src}");

Directory.CreateDirectory(dest);

foreach (var file in srcDir.EnumerateFiles()) {
if (skip.Contains(file.Name))
continue;

file.CopyTo(Path.Combine(dest, file.Name));
}

foreach (var subDir in srcDir.EnumerateDirectories()) {
if (skip.Contains(subDir.Name))
continue;

CopyDirectory(subDir.FullName, Path.Combine(dest, subDir.Name));
}
}

private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? options) {
if (args.Contains("--server")) {
var serverOptions = new ServerOptions();

options = serverOptions;
for (int i = 0; i < args.Length; i++) {
var arg = args[i];

switch (arg) {
case "--server":
break;
case "--output":
case "-o":
serverOptions.OutputDir = args[++i];
break;
case "--skip-build":
serverOptions.SkipBuild = true;
break;
case "--platform":
case "-p":
if (i + 1 >= args.Length) {
Console.Error.WriteLine("No platform given");
return false;
}

serverOptions.Platform = args[++i];
break;
case "--hybrid-acz":
serverOptions.HybridAcz = true;
break;
default:
Console.Error.WriteLine($"Invalid argument '{arg}'");
return false;
}
}

return true;
} else if (args.Contains("--client")) {
var clientOptions = new ClientOptions();

options = clientOptions;
for (int i = 0; i < args.Length; i++) {
var arg = args[i];

switch (arg) {
case "--client":
break;
case "--output":
case "-o":
clientOptions.OutputDir = args[++i];
break;
case "--skip-build":
clientOptions.SkipBuild = true;
break;
default:
Console.Error.WriteLine($"Invalid argument '{arg}'");
return false;
}
}

return true;
} else if (args.Contains("--tgs")) {
var tgsOptions = new TgsOptions();

options = tgsOptions;
for (int i = 0; i < args.Length; i++) {
var arg = args[i];

switch (arg) {
case "--tgs":
break;
case "--output":
case "-o":
tgsOptions.OutputDir = args[++i];
break;
case "--skip-build":
tgsOptions.SkipBuild = true;
break;
default:
Console.Error.WriteLine($"Invalid argument '{arg}'");
return false;
}
}

return true;
}

options = null;
Console.Error.WriteLine("One of '--server' or '--client' must be given");
return false;
}
}
Loading

0 comments on commit aafa19f

Please sign in to comment.