Profectus / features/resources/resource
features/resources/resource ​
This feature represents a resource the player can accumulate, spend, etc.
ts
const points = createResource<DecimalSource>(10, "points");
When passing this resource into other features, make sure to wrap it in noPersist
to ensure there's no issues when saving/loading.
ts
const upgrade = createUpgrade(() => ({
...,
requirements: createCostRequirement(() => ({
cost: 10,
resource: noPersist(points)
}))
}));
You can also turn refs from other features into resources, to still benefit from them having a name and precision:
ts
const repeatable = createRepeatable(() => ({ ... }));
const repeatableLevels = createResource(repeatable.amount, "levels");