Module: features/conversion
Interfaces
BaseConversion
• BaseConversion: Object
The properties that are added onto a processed ConversionOptions to create a Conversion.
Name | Type | Description |
---|---|---|
convert | VoidFunction | The function that performs the actual conversion. |
Defined in
profectus/src/features/conversion.ts:80
ConversionOptions
• ConversionOptions: Object
An object that configures a Conversion.
Name | Type | Description |
---|---|---|
actualGain? | Computable <DecimalSource > | The absolute amount the output resource will be changed by. Typically this will be set for you in a conversion constructor. This will differ from currentGain in the cases where the conversion isn't just adding the converted amount to the output resource. |
baseResource | Resource <DecimalSource > | The input Resource for this conversion. |
buyMax? | Computable <boolean > | Whether or not to cap the amount of the output resource gained by converting at 1. Defaults to true. |
convert? | VoidFunction | The function that performs the actual conversion from baseResource to gainResource. Typically this will be set for you in a conversion constructor. |
currentAt? | Computable <DecimalSource > | The amount of the input resource currently being required in order to produce the currentGain. That is, if it went below this value then currentGain would decrease. Typically this will be set for you in a conversion constructor. |
currentGain? | Computable <DecimalSource > | How much of the output resource the conversion can currently convert for. Typically this will be set for you in a conversion constructor. |
formula | (variable : InvertibleIntegralFormula ) => InvertibleFormula | The formula used to determine how much gainResource should be earned by this converting. The passed value will be a Formula representing the baseResource variable. |
gainResource | Resource <DecimalSource > | The output Resource for this conversion. i.e. the resource being generated. |
nextAt? | Computable <DecimalSource > | The amount of the input resource required to make currentGain increase. Typically this will be set for you in a conversion constructor. |
onConvert? | (amountGained : DecimalSource ) => void | A callback that happens after a conversion has been completed. Receives the amount gained via conversion. This will not be called whenever using currentGain without calling convert (e.g. passive generation) |
spend? | (amountGained : DecimalSource ) => void | The function that spends the baseResource as part of the conversion. Defaults to setting the baseResource amount to 0. |
Defined in
profectus/src/features/conversion.ts:18
Type Aliases
Conversion
Ƭ Conversion<T
>: Replace
<T
& BaseConversion
, { actualGain
: GetComputableTypeWithDefault
<T
["actualGain"
], Ref
<DecimalSource
>> ; buyMax
: GetComputableTypeWithDefault
<T
["buyMax"
], true
> ; currentAt
: GetComputableTypeWithDefault
<T
["currentAt"
], Ref
<DecimalSource
>> ; currentGain
: GetComputableTypeWithDefault
<T
["currentGain"
], Ref
<DecimalSource
>> ; formula
: InvertibleFormula
; nextAt
: GetComputableTypeWithDefault
<T
["nextAt"
], Ref
<DecimalSource
>> ; spend
: undefined
extends T
["spend"
] ? (amountGained
: DecimalSource
) => void
: T
["spend"
] }>
An object that converts one Resource into another at a given rate.
Type parameters
Name | Type |
---|---|
T | extends ConversionOptions |
Defined in
profectus/src/features/conversion.ts:88
GenericConversion
Ƭ GenericConversion: Replace
<Conversion
<ConversionOptions
>, { actualGain
: ProcessedComputable
<DecimalSource
> ; buyMax
: ProcessedComputable
<boolean
> ; currentAt
: ProcessedComputable
<DecimalSource
> ; currentGain
: ProcessedComputable
<DecimalSource
> ; nextAt
: ProcessedComputable
<DecimalSource
> ; spend
: (amountGained
: DecimalSource
) => void
}>
A type that matches any valid Conversion object.
Defined in
profectus/src/features/conversion.ts:102
Functions
createCanConvertRequirement
▸ createCanConvertRequirement(conversion
, minGainAmount?
, display?
): Requirement
Creates requirement that is met when the conversion hits a specified gain amount
Parameters
Name | Type | Default value | Description |
---|---|---|---|
conversion | GenericConversion | undefined | The conversion to check the gain amount of |
minGainAmount | Computable <DecimalSource > | 1 | The minimum gain amount that must be met for the requirement to be met |
display? | CoercableComponent | undefined | - |
Returns
Defined in
profectus/src/features/conversion.ts:302
createConversion
▸ createConversion<T
>(optionsFunc
, ...decorators
): Conversion
<T
>
Lazily creates a conversion with the given options. You typically shouldn't use this function directly. Instead use one of the other conversion constructors, which will then call this.
See
Type parameters
Name | Type |
---|---|
T | extends ConversionOptions |
Parameters
Name | Type | Description |
---|---|---|
optionsFunc | OptionsFunc <T , BaseConversion , GenericConversion > | Conversion options. |
...decorators | GenericDecorator [] | - |
Returns
Conversion
<T
>
Defined in
profectus/src/features/conversion.ts:121
createCumulativeConversion
▸ createCumulativeConversion<S
>(optionsFunc
): Conversion
<S
>
Creates a conversion that simply adds to the gainResource amount upon converting. This is similar to the behavior of "normal" layers in The Modding Tree. This is equivalent to just calling createConversion directly.
Type parameters
Name | Type |
---|---|
S | extends ConversionOptions |
Parameters
Name | Type | Description |
---|---|---|
optionsFunc | OptionsFunc <S , BaseConversion , GenericConversion > | Conversion options. |
Returns
Conversion
<S
>
Defined in
profectus/src/features/conversion.ts:205
createIndependentConversion
▸ createIndependentConversion<S
>(optionsFunc
): Conversion
<S
>
Creates a conversion that will replace the gainResource amount with the new amount upon converting. This is similar to the behavior of "static" layers in The Modding Tree.
Type parameters
Name | Type |
---|---|
S | extends ConversionOptions |
Parameters
Name | Type | Description |
---|---|---|
optionsFunc | OptionsFunc <S , BaseConversion , GenericConversion > | Converison options. |
Returns
Conversion
<S
>
Defined in
profectus/src/features/conversion.ts:216
setupPassiveGeneration
▸ setupPassiveGeneration(layer
, conversion
, rate?
, cap?
): void
This will automatically increase the value of conversion.gainResource without lowering the value of the input resource. It will by default perform 100% of a conversion's currentGain per second. If you use a ref for the rate you can set it's value to 0 when passive generation should be disabled.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
layer | BaseLayer | undefined | The layer this passive generation will be associated with. Typically this when calling this function from inside a layer's options function. |
conversion | GenericConversion | undefined | The conversion that will determine how much generation there is. |
rate | Computable <DecimalSource > | 1 | A multiplier to multiply against the conversion's currentGain. |
cap | Computable <DecimalSource > | Decimal.dInf | A value that should not be passed via passive generation. |
Returns
void