import{_ as e,c as t,o as a,a as o}from"./app.ab34650d.js";const g=JSON.parse('{"title":"Module: features/conversion","description":"","frontmatter":{"editLink":false},"headers":[{"level":2,"title":"Interfaces","slug":"interfaces"},{"level":2,"title":"Type Aliases","slug":"type-aliases"},{"level":3,"title":"Conversion","slug":"conversion"},{"level":3,"title":"GenericConversion","slug":"genericconversion"},{"level":2,"title":"Functions","slug":"functions"},{"level":3,"title":"addHardcap","slug":"addhardcap"},{"level":3,"title":"addSoftcap","slug":"addsoftcap"},{"level":3,"title":"createConversion","slug":"createconversion"},{"level":3,"title":"createCumulativeConversion","slug":"createcumulativeconversion"},{"level":3,"title":"createIndependentConversion","slug":"createindependentconversion"},{"level":3,"title":"createLinearScaling","slug":"createlinearscaling"},{"level":3,"title":"createPolynomialScaling","slug":"createpolynomialscaling"},{"level":3,"title":"setupPassiveGeneration","slug":"setuppassivegeneration"},{"level":3,"title":"softcap","slug":"softcap"}],"relativePath":"api/modules/features/conversion.md","lastUpdated":null}'),r={name:"api/modules/features/conversion.md"},d=o('
\u01AC 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
>> ; nextAt
: GetComputableTypeWithDefault
<T
["nextAt"
], Ref
<DecimalSource
>> ; roundUpCost
: GetComputableTypeWithDefault
<T
["roundUpCost"
], true
> ; spend
: undefined
extends T
["spend"
] ? (amountGained
: DecimalSource
) => void
: T
["spend"
] }>
An object that converts one Resource into another at a given rate.
Name | Type |
---|---|
T | extends ConversionOptions |
profectus/src/features/conversion.ts:103
\u01AC GenericConversion: Replace
<Conversion
<ConversionOptions
>, { actualGain
: ProcessedComputable
<DecimalSource
> ; buyMax
: ProcessedComputable
<boolean
> ; currentAt
: ProcessedComputable
<DecimalSource
> ; currentGain
: ProcessedComputable
<DecimalSource
> ; nextAt
: ProcessedComputable
<DecimalSource
> ; roundUpCost
: ProcessedComputable
<boolean
> ; spend
: (amountGained
: DecimalSource
) => void
}>
A type that matches any valid Conversion object.
profectus/src/features/conversion.ts:117
\u25B8 addHardcap(scaling
, cap
): ScalingFunction
Creates a scaling function off an existing function, with a hardcap applied to it. The harcap will ensure that the currentGain will stop at a given cap.
Name | Type | Description |
---|---|---|
scaling | ScalingFunction | The raw scaling function. |
cap | ProcessedComputable <DecimalSource > | The maximum value the scaling function can output. |
\u25B8 addSoftcap(scaling
, cap
, power?
): ScalingFunction
Creates a scaling function based off an existing scaling function, with a softcap applied to it. The softcap will take any value above a certain value and raise it to a power. If the power is <1, this will effectively make the value scale slower after the cap.
See
Name | Type | Default value | Description |
---|---|---|---|
scaling | ScalingFunction | undefined | The raw scaling function. |
cap | ProcessedComputable <DecimalSource > | undefined | The value after which the softcap should be applied. |
power | ProcessedComputable <DecimalSource > | 0.5 | The power to raise value about the cap to. |
\u25B8 createConversion<T
>(optionsFunc
): 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
Name | Type |
---|---|
T | extends ConversionOptions |
Name | Type | Description |
---|---|---|
optionsFunc | OptionsFunc <T , BaseConversion , GenericConversion > | Conversion options. |
Conversion
<T
>
\u25B8 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.
Name | Type |
---|---|
S | extends ConversionOptions |
Name | Type | Description |
---|---|---|
optionsFunc | OptionsFunc <S , BaseConversion , GenericConversion > | Conversion options. |
Conversion
<S
>
\u25B8 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.
Name | Type |
---|---|
S | extends ConversionOptions |
Name | Type | Description |
---|---|---|
optionsFunc | OptionsFunc <S , BaseConversion , GenericConversion > | Converison options. |
Conversion
<S
>
\u25B8 createLinearScaling(base
, coefficient
): ScalingFunction
Creates a scaling function based off the formula (baseResource - base) * coefficient
. If the baseResource value is less than base then the currentGain will be 0.
Example
A scaling function created via createLinearScaling(10, 0.5)
would produce the following values:
Base Resource | Current Gain |
---|---|
10 | 1 |
12 | 2 |
20 | 6 |
Name | Type | Description |
---|---|---|
base | Computable <DecimalSource > | The base variable in the scaling formula. |
coefficient | Computable <DecimalSource > | The coefficient variable in the scaling formula. |
\u25B8 createPolynomialScaling(base
, exponent
): ScalingFunction
Creates a scaling function based off the formula (baseResource / base) ^ exponent
. If the baseResource value is less than base then the currentGain will be 0.
Example
A scaling function created via createPolynomialScaling(10, 0.5)
would produce the following values:
Base Resource | Current Gain |
---|---|
10 | 1 |
40 | 2 |
250 | 5 |
Name | Type | Description |
---|---|---|
base | Computable <DecimalSource > | The base variable in the scaling formula. |
exponent | Computable <DecimalSource > | The exponent variable in the scaling formula. |
\u25B8 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.
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 <null | DecimalSource > | null | A value that should not be passed via passive generation. If null, no cap is applied. |
void
\u25B8 softcap(value
, cap
, power?
): DecimalSource
Given a value, this function finds the amount above a certain value and raises it to a power. If the power is <1, this will effectively make the value scale slower after the cap.
Example
A softcap added via addSoftcap(scaling, 100, 0.5)
would produce the following values:
Raw Value | Softcapped Value |
---|---|
1 | 1 |
100 | 100 |
125 | 105 |
200 | 110 |
Name | Type | Default value | Description |
---|---|---|---|
value | DecimalSource | undefined | The raw value. |
cap | DecimalSource | undefined | The value after which the softcap should be applied. |
power | DecimalSource | 0.5 | The power to raise value above the cap to. |