Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
start re-developing
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Feb 11, 2023
1 parent 9766d58 commit 3204697
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"confirmationDialogTitle": "Drop Mount Up!",
"confirmationDialogChoiceYes": "Yes",
"confirmationDialogChoiceNo": "No",
"isNotAMount": "The token '{mount}' is not checked as mount on the token configuration",
"tokenConfig": {
"isamount": {
"name": "Is a Mount ?",
Expand Down
25 changes: 17 additions & 8 deletions src/scripts/lib/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import CONSTANTS from "../constants";
import { SettingsForm } from "../settings-form";
import { MountUpFlags } from "../utils";
import { injectConfig } from "./injectConfig";
import { info, warn } from "./lib";

/**
* Handler called when token configuration window is opened. Injects custom form html and deals
Expand All @@ -13,15 +14,23 @@ import { injectConfig } from "./injectConfig";
* @param {JQuery} html
*/
export async function renderTokenConfigHandler(app, html, data) {
// if (!game.user?.isGM) {
// info('Only GM can edit the Mount Up Token Configuration');
// return;
// }
if (app.object.flags["token-attacher"]?.parent) {
warn("Detach token before editing token config.", true);
return;
}
const objectOri = app.object;
let object = objectOri;
// MOD 4535992
let noActorDataFlagsOnToken = false;
//@ts-ignore
// if (objectOri instanceof TokenDocument && objectOri.actorData) {
// //@ts-ignore
// object = objectOri.actorData;
// }
if (objectOri instanceof TokenDocument && objectOri.actorData) {
//@ts-ignore
object = objectOri.actorData;
}
if (!hasProperty(object, "flags")) {
object.flags = {};
noActorDataFlagsOnToken = true;
Expand All @@ -47,13 +56,13 @@ export async function renderTokenConfigHandler(app, html, data) {
type: "checkbox",
label: game.i18n.localize(`${CONSTANTS.MODULE_NAME}.tokenConfig.${MountUpFlags.IsAMount}.name`),
notes: game.i18n.localize(`${CONSTANTS.MODULE_NAME}.tokenConfig.${MountUpFlags.IsAMount}.hint`),
default: object?.flags?.[CONSTANTS.MODULE_NAME][MountUpFlags.IsAMount] ?? false,
default: object?.flags[CONSTANTS.MODULE_NAME][MountUpFlags.IsAMount] ?? false,
},
[MountUpFlags.LockRider]: {
type: "checkbox",
label: game.i18n.localize(`${CONSTANTS.MODULE_NAME}.tokenConfig.${MountUpFlags.LockRider}.name`),
notes: game.i18n.localize(`${CONSTANTS.MODULE_NAME}.tokenConfig.${MountUpFlags.LockRider}.hint`),
default: object?.flags?.[CONSTANTS.MODULE_NAME][MountUpFlags.LockRider] ?? false,
default: object?.flags[CONSTANTS.MODULE_NAME][MountUpFlags.LockRider] ?? false,
},
[MountUpFlags.IconHud]: {
type: "select",
Expand All @@ -68,7 +77,7 @@ export async function renderTokenConfigHandler(app, html, data) {
5: "Handshake",
},
default:
object?.flags?.[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
object?.flags[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
game.settings.get(CONSTANTS.MODULE_NAME, "icon"),
},
};
Expand Down Expand Up @@ -97,7 +106,7 @@ export async function renderTokenConfigHandler(app, html, data) {
if (tokenConfig.options.sheetConfig) {
isAMount = tokenConfig.object.getFlag(CONSTANTS.MODULE_NAME, MountUpFlags.IsAMount) ? "checked" : "";
} else {
isAMount = tokenConfig.token.flags?.[CONSTANTS.MODULE_NAME][MountUpFlags.IsAMount] ? "checked" : "";
isAMount = tokenConfig.token.actor.flags[CONSTANTS.MODULE_NAME][MountUpFlags.IsAMount] ? "checked" : "";
}
let data = {
Expand Down
28 changes: 14 additions & 14 deletions src/scripts/lib/injectConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ export var injectConfig = {
inject: function injectConfig(app, html, data, objectOri) {
this._generateTabStruct(app, html, data, objectOri);
const tabSize = data.tab?.width ?? 100;
let object = objectOri || app.object;
// let object = objectOri || app.object;
// MOD 4535992
// objectOri = objectOri || app.object;
// let object = objectOri;
// //@ts-ignore
// if (objectOri instanceof TokenDocument && objectOri.actorData) {
// //@ts-ignore
// object = objectOri.actorData;
// }
objectOri = objectOri || app.object;
let object = objectOri;
//@ts-ignore
if (objectOri instanceof TokenDocument && objectOri.actorData) {
//@ts-ignore
object = objectOri.actorData;
}
// END MOD 4535992
const moduleId = data.moduleId;
let injectPoint;
Expand All @@ -37,13 +37,13 @@ export var injectConfig = {
const elemData = data[k];
let flag = "flags." + moduleId + "." + (k || "");
// MOD 4535992
// //@ts-ignore
// if (objectOri instanceof TokenDocument && objectOri.actorData) {
// flag = "actorData.flags." + moduleId + "." + (k || "");
// }
// const flagValue = object?.flags[moduleId][k] ?? elemData.default ?? getDefaultFlag(k);
//@ts-ignore
if (objectOri instanceof TokenDocument && objectOri.actorData) {
flag = "actorData.flags." + moduleId + "." + (k || "");
}
const flagValue = object?.flags[moduleId][k] ?? elemData.default ?? getDefaultFlag(k);
// END MOD 4535992
const flagValue = object?.getFlag(moduleId, k) ?? elemData.default ?? getDefaultFlag(k);
// const flagValue = object?.getFlag(moduleId, k) ?? elemData.default ?? getDefaultFlag(k);
const notes = v.notes ? `<p class="notes">${v.notes}</p>` : "";
v.label = v.units ? v.label + `<span class="units"> (${v.units})</span>` : v.label;
switch (elemData.type) {
Expand Down
21 changes: 10 additions & 11 deletions src/scripts/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { MountupEffectDefinitions } from "../mountup-effect-definition";
import { mountUpTA } from "../tokenAttacherHelper";
import { ActiveTokenMountUpData, MountUpFlags, findTokenById } from "../utils";
import { SettingsForm } from "../settings-form";
import { isEmptyObject } from "jquery";

// =============================
// Module Generic function
Expand Down Expand Up @@ -613,15 +612,15 @@ export async function renderDialogDropMountUp(
<label>${msg}</label>
</div>`;

const mount: Token = findTokenById(mountTokenId);
if (!mount) {
const mountToken: Token = findTokenById(mountTokenId);
if (!mountToken) {
warn(`No mount with reference '${mountTokenId}' is been found`, true);
return;
}

const classIconIndex =
//@ts-ignore
mount?.flags?.[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
mountToken?.actor.flags[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
game.settings.get(CONSTANTS.MODULE_NAME, "icon");
const classIcon = SettingsForm.getIconClass(classIconIndex);
const d = new Dialog({
Expand Down Expand Up @@ -649,10 +648,10 @@ export async function renderDialogDropMountUp(
d.render(true);
}

export function retrieveFlagFromToken(token: Token, key: string) {
let currentFlag = getProperty(token, `flags.${CONSTANTS.MODULE_NAME}.${key}`);
if (isEmptyObject(currentFlag) && token.actor) {
currentFlag = getProperty(token.actor, `flags.${CONSTANTS.MODULE_NAME}.${key}`);
}
return currentFlag;
}
// export function retrieveFlagFromToken(token: Token, key: string) {
// let currentFlag = getProperty(token, `flags.${CONSTANTS.MODULE_NAME}.${key}`);
// if (isEmptyObject(currentFlag) && token.actor) {
// currentFlag = getProperty(token.actor, `flags.${CONSTANTS.MODULE_NAME}.${key}`);
// }
// return currentFlag;
// }
14 changes: 7 additions & 7 deletions src/scripts/mountHud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class MountHud {

const classIconIndex =
//@ts-ignore
hudToken?.flags?.[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
hudToken?.actor?.flags[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
game.settings.get(CONSTANTS.MODULE_NAME, "icon");
const classIcon = SettingsForm.getIconClass(classIconIndex);

Expand Down Expand Up @@ -101,19 +101,19 @@ export class MountHud {
return;
}
const mountId = <string>rider.actor?.getFlag(CONSTANTS.MODULE_NAME, MountUpFlags.Mount);
const mount = findTokenById(mountId);
if (!mount) {
const mountToken = findTokenById(mountId);
if (!mountToken) {
warn(`No mount with reference '${mountId}' is been found`, true);
return;
}

const classIconIndex =
//@ts-ignore
mount?.flags?.[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
mountToken?.actor.flags[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
game.settings.get(CONSTANTS.MODULE_NAME, "icon");
const classIcon = SettingsForm.getIconClass(classIconIndex);

let button = this.buildButton(html, hudToken, `Dismount ${hudToken.name} from ${mount.name}`, classIcon);
let button = this.buildButton(html, hudToken, `Dismount ${hudToken.name} from ${mountToken.name}`, classIcon);
button = this.addSlash(button);

button.find("i").on("click", async (ev) => {
Expand Down Expand Up @@ -147,7 +147,7 @@ export class MountHud {
if (token && game.user?.isGM) {
const classIconIndex =
//@ts-ignore
hudToken?.flags?.[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
hudToken?.actor?.flags[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
game.settings.get(CONSTANTS.MODULE_NAME, "icon");
const classIcon = SettingsForm.getIconClass(classIconIndex);

Expand All @@ -170,7 +170,7 @@ export class MountHud {
}
const classIconIndex =
//@ts-ignore
hudToken?.flags?.[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
hudToken?.actor?.flags[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
game.settings.get(CONSTANTS.MODULE_NAME, "icon");
const classIcon = SettingsForm.getIconClass(classIconIndex);

Expand Down
4 changes: 3 additions & 1 deletion src/scripts/mountManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SettingsForm } from "./settings-form";
import { dismountDropAllTA, dismountDropTargetTA, mountUpTA } from "./tokenAttacherHelper";
import { findTokenById, MountUpFlags, getTokenCenter, riderLock, riderX, riderY, socketAction } from "./utils";
import { error, log, warn } from "./lib/lib";
import { error, i18nFormat, log, warn } from "./lib/lib";
import CONSTANTS from "./constants";

/**
Expand All @@ -16,9 +16,11 @@ export class MountManager {
static async mountUpHud(hudToken) {
const mountToken = <Token>canvas.tokens?.controlled.find((t) => t.id === hudToken._id);
if (!mountToken) {
warn(`Token mount is not present on the canvas`, true);
return;
}
if (!(String(mountToken.actor?.getFlag(CONSTANTS.MODULE_NAME, MountUpFlags.IsAMount)) === "true")) {
warn(i18nFormat(`${CONSTANTS.MODULE_NAME}.isNotAMount`,{mount: hudToken.name}), true);
return;
}
const tokensToCheck = canvas.tokens?.controlled || [];
Expand Down
18 changes: 9 additions & 9 deletions src/scripts/tokenAttacherHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ export const mountUpTA = async function (riderToken: Token, mountToken: Token, n
return ui.notifications?.error("Can't mount more then one token!");
}

const mount = <Token>targets[0];
const mountToken = <Token>targets[0];
const newMountCoords = {
//@ts-ignore
x: mount.x,
x: mountToken.x,
//@ts-ignore
y: mount.y,
y: mountToken.y,
//@ts-ignore
w: mount.w,
w: mountToken.w,
//@ts-ignore
h: mount.h,
h: mountToken.h,
};
const newRiderCoords = {
//@ts-ignore
Expand Down Expand Up @@ -92,13 +92,13 @@ export const mountUpTA = async function (riderToken: Token, mountToken: Token, n

let message = <string>game.settings.get(CONSTANTS.MODULE_NAME, "mount-message")
? <string>game.settings.get(CONSTANTS.MODULE_NAME, "mount-message")
: `I mount this ${mount?.name}`;
: `I mount this ${mountToken?.name}`;
message = message.replace("{rider}", riderToken.name);
message = message.replace("{mount}", <string>mount?.name);
message = message.replace("{mount}", <string>mountToken?.name);

const classIconIndex =
//@ts-ignore
mount?.flags?.[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
mountToken?.actor.flags[CONSTANTS.MODULE_NAME]?.[MountUpFlags.IconHud] ??
game.settings.get(CONSTANTS.MODULE_NAME, "icon");
const classIcon = SettingsForm.getIconClass(classIconIndex);

Expand All @@ -120,7 +120,7 @@ export const mountUpTA = async function (riderToken: Token, mountToken: Token, n
//@ts-ignore
ChatMessage.create(chatData);

await window["tokenAttacher"].attachElementToToken(riderToken, mount, true);
await window["tokenAttacher"].attachElementToToken(riderToken, mountToken, true);
const isLocked = false;
await window["tokenAttacher"].setElementsLockStatus(riderToken, isLocked, true);
const canMoveConstrained =
Expand Down

0 comments on commit 3204697

Please sign in to comment.