Skip to content

Commit 237e3f9

Browse files
committed
Add SFX support
1 parent a41d918 commit 237e3f9

6 files changed

Lines changed: 95 additions & 14 deletions

File tree

scripts/apps/NpcPageSheet.mjs

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
export default class NpcPageSheet extends JournalPageSheet {
22
/** @inheritdoc */
33
static get defaultOptions() {
4-
const options = super.defaultOptions;
5-
options.classes.push("form");
6-
return options;
4+
return foundry.utils.mergeObject(super.defaultOptions, {
5+
classes: ["form", "intelligent-npcs", "actor-configuration"],
6+
dragDrop: [
7+
{dropSelector: ".playlist"}
8+
],
9+
});
710
}
811

912
/* -------------------------------------------- */
@@ -22,7 +25,7 @@ export default class NpcPageSheet extends JournalPageSheet {
2225

2326
/** @type {FishingSpotData} */
2427
let config = context.document.flags["intelligent-npcs"] ?? {};
25-
if ( foundry.utils.isEmpty(config) ) {
28+
if (foundry.utils.isEmpty(config)) {
2629
config["enabled"] = true;
2730
config["summary"] = "You are a generic NPC named Bob.";
2831
config["background"] = "You live in a quiet town where nothing much goes on.";
@@ -32,13 +35,23 @@ export default class NpcPageSheet extends JournalPageSheet {
3235
config["appearance"] = "Farmer attire";
3336
config["exampleSentence"] = "<i>Tips hat</i> \"Evening.\"";
3437
config["memory"] = "Today my wife and I went to the market. We bought some bread and milk.";
38+
config["playlist"] = null;
39+
}
40+
41+
let hasPlaylistLink = false;
42+
let playlistContentLink = "";
43+
if (config["playlist"]) {
44+
hasPlaylistLink = true;
45+
playlistContentLink = await TextEditor.enrichHTML(`@UUID[${config["playlist"]}]`);
3546
}
3647

3748
return foundry.utils.mergeObject(context, {
3849
journal: this.object,
3950
config: config,
4051
user: game.user,
41-
messageHistory: JSON.stringify(context.document.getFlag("intelligent-npcs", "messageHistory"), null, 2)
52+
messageHistory: JSON.stringify(context.document.getFlag("intelligent-npcs", "messageHistory"), null, 2),
53+
hasPlaylistLink: hasPlaylistLink,
54+
playlistContentLink: playlistContentLink,
4255
});
4356
}
4457

@@ -55,11 +68,31 @@ export default class NpcPageSheet extends JournalPageSheet {
5568

5669
/* -------------------------------------------- */
5770

71+
activateListeners(html) {
72+
super.activateListeners(html);
73+
74+
html.find(".playlist-remove").click(async (event) => {
75+
event.preventDefault();
76+
this.object.update({flags: {"intelligent-npcs": {playlist: null}}});
77+
});
78+
79+
html.find(".content-link").click(async (event) => {
80+
event.preventDefault();
81+
const uuid = this.object.getFlag("intelligent-npcs", "playlist");
82+
if (uuid) {
83+
const doc = await fromUuid(uuid);
84+
if (doc) doc.sheet.render(true);
85+
}
86+
});
87+
}
88+
89+
/* -------------------------------------------- */
90+
5891
/** @override */
5992
_getHeaderButtons() {
6093
const buttons = super._getHeaderButtons();
6194

62-
if ( !this.isEditable ) return buttons;
95+
if (!this.isEditable) return buttons;
6396

6497
buttons.unshift({
6598
label: "Import",
@@ -100,15 +133,15 @@ export default class NpcPageSheet extends JournalPageSheet {
100133
async _onImportSubmit(html) {
101134
// Get the file input
102135
const input = html.find("input[type='file']")[0];
103-
if ( !input || !input.files || !input.files.length ) return;
136+
if (!input || !input.files || !input.files.length) return;
104137

105138
// Read the file
106139
const file = input.files[0];
107140
const content = await readTextFromFile(file);
108141

109142
// Read as JSON
110143
const config = JSON.parse(content);
111-
if ( !config ) return;
144+
if (!config) return;
112145

113146
// Update the actor
114147
this.object.flags["intelligent-npcs"] = config;
@@ -125,4 +158,25 @@ export default class NpcPageSheet extends JournalPageSheet {
125158
const filename = `${this.object.name}-intelligent-npc-journal-page-config.json`;
126159
saveDataToFile(content, "application/json", filename);
127160
}
161+
162+
/* -------------------------------------------- */
163+
164+
async _onDrop(event) {
165+
super._onDrop(event);
166+
const data = JSON.parse(event.dataTransfer.getData("text/plain"));
167+
168+
if (event.currentTarget.classList.contains("playlist")) {
169+
const doc = await fromUuid(data.uuid);
170+
if (!doc) return;
171+
if (doc.documentName !== "Playlist") {
172+
ui.notifications.error(`Expected a Playlist Document, but got a ${doc.documentName} one instead. `);
173+
return;
174+
}
175+
176+
const flag = this.object.flags["intelligent-npcs"] ?? {};
177+
flag["playlist"] = data.uuid;
178+
this.object.update({flags: {"intelligent-npcs": flag}});
179+
return;
180+
}
181+
}
128182
}

styles/intelligent-npcs.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

styles/intelligent-npcs.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

styles/intelligent-npcs.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
}
55
}
66

7+
.intelligent-npcs {
8+
.playlist-none {
9+
outline: dotted 2px #999;
10+
}
11+
}
12+
713
.chat-message {
814
.message-header {
915
.message-sender {

templates/journal/page-inpc-edit.hbs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,31 @@
1010
<p class="notes">A quick summary of this NPC for human reference. Intelligent NPCs do not read this field.</p>
1111
</div>
1212

13+
<div class="form-group playlist" style="margin: 1rem;" data-name="playlist">
14+
<label>Linked Playlist</label>
15+
{{#if hasPlaylistLink}}
16+
{{{playlistContentLink}}}
17+
<a class="playlist-remove" data-name="playlist" data-action="remove" style="flex: 0;margin-left: 0.25rem;"><i class="fa-solid fa-delete-left"></i></a>
18+
{{else}}
19+
<p class="playlist-none">Drag a playlist here to link.</p>
20+
{{/if}}
21+
<p class="notes">If a Playlist is linked, the iNPC will occasionally choose to play sound from it.</p>
22+
</div>
23+
1324
<fieldset>
1425
<legend>Public Info</legend>
1526
<p class="notes">These fields will be read by other Intelligent NPCs, so don't include any info that others shouldn't generally know. These fields should be written in third person.</p>
1627

1728
<div class="form-group-stacked">
1829
<label>What Everyone Knows</label>
19-
<textarea class="form-control" rows="4" name="whatEveryoneKnows" placeholder="{{journal.name}} is a generic person who is well known for existing." maxlength="500">{{config.whatEveryoneKnows}}</textarea>
20-
<p class="notes">A quick summary of what others generally know about this person. Write in third person. Max length: 500 characters</p>
30+
<textarea class="form-control" rows="4" name="whatEveryoneKnows" placeholder="{{journal.name}} is a generic person who is well known for existing." >{{config.whatEveryoneKnows}}</textarea>
31+
<p class="notes">A quick summary of what others generally know about this person. Write in third person.</p>
2132
</div>
2233

2334
<div class="form-group-stacked">
2435
<label>Appearance</label>
25-
<textarea class="form-control" rows="4" name="appearance" placeholder="{{journal.name}} wears standard street wear." maxlength="500">{{config.appearance}}</textarea>
26-
<p class="notes">What this character looks like to others. Write in third person. Max length: 500 characters</p>
36+
<textarea class="form-control" rows="4" name="appearance" placeholder="{{journal.name}} wears standard street wear." >{{config.appearance}}</textarea>
37+
<p class="notes">What this character looks like to others. Write in third person.</p>
2738
</div>
2839
</fieldset>
2940

@@ -34,7 +45,7 @@
3445

3546
<div class="form-group-stacked">
3647
<label>Background</label>
37-
<textarea class="form-control" rows="8" name="background" placeholder="Background" maxlength="500">{{config.background}}</textarea>
48+
<textarea class="form-control" rows="8" name="background" placeholder="Background" >{{config.background}}</textarea>
3849
</div>
3950

4051
<div class="form-group-stacked">

templates/journal/page-inpc-view.hbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
<h2>Summary</h2>
88
<p>{{config.summary}}</p>
9+
10+
{{#if hasPlaylistLink}}
11+
<h2>Linked Playlist</h2>
12+
{{{playlistContentLink}}}
13+
{{/if}}
14+
</div>
915
</div>
1016
</div>
1117

0 commit comments

Comments
 (0)