Difference between revisions of "Dice/RollerConfig"
(8 intermediate revisions by the same user not shown) | |||
Line 25: | Line 25: | ||
! style="width: 5em" | | ! style="width: 5em" | | ||
! Name !! Description | ! Name !! Description | ||
− | |||
− | |||
|- | |- | ||
| {{public}} {{property}} || [[Dice/RollerConfig/FunctionRegistry|FunctionRegistry]] || Gets or sets the registry of all valid function names and their callbacks. | | {{public}} {{property}} || [[Dice/RollerConfig/FunctionRegistry|FunctionRegistry]] || Gets or sets the registry of all valid function names and their callbacks. | ||
Line 43: | Line 41: | ||
|- | |- | ||
| {{public}} {{property}} || [[Dice/RollerConfig/NormalSidesOnly|NormalSidesOnly]] || Gets or sets whether dice expressions are limited to rolling dice with a "normal" number of sides, or if they can roll dice of any number of sides. | | {{public}} {{property}} || [[Dice/RollerConfig/NormalSidesOnly|NormalSidesOnly]] || Gets or sets whether dice expressions are limited to rolling dice with a "normal" number of sides, or if they can roll dice of any number of sides. | ||
+ | |- | ||
+ | | {{public}} {{property}} || [[Dice/RollerConfig/RollDie|RollDie]] || Gets or sets the function used to generate results when a die is rolled. | ||
|} | |} | ||
Line 48: | Line 48: | ||
The default values for RollerConfig are as follows. These values are set upon constructing the object, however they can be overridden by passing in different values when creating the object (see Examples below for details). | The default values for RollerConfig are as follows. These values are set upon constructing the object, however they can be overridden by passing in different values when creating the object (see Examples below for details). | ||
<syntaxhighlight lang="C#"> | <syntaxhighlight lang="C#"> | ||
− | |||
FunctionRegistry = new FunctionRegistry(); | FunctionRegistry = new FunctionRegistry(); | ||
FunctionRegistry.RegisterType(typeof(BuiltinFunctions)); | FunctionRegistry.RegisterType(typeof(BuiltinFunctions)); | ||
MacroRegistry = new MacroRegistry(); | MacroRegistry = new MacroRegistry(); | ||
+ | MacroRegistry.RegisterType(typeof(BuiltinMacros)); | ||
+ | RollDie = null; // null makes the default implementation generate random numbers (using GetRandomBytes below) to roll dice | ||
GetRandomBytes = null; // null makes use of System.Cryptography.RNGCryptoServiceProvider to generate random numbers | GetRandomBytes = null; // null makes use of System.Cryptography.RNGCryptoServiceProvider to generate random numbers | ||
MaxDice = 1000; | MaxDice = 1000; | ||
Line 61: | Line 62: | ||
== Thread Safety == | == Thread Safety == | ||
− | RollerConfig is thread safe. | + | Reading values from RollerConfig is thread safe. Writing values or manipulating the FunctionRegistry or MacroRegistry is not thread-safe. Internal functions do not write to RollerConfig. The default implementation of GetRandomBytes is thread-safe; passing your own version here may or may not be thread-safe. |
+ | |||
+ | If full thread-safety is desired for RollerConfig, please open an issue on GitHub explaining your use-case. | ||
== Examples == | == Examples == |
Latest revision as of 18:03, 23 December 2018
Stores various configuration related to the dice roller.
- Namespace: Dice
- Assembly: DiceRoller (in DiceRoller.dll)
Inheritance Hierarchy
System.Object
- Dice.RollerConfig
Syntax
public class RollerConfig
Constructors
Name | Description | |
---|---|---|
RollerConfig() | Constructs a new RollerConfig instance with default values. |
Properties
Name | Description | |
---|---|---|
FunctionRegistry | Gets or sets the registry of all valid function names and their callbacks. | |
MacroRegistry | Gets or sets the registry of all valid macro names and their callbacks. | |
GetRandomBytes | Gets or sets the function used to generate random numbers. | |
MaxDice | Gets or sets the maximum number of dice that may be rolled. | |
MaxRecursionDepth | Gets or sets how deeply nested a dice expression can get. | |
MaxRerolls | Gets or sets the maximum number of times a single die may be rerolled. | |
MaxSides | Gets or sets the maximum number of sides a single die may have. | |
NormalSidesOnly | Gets or sets whether dice expressions are limited to rolling dice with a "normal" number of sides, or if they can roll dice of any number of sides. | |
RollDie | Gets or sets the function used to generate results when a die is rolled. |
Remarks
The default values for RollerConfig are as follows. These values are set upon constructing the object, however they can be overridden by passing in different values when creating the object (see Examples below for details).
FunctionRegistry = new FunctionRegistry();
FunctionRegistry.RegisterType(typeof(BuiltinFunctions));
MacroRegistry = new MacroRegistry();
MacroRegistry.RegisterType(typeof(BuiltinMacros));
RollDie = null; // null makes the default implementation generate random numbers (using GetRandomBytes below) to roll dice
GetRandomBytes = null; // null makes use of System.Cryptography.RNGCryptoServiceProvider to generate random numbers
MaxDice = 1000;
MaxRecursionDepth = 20;
MaxRerolls = 100;
MaxSides = 10000;
NormalSidesOnly = false;
Thread Safety
Reading values from RollerConfig is thread safe. Writing values or manipulating the FunctionRegistry or MacroRegistry is not thread-safe. Internal functions do not write to RollerConfig. The default implementation of GetRandomBytes is thread-safe; passing your own version here may or may not be thread-safe.
If full thread-safety is desired for RollerConfig, please open an issue on GitHub explaining your use-case.
Examples
The following is an example of creating a custom RollerConfig which leaves most values at their default but customizes some others.
using Dice;
class Sample
{
public static void Main()
{
var config = new RollerConfig()
{
MaxDice = 200
};
}
}