Browse Source

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.
pull/8/head
Anton Tarasenko 3 years ago
parent
commit
085a098168
  1. 32
      sources/Features/Feature.uc

32
sources/Features/Feature.uc

@ -229,24 +229,38 @@ public static final function bool IsEnabled()
/** /**
* Enables the feature and returns it's active instance. * Enables the feature and returns it's active instance.
* *
* Cannot fail. Any checks on whether it's appropriate to enable `Feature` * Does nothing if passed `configName` is `none`.
* must be done separately, before calling this method.
* *
* 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. * @return Active instance of the caller `Feature` class.
*/ */
public static final function Feature EnableMe(Text configName) public static final function Feature EnableMe(Text configName)
{ {
local Feature newInstance; local Feature myInstance;
if (IsEnabled()) { if (configName == none) {
return GetInstance(); return;
}
myInstance = GetInstance();
if (myInstance != none)
{
myInstance.ApplyConfig(configName);
return myInstance;
} }
default.currentConfigName = configName.Copy(); default.currentConfigName = configName.Copy();
default.blockSpawning = false; default.blockSpawning = false;
newInstance = Feature(__().memory.Allocate(default.class)); myInstance = Feature(__().memory.Allocate(default.class));
default.activeInstance = newInstance; default.activeInstance = myInstance;
default.activeInstanceLifeVersion = newInstance.GetLifeVersion(); default.activeInstanceLifeVersion = myInstance.GetLifeVersion();
default.blockSpawning = true; default.blockSpawning = true;
return newInstance; return myInstance;
} }
/** /**

Loading…
Cancel
Save