Updated migration guide based on feedback

This commit is contained in:
thepaperpilot 2023-04-18 20:04:40 -05:00
parent 2deeb4bb52
commit a721eedc0f
2 changed files with 45 additions and 18 deletions

View file

@ -5,15 +5,13 @@ Profectus utilizes formulas for various features, such as increasing requirement
For example, a cost function like `Decimal.pow(this.amount, 1.05).times(100)` can be represented using a Formula: `Formula.variable(this.amount).pow(1.05).times(100)`.
```ts
const myRepeatable = createRepeatable(function (this: GenericRepeatable) {
return {
const myRepeatable = createRepeatable(() => ({
requirements: createCostRequirement(() => ({
resource: points,
cost: Formula.variable(this.amount).pow(1.05).times(100)
cost: Formula.variable(myRepeatable.amount).pow(1.05).times(100)
})),
maximize: true
};
});
}));
```
## Limitations

View file

@ -44,22 +44,51 @@ The time required for this step depends on your project structure. You can use [
## Breaking feature changes
This update includes several breaking feature changes. Here are a few minor fixes:
### Achievements and Milestones
- Buyables have been renamed to repeatables. Simply replace all instances of `Buyable` with `Repeatable`.
- Achievements and Milestones have been merged. Add `small: true` to the options for existing achievements, and replace `createMilestone` calls with `createAchievement`.
Achievements and milestones have been merged. Any existing achievements should now have the `small: true` property set to keep the same display as before. Milestones should now use the `createAchievement` constructor instead of `createMilestone`, and they will appear and behave as before.
Additionally, there are changes with more significant impact on your code: Requirements, Formulas, and Modifiers.
### Buyables
Buyables have been renamed to "repeatables". To update your code, you'll need to replace all references to buyable with repeatable. Additionally, various properties have been removed or changed to no longer refer to purchases:
- `canAfford` no longer exists, and you should instead add conditions via the requirements system
- `onPurchase` should become `onClick`
- `purchase()` should become `click()`
### Requirements
Many features no longer use `cost` and `resource` properties but instead utilize a `requirements` property, which can consist of one or more `Requirement` objects. This makes it easier to support features requiring multiple currencies or other conditions. To update an existing cost requirement, wrap your current cost function and resource property as follows:
Many features now use `requirements` properties where before they would have a cost or other condition. The `requirements` property takes a single `Requirement` object or an array of them. Requirements make it easier to support features requiring multiple currencies or other conditions.
When coupled with the formulas system, they also allow for scaling requirements that can be calculated efficiently. Here is an example repeatable that starts by costing 100 points and gets 1.05x more expensive with each purchase, compounding. Thanks to formulas the repeatable will be able to immediately increase as many levels as the player can afford at once:
```ts
const myRepeatable = createRepeatable(() => ({
requirements: createCostRequirement(() => ({
resource: points,
cost: Formula.variable(myRepeatable.amount).pow(1.05).times(100)
})),
maximize: true
}));
```
To update an existing non-scaling cost requirement, wrap your current cost function and resource property as follows:
```ts
const upgrade = createUpgrade(() => ({
requirements: createCostRequirement(() => ({
cost: () => Decimal.pow(priceRatio, unref(machines.amount)),
resource: generators.energeia,
}))
}));
```
For other conditions, you can use the `createBooleanRequirement` constructor instead:
```ts
const spellExpMilestone = createAchievement(() => ({
requirements: createBooleanRequirement(() => Decimal.gte(job.rawLevel.value, 2)),
}));
```
Learn more about requirements and their capabilities in [this guide page](../important-concepts/requirements).