112 lines
3.9 KiB
JavaScript
112 lines
3.9 KiB
JavaScript
// старый способ добавить итем персонажу
|
||
//
|
||
// const compendiumPackName = 'pf2e.feature-effects';
|
||
// const effectName = 'Effect: Rage';
|
||
|
||
// const actor = game.user.character;
|
||
|
||
// await pack.getEntry(effectId).then(effect => actor.createOwnedItem(effect) );
|
||
|
||
// get item from compendium to actor
|
||
async function getItemFromCompendium (itemName){
|
||
const pack = game.packs.get("sc-items.sc-items");
|
||
await pack.getIndex();
|
||
const itemId = pack.index.find(e => e.name === itemName)._id;
|
||
item = [await pack.getDocument(itemId)]
|
||
await actor.createEmbeddedDocuments("Item", item)
|
||
}
|
||
|
||
// проверить что у игрока есть персонаж
|
||
if (game.user.character == null){
|
||
ui.notifications.warn('Игроку не назначен персонаж');
|
||
return
|
||
}
|
||
|
||
let compendium = (Array.from(game.packs)).filter(element => element.metadata.name == 'sc-items')
|
||
compendiumData = Array.from(compendium[0].index)
|
||
compendiumData.find(element => element.name == 'Рапира/Rapier')
|
||
|
||
// найти объект по имени
|
||
function findItem(itemName, compendium) {
|
||
let compendiumData = (Array.from(game.packs)).filter(element => element.metadata.name == compendium)
|
||
compArray = Array.from(compendiumData[0].index)
|
||
return compArray.find(element => element.name == itemName)
|
||
}
|
||
|
||
// получить класс персонажа
|
||
// от класса выбрать варианты стартового снаряжения
|
||
// передать выбранное снаряжение персонажу
|
||
let a = `
|
||
<html lang="en">
|
||
<form>
|
||
<fieldset>
|
||
<legend>
|
||
Select items
|
||
</legend>
|
||
<fieldset>
|
||
<legend>
|
||
Legend2
|
||
</legend>
|
||
<div>
|
||
<ul>
|
||
<li><input type="radio" id="choise1" name="set1" value="Длинный меч/Longsword">Длинный меч/Longsword</li>
|
||
<li><input type="radio" id="choise2" name="set1" value="Рапира/Rapier">Рапира/Rapier</li>
|
||
</ul>
|
||
</div>
|
||
</fieldset>
|
||
<fieldset>
|
||
<legend>
|
||
Legend3
|
||
</legend>
|
||
<div>
|
||
<ul>
|
||
<li><input type="radio" id="choise1" name="set2" value="Набор дипломата/Diplomat's Pack">Набор дипломата</li>
|
||
<li><input type="radio" id="choise2" name="set2" value="Набор артиста/Entertainer's Pack">Набор артиста</li>
|
||
</ul>
|
||
</div>
|
||
</fieldset>
|
||
</div>
|
||
</fieldset>
|
||
<input type="submit" id="button">
|
||
</form>
|
||
</html>
|
||
`
|
||
|
||
new Dialog({
|
||
title: "Test Dialog",
|
||
// content: a,
|
||
template: "./templates/bard.html"
|
||
buttons: {
|
||
one: {
|
||
icon: '<i class="fas fa-check"></i>',
|
||
label: "Option One",
|
||
callback: (html) => myCallback(html)
|
||
}
|
||
}
|
||
}
|
||
).render(true);
|
||
|
||
function myCallback(html) {
|
||
// let radios = document.querySelectorAll('input[type="radio"]');
|
||
let radios = html.find('input[type="radio"]');
|
||
// let button = document.querySelector('#button');
|
||
for (let radio of radios) {
|
||
if (radio.checked) {
|
||
console.log(radio.value);
|
||
// item = findItem(radio.value, "sc-items")
|
||
// if (item == null || item == undefined){
|
||
// ui.notifications.warn(`Предмет `+radio.value+`не найден в библиотеке`);
|
||
// return
|
||
// }
|
||
getItemFromCompendium(radio.value)
|
||
// console.log(item);
|
||
}
|
||
}
|
||
// const value = html.find("input#choise1").val();
|
||
// const array1 = [html.find('input[type="radio"]:checked').val()];
|
||
// const value = html.find('input[type="radio"]:checked').val();
|
||
// ui.notifications.info(`Value: ${value}`);
|
||
// console.log(value)
|
||
// console.log(array1)
|
||
// return value
|
||
} |