Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit of Velvet Generation support script #1873

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
}
}
}
}
})
}
})

})
Loading