internal void InitializeChargers() { QuickLogger.Debug("ChargeManager Initializing CyclopsChargers from external mods"); // First, register chargers from other mods. for (int i = 0; i < CyclopsChargerCreators.Count; i++) { ChargerCreator chargerTemplate = CyclopsChargerCreators[i]; QuickLogger.Debug($"ChargeManager creating charger '{chargerTemplate.ChargerName}'"); CyclopsCharger charger = chargerTemplate.Creator.Invoke(Cyclops); if (charger == null) { QuickLogger.Warning($"CyclopsCharger '{chargerTemplate.ChargerName}' was null"); } else if (!KnownChargers.ContainsKey(chargerTemplate.ChargerName)) { KnownChargers.Add(chargerTemplate.ChargerName, charger); QuickLogger.Debug($"Created CyclopsCharger '{chargerTemplate.ChargerName}'"); } else { QuickLogger.Warning($"Duplicate CyclopsCharger '{chargerTemplate.ChargerName}' was blocked"); } } this.Chargers = new CyclopsCharger[KnownChargers.Count]; int c = 0; foreach (CyclopsCharger charger in KnownChargers.Values) { this.Chargers[c++] = charger; } totalChargers = c; QuickLogger.Debug($"ChargeManager has '{totalChargers}' CyclopsChargers from external mods"); initialized = true; TooLateToRegister = true; requiresVanillaCharging = totalChargers == 0 || CyclopsManager.GetManager(Cyclops).Upgrade.VanillaUpgrades.IsUsingVanillaUpgrade(TechType.CyclopsThermalReactorModule); if (requiresVanillaCharging) { QuickLogger.Info("Vanilla thermal reactor charging enabled"); } else { QuickLogger.Info("Vanilla thermal reactor charging overridden by mod"); } }
internal void InitializeChargers() { TooLateToRegister = true; QuickLogger.Debug("ChargeManager Initializing CyclopsChargers from external mods"); // First, register chargers from other mods. for (int i = 0; i < CyclopsChargerCreators.Count; i++) { ChargerCreator chargerTemplate = CyclopsChargerCreators[i]; QuickLogger.Debug($"ChargeManager creating charger '{chargerTemplate.ChargerName}'"); CyclopsCharger charger = chargerTemplate.Creator.Invoke(Cyclops); if (charger == null) { QuickLogger.Warning($"CyclopsCharger '{chargerTemplate.ChargerName}' was null"); } else if (!KnownChargers.ContainsKey(chargerTemplate.ChargerName)) { KnownChargers.Add(chargerTemplate.ChargerName, charger); CyclopsHUDManager.StatusIcons.Add(charger); QuickLogger.Debug($"Created CyclopsCharger '{chargerTemplate.ChargerName}'"); } else { QuickLogger.Warning($"Duplicate CyclopsCharger '{chargerTemplate.ChargerName}' was blocked"); } } // Check if an external mod has a different upgrade handler for the original CyclopsThermalReactorModule. bool requiresVanillaCharging = CyclopsManager.GetManager(ref Cyclops).Upgrade.VanillaUpgrades.IsUsingVanillaUpgrade(TechType.CyclopsThermalReactorModule); if (requiresVanillaCharging) { QuickLogger.Debug("Vanilla thermal reactor charging handled internally"); var vanillaThermalCharger = new VanillaThermalChargeManager(Cyclops); KnownChargers.Add(nameof(VanillaThermalChargeManager), vanillaThermalCharger); CyclopsHUDManager.StatusIcons.Add(vanillaThermalCharger); MCUServices.Register.PdaIconOverlay(TechType.CyclopsThermalReactorModule, (uGUI_ItemIcon icon, InventoryItem upgradeModule) => new VanillaThermalPdaOverlay(icon, upgradeModule)); } this.Chargers = new CyclopsCharger[KnownChargers.Count]; int c = 0; foreach (CyclopsCharger charger in KnownChargers.Values) { this.Chargers[c++] = charger; } initialized = true; }
/// <summary> /// Registers a <see cref="ChargerCreator"/> method that creates returns a new <see cref="ICyclopsCharger"/> on demand that can is reused for each new Cyclops. /// </summary> /// <param name="createEvent">A method that takes no parameters a returns a new instance of an <see cref="ICyclopsCharger"/>.</param> public static void RegisterReusableChargerCreator(ChargerCreator createEvent) { ReusableCyclopsChargers.Add(createEvent); }
/// <summary> /// Registers a <see cref="ChargerCreator"/> method that creates returns a new <see cref="ICyclopsCharger"/> on demand and is only used once. /// </summary> /// <param name="createEvent">A method that takes no parameters a returns a new instance of an <see cref="ChargerCreator"/>.</param> public static void RegisterOneTimeUseChargerCreator(ChargerCreator createEvent) { OneTimeUseCyclopsChargers.Add(createEvent); }