From 085a098168a3b50629bcbde3e35a68cdc25e32e7 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Fri, 5 Nov 2021 03:36:00 +0700 Subject: [PATCH] Change `EnableMe()` to have a more sane behavior This method did not do any checks for validity of its parameters and its behavior wasn't consistent in that it woldn't set specified config in case `Feature` was already enabled. Now it will. --- sources/Features/Feature.uc | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/sources/Features/Feature.uc b/sources/Features/Feature.uc index ead6b2e..8e903d9 100644 --- a/sources/Features/Feature.uc +++ b/sources/Features/Feature.uc @@ -229,24 +229,38 @@ public static final function bool IsEnabled() /** * Enables the feature and returns it's active instance. * - * Cannot fail. Any checks on whether it's appropriate to enable `Feature` - * must be done separately, before calling this method. + * Does nothing if passed `configName` is `none`. * + * Cannot fail as long as `configName != none`. Any checks on whether it's + * appropriate to enable `Feature` must be done separately, before calling + * this method. + * + * If `Feature` is already enabled - changes its config to `configName` + * (unless it's `none`). + * + * @param configName Name of the config to use for this `Feature`. + * Passing `none` will make caller `Feature` use "default" config. * @return Active instance of the caller `Feature` class. */ public static final function Feature EnableMe(Text configName) { - local Feature newInstance; - if (IsEnabled()) { - return GetInstance(); + local Feature myInstance; + if (configName == none) { + return; + } + myInstance = GetInstance(); + if (myInstance != none) + { + myInstance.ApplyConfig(configName); + return myInstance; } default.currentConfigName = configName.Copy(); default.blockSpawning = false; - newInstance = Feature(__().memory.Allocate(default.class)); - default.activeInstance = newInstance; - default.activeInstanceLifeVersion = newInstance.GetLifeVersion(); + myInstance = Feature(__().memory.Allocate(default.class)); + default.activeInstance = myInstance; + default.activeInstanceLifeVersion = myInstance.GetLifeVersion(); default.blockSpawning = true; - return newInstance; + return myInstance; } /**