Skip to content

Commit c757172

Browse files
authored
Add migration to set token sizes from actor sizes (#19236)
1 parent 89f6e1d commit c757172

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ActorPF2e } from "@actor";
2+
import { ActorSizePF2e } from "@actor/data/size.ts";
3+
import { TokenSource } from "@common/documents/token.mjs";
4+
import { MigrationBase } from "../base.ts";
5+
6+
/**
7+
* Token dimensions are read from source data as of V13, leaving some tokens that were resized in memory now at the
8+
* incorrect size.
9+
*/
10+
export class Migration939SetTokenDimensions extends MigrationBase {
11+
static override version = 0.939;
12+
13+
override async updateToken(source: TokenSource, actor: Readonly<ActorPF2e | null>): Promise<void> {
14+
const actorSize = actor?.system.traits?.size;
15+
if (!(actorSize instanceof ActorSizePF2e)) return;
16+
const { width, length: height } = actorSize;
17+
source.width = width;
18+
source.height = height;
19+
}
20+
}

src/module/migration/migrations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,4 @@ export { Migration935DeityIconPaths } from "./935-deity-icon-paths.ts";
237237
export { Migration936MoveWorldClockSettings } from "./936-move-world-created-on.ts";
238238
export { Migration937RemoveInvalidAuraTraits } from "./937-remove-invalid-aura-traits.ts";
239239
export { Migration938RenameBroochesAndThroned } from "./938-rename-brooches-and-throned.ts";
240+
export { Migration939SetTokenDimensions } from "./939-set-token-dimensions.ts";

src/module/migration/runner/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ interface CollectionDiff<T extends foundry.documents.ActiveEffectSource | ItemSo
1414
export class MigrationRunnerBase {
1515
migrations: MigrationBase[];
1616

17-
static LATEST_SCHEMA_VERSION = 0.938;
17+
static LATEST_SCHEMA_VERSION = 0.939;
1818

1919
static MINIMUM_SAFE_VERSION = 0.7;
2020

2121
static RECOMMENDED_SAFE_VERSION = 0.84;
2222

23-
/** The minimum schema version for the foundry version number */
23+
/** The starting schema version for the Foundry generation number */
2424
static FOUNDRY_SCHEMA_VERSIONS = {
2525
0.8: 0.634,
2626
9: 0.7,

0 commit comments

Comments
 (0)