예제 #1
0
        private void SaveData()
        {
            Debug.Assert(m_currentPath != null && m_currentPath != string.Empty);

            string normalMap = (textBoxNormalMap.Text == string.Empty || textBoxNormalMap.Text == null) ? "none.png" : textBoxNormalMap.Text;

            AnimationData data = new AnimationData(m_aniSprite.FrameCount,
                new Size(m_aniSprite.FrameSize.X, m_aniSprite.FrameSize.Y),
                m_aniSprite.FrameRate, this.Text, normalMap);

            //create a default animation
            if(m_listboxData.Count < 1)
            {
                m_listboxData.Insert(0, new Animation("default", 0, m_aniSprite.FrameCount - 1));
            }

            data.Animations = m_listboxData;

            try
            {
                //save json file
                JsonSerializer srlz = new JsonSerializer();
                srlz.NullValueHandling = NullValueHandling.Ignore;
                srlz.Formatting = Formatting.Indented;

                using (StreamWriter sw = new StreamWriter(m_currentPath))
                using (JsonWriter jw = new JsonTextWriter(sw))
                {
                    srlz.Serialize(jw, data);
                }

                m_modified = false;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "Saving JSON Data");
            }
        }