Skip to content

Commit b8a0dcc

Browse files
committed
add generalized item html embedding handler
1 parent fc7672f commit b8a0dcc

9 files changed

Lines changed: 76 additions & 10 deletions

File tree

module.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "warhammer-lib",
33
"title": "Warhammer Library",
44
"description": "Common code used by the various Warhammer Systems",
5-
"version": "2.3.2",
5+
"version": "2.4.0",
66
"authors": [{"name": "Moo Man", "id": "Moo Man", "discord": "moo.man"}],
77
"scripts" : ["warhammer-lib.js"],
88
"styles" : [{"src": "warhammer.css", "layer" : "system"}],
@@ -50,5 +50,5 @@
5050
},
5151
"socket": true,
5252
"manifest": "https://github.com/moo-man/WarhammerLibrary-FVTT/releases/latest/download/module.json",
53-
"download": "https://github.com/moo-man/WarhammerLibrary-FVTT/releases/download/2.3.2/warhammer-lib.zip"
53+
"download": "https://github.com/moo-man/WarhammerLibrary-FVTT/releases/download/2.4.0/warhammer-lib.zip"
5454
}

src/apps/roll-dialogV2.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ export default class WarhammerRollDialogV2 extends HandlebarsApplicationMixin(Ap
125125
dialogData.data.speaker.alias = actor.prototypeToken.name;
126126
dialogData.data.targets = (context.skipTargets) ? [] : context.targets || Array.from(game.user.targets).filter(t => t.document.id != dialogData.data.speaker.token); // Remove self from targets
127127
delete context.targets;
128+
129+
// Used by scripts to store data and then pass onto the test
130+
if (!context.flags)
131+
{
132+
context.flags = {};
133+
}
134+
128135
if (actor && !actor?.token)
129136
{
130137
// getSpeaker retrieves tokens even if this sheet isn't a token's sheet

src/document/item.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,24 @@ export class WarhammerItem extends WarhammerDocumentMixin(Item)
389389

390390
return new SelectChoices(choices);
391391
}
392+
393+
/**
394+
*
395+
* @inheritdoc
396+
* @param {object} config Configuration for embedding behavior, changes for each system/type
397+
*/
398+
async toEmbed(config, options={})
399+
{
400+
if (this.system.toEmbed)
401+
{
402+
let embed = await this.system.toEmbed(config, options);
403+
embed.classList.add(`${game.system.id}-embed`, this.type);
404+
return embed;
405+
}
406+
else
407+
{
408+
return super.toEmbed(config, options);
409+
}
410+
}
411+
392412
}

src/document/table.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ export class WarhammerRollTable extends RollTable
88
let separator = config.separator || "";
99
console.log(config, options);
1010

11-
return $(await foundry.applications.ux.TextEditor.implementation.enrichHTML(`<table class="${game.system.id} embedded">
11+
return $(await foundry.applications.ux.TextEditor.implementation.enrichHTML(`<div class="table-container">${config.description == "top" ? this.description : ""}<table class="${game.system.id} embedded">
1212
<thead>
1313
<tr class="title"><td colspan="2">@UUID[${this.uuid}]{${this.name}}</td></tr>
14+
<tr class="description"><td colspan="2">
1415
<tr class="subheader">
1516
<td class="formula">${this.formula}</td>
1617
<td class="label">${config.label}</td>
@@ -41,6 +42,6 @@ export class WarhammerRollTable extends RollTable
4142
}).join("")}
4243
4344
</tbody>
44-
</table>`, options))[0];
45+
</table>${config.description == "bottom" ? this.description : ""}</div>`, options))[0];
4546
}
4647
}

src/model/components/choices.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ export class ChoiceModel extends foundry.abstract.DataModel
7070
let option;
7171
if (data.documentName == "Item")
7272
{
73+
let restrictions = this.schema.options.restrictType;
74+
if (restrictions?.length > 0 && !restrictions.includes(data.type))
75+
{
76+
ui.notifications.error("WH.Error.WrongChoiceOptionType", {localize : true, format : {types : restrictions.join(", ")}});
77+
throw new Error(game.i18n.format("WH.Error.WrongChoiceOptionType", {types : restrictions.join(", ")}));
78+
}
7379
option = this._createDocumentOption(data);
7480
}
7581
else if (data.documentName == "ActiveEffect")
@@ -188,7 +194,12 @@ export class ChoiceModel extends foundry.abstract.DataModel
188194
}
189195
else if (option.type == "placeholder")
190196
{
191-
return foundry.utils.mergeObject({name : option.name}, systemConfig().placeholderItemData);
197+
let data = foundry.utils.mergeObject({name : option.name}, systemConfig().placeholderItemData);
198+
if (this.schema.options.restrictType?.length)
199+
{
200+
data.type = this.schema.options.restrictType[0];
201+
}
202+
return data;
192203
}
193204
else if (["id", "uuid"].includes(option.idType))
194205
{
@@ -390,7 +401,12 @@ export class ChoiceModel extends foundry.abstract.DataModel
390401
return this._displayOptions(this.structure);
391402
}
392403

393-
_displayOptions(structure)
404+
get textDisplayWithLinks()
405+
{
406+
return this._displayOptions(this.structure, {links : true});
407+
}
408+
409+
_displayOptions(structure, displayOptions={})
394410
{
395411

396412
if (!structure)
@@ -400,7 +416,15 @@ export class ChoiceModel extends foundry.abstract.DataModel
400416

401417
if (structure.type == "option")
402418
{
403-
return this.options.find(i => i.id == structure.id).name;
419+
let option = this.options.find(i => i.id == structure.id);
420+
if (displayOptions.links && option.idType == "uuid")
421+
{
422+
return `@UUID[${option.documentId}]{${option.name}}`;
423+
}
424+
else
425+
{
426+
return option.name;
427+
}
404428
}
405429
else if (structure.type == "and" || structure.type == "or")
406430
{

src/system/tooltips.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@ export class BaseDialogTooltips
8989
}
9090

9191
// Resets a field's values to the provided value
92-
set(type, value, source)
92+
set(type, value, source, replace=false)
9393
{
9494
let field = this[`_${type}`];
9595
if (field && value && source)
9696
{
97-
field.list = [{value, source, set: true}].concat(field.list);
97+
if (replace)
98+
{
99+
field.list = [{value, source, set: true}];
100+
}
101+
else
102+
{
103+
field.list = [{value, source, set: true}].concat(field.list);
104+
}
98105
}
99106
}
100107

static/assets/marker.png

3.53 KB
Loading

static/lang/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@
162162
"NoTargetedActors": "No targeted Actors!",
163163
"NoTargets": "No targeted Actors!",
164164
"NotValidChoiceType": "Not a valid choice",
165-
"NoDrawingsToConvert" : "No Drawings to Convert!"
165+
"NoDrawingsToConvert" : "No Drawings to Convert!",
166+
"WrongChoiceOptionType" : "This type of Item isn't allowed. Allowed Types: {types}"
166167
},
167168
"ErrorNoZones": "No Zones to select. Add Regions to the Scene to create Zones.",
168169
"ErrorUnableToFindEffect": "Unable to find effect to apply.",

styles/apps/_journal.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,10 @@
4242
justify-content: space-evenly;
4343

4444
}
45+
}
46+
47+
.journal-sheet {
48+
.toc .level4 .page-title {
49+
text-indent: calc(3 * var(--level-indent));
50+
}
4551
}

0 commit comments

Comments
 (0)