12 - Buffs Obsolete
From edition=12
onwards, Buffs are now obsolete.
You should use Collectors instead.
Collectors can do everything that Buffs could do, and more.
They have a clearer syntax and so are the way forward for Easel.
Migrating from Buffs to Collectors
Collectors can do everything Buffs can do, and so every Buff can be replaced with a Collector.
Here is a step-by-step guide for converting a buff
into a collect
:
Replace your declaration
If your Buff has either a custom merge function or a default expression, congratulations, it is as simple as renaming from buff
to collect
:
pub buff unit.SpeedBoost ~ |values| values.Sum
In this case, simply replace buff
with collect
:
pub collect unit.SpeedBoost ~ |values| values.Sum
If your buff does not have a merge function, you need to give it one because the default behavior has changed for Collectors:
pub buff unit.RelayTarget
Change this to:
pub collect unit.RelayTarget ~ Max
The default behavior of buffs is to take the maximum value, and so this will make a collector that behaves exactly the same as your original buff.
Give IDs
Look at each place where you give a value to the Buff. Are there any cases where you call a buff more than once in the same file? For buffs this would overwrite the previous contribution rather than adding a new one, and so we need to keep that behavior for your code to continue working.
SpeedModifier(0.5)
// ...
once Tick(5s) {
SpeedModifier(0.7) // Replaces the previous SpeedModifier
}
Change it to this:
give<speedBoost> SpeedModifier(0.5)
// ...
once Tick(5s) {
give<speedBoost> SpeedModifier(0.7) // Replaces previous <speedBoost>
}
Deletion IDs
Do you delete
the Buff anywhere?
You now need to use an ID to do that.
SpeedModifier(0.5)
// ...
once Tick(5s) {
delete SpeedModifier
}
Replace this with the following:
give<speedBoost> SpeedModifier(0.5)
once Tick(5s) {
delete give<speedBoost> // Deletes the previous <speedBoost>
}
Targets
Do you ever use the target entity as a parameter?
SpeedModifier(0.5, that)
Replace this with the following:
give that.SpeedModifier(0.5)
Repeat
Convert every buff into a collector using the steps above.
Bump the edition
Once you are done, increase the edition
number in easel.toml
to 12
.
In Edition 12, it is an error to use a buff
anywhere in your code,
and so this ensures you have converted everything and that no one introduces them back into the code again.
[engine]
edition = 12
Opt-out
If you would like to temporarily opt-out your entire project from this change, you can set allowBuffs=true
in legacy.toml
.
This will preserve the old behavior until you have the time to upgrade your code.
Create a legacy.toml
in the root of your project that looks like this:
[legacy]
allowBuffs = true