/// <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; }
/// <summary> /// Creates a new module in the temporary directory. /// Note that this module will not become permanent until a call to SaveModule() is made. /// </summary> /// <returns>True if successful, false if unsuccessful</returns> public bool CreateModule() { try { using (FileArchiveManager manager = new FileArchiveManager()) { TemporaryDirectoryPath = manager.CreateUniqueDirectory(); } // Build a new database file and structure. using (DatabaseRepository repo = new DatabaseRepository()) { repo.CreateNewDatabase(TemporaryDirectoryPath, "WinterEngineDB", true); } EntityCreationScripts creationScripts = new EntityCreationScripts(); creationScripts.Initialize(); // Add the module details to the correct table. using (GameModuleRepository repo = new GameModuleRepository()) { GameObjectFactory factory = new GameObjectFactory(); GameModule module = factory.CreateObject(GameObjectTypeEnum.GameModule, ModuleName, ModuleTag, ModuleResref) as GameModule; repo.Add(module); } LoadSystemContentPacks(); return true; } catch(Exception ex) { throw new Exception("Error creating module.", ex); } }