/// <summary> /// Add a TowerModel to the game. /// <br/> /// Using this method is preferable than modifying the GameModel's towers list manually, as this does more things /// to more fully integrate the tower within the game /// </summary> /// <param name="towerModel">TowerModel to add</param> /// <param name="towerDetailsModel">Optionally add a TowerDetailsModel for your towerModel</param> public static void AddTowerToGame(this GameModel model, TowerModel towerModel, TowerDetailsModel towerDetailsModel = null) { model.towers = model.towers.AddTo(towerModel); model.AddChildDependant(towerModel); ModTowerHelper.TowerCache[towerModel.name] = towerModel; if (towerDetailsModel != null) { model.AddTowerDetails(towerDetailsModel, towerModel.towerSet); } // MelonLogger.Msg($"Added towerModel {towerModel.name} to the game"); }
/// <summary> /// Add multiple TowerModels to the game more efficiently than calling the single method repeatedly. /// </summary> public static void AddTowersToGame(this GameModel model, IEnumerable <TowerModel> towerModels) { var array = towerModels.ToArray(); var towersLength = model.towers.Length; var newArray = new Il2CppReferenceArray <TowerModel>(towersLength + array.Length); for (var i = 0; i < towersLength; i++) { newArray[i] = model.towers[i]; } for (var i = 0; i < array.Length; i++) { newArray[i + towersLength] = array[i]; } model.towers = newArray; foreach (var towerModel in array) { model.AddChildDependant(towerModel); ModTowerHelper.TowerCache[towerModel.name] = towerModel; } }
public static void AddUpgrade(this GameModel model, UpgradeModel upgradeModel) { model.upgrades = model.upgrades.AddTo(upgradeModel); model.upgradesByName.Add(upgradeModel.name, upgradeModel); model.AddChildDependant(upgradeModel); }