Skip to content
This repository was archived by the owner on Aug 10, 2025. It is now read-only.

Commit 726688e

Browse files
committed
allow button icon and text to be configured on a per script basis
1 parent 30e5b73 commit 726688e

6 files changed

Lines changed: 48 additions & 41 deletions

File tree

lang/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"showHeaderButtonLabel": {
2020
"Name": "Display Button Label",
21-
"Hint": "If checked, the button's label is displayed."
21+
"Hint": "If checked, the label is displayed in the header of applicable item sheets."
2222
},
2323
"chatCardScriptButtonPrefix": {
2424
"Name": "Default Chat Card Button Prefix",

scriptable-items

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/data/script-model.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { FLAG, LANG_ID, MODULE_ID } from "../constants.mjs";
1+
import { FLAG, LANG_ID, MODULE_ID, SETTING } from "../constants.mjs";
2+
import { getSetting } from "../settings.mjs";
23

34
export class ScriptModel extends foundry.abstract.DataModel {
45
static DEFAULT_ICON = "icons/svg/dice-target.svg";
@@ -40,6 +41,17 @@ export class ScriptModel extends foundry.abstract.DataModel {
4041
label: "Trigger Set",
4142
},
4243
),
44+
buttonIconClasses: new fields.StringField({
45+
required: false,
46+
blank: true,
47+
label: "Button Icon Classes",
48+
initial: () => getSetting(SETTING.CHAT_CARD_SCRIPT_BUTTON_ICON),
49+
}),
50+
buttonText: new fields.StringField({
51+
required: false,
52+
blank: true,
53+
label: "Button Text",
54+
}),
4355
};
4456
}
4557

scripts/scriptable-items.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Hooks.on("getItemSheetHeaderButtons", (app, buttons) => {
2020
const item = app.document;
2121
buttons.unshift({
2222
class: MODULE_ID,
23-
icon: "fas fa-play",
23+
icon: "fa-solid fa-code",
2424
label: getSetting(SETTING.SHOW_HEADER_BUTTON_LABEL)
2525
? "Scriptable Items"
2626
: undefined,
@@ -86,9 +86,9 @@ Hooks.on("dnd5e.renderChatMessage", async (message, html) => {
8686
{
8787
action: `${MODULE_ID}-execute`,
8888
id: script.id,
89-
iconClasses: getSetting(SETTING.CHAT_CARD_SCRIPT_BUTTON_ICON),
90-
prefix: getSetting(SETTING.CHAT_CARD_SCRIPT_BUTTON_PREFIX),
91-
name: script.name,
89+
iconClasses: script.buttonIconClasses,
90+
prefix: "",
91+
name: script.buttonText ? script.buttonText : script.name,
9292
},
9393
);
9494

scripts/settings.mjs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,12 @@ export function registerModuleSettings() {
3232
default: true,
3333
});
3434

35-
_registerSetting(SETTING.CHAT_CARD_SCRIPT_BUTTON_PREFIX, {
36-
scope: "world",
37-
config: true,
38-
requiresReload: false,
39-
type: String,
40-
default: "Execute",
41-
});
42-
4335
_registerSetting(SETTING.CHAT_CARD_SCRIPT_BUTTON_ICON, {
4436
scope: "world",
45-
config: true,
37+
config: false,
4638
requiresReload: false,
4739
type: String,
48-
default: `fas fa-play`,
40+
default: `fa-solid fa-code`,
4941
});
5042
}
5143

templates/script-config.hbs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,6 @@
1515
/></h1>
1616
</header>
1717

18-
{{!-- <div class="form-group">
19-
<label>Triggers</label>
20-
<div class="form-fields trigger-controls">
21-
<select>
22-
{{selectOptions availableTriggers}}
23-
</select>
24-
<button class="trigger-control" type="button" data-action="addTrigger">
25-
<i class="fas fa-plus"></i>
26-
Add
27-
</button>
28-
</div>
29-
</div>
30-
31-
<ol class="form-group stacked triggers">
32-
{{#each data.triggers}}
33-
<li class="flexrow" data-trigger-id="{{this}}">
34-
<span>{{localize (concat "SCRIPTABLE-ITEMS.Trigger." this)}}</span>
35-
<a class="trigger-control" data-action="removeTrigger">
36-
<i class="fas fa-trash"></i>
37-
</a>
38-
</li>
39-
{{/each}}
40-
</ol> --}}
41-
4218
<div class="form-group">
4319
<label>Triggers</label>
4420
<multi-select name="triggers">
@@ -48,6 +24,34 @@
4824
</multi-select>
4925
</div>
5026

27+
<details>
28+
<summary>Button Configuration</summary>
29+
<fieldset>
30+
<div class="form-group">
31+
<label>Icon</label>
32+
<input
33+
name="buttonIconClasses"
34+
type="text"
35+
value="{{data.buttonIconClasses}}"
36+
placeholder="fa-solid fa-code"
37+
/>
38+
<p class="hint">CSS classes used for the icon of the button. If
39+
empty, no icon will be shown.</p>
40+
</div>
41+
<div class="form-group">
42+
<label>Text</label>
43+
<input
44+
name="buttonText"
45+
type="text"
46+
value="{{data.buttonText}}"
47+
placeholder="{{data.name}}"
48+
/>
49+
<p class="hint">Text displayed on the button. Is always right of
50+
the icon and defaults to the scripts name if left empty.</p>
51+
</div>
52+
</fieldset>
53+
</details>
54+
5155
<div class="form-group stacked command">
5256
<label>{{localize "Command"}}</label>
5357
<textarea name="command">{{data.command}}</textarea>

0 commit comments

Comments
 (0)