Beispiel #1
0
        private static DataRoute CreateRoute(RootDefinition d,
                                             AssetDeclarationAttributeBase a,
                                             List <SourceBase> sources,
                                             List <Storage> storages)
        {
            var route = new DataRoute
            {
                Root      = d,
                Attribute = a,
                Sources   = sources.FindAll(s => s.Contains(a.Group)),
                Storages  = storages.FindAll(s => s.Includes(a.Group)),
            };

            if (route.Attribute.IsSingle())
            {
                var storage = route.Sources.Where(s1 => s1.IsSingle)
                              .Cast <SingleSource>()
                              .FirstOrDefault(s => s != null && s.GetAsset(route.Group) != null);
                var asset = storage != null?storage.GetAsset(route.Group) : null;

                if (asset != null)
                {
                    route.FileAssetPaths.Add(asset.GetAssetPath());
                }
            }
            else
            {
                foreach (var source in route.Sources)
                {
                    if (source.IsSingle)
                    {
                        var asset = source.GetSingleAsset(route.Group);
                        if (asset != null)
                        {
                            route.FileAssetPaths.Add(asset.GetAssetPath());
                        }
                    }
                    else
                    {
                        var isRecursive = (source as FolderSource)?.IsRecursive ?? false;
                        var paths       = isRecursive ? route.RootAssetPaths : route.FolderAssetPaths;
                        paths.Add(source.GetAssetPathFolder());
                    }
                }

                route.FileAssetPaths.AddRange(route.Sources.SelectMany(s => s.GetAssets(route.Attribute)).Select(textAsset => textAsset.GetAssetPath()));
            }

            foreach (var storage in route.Storages)
            {
                route.FileAssetPaths.Add(storage.GetAssetPath());
            }

            foreach (var source in route.Sources)
            {
                route.FileAssetPaths.Add(source.GetAssetPath());
            }

            return(route);
        }
 private static DataRoute CreateRoute(RootDefinition d,
                                      AssetDeclarationAttributeBase a,
                                      List <SourceBase> sources,
                                      List <Storage> storages)
 {
     return(CreateRoute(d, a, sources, storages, new List <string>()));
 }
Beispiel #3
0
        public KspSystemDefinition GetConfigData()
        {
            KspSystemDefinition kspSystemDefinition;

            if (system_config == null)
            {
                return(null);
            }
            else
            {
                if (!system_config.HasData && !system_config_valid)
                {
                    return(null);
                }
                else
                {
                    ConfigNode     kspNode = system_config.GetNode("KSPSystem");
                    RootDefinition rootDefinition;
                    double         sun_solar_mass;
                    SunType        sun_solar_type;
                    try
                    {
                        sun_solar_mass = double.Parse(kspNode.GetNode("Root").GetValue("SolarMasses"));
                    }
                    catch
                    {
                        sun_solar_mass = 7700;
                    }
                    try
                    {
                        sun_solar_type = ((SunType)int.Parse(kspNode.GetNode("Root").GetValue("Type")));
                    }
                    catch
                    {
                        sun_solar_type = SunType.Blackhole;
                    }
                    rootDefinition = new RootDefinition(sun_solar_mass, sun_solar_type);
                    try
                    {
                        kspSystemDefinition = new KspSystemDefinition(rootDefinition,
                                                                      double.Parse(kspNode.GetNode("Kerbol").GetValue("semiMajorAxis")));
                    }
                    catch
                    {
                        kspSystemDefinition = new KspSystemDefinition(rootDefinition, 4500000000000);
                    }
                    kspSystemDefinition.Stars = getStars(kspNode.GetNode("StarSystems").GetNodes("StarSystem"));
                }
            }
            return(kspSystemDefinition);
        }
