Skip to content

Commit

Permalink
Merge pull request #1873 from richranallo/velvet-generation-support
Browse files Browse the repository at this point in the history
initial commit of Velvet Generation support script
  • Loading branch information
Alicekb authored Dec 4, 2023
2 parents 6fe9447 + 5be5da3 commit 22472b6
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Velvet Generation/script.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "VelvetGeneration",
"script": "vg.js",
"version": "0.1",
"description": "This is a set of API helpers for Velvet Generation.\n* It automatically sets all d6 dice dragged from chat onto the table to be controlled by all players.\n* It enables the `!amped` command, which rerolls all 1s in a selection\n* It enables the `onFire|*` command, which sets all 1s in a selection to the number indicated by *.",
"authors": "Rich Ranallo",
"roll20userid": "104025",
"patreon": "https://www.patreon.com/shdwjk",
"useroptions": [
{
"name": "Players can use --ids",
"type": "checkbox",
"description": "Select this option to allow players to use the `--ids` parameter to specify tokens they don't control to be modified.",
"value": "playersCanIDs"
}
],
"dependencies": [],
"modifies": {},
"conflicts": [],
"previousversions": []
}
77 changes: 77 additions & 0 deletions Velvet Generation/vg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

on('ready',()=>{
// applies a given effect to a single token
function dieEffect(dieToken, effect) {
let dieProps = {
left: dieToken.get('left'),
top: dieToken.get('top')
}
spawnFx(dieProps.left, dieProps.top, effect);
}

// sets a die token to a given value
function setDieValue(dieToken, value) {
const boundedVal = Math.min(Math.max(value,0),5)
const sides = dieToken.get('sides').replaceAll('%3A', ':').replaceAll('%3F', '?').split('|')
const sideImg = sides[boundedVal]
dieToken.set({
imgsrc: sideImg,
currentSide: boundedVal
})
}

// regex statements used to match commands
const ampedRegex = new RegExp(/^!amped/)
const onFireRegex = new RegExp(/^!onFire\|/)
const digitRegex = new RegExp(/(?<=\|)\d/)

//images used for sides of a d6
const d6Sides = [
'images/779533',
'images/779535',
'images/779534',
'images/779531',
'images/779532',
'images/779536'
]
// recognizes d6s dragged from the chat window onto the tabletop and sets them to be controlled by all players
on('add:token', tok=>{
log(tok)
if(_.every(d6Sides, side => {
log(side)
log(tok.get('sides'))
return tok.get('sides').includes(side)
})) {
tok.set('controlledby', 'all')
}
})

//powers !amped and !onFire|* statements.
//!amped rerolls all 1s in the selected dice
//!onFire|* sets all 1s in the selection to the value inidcated by *
//both apply a visual effect to the dice
on("chat:message", msg => {
if(msg.type === 'api' && msg.selected){
msg.selected.forEach(die =>{
if (die._type === 'graphic') {
let dieToken = getObj('graphic', die._id)
if(dieToken.get('currentSide')===0){
if(msg.content.match(ampedRegex)){
dieEffect(dieToken, 'explode-charm')
const newValue = Math.floor(Math.random() * 6)
setDieValue(dieToken, newValue)
}
if(msg.content.match(onFireRegex)){
const requestedValue = msg.content.match(digitRegex)
if(requestedValue && requestedValue[0]) {
setDieValue(dieToken, parseInt(requestedValue)-1)
dieEffect(dieToken, 'burst-fire')
}
}
}
}
})
}
})

})

0 comments on commit 22472b6

Please sign in to comment.