Exemplo n.º 1
0
        public static Dictionary<string, BodySettings> Read(string input)
        {
            var result = new Dictionary<string, BodySettings>();

            var jsData = JsonObject.Parse(input);
            var jsBodies = jsData["rigidBodies"].GetArray();

            foreach (var body in jsBodies)
            {
                var jsBody = body.GetObject();

                var bodySetting = new BodySettings();
                {
                    var jsOrigin = jsBody["origin"].GetObject();
                    var x = (float)jsOrigin["x"].GetNumber();
                    var y = (float) jsOrigin["y"].GetNumber();
                    bodySetting.Origin = new cpVect(x, y);
                }

                result.Add(jsBody["name"].GetString(), bodySetting);

                var jsShapes = jsBody["shapes"].GetArray();
                var shapes = new Bag<cpVect[]>();
                foreach (var jsShape in jsShapes)
                {
                    var shape = jsShape.GetObject();
                    if (shape["type"].GetString() != "POLYGON")
                        continue;

                    var jsVertices = shape["vertices"].GetArray();
                    var vertices = new Bag<cpVect>();
                    foreach (var jsVertex in jsVertices)
                    {
                        var vertex = jsVertex.GetObject();
                        var x = (float)vertex["x"].GetNumber();
                        var y = (float) vertex["y"].GetNumber();

                        vertices.Add(new cpVect(x, y));
                    }

                    shapes.Add(vertices.ToArray());
                }

                bodySetting.Shapes = shapes.ToArray();
            }

            return result;
        }
Exemplo n.º 2
0
        public BodySettings GetSettings()
        {
            if (_model == null)
            {
                return(null);
            }

            if (_model.ActionData == null)
            {
                return(null);
            }

            BodySettings settings = JsonConvert.DeserializeObject <BodySettings>(_model.ActionData.ToString());

            return(settings);
        }
        public IActionResult PutSettings(Guid guid, [FromBody] BodySettings settings)
        {
            if (guid == Guid.Empty)
            {
                return(Problem("Empty GUID is invalid."));
            }

            _logger.LogInformation("Enter PutSettings.");

            //database process id
            Guid processId = Guid.NewGuid();

            try
            {
                Task.Run(() =>
                {
                    using (SettingsHandler handler = new SettingsHandler(_settings, _eventHub, _preingestCollection))
                    {
                        handler.Logger = _logger;
                        handler.SetSessionGuid(guid);
                        handler.CurrentSettings = settings;
                        processId = handler.AddProcessAction(processId, typeof(SettingsHandler).Name, String.Format("Save user input setting(s) for folder {0}", guid), String.Concat(typeof(SettingsHandler).Name, ".json"));
                        _logger.LogInformation("Execute handler ({0}) with GUID {1}.", typeof(SettingsHandler).Name, guid.ToString());
                        handler.Execute();
                    }
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An exception was thrown in {0}: '{1}'.", typeof(SettingsHandler).Name, e.Message);
                return(ValidationProblem(e.Message, typeof(SettingsHandler).Name));
            }

            _logger.LogInformation("Exit PutSettings.");
            return(new JsonResult(new { Message = String.Format("Settings are stored."), SessionId = guid, ActionId = processId }));
        }
Exemplo n.º 4
0
 public void Configure(int layerIndex, Texture surfaceTexture, Texture nightGlowTexture, BodySettings shapeSettings, ColorSettings colorSettings)
 {
     this.surfaceTexture   = surfaceTexture;
     this.nightGlowTexture = nightGlowTexture;
     this.radius           = shapeSettings.baseRadius + shapeSettings.radiusChange * layerIndex;
     this.tint             = colorSettings.tint;
     this.shadowStrength   = colorSettings.shadowStrength;
     this.allowRotate      = shapeSettings.allowRotate;
     this.scroll           = true;
     this.rotateSpeed      = 0.001f;
     this.nightGlow        = shapeSettings.hasNightGlow ? 1 : 0;
 }
Exemplo n.º 5
0
        private void AeroDataTab(GUIStyle buttonStyle, GUIStyle boxStyle)
        {
            GUILayout.BeginVertical(boxStyle);

            FARControllableSurface.timeConstant =
                GUIUtils.TextEntryForDouble("Ctrl Surf Time Constant:", 160, FARControllableSurface.timeConstant);
            FARControllableSurface.timeConstantFlap =
                GUIUtils.TextEntryForDouble("Flap Time Constant:", 160, FARControllableSurface.timeConstantFlap);
            FARControllableSurface.timeConstantSpoiler =
                GUIUtils.TextEntryForDouble("Spoiler Time Constant:", 160, FARControllableSurface.timeConstantSpoiler);


            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.Label("Celestial Body Atmospheric Properties");

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical(boxStyle);

            GUILayout.BeginHorizontal();
            int j = 0;

            for (int i = 0; i < FlightGlobals.Bodies.Count; i++)
            {
                CelestialBody body = FlightGlobals.Bodies[i];

                if (!body.atmosphere)
                {
                    continue;
                }

                bool active = GUILayout.Toggle(i == atmBodyIndex,
                                               body.GetName(),
                                               buttonStyle,
                                               GUILayout.Width(150),
                                               GUILayout.Height(40));
                if (active)
                {
                    atmBodyIndex = i;
                }
                if ((j + 1) % 4 == 0)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }

                j++;
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUILayout.BeginVertical(boxStyle);

            int flightGlobalsIndex = FlightGlobals.Bodies[atmBodyIndex].flightGlobalsIndex;

            BodySettings atmProperties = FARAeroData.AtmosphericConfiguration[flightGlobalsIndex];

            atmProperties.ReferenceViscosity =
                GUIUtils.TextEntryForDouble("Gas Viscosity:", 80, atmProperties.ReferenceViscosity);
            atmProperties.ReferenceTemperature =
                GUIUtils.TextEntryForDouble("Ref Temp for Viscosity:", 80, atmProperties.ReferenceTemperature);

            FARAeroData.AtmosphericConfiguration[flightGlobalsIndex] = atmProperties;

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }