Skip to content

Commit

Permalink
- ModConfig work and resource data contracts.
Browse files Browse the repository at this point in the history
  • Loading branch information
MapleWheels committed Sep 22, 2024
1 parent 942c193 commit 0e34bb9
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ public enum Target
Client=0x1,
Server=0x2
}

[Flags]
public enum TargetRunMode
{
ClientEnabled = 0x1,
ClientAlways = 0x2,
ServerEnabled = 0x4,
ServerAlways = 0x8
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Barotrauma.LuaCs.Data;

public interface IAssemblyResourceInfo
public interface IAssemblyResourceInfo : IResourceInfo
{
/// <summary>
/// The friendly name of the assembly. Script files belonging to the same assembly should all have the same name.
Expand All @@ -21,12 +21,4 @@ public interface IAssemblyResourceInfo
/// Path to the file.
/// </summary>
public string Path { get; }
/// <summary>
/// All supported platforms.
/// </summary>
public Platform Platforms { get; }
/// <summary>
/// All supported run targets (client and/or server)
/// </summary>
public Target Targets { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Immutable;
using System.Globalization;

namespace Barotrauma.LuaCs.Data;

public interface IConfigResourceInfo : IResourceInfo
{
string FilePath { get; init; }
Platform Platforms { get; init; }
Target Targets { get; init; }
ImmutableArray<CultureInfo> SupportedCultures { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

namespace Barotrauma.LuaCs.Data;

public interface ILocalizationResourceInfo
public interface ILocalizationResourceInfo : IResourceInfo
{
/// <summary>
/// The target culture (languages) that this localization data is intended for.
/// </summary>
CultureInfo TargetCulture { get; }
/// <summary>
/// List of localization files with their absolute path.
/// </summary>
ImmutableArray<string> FilePaths { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IPackageDependencyInfo
/// <summary>
/// Steam ID of the package.
/// </summary>
public int SteamId { get; }
public ulong SteamWorkshopId { get; }
/// <summary>
/// The dependency package, if found.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Barotrauma.LuaCs.Data;

public interface IResourceInfo
{
/// <summary>
/// Platforms that these localization files should be loaded for.
/// </summary>
Platform SupportedPlatforms { get; }

/// <summary>
/// Targets that these localization files should be loaded for.
/// </summary>
Target SupportedTargets { get; init; }
}
18 changes: 18 additions & 0 deletions Barotrauma/BarotraumaShared/SharedSource/LuaCs/Data/IRunConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Barotrauma.LuaCs.Data;

/// <summary>
/// Legacy data contract for the old run configuration system. Should be deprecated
/// once no longer needed.
/// </summary>
public interface IRunConfig
{
bool UseNonPublicizedAssemblies { get; }
bool AutoGenerated { get; }
bool UseInternalAssemblyName { get; }
string Client { get; }
string Server { get; }

bool IsForced();
bool IsStandard();
bool IsForcedOrStandard();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,95 @@

namespace Barotrauma.LuaCs.Data;

public readonly struct ModConfigData
#region ModConfigurationInfo

[Serializable]
public readonly struct ModConfigData : IRunConfig
{
public bool RunConfigLegacy { get; init; }
public ContentPackage Package { get; init; }
public string ModName { get; init; }


public DependencyInfo[] Dependencies { get; init; }
public AssemblyResourceInfo[] LoadableAssemblies { get; init; }
public LocalizationResourceInfo[] LocalizationFiles { get; init; }

public readonly struct LocalizationResourceInfo : ILocalizationResourceInfo
public TargetRunMode RunModes { get; init; }

public bool UseNonPublicizedAssemblies { get; }

public bool AutoGenerated => false;
public bool UseInternalAssemblyName { get; init; }

public string Client
{
public CultureInfo TargetCulture { get; init; }
public ImmutableArray<string> FilePaths { get; init; }
get
{
if (RunModes.HasFlag(TargetRunMode.ClientEnabled))
return "Standard";
if (RunModes.HasFlag(TargetRunMode.ClientAlways))
return "Forced";
return "None";
}
}

public readonly struct ConfigInitData
public string Server
{
// TODO: complete struct, data here should be already parsed and ready-to-use by the config service.
get
{
if (RunModes.HasFlag(TargetRunMode.ServerEnabled))
return "Standard";
if (RunModes.HasFlag(TargetRunMode.ServerAlways))
return "Forced";
return "None";
}
}

public readonly struct AssemblyResourceInfo : IAssemblyResourceInfo
public bool IsForced()
{
public string Name { get; init; }
public bool IsScriptFile { get; init; }
public bool LazyLoad { get; init; }
public string Path { get; init; }
public Platform Platforms { get; init; }
public Target Targets { get; init; }
throw new NotImplementedException();
}
public readonly struct DependencyInfo : IPackageDependencyInfo

public bool IsStandard()
{
public string FolderPath { get; init; }
public string PackageName { get; init; }
public int SteamId { get; init; }
public ContentPackage DependencyPackage { get; init; }
throw new NotImplementedException();
}

public bool IsForcedOrStandard()
{
throw new NotImplementedException();
}


}

#endregion

#region DataContracts

public readonly struct AssemblyResourceInfo : IAssemblyResourceInfo
{
public string Name { get; init; }
public bool IsScriptFile { get; init; }
public bool LazyLoad { get; init; }
public string Path { get; init; }
public Platform SupportedPlatforms { get; init; }
public Target SupportedTargets { get; init; }
}

public readonly struct DependencyInfo : IPackageDependencyInfo
{
public string FolderPath { get; init; }
public string PackageName { get; init; }
public ulong SteamWorkshopId { get; init; }
public ContentPackage DependencyPackage { get; init; }
}

public readonly struct LocalizationResourceInfo : ILocalizationResourceInfo
{
public CultureInfo TargetCulture { get; init; }
public ImmutableArray<string> FilePaths { get; init; }
public Platform SupportedPlatforms { get; init; }
public Target SupportedTargets { get; init; }
}

#endregion

0 comments on commit 0e34bb9

Please sign in to comment.