From 4ad904b701241f18d3c5100f399afa2c87a71035 Mon Sep 17 00:00:00 2001 From: Anthony Correa Date: Wed, 19 Jun 2024 14:49:20 -0500 Subject: [PATCH] first commit --- .gitignore | 1 + src/module.json | 35 +++++++++ src/scripts/main.js | 94 +++++++++++++++++++++++ src/templates/suggestion-content.hbs | 1 + src/templates/suggestion-flavor.hbs | 1 + src/templates/suggestion-list-content.hbs | 3 + src/templates/suggestion-list-flavor.hbs | 1 + 7 files changed, 136 insertions(+) create mode 100644 .gitignore create mode 100644 src/module.json create mode 100644 src/scripts/main.js create mode 100644 src/templates/suggestion-content.hbs create mode 100644 src/templates/suggestion-flavor.hbs create mode 100644 src/templates/suggestion-list-content.hbs create mode 100644 src/templates/suggestion-list-flavor.hbs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5427ad --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +src/vendor/ \ No newline at end of file diff --git a/src/module.json b/src/module.json new file mode 100644 index 0000000..59f3d47 --- /dev/null +++ b/src/module.json @@ -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" + } + } + ] + } +} \ No newline at end of file diff --git a/src/scripts/main.js b/src/scripts/main.js new file mode 100644 index 0000000..2f6e2b0 --- /dev/null +++ b/src/scripts/main.js @@ -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: '', + 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: '', + 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. +}); \ No newline at end of file diff --git a/src/templates/suggestion-content.hbs b/src/templates/suggestion-content.hbs new file mode 100644 index 0000000..bea0280 --- /dev/null +++ b/src/templates/suggestion-content.hbs @@ -0,0 +1 @@ +
{{content}}
\ No newline at end of file diff --git a/src/templates/suggestion-flavor.hbs b/src/templates/suggestion-flavor.hbs new file mode 100644 index 0000000..8118e99 --- /dev/null +++ b/src/templates/suggestion-flavor.hbs @@ -0,0 +1 @@ + suggesting an session title... \ No newline at end of file diff --git a/src/templates/suggestion-list-content.hbs b/src/templates/suggestion-list-content.hbs new file mode 100644 index 0000000..92e5197 --- /dev/null +++ b/src/templates/suggestion-list-content.hbs @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/src/templates/suggestion-list-flavor.hbs b/src/templates/suggestion-list-flavor.hbs new file mode 100644 index 0000000..ec50acc --- /dev/null +++ b/src/templates/suggestion-list-flavor.hbs @@ -0,0 +1 @@ + title suggestions ({{date}}): \ No newline at end of file