// Github: https://github.com/shdwjk/Roll20API/blob/master/PeekCard/PeekCard.js // By: The Aaron, Arcane Scriptomancer // Contact: https://app.roll20.net/users/104025/the-aaron const PeekCard = (() => { // eslint-disable-line no-unused-vars const version = '0.1.0'; const lastUpdate = 1546387606; const schemaVersion = 0.1; const css = { msg: "border:1px solid #999;border-radius:1em;background-color:white;padding:.5em;", clear: "clear:both;", outer: "margin:.25em;float:left;", img: "width:100%;height:100%;min-width:0;min-height:0; max-width:1000em;max-height:1000em;", hidden: "box-shadow: 0 0 8px 2px #999;background-color:#999;", visible: "" }; const playedCards = {}; const cardPlayers = {}; const checkInstall = () => { log('-=> PeekCard v'+version+' <=- ['+(new Date(lastUpdate*1000))+']'); if( ! state.hasOwnProperty('PeekCard') || state.PeekCard.version !== schemaVersion) { log(` > Updating Schema to v${schemaVersion} <`); state.PeekCard = { version: schemaVersion, config: { imgScale: 25 } }; } }; const esRE = function (s) { const escapeForRegexp = /(\\|\/|\[|\]|\(|\)|\{|\}|\?|\+|\*|\||\.|\^|\$)/g; return s.replace(escapeForRegexp,"\\$1"); }; const HE = (() => { const entities={ '&' : '&'+'amp'+';', '<' : '&'+'lt'+';', '>' : '&'+'gt'+';', "'" : '&'+'#39'+';', '@' : '&'+'#64'+';', '{' : '&'+'#123'+';', '|' : '&'+'#124'+';', '}' : '&'+'#125'+';', '[' : '&'+'#91'+';', ']' : '&'+'#93'+';', '"' : '&'+'quot'+';' }; const re=new RegExp(`(${Object.keys(entities).map(esRE).join('|')})`,'g'); return (s) => s.replace(re, (c) => (entities[c] || c) ); })(); const ch = (c) => { const entities = { '<' : 'lt', '>' : 'gt', "'" : '#39', '@' : '#64', '{' : '#123', '|' : '#124', '}' : '#125', '[' : '#91', ']' : '#93', '"' : 'quot', '*' : 'ast', '/' : 'sol', ' ' : 'nbsp' }; if( entities.hasOwnProperty(c) ){ return `&${entities[c]};`; } return ''; }; const _h = { outer: (...o) => `
${o.join(' ')}
`, group: (...o) => `${o.join(' ')}`, items: (o) => `${o.join(' ')}`,
attr: {
bare: (o)=>`${ch('@')}${ch('{')}${o}${ch('}')}`,
selected: (o)=>`${ch('@')}${ch('{')}selected${ch('|')}${o}${ch('}')}`,
target: (o)=>`${ch('@')}${ch('{')}target${ch('|')}${o}${ch('}')}`,
char: (o,c)=>`${ch('@')}${ch('{')}${c||'CHARACTER NAME'}${ch('|')}${o}${ch('}')}`
},
bold: (...o) => `${o.join(' ')}`,
italic: (...o) => `${o.join(' ')}`,
font: {
command: (...o)=>`${o.join(' ')}`
}
};
const showHelp = (who) => {
sendChat('',`/w "${who}" `+
_h.outer(
_h.title('PeekCard', version),
_h.header(
_h.paragraph(`PeekCard lets you look at the cards you${ch("'")}ve played face down without needing to pick them up.`)
),
_h.subhead('Commands'),
_h.inset(
_h.font.command(
`!peek-card`,
_h.optional(
`--help`,
`TOKEN_ID ...`
)
),
_h.paragraph( 'Whispers you the cards you have selected that you played (or that you can see).'),
_h.ul(
`${_h.bold('--help')} -- Shows the Help screen.`,
`${_h.bold('TOKEN_ID ...')} -- Optionally provide a list of token ids to show you.`
)
),
_h.subhead('Description'),
_h.inset(
_h.paragraph('Executing the !peek-card command when you have cards selected will show you the hidden side if you played them. You can also select any cards that are face up, regardless of who played them, to get a better look. Hovering over the resulting image will show a large version of the card.')
)
)
);
};
const makeTip = (img,w,h) => HE(` `);
const showCard = (c) => {
const img =decodeURIComponent(c.get('sides').split(/\|/)[0]);
return `