Beispiel #4
0
        public void OnPSystemReady(RootDefinition Root, CelestialBody OriginalSun, Transform ScaledSun)
        {
            Debug.Log("Altering sun...");

            //Set Original Sun Parameters
            double SolarMasses;


            SolarMasses = Root.SolarMasses;

            OriginalSun.Mass               = SolarMasses * OriginalSun.Mass;
            OriginalSun.Radius             = (2 * (6.74E-11) * OriginalSun.Mass) / (Math.Pow(299792458, 2.0));
            OriginalSun.GeeASL             = OriginalSun.Mass * (6.674E-11 / 9.81) / Math.Pow(OriginalSun.Radius, 2.0);
            OriginalSun.gMagnitudeAtCenter = OriginalSun.GeeASL * 9.81 * Math.Pow(OriginalSun.Radius, 2.0);
            OriginalSun.gravParameter      = OriginalSun.gMagnitudeAtCenter;

            OriginalSun.scienceValues.InSpaceLowDataValue = OriginalSun.scienceValues.InSpaceLowDataValue * 10f;
            OriginalSun.scienceValues.RecoveryValue       = OriginalSun.scienceValues.RecoveryValue * 5f;

            OriginalSun.bodyName = "Blacky Karman";

            OriginalSun.bodyDescription =
                "This recently discovered black hole, named after its discoverer Billy-Hadrick Kerman, is the central point where multiple star systems revolve around.";

            OriginalSun.CBUpdate();

            //Make Sun Black
            ScaledSun.renderer.material.SetColor("_EmitColor0", new Color(0.0f, 0.0f, 0.0f, 1));
            ScaledSun.renderer.material.SetColor("_EmitColor1", new Color(0.0f, 0.0f, 0.0f, 1));
            ScaledSun.renderer.material.SetColor("_SunspotColor", new Color(0.0f, 0.0f, 0.0f, 1));
            ScaledSun.renderer.material.SetColor("_RimColor", new Color(0.0f, 0.0f, 0.0f, 1.0f));

            //Update Sun Scale
            var ScaledSunMeshFilter = (MeshFilter)ScaledSun.GetComponent(typeof(MeshFilter));
            var SunRatio            = (float)OriginalSun.Radius / 261600000f;

            MeshScaler.ScaleMesh(ScaledSunMeshFilter.mesh, SunRatio);

            //Change Sun Corona
            foreach (var SunCorona in ScaledSun.GetComponentsInChildren <SunCoronas>())
            {
                SunCorona.renderer.material.mainTexture =
                    GameDatabase.Instance.GetTexture("StarSystems/Resources/BlackHoleCorona", false);
                var SunCoronaMeshFilter = (MeshFilter)SunCorona.GetComponent(typeof(MeshFilter));
                MeshScaler.ScaleMesh(SunCoronaMeshFilter.mesh, SunRatio);
            }

            Debug.Log("Sun altered");
        }
        private static List <string> GetCodeFiles(RootDefinition root, TextAsset[] textAssets)
        {
            var rootAssembly = root.Root.Assembly;

            if (IsProjectAssembly(rootAssembly) && IsProjectPath(rootAssembly.Location))
            {
                return(new List <string> {
                    rootAssembly.Location.ToAssetsPath()
                });
            }

            var namespaces = root.Namespaces.Select(n => new Regex(NamespacePatternBase.Replace("NamespaceName", n))).ToArray();
            var classes    = root.Types.Select(t => new Regex(ClassPatternBase.Replace("ClassName", t.Name))).ToArray();

            return(textAssets.Where(a => namespaces.Any(n => n.IsMatch(a.text)))
                   .Where(a => classes.Any(c => c.IsMatch(a.text)))
                   .Select(a => a.GetAssetPath())
                   .ToList());
        }
Beispiel #6
0
        public void OnPSystemReady(RootDefinition Root, CelestialBody OriginalSun, Transform ScaledSun)
        {
            Debug.Log("Altering sun...");

            //Set Original Sun Parameters
            OriginalSun.Mass               = Root.SolarMasses * OriginalSun.Mass;
            OriginalSun.Radius             = (2 * (6.674E-11) * OriginalSun.Mass) / (Math.Pow(299792458, 2.0));
            OriginalSun.GeeASL             = OriginalSun.Mass * (6.674E-11 / 9.81) / Math.Pow(OriginalSun.Radius, 2.0);
            OriginalSun.gMagnitudeAtCenter = OriginalSun.GeeASL * 9.81 * Math.Pow(OriginalSun.Radius, 2.0);
            OriginalSun.gravParameter      = OriginalSun.gMagnitudeAtCenter;

            OriginalSun.scienceValues.InSpaceLowDataValue = OriginalSun.scienceValues.InSpaceLowDataValue * 10f;
            OriginalSun.scienceValues.RecoveryValue       = OriginalSun.scienceValues.RecoveryValue * 5f;

            OriginalSun.bodyName = Root.name;

            OriginalSun.bodyDescription = Root.description;

            OriginalSun.CBUpdate();

            //Make Sun Black
            ScaledSun.renderer.material.SetColor("_EmitColor0", Root.color.emitColor0);
            ScaledSun.renderer.material.SetColor("_EmitColor1", Root.color.emitColor1);
            ScaledSun.renderer.material.SetColor("_SunspotColor", Root.color.sunSpotColor);
            ScaledSun.renderer.material.SetColor("_RimColor", Root.color.rimColor);

            //Update Sun Scale
            var ScaledSunMeshFilter = (MeshFilter)ScaledSun.GetComponent(typeof(MeshFilter));
            var SunRatio            = (float)OriginalSun.Radius / 261600000f;

            MeshScaler.ScaleMesh(ScaledSunMeshFilter.mesh, SunRatio);

            //Change Sun Corona
            foreach (var SunCorona in ScaledSun.GetComponentsInChildren <SunCoronas>())
            {
                SunCorona.renderer.material.mainTexture = Root.color.coronaTexture;
                var SunCoronaMeshFilter = (MeshFilter)SunCorona.GetComponent(typeof(MeshFilter));
                MeshScaler.ScaleMesh(SunCoronaMeshFilter.mesh, SunRatio);
            }

            Debug.Log("Sun altered");
        }
