Skip to content

Commit

Permalink
Improvements to Settings
Browse files Browse the repository at this point in the history
- Changed the Indicator Icon setting to a slider.
- Fix #15
  • Loading branch information
mclemente committed Nov 21, 2021
1 parent 0c1e1cf commit 1208d1f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
6 changes: 6 additions & 0 deletions about-face.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ Hooks.on("renderSceneConfig", (app, html) => {
notes: game.i18n.localize("about-face.options.lockRotation.hint"),
default: app.object.data?.flags?.[MODULE_ID]?.lockRotation ?? game.settings.get(MODULE_ID, "lockRotation"),
},
lockArrowRotation: {
type: "checkbox",
label: game.i18n.localize("about-face.options.lockArrowRotation.name"),
notes: game.i18n.localize("about-face.options.lockArrowRotation.hint"),
default: app.object.data?.flags?.[MODULE_ID]?.lockArrowRotation ?? game.settings.get(MODULE_ID, "lockArrowRotation"),
},
};
injectConfig.inject(app, html, data, app.object);
});
Expand Down
6 changes: 5 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"hint": "Configure the About Face settings for this scene.",
"scene-enabled": {
"name": "Enable on this scene",
"hint": "Rotates tokens when moving them (except when locked). If disabled, can still hold shift to rotate in place"
"hint": "Rotates tokens when moving them (except when locked). If disabled, can still hold SHIFT to rotate in place"
}
},
"options": {
Expand All @@ -19,6 +19,10 @@
"name": "Indicator Distance",
"hint": "Set the multiplier for the indicator's distance. Math: Highest Size x (Multiplier / 2)."
},
"lockArrowRotation": {
"name": "Lock Indicator Rotation",
"hint": "The indicator won't change when the token moves. Use SHIFT + direction key to rotate the indicator."
},
"lockRotation": {
"name": "Lock Rotation",
"hint": "Every token will be created with the Lock Rotation Token Configuration toggled on."
Expand Down
4 changes: 4 additions & 0 deletions lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"name": "Distancia del Indicador",
"hint": "Defina el multiplicador para la distancia del indicador. Matemáticas: Tamaño más alto x (Multiplicador / 2)."
},
"lockArrowRotation": {
"name": "Bloquear Rotación del Indicator",
"hint": "El indicador no cambiará cuando el icono se mueve. Use SHIFT + tecla de dirección para rotar el indicador."
},
"enable-indicator.name": "Activar el indicador de orientación del icono",
"enable-indicator.hint": "Añade un indicador de la orientación actual del icono",
"enable-indicator.choices.0": "No mostrar nunca",
Expand Down
4 changes: 4 additions & 0 deletions lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"name": "Distância do Indicador",
"hint": "Define o multiplicador da distância do indicador. Matemática: Maior Tamanho x (Multiplicador / 2)."
},
"lockArrowRotation": {
"name": "Bloquear Rotação do Indicador",
"hint": "O indicador não mudará quando o token se move. Use SHIFT + tecla da direção para rotacionar o indicador."
},
"enable-indicator.name": "Habilitar indicadores de token",
"enable-indicator.hint": "Adiciona um indicador para a direção dos tokens",
"enable-indicator.choices.0": "Nunca",
Expand Down
5 changes: 2 additions & 3 deletions scripts/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ export function drawAboutFaceIndicator(wrapped, ...args) {
try {
//get the rotation of the token
let dir = this.data.flags[MODULE_ID]?.direction ?? getIndicatorDirection(this) ?? 90;
const indicatorSize = [1, 1.5][game.settings.get(MODULE_ID, "sprite-type")];
//calc distance
const r = (Math.max(this.w, this.h) / 2) * indicatorDistance;
//calc scale
const scale = Math.max(this.data.width, this.data.height) * this.data.scale * indicatorSize;
const scale = Math.max(this.data.width, this.data.height) * this.data.scale * (game.settings.get(MODULE_ID, "sprite-type") || 1);
if (!this.aboutFaceIndicator || this.aboutFaceIndicator._destroyed) {
const container = new PIXI.Container();
container.name = "aboutFaceIndicator";
Expand Down Expand Up @@ -105,7 +104,7 @@ export function onPreUpdateToken(token, updates) {
if (mirrorKey) updates[mirrorKey] = mirrorVal;
return;
}
} else if ("x" in updates || "y" in updates) {
} else if (("x" in updates || "y" in updates) && !game.settings.get(MODULE_ID, "lockArrowRotation")) {
//get previews and new positions
const prevPos = { x: token.data.x, y: token.data.y };
const newPos = { x: updates.x ?? token.data.x, y: updates.y ?? token.data.y };
Expand Down
20 changes: 15 additions & 5 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,32 @@ export function registerSettings() {
hint: "about-face.options.indicator-sprite.hint",
scope: "world",
config: true,
default: 0,
default: 1.0,
type: Number,
choices: {
0: "about-face.options.indicator-sprite.choices.normal",
1: "about-face.options.indicator-sprite.choices.large",
range: {
min: 0.5,
max: 2.0,
step: 0.05,
},
onChange: (value) => {
if (canvas == null) return;
const tokens = getAllTokens();
for (const token of tokens) {
const scale = Math.max(token.data.width, token.data.height) * token.data.scale * [1, 1.5][value];
const scale = Math.max(token.data.width, token.data.height) * token.data.scale * value;
if (token.aboutFaceIndicator) token.aboutFaceIndicator.graphics.scale.set(scale, scale);
}
},
});

game.settings.register(MODULE_ID, "lockArrowRotation", {
name: "about-face.options.lockArrowRotation.name",
hint: "about-face.options.lockArrowRotation.hint",
scope: "world",
config: true,
default: false,
type: Boolean,
});

game.settings.register(MODULE_ID, "lockRotation", {
name: "about-face.options.lockRotation.name",
hint: "about-face.options.lockRotation.hint",
Expand Down

0 comments on commit 1208d1f

Please sign in to comment.