예제 #1
0
 public AssetCategory(string code, bool AffectsGameplay, EnumAppSide SideType)
 {
     AssetCategory.categories.Add(code, this);
     this.Code            = code;
     this.AffectsGameplay = AffectsGameplay;
     this.SideType        = SideType;
 }
예제 #2
0
        public ModInfo(EnumModType type, string name, string modID, string version,
                       string description, IEnumerable <string> authors, IEnumerable <string> contributors, string website,
                       EnumAppSide side, bool requiredOnClient, bool requiredOnServer,
                       IEnumerable <ModDependency> dependencies)
        {
            Type    = type;
            Name    = name ?? throw new ArgumentNullException(nameof(name));
            ModID   = modID ?? throw new ArgumentNullException(nameof(modID));
            Version = version ?? "";

            Description  = description ?? "";
            Authors      = ReadOnlyCopy(authors);
            Contributors = ReadOnlyCopy(contributors);
            Website      = website ?? "";

            Side             = side;
            RequiredOnClient = requiredOnClient;
            RequiredOnServer = requiredOnServer;
            Dependencies     = ReadOnlyCopy(dependencies);

            // Null-safe helper method which copies the specified elements into a read-only list.
            IReadOnlyList <T> ReadOnlyCopy <T>(IEnumerable <T> elements)
            => (elements ?? Enumerable.Empty <T>()).ToList().AsReadOnly();
        }
 public override bool ShouldLoad(EnumAppSide side)
 {
     return(true);
 }
예제 #4
0
 public override bool ShouldLoad(EnumAppSide side) => side == EnumAppSide.Client;
예제 #5
0
 public override bool ShouldLoad(EnumAppSide side)
 {
     return(side == EnumAppSide.Server);
 }
 public override bool ShouldLoad(EnumAppSide side)
 {
     return(side == EnumAppSide.Client);
 }
예제 #7
0
 public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server;
예제 #8
0
 /// <summary>
 /// Am I a universal?
 /// </summary>
 /// <param name="side"></param>
 /// <returns></returns>
 public static bool IsUniversal(this EnumAppSide side)
 {
     return(side.Is(EnumAppSide.Universal));
 }
예제 #9
0
 /// <summary>
 /// Am I this side?
 /// </summary>
 /// <param name="side"></param>
 /// <param name="other"></param>
 /// <returns></returns>
 public static bool Is(this EnumAppSide side, EnumAppSide other)
 {
     return((side & other) == other);
 }
예제 #10
0
 /// <summary>
 /// Am I the server?
 /// </summary>
 /// <param name="side"></param>
 /// <returns></returns>
 public static bool IsServer(this EnumAppSide side)
 {
     return(side.Is(EnumAppSide.Server));
 }
예제 #11
0
 /// <summary>
 /// Am I the client?
 /// </summary>
 /// <param name="side"></param>
 /// <returns></returns>
 public static bool IsClient(this EnumAppSide side)
 {
     return(side.Is(EnumAppSide.Client));
 }
예제 #12
0
파일: ModSystem.cs 프로젝트: Archina/vsapi
 /// <summary>
 /// Returns if this mod should be loaded for the given app side.
 /// </summary>
 public virtual bool ShouldLoad(EnumAppSide forSide)
 {
     return(true);
 }
예제 #13
0
 public override bool ShouldLoad(EnumAppSide forSide) => forSide.IsClient();
