예제 #1
0
        /// <summary>
        /// Adds a game object to the database.
        /// </summary>
        /// <param name="gameObject">The game object to add to the database. This will be type-converted and added to the correct table when run.</param>
        /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param>
        public GameObjectBase AddToDatabase(GameObjectBase gameObject, string connectionString = "")
        {
            GameObjectBase resultGameObject;
            try
            {
                if (gameObject.GameObjectType == GameObjectTypeEnum.Area)
                {
                    using (AreaRepository repo = new AreaRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Area);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation)
                {
                    using (ConversationRepository repo = new ConversationRepository())
                    {
                        resultGameObject = repo.Add(gameObject as Conversation);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature)
                {
                    using (CreatureRepository repo = new CreatureRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Creature);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Item)
                {
                    using (ItemRepository repo = new ItemRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Item);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable)
                {
                    using (PlaceableRepository repo = new PlaceableRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Placeable);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Script)
                {
                    using (ScriptRepository repo = new ScriptRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Script);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset)
                {
                    using (TilesetRepository repo = new TilesetRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Tileset);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.GameModule)
                {
                    using (GameModuleRepository repo = new GameModuleRepository())
                    {
                        resultGameObject = repo.Add(gameObject as GameModule);
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            catch
            {
                throw;
            }

            return resultGameObject;
        }