Last active
December 17, 2024 22:55
-
-
Save revilowaldow/782cd90e153f865b4afb9b8fd8b1a142 to your computer and use it in GitHub Desktop.
Foundry Scene & Token Handling Macros
This file contains hidden or 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 () => { | |
const api = game.modules.get("plutonium").api; | |
const ipt = [ | |
["Bounty Hunter", "M"], // Replace this table | |
["NAME", "SIZE_ABV"] | |
]; | |
for (const [name, size] of ipt) { | |
const {dimensions = 1, scale = 1} = api.util.tokens.getTokenDimensionsAndScale(size); | |
await api.token.pCreateToken({ | |
name, | |
xScene: 0, | |
yScene: 0, | |
width: dimensions, | |
height: dimensions, | |
scale, | |
}); | |
} | |
})(); |
This file contains hidden or 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
let gridTypes = [ | |
"none", | |
"square", | |
"hexRowsOdd", | |
"hexRowsEven", | |
"hexColsOdd", | |
"hexColsEven" | |
]; | |
let currentScene = game.scenes.viewed; | |
let img = new Image(); | |
img.src = currentScene.background.src; | |
img.onload = function () { | |
let grid = {}; | |
if (currentScene.grid.type != 1) { grid.type = gridTypes[currentScene.grid.type] } else { grid.type = "square" }; // Default Square Grid, this way we always know if we've checked a map | |
if (currentScene.dimensions.size != 100) { grid.size = currentScene.dimensions.size }; // Default Size 100 | |
if (currentScene.background.offsetX != 0) { grid.offsetX = currentScene.background.offsetX }; // Default Offset 0 | |
if (currentScene.background.offsetY != 0) { grid.offsetY = currentScene.background.offsetY }; // Default Offset 0 | |
let scale = Math.round((currentScene.height / img.naturalHeight) * 1000) / 1000; // Get the natural height of the image and recompute the scale factor to 2dp | |
if (scale != 1) { grid.scale = scale }; // Default scaling value 1 | |
if (currentScene.grid.distance != 5) { grid.distance = currentScene.grid.distance }; // Default square size 5ft | |
if (currentScene.grid.units != "ft") { grid.units = currentScene.grid.units }; // Default square size 5ft | |
let json = "\"grid\": " + JSON.stringify(grid, null, "\t"); | |
console.log(json + "\n// Background: " + img.src) // Pretty Print to Console | |
navigator.clipboard.writeText(",\n" + json); // Copy to Clipboard | |
console.log(grid) // Log Object | |
} |
This file contains hidden or 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
// Use after right clicking a document header icon | |
console.log(fromUuidSync(await navigator.clipboard.readText())) |
This file contains hidden or 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
const drawings = game.scenes.viewed.drawings._source; | |
const drawingsReduced = []; | |
const initial = DrawingDocument.prototype.constructor._schema.initial(); | |
for (const drawing of drawings) { | |
const drawingReduced = foundry.utils.diffObject(initial, drawing, { inner: true }); | |
delete drawingReduced._id; | |
delete drawingReduced.author; | |
delete drawingReduced.strokeColor; | |
drawingsReduced.push(drawingReduced); | |
} | |
console.log(drawingsReduced); | |
navigator.clipboard.writeText(`,\n"drawings": ${JSON.stringify(drawingsReduced, null, "\t")}`); |
This file contains hidden or 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
const lights = game.scenes.viewed.lights._source; | |
const lightsReduced = []; | |
const initial = AmbientLightDocument.prototype.constructor._schema.initial(); | |
for (const light of lights) { | |
const lightReduced = foundry.utils.diffObject(initial, light, { inner: true }); | |
delete lightReduced._id; | |
lightsReduced.push(lightReduced); | |
} | |
console.log(lightsReduced); | |
navigator.clipboard.writeText(`,\n"lights": ${JSON.stringify(lightsReduced, null, "\t")}`); |
This file contains hidden or 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
const regions = game.scenes.viewed.regions._source | |
const regionsReduced = []; | |
const initial = RegionDocument.prototype.constructor._schema.initial(); | |
for (const region of regions) { | |
const regionReduced = foundry.utils.diffObject(initial, region, { inner: true }); | |
delete regionReduced._id; | |
regionsReduced.push(regionReduced); | |
} | |
console.log(regionsReduced); | |
navigator.clipboard.writeText(`,\n"regions": ${JSON.stringify(regionsReduced, null, "\t")}`); |
This file contains hidden or 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
const templates = game.scenes.viewed.templates._source; | |
const templatesReduced = []; | |
const initial = MeasuredTemplateDocument.prototype.constructor._schema.initial(); | |
for (const template of templates) { | |
const templateReduced = foundry.utils.diffObject(initial, template, { inner: true }); | |
delete templateReduced._id; | |
delete templateReduced.user; | |
templatesReduced.push(templateReduced); | |
} | |
console.log(templatesReduced); | |
navigator.clipboard.writeText(`,\n"templates": ${JSON.stringify(templatesReduced, null, "\t")}`); |
This file contains hidden or 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
const tiles = game.scenes.viewed.tiles._source; | |
const tilesReduced = []; | |
const initial = TileDocument.prototype.constructor._schema.initial(); | |
for (const tile of tiles) { | |
const tileReduced = foundry.utils.diffObject(initial, tile, { inner: true }); | |
delete tileReduced._id; | |
tilesReduced.push(tileReduced); | |
} | |
console.log(tilesReduced); | |
navigator.clipboard.writeText(`,\n"tiles": ${JSON.stringify(tilesReduced, null, "\t")}`); |
This file contains hidden or 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
const walls = game.scenes.viewed.walls._source; | |
const wallsReduced = []; | |
const initial = WallDocument.prototype.constructor._schema.initial(); | |
for (const wall of walls) { | |
const wallReduced = foundry.utils.diffObject(initial, wall, { inner: true }); | |
delete wallReduced._id; | |
wallsReduced.push(wallReduced); | |
} | |
console.log(wallsReduced); | |
navigator.clipboard.writeText(`,\n"walls": ${JSON.stringify(wallsReduced, null, "\t")}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
N.B. Typically we also wish to retain the following root scene properties: (values placeholders only)
tiles.texture.src
should be overwritten manually with remote urls