Skip to content

Commit 3ac359d

Browse files
KapuzenjoearbronFyorl
authored
[#4060] Add teleport activity (#6904)
Co-authored-by: Jeff Hitchcock <github444@command-center.org> Co-authored-by: Kim Mantas <kim.mantas@gmail.com>
1 parent afd5b96 commit 3ac359d

13 files changed

Lines changed: 295 additions & 0 deletions

File tree

icons/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The dnd5e system for Foundry Virtual Tabletop includes icon artwork licensed fro
4141
/svg/activity/order.svg - "Pointing" by Lord under CC BY 3.0
4242
/svg/activity/save.svg - "Shield reflect" by Lorc under CC BY 3.0
4343
/svg/activity/summon.svg - "Pentagram rose" by Lorc under CC BY 3.0
44+
/svg/activity/teleport.svg - "Teleport" by Lorc under CC BY 3.0
4445
/svg/activity/transform.svg - "Frog prince" by Delapouite under CC BY 3.0
4546
/svg/activity/utility.svg - "Spanner" by Lorc under CC BY 3.0
4647
/svg/actors/encounter.svg - "Sverd I Fjell" by Delapouite under CC BY 3.0

icons/svg/activity/teleport.svg

Lines changed: 6 additions & 0 deletions
Loading

lang/en.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5206,6 +5206,37 @@
52065206
}
52075207
},
52085208

5209+
"DND5E.TELEPORT": {
5210+
"Action": {
5211+
"Teleport": "Teleport"
5212+
},
5213+
"FIELDS": {
5214+
"teleport": {
5215+
"label": "Distance",
5216+
"hint": "Set the maximum teleport distance.",
5217+
"useRange": {
5218+
"label": "Use Range",
5219+
"hint": "Use the activity's configured range as the maximum teleport distance."
5220+
},
5221+
"unlimited": {
5222+
"label": "Unlimited",
5223+
"hint": "Ignore distance limits when teleporting."
5224+
},
5225+
"value": {
5226+
"label": "Distance"
5227+
}
5228+
}
5229+
},
5230+
"Hint": "Teleport a token to a chosen destination.",
5231+
"SECTIONS": {
5232+
"Teleport": "Teleport"
5233+
},
5234+
"Title": "Teleport",
5235+
"Warning": {
5236+
"InvalidDistance": "Teleport can't be used in scenes without supported movement units."
5237+
}
5238+
},
5239+
52095240
"DND5E.Target": "Target",
52105241
"DND5E.TargetPl": "Targets",
52115242
"DND5E.TargetType": "Target Type",

module/applications/activity/_module.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export {default as ForwardSheet} from "./forward-sheet.mjs";
88
export {default as HealSheet} from "./heal-sheet.mjs";
99
export {default as SaveSheet} from "./save-sheet.mjs";
1010
export {default as SummonSheet} from "./summon-sheet.mjs";
11+
export {default as TeleportSheet} from "./teleport-sheet.mjs";
1112
export {default as TransformSheet} from "./transform-sheet.mjs";
1213
export {default as UtilitySheet} from "./utility-sheet.mjs";
1314

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import ActivitySheet from "./activity-sheet.mjs";
2+
3+
/**
4+
* Sheet for the teleport activity.
5+
*/
6+
export default class TeleportSheet extends ActivitySheet {
7+
8+
/** @inheritDoc */
9+
static DEFAULT_OPTIONS = {
10+
classes: ["teleport-activity"]
11+
};
12+
13+
/* -------------------------------------------- */
14+
15+
/** @inheritDoc */
16+
static PARTS = {
17+
...super.PARTS,
18+
effect: {
19+
template: "systems/dnd5e/templates/activity/teleport-effect.hbs",
20+
templates: [
21+
"systems/dnd5e/templates/activity/parts/teleport-settings.hbs"
22+
]
23+
}
24+
};
25+
26+
/* -------------------------------------------- */
27+
28+
/** @inheritDoc */
29+
_getTabs() {
30+
const tabs = super._getTabs();
31+
tabs.effect.label = "DND5E.TELEPORT.SECTIONS.Teleport";
32+
tabs.effect.icon = "fa-solid fa-person-walking-dashed-line-arrow-right";
33+
return tabs;
34+
}
35+
}

