Пример #1
0
        private void saveFile()
        {
            Debug.Assert(m_filePath != string.Empty);

            ParticleDefiniton pd = new ParticleDefiniton();

            pd.Editor = new EditorSettings();
            pd.Editor.BackgroundColour = colourToInt(m_sfmlControl.BackgroundColour);
            pd.Editor.EmitterPosition  = new Point((int)m_defaultPos.X, (int)m_defaultPos.Y);
            pd.Editor.EnableMovement   = enableMovementToolStripMenuItem.Checked;

            pd.BlendMode              = m_particleSystem.blendMode.ToString();
            pd.Colour                 = colourToInt(m_particleSystem.colour);
            pd.Delay                  = (float)numericUpDownStartDelay.Value;
            pd.Duration               = (float)numericUpDownDuration.Value;
            pd.EmitRate               = (float)numericUpDownEmitRate.Value;
            pd.InitialVelocity        = new Point((int)m_particleSystem.initialVelocity.X, (int)m_particleSystem.initialVelocity.Y);
            pd.Lifetime               = m_particleSystem.particleLifetime;
            pd.ParticleSize           = new Size((int)numericUpDownSizeX.Value, (int)numericUpDownSizeY.Value);
            pd.RandomInitialPositions = new List <Point>();
            if (m_particleSystem.randomInitialPositions != null)
            {
                foreach (var v in m_particleSystem.randomInitialPositions)
                {
                    pd.RandomInitialPositions.Add(new Point((int)v.X, (int)v.Y));
                }
            }

            pd.RandomInitialVelocities = new List <Point>();
            if (m_particleSystem.randomInitialVelocities != null)
            {
                foreach (var v in m_particleSystem.randomInitialVelocities)
                {
                    pd.RandomInitialVelocities.Add(new Point((int)v.X, (int)v.Y));
                }
            }
            pd.Affectors = new List <AffectorDefinition>();
            foreach (var a in m_particleSystem.Affectors)
            {
                AffectorDefinition ad = new AffectorDefinition();
                ad.Type = a.type().ToString();
                ad.Data = new List <float>();
                switch (a.type())
                {
                case AffectorType.Colour:
                    ColourAffector ca = (ColourAffector)a;
                    ad.Data.Add(colourToInt(ca.StartColour));
                    ad.Data.Add(colourToInt(ca.EndColour));
                    ad.Data.Add(ca.Duration);
                    break;

                case AffectorType.Force:
                    var force = ((ForceAffector)a).Force;
                    ad.Data.Add(force.X);
                    ad.Data.Add(force.Y);
                    break;

                case AffectorType.Rotation:
                    ad.Data.Add(((RotationAffector)a).Rotation);
                    break;

                case AffectorType.Scale:
                    var scale = ((ScaleAffector)a).Scale;
                    ad.Data.Add(scale.X);
                    ad.Data.Add(scale.Y);
                    break;

                case AffectorType.Velocity:
                    var vscale = ((VelocityAffector)a).Scale;
                    ad.Data.Add(vscale.X);
                    ad.Data.Add(vscale.Y);
                    break;
                }
                pd.Affectors.Add(ad);
            }

            pd.ReleaseCount = (byte)numericUpDownReleaseCount.Value;
            pd.Texture      = textBoxTexturePath.Text;

            try
            {
                JsonSerializer srlz = new JsonSerializer();
                srlz.NullValueHandling = NullValueHandling.Ignore;
                srlz.Formatting        = Formatting.Indented;

                using (StreamWriter sw = new StreamWriter(m_filePath))
                    using (JsonWriter jw = new JsonTextWriter(sw))
                    {
                        srlz.Serialize(jw, pd);
                    }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Output failed");
            }
        }
Пример #2
0
        private void saveFile()
        {
            Debug.Assert(m_filePath != string.Empty);

            ParticleDefiniton pd = new ParticleDefiniton();
            pd.Editor = new EditorSettings();
            pd.Editor.BackgroundColour = colourToInt(m_sfmlControl.BackgroundColour);
            pd.Editor.EmitterPosition = new Point((int)m_defaultPos.X, (int)m_defaultPos.Y);
            pd.Editor.EnableMovement = enableMovementToolStripMenuItem.Checked;

            pd.BlendMode = m_particleSystem.blendMode.ToString();
            pd.Colour = colourToInt(m_particleSystem.colour);
            pd.Delay = (float)numericUpDownStartDelay.Value;
            pd.Duration = (float)numericUpDownDuration.Value;
            pd.EmitRate = (float)numericUpDownEmitRate.Value;
            pd.InitialVelocity = new Point((int)m_particleSystem.initialVelocity.X, (int)m_particleSystem.initialVelocity.Y);
            pd.Lifetime = m_particleSystem.particleLifetime;
            pd.ParticleSize = new Size((int)numericUpDownSizeX.Value, (int)numericUpDownSizeY.Value);
            pd.RandomInitialPositions = new List<Point>();
            if (m_particleSystem.randomInitialPositions != null)
            {
                foreach (var v in m_particleSystem.randomInitialPositions)
                {
                    pd.RandomInitialPositions.Add(new Point((int)v.X, (int)v.Y));
                }
            }

            pd.RandomInitialVelocities = new List<Point>();
            if (m_particleSystem.randomInitialVelocities != null)
            {
                foreach (var v in m_particleSystem.randomInitialVelocities)
                {
                    pd.RandomInitialVelocities.Add(new Point((int)v.X, (int)v.Y));
                }
            }
            pd.Affectors = new List<AffectorDefinition>();
            foreach(var a in m_particleSystem.Affectors)
            {
                AffectorDefinition ad = new AffectorDefinition();
                ad.Type = a.type().ToString();
                ad.Data = new List<float>();
                switch (a.type())
                {
                    case AffectorType.Colour:
                        ColourAffector ca = (ColourAffector)a;
                        ad.Data.Add(colourToInt(ca.StartColour));
                        ad.Data.Add(colourToInt(ca.EndColour));
                        ad.Data.Add(ca.Duration);
                        break;
                    case AffectorType.Force:
                        var force = ((ForceAffector)a).Force;
                        ad.Data.Add(force.X);
                        ad.Data.Add(force.Y);
                        break;
                    case AffectorType.Rotation:
                        ad.Data.Add(((RotationAffector)a).Rotation);
                        break;
                    case AffectorType.Scale:
                        var scale = ((ScaleAffector)a).Scale;
                        ad.Data.Add(scale.X);
                        ad.Data.Add(scale.Y);
                        break;
                    case AffectorType.Velocity:
                        var vscale = ((VelocityAffector)a).Scale;
                        ad.Data.Add(vscale.X);
                        ad.Data.Add(vscale.Y);
                        break;
                }
                pd.Affectors.Add(ad);
            }

            pd.ReleaseCount = (byte)numericUpDownReleaseCount.Value;
            pd.Texture = textBoxTexturePath.Text;

            try
            {
                JsonSerializer srlz = new JsonSerializer();
                srlz.NullValueHandling = NullValueHandling.Ignore;
                srlz.Formatting = Formatting.Indented;

                using (StreamWriter sw = new StreamWriter(m_filePath))
                using (JsonWriter jw = new JsonTextWriter(sw))
                {
                    srlz.Serialize(jw, pd);
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "Output failed");
            }
        }