generated from League-of-Foundry-Developers/FoundryVTT-Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathupdateMessage.js
More file actions
69 lines (61 loc) · 2.31 KB
/
updateMessage.js
File metadata and controls
69 lines (61 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { MODULE_ID } from "./helpers/const.js";
const sampleData = {
new: [{ item: "" }, { item: "", feat: true }, { children: [""] }],
update: [{ item: "" }, { children: [""] }],
};
const updateData = {
'13.4.0': {
new: [
{ item: "Darkest Dungeon: Stress / Relief", feat: true },
{ children: ["Adds a new animation that will either play the stress or relief icon on friendly tokens based on either Critical Success or Failures"] },
{ item: "Update Messages", feat: true },
{ children: ["Occassionally will have update messages with some patch notes (General Reserved for Feature releases and not patches)"] },
],
update: [
{ item: "Updated French translation (@rectulo)" },
{ item: "Updated Polish translation (@Lioheart)" },
{ item: "Updated `Genga` requirement to `0.7.1`" },
],
}
};
export async function handleUpdateMessage() {
if (!game.user.isGM) return;
const last_version = game.settings.get(MODULE_ID, "last-version");
game.settings.set(
MODULE_ID,
"last-version",
game.modules.get(MODULE_ID).version
);
if (
last_version === game.modules.get(MODULE_ID).version
&& !game.modules.get(MODULE_ID).version.endsWith(".0")
) {
return;
}
const updateStuff = updateData?.[game.modules.get(MODULE_ID).version];
if (!updateStuff) return;
const updateMessage = {
name: game.modules.get(MODULE_ID).title,
icon: "fa-solid fa-dragon",
version: game.modules.get(MODULE_ID).version,
...updateStuff,
};
updateMessage.isNew = updateMessage?.new && updateMessage?.new?.length > 0
updateMessage.isUpdate = updateMessage?.update && updateMessage?.update?.length > 0
updateMessage.new = updateMessage?.new?.map(it => ({
hasChild: !!it?.children && !!it?.children?.length > 0,
...it
}))
updateMessage.update = updateMessage?.update?.map(it => ({
hasChild: !!it?.children && !!it?.children?.length > 0,
...it
}))
const content = await renderTemplate(
`modules/${MODULE_ID}/templates/updateMessage.hbs`,
updateMessage
);
ChatMessage.create({
content,
whisper: game.users.filter((u) => u.isGM).map((u) => u.id),
});
}