Difference between revisions of "Dice/RollerConfig"
m |
|||
(18 intermediate revisions by the same user not shown) | |||
Line 18: | Line 18: | ||
! Name !! Description | ! Name !! Description | ||
|- | |- | ||
− | | {{public}} {{method}} || [[ | + | | {{public}} {{method}} || [[Dice/RollerConfig/RollerConfig|RollerConfig()]] || Constructs a new RollerConfig instance with default values. |
|} | |} | ||
Line 26: | Line 26: | ||
! Name !! Description | ! Name !! Description | ||
|- | |- | ||
− | | {{public}} {{property}} || [[ | + | | {{public}} {{property}} || [[Dice/RollerConfig/FunctionRegistry|FunctionRegistry]] || Gets or sets the registry of all valid function names and their callbacks. |
|- | |- | ||
− | | {{public}} {{property}} || [[ | + | | {{public}} {{property}} || [[/MacroRegistry|MacroRegistry]] || Gets or sets the registry of all valid macro names and their callbacks. |
|- | |- | ||
− | | {{public}} {{property}} || [[ | + | | {{public}} {{property}} || [[Dice/RollerConfig/GetRandomBytes|GetRandomBytes]] || Gets or sets the function used to generate random numbers. |
|- | |- | ||
− | | {{public}} {{property}} || [[ | + | | {{public}} {{property}} || [[Dice/RollerConfig/MaxDice|MaxDice]] || Gets or sets the maximum number of dice that may be rolled. |
|- | |- | ||
− | | {{public}} {{property}} || [[ | + | | {{public}} {{property}} || [[Dice/RollerConfig/MaxRecursionDepth|MaxRecursionDepth]] || Gets or sets how deeply nested a dice expression can get. |
|- | |- | ||
− | | {{public}} {{property}} || [[ | + | | {{public}} {{property}} || [[Dice/RollerConfig/MaxRerolls|MaxRerolls]] || Gets or sets the maximum number of times a single die may be rerolled. |
|- | |- | ||
− | | {{public}} {{property}} || [[ | + | | {{public}} {{property}} || [[Dice/RollerConfig/MaxSides|MaxSides]] || Gets or sets the maximum number of sides a single die may have. |
+ | |- | ||
+ | | {{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 44: | 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.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 | GetRandomBytes = null; // null makes use of System.Cryptography.RNGCryptoServiceProvider to generate random numbers | ||
MaxDice = 1000; | MaxDice = 1000; | ||
Line 54: | 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 == | ||
Line 68: | Line 78: | ||
var config = new RollerConfig() | var config = new RollerConfig() | ||
{ | { | ||
− | + | MaxDice = 200 | |
}; | }; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
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
};
}
}