first commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
src/vendor/
|
||||
35
src/module.json
Normal file
35
src/module.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"id": "asc-session-title-suggestions",
|
||||
"title": "Session Title Suggestions",
|
||||
"description": "A simple module that keeps track of session title suggestions",
|
||||
"authors": [
|
||||
{
|
||||
"name": "lmxsdl"
|
||||
}
|
||||
],
|
||||
"version": "0.1",
|
||||
"compatibility": {
|
||||
"minimum": "10",
|
||||
"verified": "11"
|
||||
},
|
||||
"download": "https://gitea.ascorrea.com/asc/asc-session-title-suggestions/releases/download/0.1/src.zip",
|
||||
"manifest":"https://gitea.ascorrea.com/asc/asc-session-title-suggestions/raw/branch/master/src/module.json",
|
||||
"scripts": [
|
||||
"scripts/main.js"
|
||||
],
|
||||
"esmodules":[
|
||||
],
|
||||
"relationships": {
|
||||
"requires": [
|
||||
{
|
||||
"id": "_chatcommands",
|
||||
"type": "module",
|
||||
"manifest": "https://gitlab.com/woodentavern/foundryvtt-chat-command-lib/-/raw/master/src/module.json",
|
||||
"compatability": {
|
||||
"minimum": "2.0.2",
|
||||
"verified": "2.0.2"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
94
src/scripts/main.js
Normal file
94
src/scripts/main.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const NAME = "/title"
|
||||
|
||||
const template_path = "modules/asc-session-title-suggestions/templates"
|
||||
|
||||
const TEMPLATES = {
|
||||
'suggestion': {
|
||||
flavor:`${template_path}/suggestion-flavor.hbs`,
|
||||
content:`${template_path}/suggestion-content.hbs`
|
||||
},
|
||||
"suggestionList": {
|
||||
flavor:`${template_path}/suggestion-list-flavor.hbs`,
|
||||
content:`${template_path}/suggestion-list-content.hbs`
|
||||
}
|
||||
}
|
||||
|
||||
function registerClipboardCopyButton() {
|
||||
copyToClipboardListener = (event) => {
|
||||
const text=event.target.dataset.clipboardText;
|
||||
console.log(`Session Title Suggestions | Copying "${text}" to clipboard`);
|
||||
navigator.clipboard.writeText(text)
|
||||
}
|
||||
$(document).on('click', 'a.clipboard', copyToClipboardListener);
|
||||
}
|
||||
|
||||
|
||||
function registerCustomChatCommands() {
|
||||
game.chatCommands.unregister(NAME)
|
||||
game.chatCommands.register({
|
||||
name: NAME,
|
||||
module: "_chatcommands",
|
||||
aliases: ["/t", "t/"],
|
||||
description: "Suggest a title for this episode",
|
||||
icon: '<i class="fa-solid fa-podcast"></i>',
|
||||
requiredRole: "NONE",
|
||||
callback: async (chat, parameters, messageData) => {
|
||||
const titleSuggestion = parameters
|
||||
const newMessageData = {}
|
||||
newMessageData.content = await renderTemplate(TEMPLATES.suggestion.content, {content:titleSuggestion})
|
||||
newMessageData.flavor = await renderTemplate(TEMPLATES.suggestion.flavor)
|
||||
newMessageData.flags = {session_title_suggestion: titleSuggestion}
|
||||
return newMessageData;
|
||||
},
|
||||
autocompleteCallback: (menu, alias, parameters) => [game.chatCommands.createInfoElement("Enter a message.")],
|
||||
closeOnComplete: true
|
||||
});
|
||||
|
||||
game.chatCommands.unregister(NAME+"s")
|
||||
game.chatCommands.register({
|
||||
name: NAME+"s",
|
||||
module: "_chatcommands",
|
||||
aliases: ["/ts"],
|
||||
description: "List all titles for the most recent episode",
|
||||
icon: '<i class="fa-solid fa-podcast"></i>',
|
||||
requiredRole: "GAMEMASTER",
|
||||
callback: async (chat, parameters, messageData) => {
|
||||
const newMessageData = {}
|
||||
const suggestions = game.messages.filter(m => {
|
||||
return m.flags.session_title_suggestion
|
||||
})
|
||||
|
||||
const last_message_date = new Date(suggestions[suggestions.length-1].timestamp)
|
||||
const filtered_suggestions = suggestions.filter(m=>{
|
||||
const message_date = new Date(m.timestamp)
|
||||
return message_date.toDateString() == last_message_date.toDateString()
|
||||
})
|
||||
newMessageData.content = await renderTemplate(TEMPLATES.suggestionList.content, {messages:filtered_suggestions })
|
||||
newMessageData.flavor = await renderTemplate(TEMPLATES.suggestionList.flavor, {date:last_message_date.toDateString()})
|
||||
return newMessageData;
|
||||
},
|
||||
autocompleteCallback: (menu, alias, parameters) => [game.chatCommands.createInfoElement("Enter a message.")],
|
||||
closeOnComplete: true
|
||||
});
|
||||
}
|
||||
|
||||
console.log("Hello World! This code runs immediately when the file is loaded.");
|
||||
|
||||
Hooks.on("init", function() {
|
||||
//This code runs once the Foundry VTT software begins its initialization workflow
|
||||
registerCustomChatCommands();
|
||||
registerClipboardCopyButton();
|
||||
loadTemplates(flavor_template_path)
|
||||
Object.values(TEMPLATES.suggestion).forEach((template_path)=>{
|
||||
loadTemplates(template_path)
|
||||
}
|
||||
)
|
||||
Object.values(TEMPLATES.suggestionList).forEach((template_path)=>{
|
||||
loadTemplates(template_path)
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
Hooks.on("ready", function() {
|
||||
//This code runs once core initialization is ready and game data is available.
|
||||
});
|
||||
1
src/templates/suggestion-content.hbs
Normal file
1
src/templates/suggestion-content.hbs
Normal file
@@ -0,0 +1 @@
|
||||
<blockquote>{{content}}</blockquote>
|
||||
1
src/templates/suggestion-flavor.hbs
Normal file
1
src/templates/suggestion-flavor.hbs
Normal file
@@ -0,0 +1 @@
|
||||
<i class="fa-solid fa-podcast"></i> suggesting an session title...
|
||||
3
src/templates/suggestion-list-content.hbs
Normal file
3
src/templates/suggestion-list-content.hbs
Normal file
@@ -0,0 +1,3 @@
|
||||
<ul>{{~#each messages ~}}
|
||||
<li><a class="fa-regular fa-clipboard clipboard" style="padding-left:.5em;padding-right:.5em;" data-clipboard-text="{{this.flags.session_title_suggestion}}"></a><i>"{{this.flags.session_title_suggestion}}"</i> - {{this.user?.name}}</li>
|
||||
{{~/each~}}</ul>
|
||||
1
src/templates/suggestion-list-flavor.hbs
Normal file
1
src/templates/suggestion-list-flavor.hbs
Normal file
@@ -0,0 +1 @@
|
||||
<i class="fa-solid fa-podcast"></i> title suggestions ({{date}}):
|
||||
Reference in New Issue
Block a user