Last active
March 19, 2023 15:31
-
-
Save thebwt/e87e1a5ee4d27fb2411c85f146008dab to your computer and use it in GitHub Desktop.
symbaroum foundryvtt clipboard import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
// Parse JSON from clipboard | |
const clipboardText = await navigator.clipboard.readText(); | |
const inputData = JSON.parse(clipboardText); | |
// Check if the "GPTImport" folder exists, if not, create it | |
let folder = game.folders.find( | |
(folder) => folder.data.name === "GPTImport" && folder.data.type === "Actor" | |
); | |
if (!folder) { | |
folder = await Folder.create({ | |
name: "GPTImport", | |
type: "Actor", | |
parent: null, | |
}); | |
} | |
// Create a new actor and set its attributes | |
const actorData = { | |
name: inputData.name, | |
type: "monster", // or another type based on the Symbaroum system | |
folder: folder.id, | |
data: { | |
attributes: { | |
accurate: { value: inputData.attributes.accurate }, | |
cunning: { value: inputData.attributes.cunning }, | |
discreet: { value: inputData.attributes.discreet }, | |
persuasive: { value: inputData.attributes.persuasive }, | |
quick: { value: inputData.attributes.quick }, | |
resolute: { value: inputData.attributes.resolute }, | |
strong: { value: inputData.attributes.strong }, | |
vigilant: { value: inputData.attributes.vigilant }, | |
}, | |
}, | |
}; | |
const newActor = await Actor.create(actorData); | |
// Loop through abilities and add them to the actor | |
for (const abilityData of inputData.abilities) { | |
const abilityName = abilityData.name; | |
const abilityTier = abilityData.tier; | |
// Find the ability item in the game items | |
let abilityItem = | |
await game.items.filter( | |
(item) => | |
item.name.trim().toLowerCase() === abilityName.trim().toLowerCase() | |
)[0] | |
if (abilityItem) { | |
abilityItem = duplicate(abilityItem); | |
} | |
if (abilityItem) { | |
// Set the ability tier based on the input value (0-3) | |
abilityItem.system.novice.isActive = abilityTier >= 1; | |
abilityItem.system.adept.isActive = abilityTier >= 2; | |
abilityItem.system.master.isActive = abilityTier >= 3; | |
await newActor.createEmbeddedDocuments("Item", [abilityItem]); | |
} else { | |
ui.notifications.error( | |
`Could not find ability ${abilityName} in the game items.` | |
); | |
abilityItem = { | |
name: abilityName, | |
type: "ability", // Set the appropriate type for abilities | |
system: { | |
novice: { | |
isActive: abilityTier >= 1, | |
action: "A", | |
}, | |
adept: { | |
isActive: abilityTier >= 2, | |
action: "A", | |
}, | |
master: { | |
isActive: abilityTier >= 3, | |
action: "A", | |
}, | |
} | |
}; | |
await newActor.createEmbeddedDocuments("Item", [abilityItem]); | |
} | |
} | |
// Loop through weapons and add them to the actor | |
for (const weaponName of inputData.weapons) { | |
console.log("looking for... " + weaponName); | |
let weaponItem = await game.items.filter( | |
(item) => | |
item.name.trim().toLowerCase() === weaponName.trim().toLowerCase() | |
)[0]; | |
if (weaponItem) { | |
weaponItem = duplicate(weaponItem); | |
} | |
if (!weaponItem) { | |
// Create a new weapon item with the given name and leave it blank | |
weaponItem = { | |
name: weaponName, | |
type: "weapon", // Set the appropriate type for weapons | |
}; | |
} | |
await newActor.createEmbeddedDocuments("Item", [weaponItem]); | |
} | |
// Loop through armor and add them to the actor | |
for (const armorName of inputData.armor) { | |
let armorItem = await game.items.filter( | |
(item) => | |
item.name.trim().toLowerCase() === armorName.trim().toLowerCase() | |
)[0]; | |
if (armorItem) { | |
armorItem = duplicate(armorItem); | |
} | |
if (!armorItem) { | |
// Create a new armor item with the given name and leave it blank | |
armorItem = { | |
name: armorName, | |
type: "armor", // Set the appropriate type for armor | |
}; | |
} | |
await newActor.createEmbeddedDocuments("Item", [armorItem]); | |
} | |
ui.notifications.info( | |
`Actor ${inputData.name} successfully imported into the GPTImport folder.` | |
); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment