Skip to content

Commit

Permalink
- Minor work.
Browse files Browse the repository at this point in the history
  • Loading branch information
TBN-MapleWheels committed Oct 2, 2024
1 parent 9df95a3 commit 1a27ee2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace Barotrauma.LuaCs.Services;

public interface IContentPackageService : IService
{
/// <summary>
/// Tries to parse a package to produce a working ModConfigInfo.
/// </summary>
/// <param name="package"></param>
/// <returns></returns>
bool TryParsePackage(ContentPackage package);
ContentPackage Package { get; }
IModConfigInfo ModConfigInfo { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,32 @@ public partial class PackageService : IContentPackageService

public bool TryParsePackage(ContentPackage package)
{
if (_storageService.TryLoadPackageXml(package, "ModConfig.xml", out var config))
if (_storageService.TryLoadPackageXml(package, "ModConfig.xml", out var configXml)
&& configXml.Root is not null)
{


if (_modConfigConverterService.Value.TryParseResource(configXml.Root, out IModConfigInfo configInfo))
{
ModConfigInfo = configInfo;
}
else
{
_loggerService.LogError($"Failed to parse ModConfig.xml for package {package.Name}");
return false;
}
}
else if (_legacyConfigService.Value.TryBuildModConfigFromLegacy(package, out var legacyConfig))
{
ModConfigInfo = legacyConfig;
}
else
{
if (_legacyConfigService.Value.TryBuildModConfigFromLegacy(package, out var legacyConfig))
{
ModConfigInfo = legacyConfig;
// no support for newer features, end here.
return true;
}

// no mod data present, either a vanilla mod or broken.
// vanilla mod or broken
return false;
}

// load resources info for: config, assemblies, lua files, localization

throw new NotImplementedException();
// load client resources
TryParsePackageClient(package);
return true;
}

partial void TryParsePackageClient(ContentPackage package);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ namespace Barotrauma.LuaCs.Services.Processing;

#region TypeDef

// ReSharper disable once TypeParameterCanBeVariant
public interface IConverterService<TSrc, TOut> : IService
{
bool TryParseResource(in TSrc src, out TOut resources);
bool TryParseResources(in IEnumerable<TSrc> sources, out List<TOut> resources);
bool TryParseResource(TSrc src, out TOut resources);
bool TryParseResources(IEnumerable<TSrc> sources, out List<TOut> resources);
}

public interface IXmlResourceConverterService<TOut> : IConverterService<XElement, TOut> { }
Expand Down

0 comments on commit 1a27ee2

Please sign in to comment.