Advertisement
ineedanewgame

FVTT-CYPHER Macro to Import Artifact Item

Mar 30th, 2025 (edited)
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.92 KB | Source Code | 0 0
  1. // Function to create the artifact item
  2. async function createArtifactItem(name, description, level, folderId) {
  3.     let itemData = {
  4.         name: name, // Use the name from the dialog
  5.         type: "artifact", // Set the type to "cypher"
  6.         system: {
  7.             description: `<p>${description}</p>`, // Directly assign the description wrapped in <p> tags
  8.             level: level
  9.         },
  10.         folder: folderId,
  11.     };
  12.  
  13.     Item.create(itemData).then(item => {
  14.         ui.notifications.info(`Created item: ${item.name}`);
  15.     }).catch(err => {
  16.         console.error(err);
  17.         ui.notifications.error(`Could not create item: ${err.message}`);
  18.     });
  19. }
  20.  
  21. new Dialog({
  22.     title: "New Artifact",
  23.     content: `
  24.         <form>
  25.             <div class="form-group">
  26.                 <label>Artifact Name:</label>
  27.                 <input type="text" name="name" />
  28.             </div>
  29.             <div class="form-group">
  30.                 <label>Artifact Description:</label>
  31.                 <textarea name="description" rows="5"></textarea>
  32.             </div>
  33.             <div class="form-group">
  34.                 <label>Level:</label>
  35.                 <textarea name="level" rows="1"></textarea>
  36.             </div>
  37.         </form>
  38.     `,
  39.     buttons: {
  40.         create: {
  41.             label: "Create Artifact",
  42.             callback: html => {
  43.                 let name = html.find("[name='name']").val();
  44.                 let description = html.find("[name='description']").val();
  45.                 let level = html.find("[name='level']").val();
  46.                 const folderId = 'Usrhaxw1OYfd0nUM'; // Use the folder id
  47.                 // Create the artifact item with the provided name, description, and level
  48.                 createArtifactItem(name, description, level, folderId);
  49.             }
  50.         },
  51.         cancel: {
  52.             label: "Cancel"
  53.         }
  54.     },
  55.     default: "create"
  56. }).render(true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement