Skip to content

Commit

Permalink
Merge pull request #57 from Feu-Secret/tokenmagic-dev
Browse files Browse the repository at this point in the history
Tokenmagic Update v0.4.4-alpha
  • Loading branch information
Feu-Secret authored Oct 18, 2020
2 parents f48d8c8 + 8f5bfd4 commit 6958483
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 97 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Token Magic FX - Update v0.4.4-alpha (Mess edition PART I)

*News :*
- Integration of Mess Moerill's Supersuit(e) (for templates) part I :
- Video support in templates :
- You can set webm, mp4, etc. as video texture.
- You can define videos in the automatic spell templates options (for dd5 only).
- Texture autoresize :
- The choosen texture is resized to fit the template.
- TMFX now supports the Spanish language!

Many thanks to Lozalojo (Spanish translation) and Moerill (video) for this release!

*Fixed Issues :*
- Template effect tint was badly formatted during an automatic template creation.

# Token Magic FX - Update v0.4.3-alpha

*News :*
Expand Down
2 changes: 2 additions & 0 deletions tokenmagic/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"TMFX.settings.disableAnimations.hint": "Check this option if you want to disable FX animations. Requires a foundry reload.",
"TMFX.settings.disableCaching.name": "Disable filter caching on startup",
"TMFX.settings.disableCaching.hint": "Check this option if you want to disable filter caching on foundry startup.",
"TMFX.settings.disableVideo.name": "Disable video support in templates",
"TMFX.settings.disableVideo.hint": "Check this option if you want to disable video support and texture autoresize in templates.",
"TMFX.settings.autoTemplateEnabled.name": "Enable automatic template effects",
"TMFX.settings.autoTemplateEnabled.hint": "Disabling this option will disable all automatic template effects. NOTE: Only affects newly placed templates.",
"TMFX.settings.defaultTemplateOnHover.name": "Default template grid on hover",
Expand Down
52 changes: 52 additions & 0 deletions tokenmagic/lang/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"TMFX.TokenMagic": "TokenMagic",
"TMFX.preset.add.success": "FX añadido con éxito a la biblioteca de parámetros predeterminados.",
"TMFX.preset.add.permission.failure": "No tienes permisos para añadir el FX a la biblioteca de parámetros predeterminados.",
"TMFX.preset.add.params.failure": "El FX no ha podido ser añadido a la biblioteca de parámetros predeterminados. Parámetros incorrectos.",
"TMFX.preset.add.duplicate.failure": "El FX no ha podido ser añadido a la biblioteca de parámetros predeterminados. Ya existe un FX con el mismo nombre.",
"TMFX.preset.delete.success": "Se ha eliminado correctamente el FX de la biblioteca de parámetros predeterminados.",
"TMFX.preset.delete.permission.failure": "No tienes permisos para borrar el FX de la biblioteca de parámetros predeterminados.",
"TMFX.preset.delete.params.failure": "Fallo en la eliminación : el parámetro \"name\" debe ser un carácter.",
"TMFX.preset.delete.notfound.failure": "El FX que se quiere borrar no existe en la biblioteca de parámetros predeterminados.",
"TMFX.preset.delete.empty.failure": "Fallo : ¡ la biblioteca de parámetros predeterminados ya está vacía !",
"TMFX.preset.import.format.failure": "Importación no completada. Formato inválido.",
"TMFX.preset.import.success": "La importación de FX ha sido completada con éxito.",
"TMFX.preset.import.failure": "La importación no pudo ser completada.",
"TMFX.preset.reset.message": "¿Está seguro de que quiere reiniciar su bibloteca de parámetros predeterminados?",
"TMFX.preset.reset.success": "Su biblioteca de parámetros predeterminados ha sido reiniciada con éxito.",
"TMFX.settings.importOverwrite.name": "Sobrescribir al importar",
"TMFX.settings.importOverwrite.hint": "Marca esta opción si quieres reemplazar los parámetros predeterminados que tengan los mismos nombres al importar.",
"TMFX.template.opacity": "Opacidad Interior:",
"TMFX.template.fx": "Efectos Especiales:",
"TMFX.template.tint": "Efecto de Tono:",
"TMFX.settings.useMaxPadding.name": "FX en modo de relleno aditivo",
"TMFX.settings.useMaxPadding.hint": "Por defecto, los rellenos de FX son aditivos al aplicarlos a un determinado contenedor. Si se desmarca la casilla, se usa el relleno máximo.",
"TMFX.settings.minPadding.name": "Relleno mínimo",
"TMFX.settings.minPadding.hint": "El relleno mínimo aplicado a un FX.",
"TMFX.settings.fxPlayerPermission.name": "Modo permisivo",
"TMFX.settings.fxPlayerPermission.hint": "Si se marca esta opción, los usuarios no GM pueden añadir, modificar y borrar FX en contenedores que no son de su propiedad. El GM debe estar conectado.",
"TMFX.settings.useZOrder.name": "Ordenar FX",
"TMFX.settings.useZOrder.hint": "Marca esta opción si quieres que los efectos se apliquen en el orden de su propiedad zOrder. Se aplican primero los efectos con el zOrder menor (leer la documentación)",
"TMFX.settings.disableAnimations.name": "Deshabilitar Animaciones FX",
"TMFX.settings.disableAnimations.hint": "Marca esta opción si quieres deshabilitar las animaciones FX. Requiere que se recargue Foundry.",
"TMFX.settings.disableCaching.name": "Deshabilitar caché de filtros al inicio",
"TMFX.settings.disableCaching.hint": "Marca esta opción si quieres deshabilitar la caché de filtros al inicio de Foundry.",
"TMFX.settings.autoTemplateEnabled.name": "Habilitar efectos de plantilla automáticos",
"TMFX.settings.autoTemplateEnabled.hint": "Desmarcar esta opción deshabilitará todos los efectos de plantilla automáticos. NOTA: Solo afecta a las plantillas colocadas recientemente.",
"TMFX.settings.defaultTemplateOnHover.name": "Rejilla de plantilla por defecto al pasar el ratón",
"TMFX.settings.defaultTemplateOnHover.hint": "Muestra la rejilla de plantilla por defecto solo cuando se pasa el ratón por encima de la capa de plantillas.",
"TMFX.settings.autoTemplateSettings.button.name": "Efectos de Plantilla Automáticos",
"TMFX.settings.autoTemplateSettings.button.label": "Ajustes de Plantilla",
"TMFX.settings.autoTemplateSettings.button.hint": "En los sistemas que lo soporten, los efectos de plantilla pueden activarse en base al tipo de hechizo de área de efecto y tipo de daño, o sobrescribiendo para ciertos hechizos.",
"TMFX.settings.autoTemplateSettings.tabs.general": "General",
"TMFX.settings.autoTemplateSettings.tabs.categories": "Categorías",
"TMFX.settings.autoTemplateSettings.tabs.overrides": "Sobrescribir",
"TMFX.settings.autoTemplateSettings.texture.label": "Textura (opcional):",
"TMFX.settings.autoTemplateSettings.target.label": "Objetivo:",
"TMFX.settings.autoTemplateSettings.texture.hint": "Especificar opcionalmente una textura para el filtro. Si no se especifica ninguna, se utilizará una textura apropiada.",
"TMFX.settings.autoTemplateSettings.unsupported": "característica no soportada por el sistema, ¡Cualquier contribución para habilitar más sistemas es bienvenida!",
"TMFX.settings.autoTemplateSettings.overrides.introduction": "Aquí puedes configurar la sobrescritura para objetos/hechizos individuales. Escribe en el Campo Objetivo el nombre del objeto/hechizo tal y como aparece en tus Objetos/Compendios y configura los ajustes que prefieras.",
"TMFX.settings.autoTemplateSettings.overrides.add": "Añadir sobreescritura",
"TMFX.settings.autoTemplateSettings.dialog.title": "Ajustes de plantilla de Token Magic",
"TMFX.save": "Guardar"
}
2 changes: 2 additions & 0 deletions tokenmagic/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"TMFX.template.tint": "Teinte de l'Effet:",
"TMFX.settings.disableCaching.name": "Désactiver la mise en cache des filtres",
"TMFX.settings.disableCaching.hint": "Cochez cette option pour désactiver la mise en cache des filtres au démarrage de Foundry.",
"TMFX.settings.disableVideo.name": "Désactiver la prise en charge des vidéos",
"TMFX.settings.disableVideo.hint": "Cochez cette option si vous souhaitez désactiver la prise en charge des vidéos et le recadrage automatique des textures dans les templates.",
"TMFX.settings.autoTemplateEnabled.name": "Activation automatique des effets",
"TMFX.settings.autoTemplateEnabled.hint": "Décocher cette option désactivera tous les effets automatiques sur les templates. REMARQUE: affecte uniquement les templates nouvellement placés.",
"TMFX.settings.defaultTemplateOnHover.name": "Grille sur demande",
Expand Down
12 changes: 10 additions & 2 deletions tokenmagic/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tokenmagic",
"title": "Token Magic FX",
"description": "<p>Add special effects and animations on your tokens, tiles, drawings and templates.</p>",
"version": "0.4.3",
"version": "0.4.4",
"compatibleCoreVersion": "0.6.6",
"minimumCoreVersion": "0.6.0",
"author": "SecretFire and sPOiDar (Auto-Templates)",
Expand All @@ -15,6 +15,9 @@
},
{
"name": "Zimm"
},
{
"name": "Lozalojo"
}
],
"scripts": [
Expand Down Expand Up @@ -90,10 +93,15 @@
"lang": "pt-BR",
"name": "Português (Brasil)",
"path": "lang/pt-BR.json"
},
{
"lang": "es",
"name": "Spanish",
"path": "lang/es.json"
}
],
"socket": true,
"url": "https://github.com/Feu-Secret/Tokenmagic",
"manifest": "https://raw.githubusercontent.com/Feu-Secret/Tokenmagic/master/tokenmagic/module.json",
"download": "https://github.com/Feu-Secret/Tokenmagic/releases/download/v0.4.3-alpha/Tokenmagic.zip"
"download": "https://github.com/Feu-Secret/Tokenmagic/releases/download/v0.4.4-alpha/Tokenmagic.zip"
}
124 changes: 114 additions & 10 deletions tokenmagic/module/proto/PlaceableObjectProto.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlaceableType, Magic, broadcast, SocketAction, mustBroadCast, isZOrderConfig } from "../tokenmagic.js";
import { PlaceableType, Magic, broadcast, SocketAction, mustBroadCast, isZOrderConfig, isVideoDisabled } from "../tokenmagic.js";
import { emptyPreset, autoMinRank } from '../constants.js';