Beispiel #7
0
        private static bool IsCodeFile(RootDefinition root, string assetPath)
        {
            if (assetPath.EndsWith(".dll"))
            {
                return(root.Assembly.IsProjectAssembly() &&
                       assetPath == root.Assembly.Location.ToUnityPath());
            }

            if (!assetPath.EndsWith(".cs"))
            {
                return(false);
            }

            var textAsset = Context.GetAsset <TextAsset>(assetPath);

            if (textAsset == null)
            {
                return(false);
            }

            return(root.GetCodeRegex(Context.RegexCache).Any(r => r.IsMatch(textAsset.text)));
        }
 private static DataRoute CreateRoute(RootDefinition d,
                                      AssetDeclarationAttributeBase a,
                                      YamlyProjectContext c)
 {
     return(CreateRoute(d, a, c.Sources, c.Storages));
 }
Beispiel #9
0
        public KspSystemDefinition GetConfigData()
        {
            KspSystemDefinition kspSystemDefinition;

            if (system_config == null)
            {
                return(null);
            }
            else
            {
                if (!system_config.HasData && !system_config_valid)
                {
                    return(null);
                }
                else
                {
                    UrlDir.UrlConfig[] kspNodes = GameDatabase.Instance.GetConfigs("KSPSystem");
                    if (kspNodes.Count() > 1)//TODO: Do something about this...
                    {
                        Debug.Log("There shouldn't be more than 1 KSPSystem config! Use ModuleManager to patch the existing config!");
                        return(null);
                    }
                    ConfigNode kspNode = kspNodes[0].config;
                    try
                    {
                        foreach (ConfigNode color in kspNode.GetNode("StarColors").GetNodes("StarColor"))
                        {
                            if (color.GetValue("name") != null)
                            {
                                StarColor sc = new StarColor();
                                sc.givesOffLight = (color.GetValue("GivesOffLight") ?? "true") == "true";
                                Vector4 lightColor = ConfigNode.ParseVector4(color.GetValue("LightColor") ?? "0,0,0,0");
                                sc.lightColor = new Color(lightColor.x, lightColor.y, lightColor.z, lightColor.w);
                                Vector4 emitColor0 = ConfigNode.ParseVector4(color.GetValue("EmitColor0") ?? "0,0,0,0");
                                sc.emitColor0 = new Color(emitColor0.x, emitColor0.y, emitColor0.z, emitColor0.w);
                                Vector4 emitColor1 = ConfigNode.ParseVector4(color.GetValue("EmitColor1") ?? "0,0,0,0");
                                sc.emitColor1 = new Color(emitColor1.x, emitColor1.y, emitColor1.z, emitColor1.w);
                                Vector4 sunspotColor = ConfigNode.ParseVector4(color.GetValue("SunspotColor") ?? "0,0,0,0");
                                sc.sunSpotColor = new Color(sunspotColor.x, sunspotColor.y, sunspotColor.z, sunspotColor.w);
                                Vector4 rimColor = ConfigNode.ParseVector4(color.GetValue("RimColor") ?? "0,0,0,0");
                                sc.rimColor      = new Color(rimColor.x, rimColor.y, rimColor.z, rimColor.w);
                                sc.coronaTexture = GameDatabase.Instance.GetTexture(color.GetValue("CoronaTexture") ?? "", false);
                                StarSystem.StarColors.Add(color.GetValue("name"), sc);
                                Debug.Log("Added star color " + color.GetValue("name"));
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Log("Error loading star colors: " + e);
                    }
                    RootDefinition rootDefinition;
                    double         sun_solar_mass;
                    try
                    {
                        sun_solar_mass = double.Parse(kspNode.GetNode("Root").GetValue("SolarMasses"));
                    }
                    catch
                    {
                        sun_solar_mass = 7700;
                    }
                    string rootName        = kspNode.GetNode("Root").GetValue("name") ?? "Root";
                    string rootDescription = kspNode.GetNode("Root").GetValue("BodyDescription") ?? "";
                    string rootColor       = kspNode.GetNode("Root").GetValue("StarColor") ?? "";
                    Debug.Log("Setting the root's color to " + rootColor);
                    StarColor blackHoleColor = (StarSystem.StarColors.ContainsKey(rootColor)) ? StarSystem.StarColors[rootColor] : null;
                    rootDefinition            = new RootDefinition(sun_solar_mass, blackHoleColor, rootName, rootDescription);
                    kspSystemDefinition       = new KspSystemDefinition(rootDefinition);
                    kspSystemDefinition.Stars = getStars(kspNode.GetNode("StarSystems").GetNodes("StarSystem"));
                }
            }
            return(kspSystemDefinition);
        }
Beispiel #10
0
 private static DataRoute CreateRoute(RootDefinition d,
                                      AssetDeclarationAttributeBase a)
 {
     return(CreateRoute(d, a, Context.Sources, Context.Storages));
 }