Working on 0.8.x
-dot separator in settings -mergeObject ns -added a option to enable/disable custom techs -removed "foundry-pc-types" as it was absolutely obsolete -fixed some roll errors (_rolled -> _evaluated)
This commit is contained in:
@@ -46,7 +46,7 @@ export class DicePickerDialog extends FormApplication {
|
||||
* @override
|
||||
*/
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
id: "l5r5e-dice-picker-dialog",
|
||||
classes: ["l5r5e", "dice-picker-dialog"],
|
||||
template: CONFIG.l5r5e.paths.templates + "dice/dice-picker-dialog.html",
|
||||
@@ -131,7 +131,7 @@ export class DicePickerDialog extends FormApplication {
|
||||
if (options.difficulty) {
|
||||
this.difficulty = options.difficulty;
|
||||
} else {
|
||||
this.difficulty = game.settings.get("l5r5e", "initiative.difficulty.value");
|
||||
this.difficulty = game.settings.get("l5r5e", "initiative-difficulty-value");
|
||||
}
|
||||
|
||||
// DifficultyHidden
|
||||
@@ -145,7 +145,7 @@ export class DicePickerDialog extends FormApplication {
|
||||
* Refresh data (used from socket)
|
||||
*/
|
||||
async refresh() {
|
||||
this.difficulty = game.settings.get("l5r5e", "initiative.difficulty.value");
|
||||
this.difficulty = game.settings.get("l5r5e", "initiative-difficulty-value");
|
||||
this.difficultyHidden = false;
|
||||
this.render(false);
|
||||
}
|
||||
@@ -244,7 +244,7 @@ export class DicePickerDialog extends FormApplication {
|
||||
*/
|
||||
set difficultyHidden(isHidden) {
|
||||
// If GM hide, then player choice don't matter
|
||||
this._difficultyHiddenIsLock = game.settings.get("l5r5e", "initiative.difficulty.hidden");
|
||||
this._difficultyHiddenIsLock = game.settings.get("l5r5e", "initiative-difficulty-hidden");
|
||||
if (this._difficultyHiddenIsLock) {
|
||||
isHidden = true;
|
||||
}
|
||||
@@ -390,7 +390,7 @@ export class DicePickerDialog extends FormApplication {
|
||||
|
||||
// If initiative roll, check if player already have
|
||||
if (this.object.isInitiativeRoll) {
|
||||
const combatant = game.combat.combatants.find((c) => c.actor._id === this._actor._id && c.initiative > 0);
|
||||
const combatant = game.combat.combatants.find((c) => c.actor.id === this._actor.id && c.initiative > 0);
|
||||
if (combatant) {
|
||||
ui.notifications.error(game.i18n.localize("l5r5e.conflict.initiative.already_set"));
|
||||
return this.close();
|
||||
@@ -470,7 +470,7 @@ export class DicePickerDialog extends FormApplication {
|
||||
}
|
||||
|
||||
if (message) {
|
||||
new game.l5r5e.RollnKeepDialog(message._id).render(true);
|
||||
new game.l5r5e.RollnKeepDialog(message.id).render(true);
|
||||
}
|
||||
|
||||
return this.close();
|
||||
@@ -508,8 +508,8 @@ export class DicePickerDialog extends FormApplication {
|
||||
const params = {};
|
||||
let name = "DicePicker";
|
||||
|
||||
if (this._actor?._id) {
|
||||
params.actorId = this._actor._id;
|
||||
if (this._actor?.id) {
|
||||
params.actorId = this._actor.id;
|
||||
name = this._actor.name;
|
||||
}
|
||||
|
||||
@@ -536,7 +536,7 @@ export class DicePickerDialog extends FormApplication {
|
||||
}
|
||||
|
||||
// Search if already in player hotbar
|
||||
if (Object.values(game.user.data.hotbar).includes(macro._id)) {
|
||||
if (Object.values(game.user.data.hotbar).includes(macro.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export class GmToolsDialog extends FormApplication {
|
||||
static get defaultOptions() {
|
||||
const x = $(window).width();
|
||||
const y = $(window).height();
|
||||
return mergeObject(super.defaultOptions, {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
id: "l5r5e-gm-tools-dialog",
|
||||
classes: ["l5r5e", "gm-tools-dialog"],
|
||||
template: CONFIG.l5r5e.paths.templates + "dice/gm-tools-dialog.html",
|
||||
@@ -54,8 +54,8 @@ export class GmToolsDialog extends FormApplication {
|
||||
*/
|
||||
_initialize() {
|
||||
this.object = {
|
||||
difficulty: game.settings.get("l5r5e", "initiative.difficulty.value"),
|
||||
difficultyHidden: game.settings.get("l5r5e", "initiative.difficulty.hidden"),
|
||||
difficulty: game.settings.get("l5r5e", "initiative-difficulty-value"),
|
||||
difficultyHidden: game.settings.get("l5r5e", "initiative-difficulty-hidden"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ export class GmToolsDialog extends FormApplication {
|
||||
event.stopPropagation();
|
||||
this.object.difficultyHidden = !this.object.difficultyHidden;
|
||||
game.settings
|
||||
.set("l5r5e", "initiative.difficulty.hidden", this.object.difficultyHidden)
|
||||
.set("l5r5e", "initiative-difficulty-hidden", this.object.difficultyHidden)
|
||||
.then(() => this.submit());
|
||||
});
|
||||
|
||||
@@ -148,7 +148,7 @@ export class GmToolsDialog extends FormApplication {
|
||||
this.object.difficulty = Math.max(0, this.object.difficulty - 1);
|
||||
break;
|
||||
}
|
||||
game.settings.set("l5r5e", "initiative.difficulty.value", this.object.difficulty).then(() => this.submit());
|
||||
game.settings.set("l5r5e", "initiative-difficulty-value", this.object.difficulty).then(() => this.submit());
|
||||
});
|
||||
|
||||
// Scene End & Sleep
|
||||
|
||||
@@ -45,7 +45,7 @@ export class RollnKeepDialog extends FormApplication {
|
||||
* @override
|
||||
*/
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
id: "l5r5e-roll-n-keep-dialog",
|
||||
classes: ["l5r5e", "roll-n-keep-dialog"],
|
||||
template: CONFIG.l5r5e.paths.templates + "dice/roll-n-keep-dialog.html",
|
||||
@@ -58,7 +58,7 @@ export class RollnKeepDialog extends FormApplication {
|
||||
* Define a unique and dynamic element ID for the rendered application
|
||||
*/
|
||||
get id() {
|
||||
return `l5r5e-roll-n-keep-dialog-${this._message._id}`;
|
||||
return `l5r5e-roll-n-keep-dialog-${this._message.id}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,6 +85,7 @@ export class RollnKeepDialog extends FormApplication {
|
||||
constructor(messageId, options = {}) {
|
||||
super({}, options);
|
||||
this.message = game.messages.get(messageId);
|
||||
|
||||
this.options.editable =
|
||||
this._message?.isAuthor || this._message?._roll.l5r5e.actor?.isOwner || this._message?.isOwner || false;
|
||||
|
||||
@@ -146,7 +147,7 @@ export class RollnKeepDialog extends FormApplication {
|
||||
// New
|
||||
this.object.dicesList = [[]];
|
||||
this.roll.terms.forEach((term) => {
|
||||
if (typeof term !== "object") {
|
||||
if (!(term instanceof game.l5r5e.L5rBaseDie)) {
|
||||
return;
|
||||
}
|
||||
term.results.forEach((res) => {
|
||||
@@ -514,7 +515,7 @@ export class RollnKeepDialog extends FormApplication {
|
||||
}
|
||||
|
||||
roll.terms.forEach((term) => {
|
||||
if (typeof term !== "object") {
|
||||
if (!(term instanceof game.l5r5e.L5rBaseDie)) {
|
||||
return;
|
||||
}
|
||||
term.results.forEach((res) => {
|
||||
@@ -610,7 +611,7 @@ export class RollnKeepDialog extends FormApplication {
|
||||
async _toChatMessage() {
|
||||
// Keep old Ids
|
||||
const appOldId = this.id;
|
||||
const msgOldId = this._message._id;
|
||||
const msgOldId = this._message.id;
|
||||
|
||||
if (this.roll.l5r5e.isInitiativeRoll) {
|
||||
let msgOptions = {
|
||||
@@ -633,11 +634,11 @@ export class RollnKeepDialog extends FormApplication {
|
||||
|
||||
// Refresh viewers
|
||||
if (this._message) {
|
||||
game.l5r5e.sockets.updateMessageIdAndRefresh(appOldId, this._message._id);
|
||||
game.l5r5e.sockets.updateMessageIdAndRefresh(appOldId, this._message.id);
|
||||
}
|
||||
|
||||
// Delete old chat message related to this series
|
||||
if (game.settings.get("l5r5e", "rnk.deleteOldMessage")) {
|
||||
if (game.settings.get("l5r5e", "rnk-deleteOldMessage")) {
|
||||
if (game.user.isGM) {
|
||||
const message = game.messages.get(msgOldId);
|
||||
if (message) {
|
||||
|
||||
@@ -55,8 +55,8 @@ export class RollL5r5e extends Roll {
|
||||
* Execute the Roll, replacing dice and evaluating the total result
|
||||
* @override
|
||||
**/
|
||||
evaluate({ minimize = false, maximize = false } = {}) {
|
||||
if (this._rolled) {
|
||||
evaluate({ minimize = false, maximize = false, async = false } = {}) {
|
||||
if (this._evaluated) {
|
||||
throw new Error("This Roll object has already been rolled.");
|
||||
}
|
||||
if (this.terms.length < 1) {
|
||||
@@ -64,14 +64,14 @@ export class RollL5r5e extends Roll {
|
||||
}
|
||||
|
||||
// Clean terms (trim symbols)
|
||||
this.terms = this._identifyTerms(this.constructor.cleanFormula(this.terms));
|
||||
this.terms = this.constructor.simplifyTerms(this.terms);
|
||||
|
||||
// Roll dices and inner dices
|
||||
this._total = 0;
|
||||
|
||||
// Roll
|
||||
super.evaluate({ minimize, maximize });
|
||||
this._rolled = true;
|
||||
super.evaluate({ minimize, maximize, async });
|
||||
this._evaluated = true;
|
||||
|
||||
// Save initial formula
|
||||
if (!this.l5r5e.initialFormula) {
|
||||
@@ -152,7 +152,7 @@ export class RollL5r5e extends Roll {
|
||||
* @override
|
||||
*/
|
||||
get total() {
|
||||
if (!this._rolled) {
|
||||
if (!this._evaluated) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -230,9 +230,9 @@ export class RollL5r5e extends Roll {
|
||||
* @override
|
||||
*/
|
||||
async render(chatOptions = {}) {
|
||||
chatOptions = mergeObject(
|
||||
chatOptions = foundry.utils.mergeObject(
|
||||
{
|
||||
user: game.user._id,
|
||||
user: game.user.id,
|
||||
flavor: null,
|
||||
template: CONFIG.l5r5e.paths.templates + this.constructor.CHAT_TEMPLATE,
|
||||
blind: false,
|
||||
@@ -242,7 +242,7 @@ export class RollL5r5e extends Roll {
|
||||
const isPrivate = chatOptions.isPrivate;
|
||||
|
||||
// Execute the roll, if needed
|
||||
if (!this._rolled) {
|
||||
if (!this._evaluated) {
|
||||
this.roll();
|
||||
}
|
||||
|
||||
@@ -289,30 +289,32 @@ export class RollL5r5e extends Roll {
|
||||
* This function can either create the ChatMessage directly, or return the data object that will be used to create.
|
||||
* @override
|
||||
*/
|
||||
toMessage(messageData = {}, { rollMode = null, create = true } = {}) {
|
||||
async toMessage(messageData = {}, { rollMode = null, create = true } = {}) {
|
||||
// Perform the roll, if it has not yet been rolled
|
||||
if (!this._rolled) {
|
||||
if (!this._evaluated) {
|
||||
this.evaluate();
|
||||
}
|
||||
|
||||
const rMode = rollMode || messageData.rollMode || game.settings.get("core", "rollMode");
|
||||
|
||||
let template = CONST.CHAT_MESSAGE_TYPES.ROLL;
|
||||
if (["gmroll", "blindroll"].includes(rMode)) {
|
||||
messageData.whisper = ChatMessage.getWhisperRecipients("GM");
|
||||
}
|
||||
if (rMode === "blindroll") messageData.blind = true;
|
||||
if (rMode === "selfroll") messageData.whisper = [game.user.id];
|
||||
if (rMode === "blindroll") {
|
||||
messageData.blind = true;
|
||||
}
|
||||
if (rMode === "selfroll") {
|
||||
messageData.whisper = [game.user.id];
|
||||
}
|
||||
|
||||
// Prepare chat data
|
||||
messageData = mergeObject(
|
||||
messageData = foundry.utils.mergeObject(
|
||||
{
|
||||
user: game.user._id,
|
||||
type: template,
|
||||
user: game.user.id,
|
||||
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
|
||||
content: this._total,
|
||||
sound: CONFIG.sounds.dice,
|
||||
speaker: {
|
||||
actor: this.l5r5e.actor?._id || null,
|
||||
actor: this.l5r5e.actor?.id || null,
|
||||
token: this.l5r5e.actor?.token || null,
|
||||
alias: this.l5r5e.actor?.name || null,
|
||||
},
|
||||
@@ -321,11 +323,11 @@ export class RollL5r5e extends Roll {
|
||||
);
|
||||
messageData.roll = this;
|
||||
|
||||
// Prepare message options
|
||||
const messageOptions = { rollMode: rMode };
|
||||
// TODO Bug on non link pnj : infinity deepClone recursion
|
||||
|
||||
// Either create the message or just return the chat data
|
||||
return create ? CONFIG.ChatMessage.entityClass.create(messageData, messageOptions) : messageData;
|
||||
const message = await ChatMessage.implementation.create(messageData, { rollMode: rMode, temporary: !create });
|
||||
return create ? message : message.data;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
@@ -365,7 +367,7 @@ export class RollL5r5e extends Roll {
|
||||
// lightweight the Actor
|
||||
if (json.l5r5e.actor) {
|
||||
json.l5r5e.actor = {
|
||||
id: json.l5r5e.actor._id,
|
||||
id: json.l5r5e.actor._id, // method "id" not exist in json, need to use "_id" here
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user