export var gMaxRank = autoMinRank;
Expand Down Expand Up @@ -204,14 +204,118 @@ MeasuredTemplate.prototype.update = (function () {
};
})();

export function enableMeasuredTemplatePrototypeRefresh() {
MeasuredTemplate.prototype.refresh = (function () {
const cachedMTR = MeasuredTemplate.prototype.refresh;
return function () {
if (this.template && !this.template._destroyed) {
MeasuredTemplate.prototype.refresh = (function () {
const cachedMTR = MeasuredTemplate.prototype.refresh;
return function () {
if (this.template && !this.template._destroyed) {
if (isVideoDisabled()) {
return cachedMTR.apply(this);
} else {
// INTEGRATION FROM MESS
// THANKS TO MOERILL !!
let d = canvas.dimensions;
this.position.set(this.data.x, this.data.y);

// Extract and prepare data
let { direction, distance, angle, width } = this.data;
distance *= (d.size / d.distance);
width *= (d.size / d.distance);
direction = toRadians(direction);

// Create ray and bounding rectangle
this.ray = Ray.fromAngle(this.data.x, this.data.y, direction, distance);

// Get the Template shape
switch (this.data.t) {
case "circle":
this.shape = this._getCircleShape(distance);
break;
case "cone":
this.shape = this._getConeShape(direction, angle, distance);
break;
case "rect":
this.shape = this._getRectShape(direction, distance);
break;
case "ray":
this.shape = this._getRayShape(direction, distance, width);
}

// Draw the Template outline
this.template.clear()
.lineStyle(this._borderThickness, this.borderColor, 0.75)
.beginFill(0x000000, 0.0);

// Fill Color or Texture
if (this.texture) {
let mat = PIXI.Matrix.IDENTITY;
// rectangle
if (this.shape.width && this.shape.height)
mat.scale(this.shape.width / this.texture.width, this.shape.height / this.texture.height);
else if (this.shape.radius) {
mat.scale(this.shape.radius * 2 / this.texture.height, this.shape.radius * 2 / this.texture.width)
// Circle center is texture start...
mat.translate(-this.shape.radius, -this.shape.radius);
} else if (this.data.t === "ray") {
const d = canvas.dimensions,
height = this.data.width * d.size / d.distance,
width = this.data.distance * d.size / d.distance;
mat.scale(width / this.texture.width, height / this.texture.height);
mat.translate(0, -height * 0.5);

mat.rotate(toRadians(this.data.direction));
} else {// cone
const d = canvas.dimensions;

// Extract and prepare data
let { direction, distance, angle } = this.data;
distance *= (d.size / d.distance);
direction = toRadians(direction);
const width = this.data.distance * d.size / d.distance;

const angles = [(angle / -2), (angle / 2)];
distance = distance / Math.cos(toRadians(angle / 2));

// Get the cone shape as a polygon
const rays = angles.map(a => Ray.fromAngle(0, 0, direction + toRadians(a), distance + 1));
const height = Math.sqrt((rays[0].B.x - rays[1].B.x) * (rays[0].B.x - rays[1].B.x)
+ (rays[0].B.y - rays[1].B.y) * (rays[0].B.y - rays[1].B.y));
mat.scale(width / this.texture.width, height / this.texture.height);
mat.translate(0, -height / 2)
mat.rotate(toRadians(this.data.direction));
}
this.template.beginTextureFill({
texture: this.texture,
matrix: mat,
alpha: 1.0
});
// move into draw or so
const source = getProperty(this.texture, "baseTexture.resource.source")
if (source && (source.tagName === "VIDEO")) {
source.loop = true;
source.muted = true;
game.video.play(source);
}
}
else this.template.beginFill(0x000000, 0.0);

// Draw the shape
this.template.drawShape(this.shape);

// Draw origin and destination points
this.template.lineStyle(this._borderThickness, 0x000000)
.beginFill(0x000000, 0.5)
.drawCircle(0, 0, 6)
.drawCircle(this.ray.dx, this.ray.dy, 6);

// Update visibility
this.controlIcon.visible = this.layer._active;
this.controlIcon.border.visible = this._hover;

// Draw ruler text
this._refreshRulerText();
return this;
}
return this;
};
})();
}
}
return this;
};
})();
9 changes: 9 additions & 0 deletions tokenmagic/module/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ export class TokenMagicSettings extends FormApplication {
type: Boolean
});

