-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Now it works with renderTokenConfig in PF1 * Added a global setting to allow setting opacity of token image preview * Improved localization for english and spanish
- Loading branch information
1 parent
5241601
commit e0a7a64
Showing
7 changed files
with
130 additions
and
113 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
{ | ||
"THWildcard.Title": "Haz click aquí para mostrar opciones de imagen", | ||
"THWildcard.Fieldset": "Wildcard token por defecto", | ||
"THWildcard.DefaultDescription": "Cuando un token es soltado en el canvas con wildcard seleccionado, si el campo ha sido llenado esta imagen se seleccionara en vez de una al azar.", | ||
"THWildcard.DefaultDescription": "Cuando un token es soltado en el canvas con comodín seleccionado, si el campo ha sido llenado esta imagen se seleccionara en vez de una al azar.", | ||
"THWildcard.DefaultLabel": "Imagen por Defecto:", | ||
"THWildcard.ButtonTitle": "Buscar Archivo" | ||
"THWildcard.ButtonTitle": "Buscar Archivo", | ||
"THWildcard.DisplaySettingName": "¿Mostrar como imagen?", | ||
"THWildcard.DisplaySettingHint": "Deshabilitar para mostrar opciones de comodín como una lista de nombres de archivos en vez de previsualizar la image en el HUD.", | ||
"THWildcard.OpacitySettingName": "Opacidad de las imagenes previsualizadas", | ||
"THWildcard.OpacitySettingHint": "Configura la opacidad de las imagenes en el HUD cuando no pasas el puntero por encima de ellas." | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,127 @@ | ||
const tokenHUDWildcard = { | ||
registerSettings: () => { | ||
game.settings.register('token-hud-wildcard', 'imageDisplay', { | ||
name : 'Display as Image?', | ||
hint : 'Disable to display wildcard options as a list of their filenames', | ||
scope : 'world', | ||
config : true, | ||
type : Boolean, | ||
default : true | ||
}) | ||
} | ||
registerSettings: () => { | ||
game.settings.register('token-hud-wildcard', 'imageDisplay', { | ||
name: game.i18n.format('THWildcard.DisplaySettingName'), | ||
hint: game.i18n.format('THWildcard.DisplaySettingHint'), | ||
scope: 'world', | ||
config: true, | ||
type: Boolean, | ||
default: true | ||
}) | ||
game.settings.register("token-hud-wildcard", "imageOpacity", { | ||
name: game.i18n.format('THWildcard.OpacitySettingName'), | ||
hint: game.i18n.format('THWildcard.OpacitySettingHint'), | ||
scope: "world", | ||
config: true, | ||
range: { min: 0, max: 100, step: 1 }, | ||
type: Number, | ||
default: 50 | ||
}) | ||
} | ||
} | ||
|
||
Hooks.on('init', ()=> { | ||
Hooks.on('init', () => { | ||
tokenHUDWildcard.registerSettings() | ||
}) | ||
|
||
Hooks.on('ready', () => { | ||
const renderTokenConfig = `renderTokenConfig${game.system.id === 'pf1' ? 'PF' : ''}` | ||
Hooks.on(renderTokenConfig, WildcardDefault.render) | ||
WildcardDefault._hookPreTokenCreate() | ||
const renderTokenConfig = 'renderTokenConfig' | ||
Hooks.on(renderTokenConfig, WildcardDefault.render) | ||
WildcardDefault._hookPreTokenCreate() | ||
}) | ||
|
||
const WildcardDefault = { | ||
getDefaultImg: async (token) => { | ||
const flag = token.getFlag('token-hud-wildcard', 'default') || '' | ||
return flag | ||
}, | ||
_hookPreTokenCreate() { | ||
getDefaultImg: async (token) => { | ||
const flag = token.getFlag('token-hud-wildcard', 'default') || '' | ||
return flag | ||
}, | ||
_hookPreTokenCreate () { | ||
Hooks.on('preCreateToken', (scene, data, options, userId) => { | ||
const actor = game.actors.get(data.actorId); | ||
console.log(actor) | ||
const defaultValue = data.flags['token-hud-wildcard'] ? data.flags['token-hud-wildcard'].default : '' | ||
if (defaultValue !== '' && actor.data.token.randomImg) { | ||
setProperty(data, 'img', defaultValue); | ||
} | ||
const actor = game.actors.get(data.actorId) | ||
|
||
const defaultValue = data.flags['token-hud-wildcard'] ? data.flags['token-hud-wildcard'].default : '' | ||
if (defaultValue !== '' && actor.data.token.randomImg) { | ||
setProperty(data, 'img', defaultValue) | ||
} | ||
}) | ||
}, | ||
render: async (config, html) => { | ||
const defaultImg = await WildcardDefault.getDefaultImg(config.token) | ||
if (config.token.data._id) { | ||
return | ||
} | ||
const imageDataTab = html.find('.tab[data-tab="image"]') | ||
const checkBoxWildcard = imageDataTab.find('input[name="randomImg"]') | ||
let configField = await renderTemplate('/modules/token-hud-wildcard/templates/configField.html', { defaultImg, available: checkBoxWildcard[0].checked }) | ||
|
||
imageDataTab.append(configField) | ||
const defaultConfig = imageDataTab.find('.thwildcard-default') | ||
|
||
defaultConfig.find('button').click(event => { | ||
event.preventDefault() | ||
const input = defaultConfig.find('input')[0] | ||
console.log(input) | ||
const fp = new FilePicker({ current: input.value, field: input }) | ||
fp.browse(defaultImg) | ||
}) | ||
|
||
checkBoxWildcard.click(event => { | ||
// console.log(event.target.checked) | ||
if (event.target.checked) { | ||
defaultConfig[0].classList.add('active') | ||
} else { | ||
defaultConfig[0].classList.remove('active') | ||
} | ||
|
||
}) | ||
} | ||
render: async (config, html) => { | ||
const defaultImg = await WildcardDefault.getDefaultImg(config.token) | ||
if (config.token.data._id) { | ||
return | ||
} | ||
const imageDataTab = html.find('.tab[data-tab="image"]') | ||
const checkBoxWildcard = imageDataTab.find('input[name="randomImg"]') | ||
const configField = await renderTemplate('/modules/token-hud-wildcard/templates/configField.html', { defaultImg, available: checkBoxWildcard[0].checked }) | ||
|
||
imageDataTab.append(configField) | ||
const defaultConfig = imageDataTab.find('.thwildcard-default') | ||
|
||
defaultConfig.find('button').click(event => { | ||
event.preventDefault() | ||
const input = defaultConfig.find('input')[0] | ||
|
||
const fp = new FilePicker({ current: input.value, field: input }) | ||
fp.browse(defaultImg) | ||
}) | ||
|
||
checkBoxWildcard.click(event => { | ||
if (event.target.checked) { | ||
defaultConfig[0].classList.add('active') | ||
} else { | ||
defaultConfig[0].classList.remove('active') | ||
} | ||
}) | ||
} | ||
} | ||
|
||
Hooks.on('renderTokenHUD', async (hud, html, token) => { | ||
let actor = game.actors.get(token.actorId) | ||
let images = await actor.getTokenImages() | ||
|
||
if (images.length < 2) { | ||
return | ||
} | ||
|
||
let imageDisplay = game.settings.get('token-hud-wildcard', 'imageDisplay') | ||
let imagesParsed = images.map(im => { | ||
const split = im.split('/') | ||
return { route: im, name: split[split.length - 1], used: im === token.img } | ||
}) | ||
|
||
console.log(imagesParsed) | ||
|
||
let wildcardDisplay = await renderTemplate('/modules/token-hud-wildcard/templates/hud.html', { imagesParsed, imageDisplay }) | ||
|
||
html.find('div.right') | ||
.append(wildcardDisplay) | ||
.click((event) => { | ||
const buttonFind = html.find('.control-icon.thwildcard-selector') | ||
const cList = event.target.parentElement.classList | ||
const correctButton = cList.contains('thwildcard-selector') | ||
const active = cList.contains('active') | ||
|
||
if (correctButton && !active) { | ||
buttonFind[0].classList.add('active') | ||
html.find('.thwildcard-selector-wrap')[0].classList.add('active') | ||
|
||
html.find('.control-icon.effects')[0].classList.remove('active') | ||
html.find('.status-effects')[0].classList.remove('active') | ||
} else { | ||
buttonFind[0].classList.remove('active') | ||
html.find('.thwildcard-selector-wrap')[0].classList.remove('active') | ||
} | ||
}) | ||
|
||
const buttons = html.find('.thwildcard-button-select') | ||
|
||
buttons.map((button) => { | ||
buttons[button].addEventListener('click', function (event) { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
console.log('Click Button', event) | ||
console.log('Token', token) | ||
const controlled = canvas.tokens.controlled | ||
const index = controlled.findIndex(x => x.data._id === token._id) | ||
const tokenToChange = controlled[index] | ||
tokenToChange.update({ img: event.target.dataset.name }) | ||
}) | ||
}) | ||
const actor = game.actors.get(token.actorId) | ||
const images = await actor.getTokenImages() | ||
|
||
if (images.length < 2) { | ||
return | ||
} | ||
|
||
const imageDisplay = game.settings.get('token-hud-wildcard', 'imageDisplay') | ||
const imageOpacity = game.settings.get('token-hud-wildcard', 'imageOpacity')/100 | ||
const imagesParsed = images.map(im => { | ||
const split = im.split('/') | ||
return { route: im, name: split[split.length - 1], used: im === token.img } | ||
}) | ||
|
||
const wildcardDisplay = await renderTemplate('/modules/token-hud-wildcard/templates/hud.html', { imagesParsed, imageDisplay, imageOpacity }) | ||
|
||
html.find('div.right') | ||
.append(wildcardDisplay) | ||
.click((event) => { | ||
const buttonFind = html.find('.control-icon.thwildcard-selector') | ||
const cList = event.target.parentElement.classList | ||
const correctButton = cList.contains('thwildcard-selector') | ||
const active = cList.contains('active') | ||
|
||
if (correctButton && !active) { | ||
buttonFind[0].classList.add('active') | ||
html.find('.thwildcard-selector-wrap')[0].classList.add('active') | ||
|
||
html.find('.control-icon.effects')[0].classList.remove('active') | ||
html.find('.status-effects')[0].classList.remove('active') | ||
} else { | ||
buttonFind[0].classList.remove('active') | ||
html.find('.thwildcard-selector-wrap')[0].classList.remove('active') | ||
} | ||
}) | ||
|
||
const buttons = html.find('.thwildcard-button-select') | ||
|
||
buttons.map((button) => { | ||
buttons[button].addEventListener('click', function (event) { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
const controlled = canvas.tokens.controlled | ||
const index = controlled.findIndex(x => x.data._id === token._id) | ||
const tokenToChange = controlled[index] | ||
tokenToChange.update({ img: event.target.dataset.name }) | ||
}) | ||
}) | ||
}) |
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
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