Ejemplo n.º 1
0
        internal static ChoiceList DataTableToTitleList(DataTable Dt)
        {
            ChoiceList choices = new ChoiceList();

            try
            {
                foreach (DataRow item in Dt.Rows)
                {
                    choices.Add(DataRowToTitle(item));
                }
            }
            catch
            {
            }
            return(choices);
        }
Ejemplo n.º 2
0
        public void ImportFromCsv(string path)
        {
            Database.EnsureDeleted();
            Database.Migrate();

            #region WalkableAreaMap

            var walkableAreaMapCsv = ParseCsv(Path.Combine(path, "walkableareamap.csv"));

            foreach (var result in walkableAreaMapCsv)
            {
                if (result.Length != 3)
                {
                    continue;
                }

                WalkableAreaMap.Add(new WalkableAreaMap
                {
                    Id      = int.Parse(result[0]),
                    WamFile = result[2]
                });
            }

            #endregion

            #region Script

            var scriptCsv = ParseCsv(Path.Combine(path, "skript.csv"));

            foreach (var result in scriptCsv)
            {
                System.Diagnostics.Debug.Assert(result.Length <= 5, "SKRIPT column count failed?");

                if (result.Length != 4)
                {
                    continue;
                }

                Script.Add(new Skript()
                {
                    SkriptId     = int.Parse(result[0]),
                    Zeilennummer = int.Parse(result[1]),
                    SkriptAktion = result[2],
                    Kommentar    = result[3]
                });
            }

            #endregion

            #region FrameSet

            var frameSetCsv = ParseCsv(Path.Combine(path, "bildfolge.csv"));

            foreach (var result in frameSetCsv)
            {
                System.Diagnostics.Debug.Assert(result.Length <= 4, "BILDFOLGE column count failed?");

                if (result.Length != 4)
                {
                    continue;
                }

                FrameSet.Add(new Bildfolge()
                {
                    Id           = int.Parse(result[0]),
                    Bezeichnung  = result[1],
                    Anzeigedauer = int.Parse(result[2]),
                    Loop         = bool.Parse(result[3])
                });

                System.Diagnostics.Debug.Assert(!FrameSet.Any(x => x.Id == int.Parse(result[0])), "duplicate BILDFOLGE?");
            }

            #endregion

            SaveChanges();

            #region CharacterAnimationSet

            var characterAnimationSetCsv = ParseCsv(Path.Combine(path, "characteranimationset.csv"));

            foreach (var result in characterAnimationSetCsv)
            {
                System.Diagnostics.Debug.Assert(result.Length <= 7, "CHARACTERANIMATIONSET column count failed?");

                if (result.Length != 7)
                {
                    continue;
                }

                var thisSet = new CharacterAnimationSet()
                {
                    SetId           = int.Parse(result[0]),
                    AktionsmodusId  = int.Parse(result[1]),
                    Bezeichnung     = result[2],
                    LinksBildfolge  = FrameSet.Find(int.Parse(result[3])),
                    RechtsBildfolge = FrameSet.Find(int.Parse(result[4])),
                    VorneBildfolge  = FrameSet.Find(int.Parse(result[5])),
                    HintenBildfolge = FrameSet.Find(int.Parse(result[6])),
                };

                CharacterAnimationSet.Add(thisSet);

                // There are various CAS with null animations
                //System.Diagnostics.Debug.Assert(thisSet.LinksBildfolge != null && thisSet.RechtsBildfolge != null && thisSet.VorneBildfolge != null && thisSet.HintenBildfolge != null, $"CHARACTERANIMATIONSET {thisSet.Bezeichnung} has null bildfolge?");
            }

            #endregion

            #region ChoiceList

            var choiceListCsv = ParseCsv(Path.Combine(path, "choiceliste.csv"));

            foreach (var result in choiceListCsv)
            {
                System.Diagnostics.Debug.Assert(result.Length <= 5, "CHOICELISTE column count failed?");

                if (result.Length != 5)
                {
                    continue;
                }

                var thisSet = new ChoiceListeEntry()
                {
                    ChoiceId      = int.Parse(result[0]),
                    AuswahlNummer = int.Parse(result[1]),
                    Aktiv         = bool.Parse(result[2]),
                    AuswahlText   = result[3],
                    SkriptId      = int.Parse(result[4])
                };

                ChoiceList.Add(thisSet);
            }

            #endregion

            #region Timer

            var timerCsv = ParseCsv(Path.Combine(path, "timer.csv"));

            foreach (var result in timerCsv)
            {
                System.Diagnostics.Debug.Assert(result.Length <= 4, "TIMER column count failed?");

                if (result.Length != 4)
                {
                    continue;
                }

                Timer.Add(new Timer()
                {
                    Id       = int.Parse(result[0]),
                    SkriptId = int.Parse(result[1]),
                    Dauer    = int.Parse(result[2]),
                    Aktiv    = bool.Parse(result[3])
                });
            }

            #endregion

            #region ChoiceList

            var roomCsv = ParseCsv(Path.Combine(path, "raum.csv"));

            foreach (var result in roomCsv)
            {
                System.Diagnostics.Debug.Assert(result.Length <= 13, "RAUM column count failed?");

                if (result.Length > 13 || result.Length < 12)
                {
                    continue;
                }

                var thisRoom = new Raum
                {
                    Id                      = int.Parse(result[0]),
                    Bezeichnung             = result[1],
                    BildDatei               = result[2],
                    MusikDatei              = result[3],
                    WalkableAreaMap         = WalkableAreaMap.Find(int.Parse(result[4])),
                    VSpeed                  = ParseDouble(result[5]),
                    HSpeed                  = ParseDouble(result[6]),
                    BaseYatZeroScale        = ParseDouble(result[7]),
                    BaseYatFullScale        = ParseDouble(result[8]),
                    GuiId                   = int.Parse(result[9]),
                    CharacterAnimationSetId = int.Parse(result[10]),
                    Timer                   = Timer.Find(int.Parse(result[11]))
                };

                Room.Add(thisRoom);
            }

            #endregion

            SaveChanges();
        }