game.settings.register("tokenmagic", "disableVideo", {
name: game.i18n.localize("TMFX.settings.disableVideo.name"),
hint: game.i18n.localize("TMFX.settings.disableVideo.hint"),
scope: "world",
config: true,
default: false,
type: Boolean
});

game.settings.register("tokenmagic", "presets", {
name: "Token Magic FX presets",
hint: "Token Magic FX presets",
Expand Down
22 changes: 16 additions & 6 deletions tokenmagic/module/tokenmagic.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { Anime } from "../fx/Anime.js";
import { allPresets, PresetsLibrary } from "../fx/presets/defaultpresets.js";
import { tmfxDataMigration } from "../migration/migration.js";
import { emptyPreset } from './constants.js';
import { enableMeasuredTemplatePrototypeRefresh } from "./proto/PlaceableObjectProto.js";
import "./proto/PlaceableObjectProto.js";

/*
Expand Down Expand Up @@ -151,6 +150,10 @@ export function isFilterCachingDisabled() {
return game.settings.get("tokenmagic", "disableCaching");
}

export function isVideoDisabled() {
return game.settings.get("tokenmagic", "disableVideo");
}

export var isFurnaceDrawingsActive = () => {
// module exeption for the Furnace by KaKaRoTo
if (isActiveModule("furnace")
Expand Down Expand Up @@ -1400,6 +1403,10 @@ function getAnchor(direction, angle, shapeType) {

function onMeasuredTemplateConfig(data, html) {

if (!isVideoDisabled()) {
html[0].querySelector('.file-picker').dataset.type = 'imagevideo';
}

function compare(a, b) {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
Expand Down Expand Up @@ -1465,8 +1472,8 @@ Hooks.on("ready", () => {
tmfxDataMigration();
initSocketListener();
initFurnaceDrawingsException();
enableMeasuredTemplatePrototypeRefresh();
window.TokenMagic = Magic;

Hooks.on("renderMeasuredTemplateConfig", onMeasuredTemplateConfig);
});

Expand Down Expand Up @@ -1811,6 +1818,11 @@ Hooks.on("preCreateMeasuredTemplate", (scene, data, options, user) => {
data.flags = {};
}

// normalizing color to value if needed
if (hasTint && typeof data.tmfxTint !== "number") {
data.tmfxTint = colorStringToHex(data.tmfxTint);
}

// FX to add ?
if (hasPreset) {

Expand All @@ -1827,9 +1839,7 @@ Hooks.on("preCreateMeasuredTemplate", (scene, data, options, user) => {
};

// Adding tint if needed
let tint = data.tmfxTint;
if (hasTint && typeof data.tmfxTint !== "number") tint = colorStringToHex(tint);
if (hasTint) pstSearch.color = tint;
if (hasTint) pstSearch.color = data.tmfxTint;

// Retrieving the preset
let preset = Magic.getPreset(pstSearch);
Expand Down Expand Up @@ -1889,7 +1899,7 @@ Hooks.on("preCreateMeasuredTemplate", (scene, data, options, user) => {

if (!hasOpacity) data.tmfxTextureAlpha = 1;
if (!hasTint) data.tmfxTint = null;

let tmfxTemplateData = {
templateData: {
opacity: data.tmfxTextureAlpha,
Expand Down
Loading

0 comments on commit 6958483

Please sign in to comment.