Beispiel #1
0
        /// <summary>
        /// セクションコレクションからレイヤーアイテムを作成する。
        /// </summary>
        /// <param name="sections">セクションコレクション。</param>
        /// <param name="baseSection">ベースセクション。</param>
        /// <returns>レイヤーアイテム。</returns>
        private static LayerItem FromSectionsToLayerItem(
            IniFileSectionCollection sections,
            IniFileSection baseSection)
        {
            Debug.Assert(sections != null);
            Debug.Assert(baseSection != null);

            var result = new LayerItem();

            // ベースセクションのプロパティ値設定
            ExoFileItemsConverter.ToProperties(baseSection.Items, ref result);

            // コンポーネント群追加
            var componentSections =
                Enumerable
                .Range(0, int.MaxValue)
                .Select(
                    i =>
                    sections.FirstOrDefault(
                        s => s.Name == baseSection.Name + @"." + i))
                .TakeWhile(s => s != null);

            foreach (var cs in componentSections)
            {
                result.Components.Add(ComponentMaker.FromExoFileItems(cs.Items));
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// レイヤーアイテムからセクション群を作成して追加する。
        /// </summary>
        /// <param name="layerItem">レイヤーアイテム。</param>
        /// <param name="index">レイヤーアイテムインデックス。</param>
        /// <param name="target">追加先のセクションコレクション。</param>
        private static void FromLayerItemToSections(
            LayerItem layerItem,
            int index,
            IniFileSectionCollection target)
        {
            Debug.Assert(layerItem != null);
            Debug.Assert(index >= 0);
            Debug.Assert(target != null);

            // ベースセクションアイテム群取得
            var items = ExoFileItemsConverter.ToItems(layerItem);

            // ベースセクションアイテム群を整理
            if (layerItem.GroupId <= 0)
            {
                items.Remove(LayerItem.ExoFileItemNameOfGroupId);
            }
            if (layerItem.IsAudio)
            {
                items.Remove(LayerItem.ExoFileItemNameOfIsClipping);
                items.Remove(LayerItem.ExoFileItemNameOfIsCameraTarget);
            }
            else
            {
                items.Remove(LayerItem.ExoFileItemNameOfIsAudio);
                if (!layerItem.IsClipping)
                {
                    items.Remove(LayerItem.ExoFileItemNameOfIsClipping);
                }
            }
            if (layerItem.ChainIndex < 0)
            {
                items.Remove(LayerItem.ExoFileItemNameOfChainIndex);
            }

            // ベースセクション追加
            var baseName = index.ToString();

            target.Add(baseName, items);

            // コンポーネントセクション群追加
            baseName += '.';
            foreach (var v in layerItem.Components.Select((c, i) => new { c, i }))
            {
                target.Add(baseName + v.i, v.c.ToExoFileItems());
            }
        }
Beispiel #3
0
        /// <summary>
        /// このオブジェクトを拡張編集オブジェクトファイルのセクション形式に変換する。
        /// </summary>
        /// <returns>セクションコレクションデータ。</returns>
        public IniFileSectionCollection ToExoFileSections()
        {
            // ファイルセクション追加しつつ作成
            var sections =
                new IniFileSectionCollection
            {
                { SectionNameOfFile, ExoFileItemsConverter.ToItems(this) },
            };

            // レイヤーアイテムセクション群追加
            foreach (var v in this.LayerItems.Select((item, i) => new { item, i }))
            {
                FromLayerItemToSections(v.item, v.i, sections);
            }

            return(sections);
        }
Beispiel #4
0
        /// <summary>
        /// セクションコレクションからファイルセクションを取得、変換し、
        /// 拡張編集オブジェクトのプロパティ値を設定する。
        /// </summary>
        /// <param name="sections">セクションコレクション。</param>
        /// <param name="target">設定先の拡張編集オブジェクト。</param>
        private static void FromSectionsToFileProperties(
            IniFileSectionCollection sections,
            ExEditObject target)
        {
            Debug.Assert(sections != null);
            Debug.Assert(target != null);

            // ファイルセクション取得
            var section = sections.FirstOrDefault(s => s.Name == SectionNameOfFile);

            if (section == null)
            {
                throw new FormatException(
                          @"The [" + SectionNameOfFile + @"] section is not found.");
            }

            // プロパティ値設定
            ExoFileItemsConverter.ToProperties(section.Items, ref target);
        }
        /// <summary>
        /// 拡張編集オブジェクトファイルのアイテムコレクションから
        /// コンポーネントを作成する。
        /// </summary>
        /// <typeparam name="T">コンポーネント型。</typeparam>
        /// <param name="items">アイテムコレクション。</param>
        /// <param name="creater">コンポーネント生成デリゲート。</param>
        /// <returns>コンポーネント。</returns>
        /// <remarks>
        /// 継承先での FromExoFileItems 静的メソッドの実装に用いることができる。
        /// </remarks>
        protected static T FromExoFileItemsCore <T>(
            IniFileItemCollection items,
            Func <T> creater)
            where T : ComponentBase
        {
            if (creater == null)
            {
                throw new ArgumentNullException(nameof(creater));
            }

            // コンポーネント生成
            var result = creater();

            if (result == null)
            {
                throw new ArgumentException(
                          @"Cannot create the component.",
                          nameof(creater));
            }

            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            // コンポーネント名をチェック
            if (!HasComponentNameCore(items, result.ComponentName))
            {
                throw new ArgumentException(
                          @"The component name is not found.",
                          nameof(items));
            }

            // プロパティ群設定
            ExoFileItemsConverter.ToProperties(items, ref result);

            return(result);
        }
 /// <summary>
 /// このコンポーネントを
 /// 拡張編集オブジェクトファイルのアイテムコレクションに変換する。
 /// </summary>
 /// <returns>アイテムコレクション。</returns>
 public IniFileItemCollection ToExoFileItems() =>
 ExoFileItemsConverter.ToItems(this);