module/config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,6 +4427,9 @@ DND5E.activityTypes = {
44274427
summon: {
44284428
documentClass: activities.SummonActivity
44294429
},
4430+
teleport: {
4431+
documentClass: activities.TeleportActivity
4432+
},
44304433
transform: {
44314434
documentClass: activities.TransformActivity
44324435
},

module/data/activity/_module.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {default as ForwardActivityData} from "./forward-data.mjs";
99
export {default as HealActivityData} from "./heal-data.mjs";
1010
export {default as SaveActivityData} from "./save-data.mjs";
1111
export {default as SummonActivityData} from "./summon-data.mjs";
12+
export {default as TeleportActivityData} from "./teleport-data.mjs";
1213
export {default as TransformActivityData} from "./transform-data.mjs";
1314
export {default as UtilityActivityData} from "./utility-data.mjs";
1415

module/data/activity/_types.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@
217217

218218
/* -------------------------------------------- */
219219

220+
/**
221+
* @typedef {ActivityData} TeleportActivityData
222+
* @property {object} teleport
223+
* @property {boolean} teleport.useRange Use the activity's range as the maximum teleport distance.
224+
* @property {string} teleport.units Units used to measure teleport distance.
225+
* @property {boolean} teleport.unlimited Ignore teleport distance limits.
226+
* @property {string} teleport.value Maximum distance the token can teleport.
227+
*/
228+
220229
/**
221230
* @typedef {ActivityData} TransformActivityData
222231
* @property {TransformProfile[]} profiles Information on transformation methods and sources.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { defaultUnits, prepareFormulaValue } from "../../utils.mjs";
2+
import FormulaField from "../fields/formula-field.mjs";
3+
import BaseActivityData from "./base-activity.mjs";
4+
5+
const { BooleanField, SchemaField, StringField } = foundry.data.fields;
6+
7+
/**
8+
* @import { TeleportActivityData } from "./_types.mjs";
9+
*/
10+
11+
/**
12+
* Data model for a teleport activity.
13+
* @extends {BaseActivityData<TeleportActivityData>}
14+
* @mixes TeleportActivityData
15+
*/
16+
export default class BaseTeleportActivityData extends BaseActivityData {
17+
/** @inheritDoc */
18+
static defineSchema() {
19+
return {
20+
...super.defineSchema(),
21+
teleport: new SchemaField({
22+
useRange: new BooleanField({ initial: true }),
23+
units: new StringField({ required: true, blank: false, initial: () => defaultUnits("length") }),
24+
unlimited: new BooleanField(),
25+
value: new FormulaField({ deterministic: true })
26+
})
27+
};
28+
}
29+
30+
/* -------------------------------------------- */
31+
/* Data Preparation */
32+
/* -------------------------------------------- */
33+
34+
/** @inheritDoc */
35+
prepareFinalData(rollData) {
36+
rollData ??= this.getRollData({ deterministic: true });
37+
super.prepareFinalData(rollData);
38+
39+
if ( this.teleport.useRange ) {
40+
this.teleport.unlimited = this.range.units === "any";
41+
if ( this.range.scalar ) {
42+
this.teleport.units = this.range.units;
43+
this.teleport.value = this.range.value;
44+
}
45+
} else if ( !this.teleport.unlimited ) {
46+
prepareFormulaValue(this, "teleport.value", "DND5E.TELEPORT.FIELDS.teleport.value.label", rollData);
47+
}
48+
}
49+
}

module/documents/activity/_module.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export {default as HealActivity} from "./heal.mjs";
1010
export {default as OrderActivity} from "./order.mjs";
1111
export {default as SaveActivity} from "./save.mjs";
1212
export {default as SummonActivity} from "./summon.mjs";
13+
export {default as TeleportActivity} from "./teleport.mjs";
1314
export {default as TransformActivity} from "./transform.mjs";
1415
export {default as UtilityActivity} from "./utility.mjs";

0 commit comments

Comments
 (0)