Skip to content

Commit

Permalink
uncommented issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ChasarooniZ committed Aug 6, 2024
1 parent ee172ff commit c354c01
Showing 1 changed file with 120 additions and 120 deletions.
240 changes: 120 additions & 120 deletions scripts/helpers/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,127 +93,127 @@ function transformData(dataArray) {
return { settings: result };
}

// export class FinisherDialog extends ApplicationV2 {
// static DEFAULT_OPTIONS = {
// id: "pf2e-rpg-numbers-actor",
// tag: "form", //use for form
// form: {
// handler: FinisherDialog.myFormHandler,
// submitOnChange: false,
// closeOnSubmit: true,
// },
// position: {
// width: 640,
// height: "auto",
// },
// window: {
// icon: "fas fa-gear", // You can now add an icon to the header
// title: "FOO.form.title",
// contentClasses: ["standard-form"],
// },
// };
// static PARTS = {
// foo: {
// template: "modules/pf2e-rpg-numbers/templates/actor-finisher.html",
// },
// footer: {
// template: "templates/generic/form-footer.hbs",
// },
// };
export class FinisherDialog extends ApplicationV2 {
static DEFAULT_OPTIONS = {
id: "pf2e-rpg-numbers-actor",
tag: "form", //use for form
form: {
handler: FinisherDialog.myFormHandler,
submitOnChange: false,
closeOnSubmit: true,
},
position: {
width: 640,
height: "auto",
},
window: {
icon: "fas fa-gear", // You can now add an icon to the header
title: "FOO.form.title",
contentClasses: ["standard-form"],
},
};
static PARTS = {
foo: {
template: "modules/pf2e-rpg-numbers/templates/actor-finisher.html",
},
footer: {
template: "templates/generic/form-footer.hbs",
},
};

// get title() {
// return `PF2e RPG #s: Actor Config`;
// }

// /**
// * Process form submission for the sheet
// * @this {MyApplication} The handler is called with the application as its bound scope
// * @param {SubmitEvent} event The originating form submission event
// * @param {HTMLFormElement} form The form element that was submitted
// * @param {FormDataExtended} formData Processed data for the submitted form
// * @returns {Promise<void>}
// */
// static async myFormHandler(_event, _form, formData) {
// // Do things with the returned FormData

// const items = [];
// const color = formData.get("color");

// for (const [key, value] of formData.entries()) {
// if (key.startsWith("predicate.")) {
// const index = key.split(".")[1];
// items[index] = items[index] || {};
// items[index].predicate = value;
// } else if (key.startsWith("onlyCrit.")) {
// const index = key.split(".")[1];
// items[index] = items[index] || {};
// items[index].onlyCrit = formData.get(key) === "on";
// } else if (key.startsWith("finisherText.")) {
// const index = key.split(".")[1];
// items[index] = items[index] || {};
// items[index].finisherText = value;
// }
// }

// const finisherData = {
// color: color,
// items: items.filter((item) => item !== null),
// };

// await this.actor.setFlag(MODULE_ID, "finisherData", finisherData);
// }
// constructor(actor, options = {}) {
// super(options);
// this.actor = actor;
// }

// static get defaultOptions() {
// return mergeObject(super.defaultOptions, {
// id: "finisher-dialog",
// title: "Finisher Settings",
// template: "modules/pf2e-rpg-numbers/templates/actor-finisher.html",
// width: 600,
// submitOnChange: false,
// closeOnSubmit: true,
// });
// }

// _prepareContext(actor) {
// const finisherData = actor.getFlag(MODULE_ID, "finisherData") || { color: "#000000", items: [] };
// return {
// color: finisherData.color,
// items: finisherData.items,
// actor,
// buttons: [{ type: "submit", icon: "fa-solid fa-save", label: "SETTINGS.Save" }],
// };
// }

// _onRender(_context, _options) {
// this.element.find(".add-row").on("click", this._onAddRow.bind(this));
// this.element.on("click", ".delete-row", this._onDeleteRow.bind(this));
// }

// _onAddRow(event) {
// const items = this.element.find(".finisher-item").length;
// const newRow = `
// <div class="form-group finisher-item">
// <input type="text" name="predicate.${items}" value="" placeholder="Predicate">
// <input type="checkbox" name="onlyCrit.${items}">
// <input type="text" name="finisherText.${items}" value="" placeholder="Finisher Text">
// <button type="button" class="delete-row">Delete</button>
// </div>
// `;
// this.element.find(".finisher-items").append(newRow);
// }

// async _onDeleteRow(event) {
// event.preventDefault();
// let r = await Dialog.confirm({title: "Delete Row of Finishing Moves", content: "Are you sure you want to delete this row?"});
// if (r) {
// event.target.closest(".finisher-item").remove();
// }
// }
// }
get title() {
return `PF2e RPG #s: Actor Config`;
}

/**
* Process form submission for the sheet
* @this {MyApplication} The handler is called with the application as its bound scope
* @param {SubmitEvent} event The originating form submission event
* @param {HTMLFormElement} form The form element that was submitted
* @param {FormDataExtended} formData Processed data for the submitted form
* @returns {Promise<void>}
*/
static async myFormHandler(_event, _form, formData) {
// Do things with the returned FormData

const items = [];
const color = formData.get("color");

for (const [key, value] of formData.entries()) {
if (key.startsWith("predicate.")) {
const index = key.split(".")[1];
items[index] = items[index] || {};
items[index].predicate = value;
} else if (key.startsWith("onlyCrit.")) {
const index = key.split(".")[1];
items[index] = items[index] || {};
items[index].onlyCrit = formData.get(key) === "on";
} else if (key.startsWith("finisherText.")) {
const index = key.split(".")[1];
items[index] = items[index] || {};
items[index].finisherText = value;
}
}

const finisherData = {
color: color,
items: items.filter((item) => item !== null),
};

await this.actor.setFlag(MODULE_ID, "finisherData", finisherData);
}
constructor(actor, options = {}) {
super(options);
this.actor = actor;
}

static get defaultOptions() {
return mergeObject(super.defaultOptions, {
id: "finisher-dialog",
title: "Finisher Settings",
template: "modules/pf2e-rpg-numbers/templates/actor-finisher.html",
width: 600,
submitOnChange: false,
closeOnSubmit: true,
});
}

_prepareContext(actor) {
const finisherData = actor.getFlag(MODULE_ID, "finisherData") || { color: "#000000", items: [] };
return {
color: finisherData.color,
items: finisherData.items,
actor,
buttons: [{ type: "submit", icon: "fa-solid fa-save", label: "SETTINGS.Save" }],
};
}

_onRender(_context, _options) {
this.element.find(".add-row").on("click", this._onAddRow.bind(this));
this.element.on("click", ".delete-row", this._onDeleteRow.bind(this));
}

_onAddRow(event) {
const items = this.element.find(".finisher-item").length;
const newRow = `
<div class="form-group finisher-item">
<input type="text" name="predicate.${items}" value="" placeholder="Predicate">
<input type="checkbox" name="onlyCrit.${items}">
<input type="text" name="finisherText.${items}" value="" placeholder="Finisher Text">
<button type="button" class="delete-row">Delete</button>
</div>
`;
this.element.find(".finisher-items").append(newRow);
}

async _onDeleteRow(event) {
event.preventDefault();
let r = await Dialog.confirm({title: "Delete Row of Finishing Moves", content: "Are you sure you want to delete this row?"});
if (r) {
event.target.closest(".finisher-item").remove();
}
}
}

// export function exportDebugInfo() {
// const settingsInfo = [...game.settings.settings.values()]
Expand Down

0 comments on commit c354c01

Please sign in to comment.