Example #1
0
 /// <summary>
 /// データをダンプする。
 /// </summary>
 /// <param name="path">ファイルパス</param>
 private static void DumpDataProc(string path)
 {
     try
     {
         string fileName = System.IO.Path.GetFileName(path);
         if (fileName.Equals("Actors.json"))
         {
             DumpItems(DataActorListParser.Read(path));
         }
         else if (fileName.Equals("Items.json"))
         {
             DumpItems(DataItemListParser.Read(path));
         }
         else if (fileName.Equals("Weapons.json"))
         {
             DumpItems(DataWeaponListParser.Read(path));
         }
         else if (fileName.Equals("Armors.json"))
         {
             DumpItems(DataArmorListParser.Read(path));
         }
         else if (fileName.Equals("Enemies.json"))
         {
             DumpItems(DataEnemyListParser.Read(path));
         }
         else if (path.EndsWith(".json"))
         {
             DumpGenericJsonData(path);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
     Console.ReadKey();
 }
Example #2
0
        /// <summary>
        /// プロフィールデータを読み出す。
        /// </summary>
        /// <param name="dir">フォルダ</param>
        /// <returns>プロフィールデータ配列</returns>
        public static List <DataActorProfile> Read(string dir)
        {
            List <DataActorProfile> list = null;
            string actorsPath            = System.IO.Path.Combine(dir, "Actors.json");
            string profilePath           = System.IO.Path.Combine(dir, "ActorProfiles.json");

            if (!System.IO.File.Exists(actorsPath) &&
                !System.IO.File.Exists(profilePath))
            {
                throw new System.IO.FileNotFoundException("Profile data not exists.");
            }

            List <DataActor> actorList = null;

            if (System.IO.File.Exists(actorsPath))
            {
                // 一覧があるので、こちらからインデックスデータを構築する。
                actorList = DataActorListParser.Read(actorsPath);
            }
            else
            {
                actorList = new List <DataActor>();
            }

            if (System.IO.File.Exists(profilePath))
            {
                MVUtils.JsonData.DataReader reader = new MVUtils.JsonData.DataReader()
                {
                    DataConstructor = new DataActorProfileConstructor()
                };
                list = (List <DataActorProfile>)(reader.Read(profilePath));
            }
            else
            {
                list = new List <DataActorProfile>();
            }

            // acotrListにあって、listにないエントリがあったらlistに追加する。
            // 逆はやらないでおく。
            foreach (DataActor actor in actorList)
            {
                if (actor == null)
                {
                    continue;
                }
                var actorProfile = list.Find((ap) => (ap != null) && (ap.Id == actor.Id));
                if (actorProfile != null)
                {
                    // 存在する。
                    actorProfile.Name = actor.Name;
                }
                else
                {
                    // 存在しない。
                    list.Add(new DataActorProfile()
                    {
                        Id = actor.Id, Name = actor.Name
                    });
                }
            }
            if (!list.Contains(null))
            {
                // nullは1つは必要。
                list.Add(null);
            }

            // ID順にソート
            list.Sort((ap1, ap2) =>
            {
                if (ap1 == null)
                {
                    return(-1);
                }
                else if (ap2 == null)
                {
                    return(1);
                }
                else
                {
                    return(ap1.Id - ap2.Id);
                }
            });

            return(list);
        }