예제 #14
0
        private void ApplyPatch(int patchIndex, AssetLocation patchSourcefile, JsonPatch jsonPatch, ref int applied, ref int notFound, ref int errorCount)
        {
            EnumAppSide targetSide = jsonPatch.Side == null ? jsonPatch.File.Category.SideType : (EnumAppSide)jsonPatch.Side;

            if (targetSide != EnumAppSide.Universal && jsonPatch.Side != api.Side)
            {
                return;
            }

            var loc = jsonPatch.File.Clone();

            if (jsonPatch.File.Path.EndsWith("*"))
            {
                List <IAsset> assets = api.Assets.GetMany(jsonPatch.File.Path.TrimEnd('*'), jsonPatch.File.Domain, false);
                foreach (var val in assets)
                {
                    jsonPatch.File = val.Location;
                    ApplyPatch(patchIndex, patchSourcefile, jsonPatch, ref applied, ref notFound, ref errorCount);
                }

                jsonPatch.File = loc;

                return;
            }



            if (!loc.Path.EndsWith(".json"))
            {
                loc.Path += ".json";
            }

            var asset = api.Assets.TryGet(loc);

            if (asset == null)
            {
                if (jsonPatch.File.Category == null)
                {
                    api.World.Logger.VerboseDebug("Patch {0} in {1}: File {2} not found. Wrong asset category", patchIndex, patchSourcefile, loc);
                }
                else
                {
                    EnumAppSide catSide = jsonPatch.File.Category.SideType;
                    if (catSide != EnumAppSide.Universal && api.Side != catSide)
                    {
                        api.World.Logger.VerboseDebug("Patch {0} in {1}: File {2} not found. Hint: This asset is usually only loaded {3} side", patchIndex, patchSourcefile, loc, catSide);
                    }
                    else
                    {
                        api.World.Logger.VerboseDebug("Patch {0} in {1}: File {2} not found", patchIndex, patchSourcefile, loc);
                    }
                }


                notFound++;
                return;
            }

            Operation op = null;

            switch (jsonPatch.Op)
            {
            case EnumJsonPatchOp.Add:
                if (jsonPatch.Value == null)
                {
                    api.World.Logger.Error("Patch {0} in {1} failed probably because it is an add operation and the value property is not set or misspelled", patchIndex, patchSourcefile);
                    errorCount++;
                    return;
                }
                op = new AddOperation()
                {
                    Path = new Tavis.JsonPointer(jsonPatch.Path), Value = jsonPatch.Value.Token
                };
                break;

            case EnumJsonPatchOp.Remove:
                op = new RemoveOperation()
                {
                    Path = new Tavis.JsonPointer(jsonPatch.Path)
                };
                break;

            case EnumJsonPatchOp.Replace:
                if (jsonPatch.Value == null)
                {
                    api.World.Logger.Error("Patch {0} in {1} failed probably because it is a replace operation and the value property is not set or misspelled", patchIndex, patchSourcefile);
                    errorCount++;
                    return;
                }

                op = new ReplaceOperation()
                {
                    Path = new Tavis.JsonPointer(jsonPatch.Path), Value = jsonPatch.Value.Token
                };
                break;

            case EnumJsonPatchOp.Copy:
                op = new CopyOperation()
                {
                    Path = new Tavis.JsonPointer(jsonPatch.Path), FromPath = new JsonPointer(jsonPatch.FromPath)
                };
                break;

            case EnumJsonPatchOp.Move:
                op = new MoveOperation()
                {
                    Path = new Tavis.JsonPointer(jsonPatch.Path), FromPath = new JsonPointer(jsonPatch.FromPath)
                };
                break;
            }

            PatchDocument patchdoc = new PatchDocument(op);
            JToken        token    = null;

            try
            {
                token = JToken.Parse(asset.ToText());
            }
            catch (Exception e)
            {
                api.World.Logger.Error("Patch {0} (target: {3}) in {1} failed probably because the syntax of the value is broken: {2}", patchIndex, patchSourcefile, e, loc);
                errorCount++;
                return;
            }

            try
            {
                patchdoc.ApplyTo(token);
            }
            catch (Tavis.PathNotFoundException p)
            {
                api.World.Logger.Error("Patch {0} (target: {4}) in {1} failed because supplied path {2} is invalid: {3}", patchIndex, patchSourcefile, jsonPatch.Path, p.Message, loc);
                errorCount++;
                return;
            }
            catch (Exception e)
            {
                api.World.Logger.Error("Patch {0} (target: {3}) in {1} failed, following Exception was thrown: {2}", patchIndex, patchSourcefile, e.Message, loc);
                errorCount++;
                return;
            }

            string text = token.ToString();

            asset.Data = System.Text.Encoding.UTF8.GetBytes(text);

            applied++;
        }
예제 #15
0
 public override bool ShouldLoad(EnumAppSide forSide) => true;
예제 #16
0
 public override bool ShouldLoad(EnumAppSide forSide) => forSide.IsServer();