Exemplo n.º 1
0
        internal void SetModinfo(ModInfo modInfo)
        {
            this.modInfo = modInfo;

            ModDependency[] dependencies    = modInfo.Dependencies ?? Array.Empty <ModDependency>();
            var             editorDataGroup = new ModDependencyEditorData[dependencies.Length];

            for (int i = 0; i < dependencies.Length; i++)
            {
                ModDependency           dependency = dependencies[i];
                ModDependencyEditorData editorData = new ModDependencyEditorData();

                editorData.ModIndex = availableMods.ToList().IndexOf(dependency.Name);
                if (editorData.ModIndex == -1)
                {
                    editorData.ModIndex = availableMods.Length - 1;
                }
                editorData.Name = dependency.Name;

                editorData.IsOptional = dependency.IsOptional ? 1 : 0;
                editorData.IsPeer     = dependency.IsPeer ? 1 : 0;

                editorData.RequireVersion = !string.IsNullOrWhiteSpace(dependency.Version);
                if (editorData.RequireVersion)
                {
                    int[] versionParts = dependency.Version.Split('.').Select(x => int.Parse(x)).ToArray();
                    editorData.Version = new Vector3Int(versionParts[0], versionParts[1], versionParts[2]);
                }

                editorDataGroup[i] = editorData;
            }

            this.dependencies = editorDataGroup.ToList();
        }
Exemplo n.º 2
0
        private void SaveChanges()
        {
            if (modInfo == null)
            {
                return;
            }

            var dependencies = new List <ModDependency>();

            foreach (ModDependencyEditorData editorData in this.dependencies)
            {
                if (string.IsNullOrWhiteSpace(editorData.Name))
                {
                    continue;
                }

                var dependency = new ModDependency();
                dependency.Name = editorData.Name;

                dependency.IsOptional = editorData.IsOptional == 1;
                dependency.IsPeer     = editorData.IsPeer == 1;

                dependency.Version = null;
                if (editorData.RequireVersion)
                {
                    Vector3Int version = editorData.Version;
                    dependency.Version = $"{version.x}.{version.y}.{version.z}";
                }

                dependencies.Add(dependency);
            }

            modInfo.Dependencies = dependencies.ToArray();
        }
        private static Type FindType(Mod mod, string typeName)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                return(null);
            }

            Type type;

            if (types.TryGetValue(typeName, out type))
            {
                return(type);
            }

            if ((type = mod.GetCompiledType(typeName)) == null && mod.ModInfo.Dependencies != null)
            {
                for (int i = 0; i < mod.ModInfo.Dependencies.Length; i++)
                {
                    ModDependency dependency = mod.ModInfo.Dependencies[i];
                    if (!dependency.IsOptional)
                    {
                        Mod target = ModManager.Instance.GetModFromName(dependency.Name);
                        if (target != null && (type = target.GetCompiledType(typeName)) != null)
                        {
                            break;
                        }
                    }
                }
            }

            return(types[typeName] = type);
        }