Client LuaCsForBarotrauma
CorePackage.cs
2 using System;
3 using System.Collections.Generic;
4 using System.Collections.Immutable;
5 using System.Linq;
6 using System.Reflection;
7 using System.Xml.Linq;
8 
9 namespace Barotrauma
10 {
11  [AttributeUsage(AttributeTargets.Class, Inherited = false)]
12  public class RequiredByCorePackage : Attribute
13  {
14  public readonly ImmutableHashSet<Type> AlternativeTypes;
15  public RequiredByCorePackage(params Type[] alternativeTypes)
16  {
17  AlternativeTypes = alternativeTypes.ToImmutableHashSet();
18  }
19  }
20 
21  [AttributeUsage(AttributeTargets.Class, Inherited = false)]
22  public class AlternativeContentTypeNames : Attribute
23  {
24  public readonly ImmutableHashSet<Identifier> Names;
25  public AlternativeContentTypeNames(params string[] names)
26  {
27  Names = names.ToIdentifiers().ToImmutableHashSet();
28  }
29  }
30 
31  public class CorePackage : ContentPackage
32  {
33  public CorePackage(XDocument doc, string path) : base(doc, path)
34  {
35  AssertCondition(doc.Root.GetAttributeBool("corepackage", false),
36  "Expected a core package, got a regular package");
37 
38  var missingFileTypes = ContentFile.Types.Where(
39  t => t.RequiredByCorePackage
40  && !Files.Any(f => t.Type == f.GetType()
41  || t.AlternativeTypes.Contains(f.GetType())));
42  AssertCondition(!missingFileTypes.Any(),
43  "Core package requires at least one of the following content types: " +
44  string.Join(", ", missingFileTypes.Select(t => t.Type.Name)));
45  }
46  }
47 }
readonly ImmutableHashSet< Identifier > Names
Definition: CorePackage.cs:24
AlternativeContentTypeNames(params string[] names)
Definition: CorePackage.cs:25
Base class for content file types, which are loaded from filelist.xml via reflection....
Definition: ContentFile.cs:23
static readonly ImmutableHashSet< TypeInfo > Types
Definition: ContentFile.cs:62
ImmutableArray< ContentFile > Files
void AssertCondition(bool condition, string errorMsg)
CorePackage(XDocument doc, string path)
Definition: CorePackage.cs:33
RequiredByCorePackage(params Type[] alternativeTypes)
Definition: CorePackage.cs:15
readonly ImmutableHashSet< Type > AlternativeTypes
Definition: CorePackage.cs:14