BattlerTags are used to represent semi-persistent effects attached to individual Pokemon.
During serialization, a new blank tag object is created, before its loadTag is called
with the object that was serialized.
This makes it fairly straightforward to avoid serializing fields — anything not set in the class constructor
or the tag's loadTag method will not be serialized.
Any battler tag that can persist across waves (meaning it lasts longer than 1 turn)
must extend SerializableBattlerTag in its class definition signature.
SerializableBattlerTags have strict requirements for their fields:
Properties that are not necessary to reconstruct the tag must not be serialized
This can be accomplished by using private elements
and/or getters.
Note that getters do not need to be tied to a class field, for example:
classExample { publicgetthing(): number { return5; } }
If a property that is intended to be "private" should be serialized, it must
be declared as public readonly instead.
Then, in the loadTag method (or any internal method that needs to adjust the property),
use a cast to Writable<this> (such as (this as Writable<this>).propertyName = value).
This ensures that Typescript is aware of the shape of the serialized version of the class.
If any new serializable fields are added, then the class must override the
loadTag method to set the new fields.
Its signature must match the example below:
classExampleTagextendsSerializableBattlerTag { // Example, if we add 2 new fields that should be serialized: publica: string; publicb: number; // Then we must also define a loadTag method with one of the following signatures: // This signature should be used if the class has no subclasses: publicoverrideloadTag(source: BaseBattlerTag & Pick<ExampleTag, "tagType" | "a" | "b"): void; // This signature should be used if the class has any subclasses: publicoverrideloadTag<constTextendsthis>(source: BaseBattlerTag & Pick<T, "tagType" | "a" | "b">): void { this.a = source.a; this.b = source.b; } }
BattlerTags are used to represent semi-persistent effects attached to individual Pokemon.During serialization, a new blank tag object is created, before its
loadTagis called with the object that was serialized.This makes it fairly straightforward to avoid serializing fields — anything not set in the class constructor or the tag's
loadTagmethod will not be serialized.Any battler tag that can persist across waves (meaning it lasts longer than 1 turn) must extend
SerializableBattlerTagin its class definition signature.SerializableBattlerTags have strict requirements for their fields:Properties that are not necessary to reconstruct the tag must not be serialized This can be accomplished by using private elements and/or
getters.Note that
getters do not need to be tied to a class field, for example:If a property that is intended to be "private" should be serialized, it must be declared as
public readonlyinstead. Then, in theloadTagmethod (or any internal method that needs to adjust the property), use a cast toWritable<this>(such as(this as Writable<this>).propertyName = value).This ensures that Typescript is aware of the shape of the serialized version of the class.
If any new serializable fields are added, then the class must override the
loadTagmethod to set the new fields.Its signature must match the example below: