Skip to content

Commit

Permalink
templates: Migrated to v10, pt-BR localization
Browse files Browse the repository at this point in the history
Resolves #339
  • Loading branch information
flamewave000 committed Oct 23, 2022
1 parent e160cb6 commit e9e9a38
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 127 deletions.
4 changes: 4 additions & 0 deletions df-templates/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# DragonFlagon Template Enhancements

## Release 1.3.0 (2022-10-23)
- **UPDATE:** Migrated to v10.
- **NEW #339:** Brazillian Portuguese Localization: Courtesy of [MagelaCE](https://github.com/MagelaCE).

## Release 1.2.1 (2022-04-05)
- **FIX #350:** Error when opening config while on a language other than English.

Expand Down
1 change: 1 addition & 0 deletions df-templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Various enhancements to the FoundryVTT Templates layer. This brings different fo
## Contributers

- Touge & [BrotherSharper](https://github.com/BrotherSharper): Japanese Localization
- [MagelaCE](https://github.com/MagelaCE): Brazillian Portuguese Localization

## Auto-Target Tokens with Template

Expand Down
28 changes: 28 additions & 0 deletions df-templates/lang/pt-BR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"DF_TEMPLATES": {
"errorLibWrapperMissing": "'DF Template Enhancements' requer o módulo 'libWrapper'. Instale e ative 'libWrapper'.",
"ToggleTitle": "Selecionar Tokens Automáticamente",
"AutoTargetName": "Modelos Selecionam Tokens Automáticamente",
"AutoTargetHint": "Se ativado, irá automaticamente selecionar tokens que são atingidos por um Modelo de Medida",
"SnapIntersectName": "Encaixe os modelos nas interseções da grade",
"SnapIntersectHint": "Alguns sistemas de regras (como D&D 5e) afirmam que os modelos de magia devem se originar de uma interseção do grid.",
"GridlessPointResolutionName": "Resolução para Seleção Automática Sem Grid (Padrão: 3)",
"GridlessPointResolutionHint": "Quantos pontos ao longo de cada eixo devem ser gerados para seleção automática em cenas sem grid (Exemplo: para 3, haverá 3 x 3 = 9 pontos sobre cada quadrado). Um número mais alto pode causar desempenho mais lento com muitos tokens em uma cena.",
"PreviewName": "Pré-visualizar Realce/Seleção do Modelo",
"PreviewHint": "Mostra o realce da grade e executa a seleção automática ao mover ou criar um modelo.",
"SquareRotateName": "Corrigir a Rotação do Modelo Quadrado",
"SquareRotateHint": "Os modelos quadrados não mantêm sua forma ao girar. Isso corrigirá a rotação para que um modelo quadrado mantenha sua forma enquanto gira em torno do ponto de origem do modelo.",
"DebugName": "[DEBUG Somente] Exibir Pontos do Grid de Segleção Automática e Testa Grids",
"DebugHint": "Para fins de depuração do recurso de selecão automática, esta opção exibirá os pontos usados para detectar a seleção de token em uma cena sem grid. Ou exibirá toda a zona de teste para realce do grid.",
"Patch5e_Name": "Use Modelos no Estilo D&D 5e",
"Patch5e_Hint": "O padrão do Foundry requer que o centro de um quadrado do grid esteja dentro de um modelo para ser afetado. Isso ajusta os modelos para seguir as regras D&D5e para selecionar quadrados do grid onde qualquer quadrado TOCADO por um modelo é atingido (com exceção de círculos).",
"Patch5e_Circle_Name": "Tornar os Modelos de Círculo Gananciosos (Requer os Modelos no Estilo D&D 5e)",
"Patch5e_Circle_Hint": "Se você quiser que os modelos de círculo não sejam uma exceção às regras do estilo D&D 5e acima, habilite isso e qualquer quadrado tocado por um círculo será atingido.",
"AngleSnap": {
"MacroName": "Contagem de Pontos de Encaixe do Ângulo do Modelo (Padrão do FoundryVTT: 24)",
"MacroHint": "Quantos pontos de encaixe estão disponíveis para girar um modelo. Isso pode ser usado para reduzir o número de ângulos que um jogador tem que escolher para acelerar o combate",
"MicroName": "Multiplicador de Rotação Pequeno (Padrão do FoundryVTT: 3)",
"MicroHint": "Ao segurar Ctrl, você pode realizar encaixes de rotação menores. Isso basicamente multiplica a configuração acima por esse valor para gerar um subconjunto de encaixes de ângulo. Definir isso para 1 desativa efetivamente as etapas de micro ângulo."
}
}
}
34 changes: 27 additions & 7 deletions df-templates/module.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
{
"name": "df-templates",
"version": "1.2.1",
"id": "df-templates",
"version": "1.3.0",
"title": "DF Template Enhancements",
"description": "Enhanced templates for different types of grid targetting.",
"author": "flamewave000#0001",
"minimumCoreVersion": "9",
"compatibleCoreVersion": "9",
"dependencies": [ { "name": "lib-wrapper" } ],
"compatibility": {
"minimum": 10,
"verified": 10.288
},
"relationships": {
"requires": [
{
"id": "lib-wrapper",
"type": "module",
"compatibility": {
"verified": "1.12.10.0"
}
}
]
},
"esmodules": "{{sources}}",
"styles": "{{css}}",
"languages": [
{ "lang": "en", "path": "lang/en.json", "name": "English" },
{ "lang": "ja", "path": "lang/ja.json", "name": "日本語" }
{ "lang": "ja", "path": "lang/ja.json", "name": "日本語" },
{ "lang": "pt-BR", "path": "lang/pt-BR.json", "name": "Português (Brasil)" }
],
"url": "https://github.com/flamewave000/dragonflagon-fvtt/tree/master/df-templates",
"license": "https://raw.githubusercontent.com/flamewave000/dragonflagon-fvtt/master/LICENSE",
Expand All @@ -23,6 +36,13 @@
"bugs": "https://github.com/flamewave000/dragonflagon-fvtt/issues",
"authors": [ { "name": "flamewave000", "discord": "flamewave000#0001", "url": "https://github.com/flamewave000" } ],
"media": [
{ "type": "icon", "url": "https://raw.githubusercontent.com/flamewave000/dragonflagon-fvtt/master/.assets/logo.png" }
{ "type": "icon", "url": "https://raw.githubusercontent.com/flamewave000/dragonflagon-fvtt/master/.assets/logo.png" },
{ "type": "cover", "url": "https://raw.githubusercontent.com/flamewave000/dragonflagon-fvtt/master/.assets/df-templates/templates-dnd5e.png" },
{ "type": "screenshot", "url": "https://raw.githubusercontent.com/flamewave000/dragonflagon-fvtt/master/.assets/df-templates/auto-target.gif" },
{ "type": "screenshot", "url": "https://raw.githubusercontent.com/flamewave000/dragonflagon-fvtt/master/.assets/df-templates/grid-intersect-snapping.gif" },
{ "type": "screenshot", "url": "https://raw.githubusercontent.com/flamewave000/dragonflagon-fvtt/master/.assets/df-templates/square-rotate-core.gif" },
{ "type": "screenshot", "url": "https://raw.githubusercontent.com/flamewave000/dragonflagon-fvtt/master/.assets/df-templates/square-rotate-corrected.gif" },
{ "type": "screenshot", "url": "https://raw.githubusercontent.com/flamewave000/dragonflagon-fvtt/master/.assets/df-templates/square-rotate-corrected-5e.gif" },
{ "type": "screenshot", "url": "https://raw.githubusercontent.com/flamewave000/dragonflagon-fvtt/master/.assets/df-templates/template-preview.gif" }
]
}
44 changes: 23 additions & 21 deletions df-templates/src/AngleSnaps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SETTINGS from "../../common/Settings";
import DnD5eAbilityTemplateHandlers from "./DnD5eAbilityTemplateHandlers";

export default class AngleSnaps {
static init() {
Expand Down Expand Up @@ -34,7 +33,7 @@ export default class AngleSnaps {
static ready() {
libWrapper.register(SETTINGS.MOD_NAME, 'canvas.templates._onMouseWheel', function (this: TemplateLayer, event: MouseEvent): any {
// Determine whether we have a hovered template?
const template = this._hover;
const template = this.hover;
if (!template) return;
// Determine the incremental angle of rotation from event data
const snapCount = SETTINGS.get<number>('angle-snap-macro');
Expand All @@ -44,31 +43,34 @@ export default class AngleSnaps {

const sign = Math.sign((event as any).deltaY);
const delta = snap * sign;
let direction = template.data.direction - (template.data.direction % snap);
if (template.data.direction % snap !== 0 && sign < 0)
let direction = template.document.direction - (template.document.direction % snap);
if (template.document.direction % snap !== 0 && sign < 0)
direction += snap;
return template.rotate(direction + delta, snap);
}, 'OVERRIDE');
}

static handleDnD5eAbilityTemplate(abilityTemplate: any, handlers: DnD5eAbilityTemplateHandlers) {
handlers.mw = event => {
if (event.ctrlKey) event.preventDefault(); // Avoid zooming the browser window
event.stopPropagation();
const snapCount = SETTINGS.get<number>('angle-snap-macro');
let snap = 360 / snapCount;
if (event.shiftKey)
snap /= SETTINGS.get<number>('angle-snap-micro');
static handleDnD5eAbilityTemplate(this: any, event: any) {
/***************** THIS IS COPIED FROM THE DnD 5e CODE BASE `AbilityTemplate.prototype._onRotatePlacement `module/canvas/ability-template.mjs`` ***************/
if (event.ctrlKey) event.preventDefault(); // Avoid zooming the browser window
event.stopPropagation();

const sign = Math.sign(event.deltaY);
let direction = abilityTemplate.data.direction;
if (direction < 0) direction += 360;
direction = direction - (direction % snap);
if (abilityTemplate.data.direction % snap !== 0 && sign < 0)
direction += snap;
/**** MODIFIED THIS REGION ****/
const snapCount = SETTINGS.get<number>('angle-snap-macro');
let snap = 360 / snapCount;
if (event.shiftKey)
snap /= SETTINGS.get<number>('angle-snap-micro');

const sign = Math.sign(event.deltaY);
let direction = this.document.direction;
if (direction < 0) direction += 360;
direction = direction - (direction % snap);
if (this.document.direction % snap !== 0 && sign < 0)
direction += snap;
this.document.updateSource({ direction: direction + (snap * sign) });
/**** END OF MODIFICATION ****/

abilityTemplate.data.update({ direction: direction + (snap * sign) });
abilityTemplate.refresh();
};
this.refresh();
/***************** END OF COPY ***************/
}
}
7 changes: 0 additions & 7 deletions df-templates/src/DnD5eAbilityTemplateHandlers.ts

This file was deleted.

26 changes: 10 additions & 16 deletions df-templates/src/SnapIntersect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SETTINGS from "../../common/Settings";
import DnD5eAbilityTemplateHandlers from "./DnD5eAbilityTemplateHandlers";

export default class SnapIntersect {
static init() {
Expand Down Expand Up @@ -30,21 +29,16 @@ export default class SnapIntersect {
return canvas.grid.type === CONST.GRID_TYPES.GRIDLESS ? 0 : 1;
}

static handleDnD5eAbilityTemplate(abilityTemplate: any, handlers: DnD5eAbilityTemplateHandlers) {
/***************** THIS IS COPIED FROM THE DnD 5e CODE BASE `AbilityTemplate.prototype.activatePreviewListeners` ***************/
let moveTime = 0;
// Update placement (mouse-move)
handlers.mm = event => {
event.stopPropagation();
const now = Date.now(); // Apply a 20ms throttle
if (now - moveTime <= 20) return;
const center = event.data.getLocalPosition(abilityTemplate.layer);
/**** MODIFIED THIS `getSnappedPosition` TO HAVE INTERVAL 1 INSTEAD OF 2 IF ENABLED ****/
const snapped = canvas.grid.getSnappedPosition(center.x, center.y, SETTINGS.get('SnapIntersect') ? 1 : 2);
abilityTemplate.data.update({ x: snapped.x, y: snapped.y });
abilityTemplate.refresh();
moveTime = now;
};
static handleDnD5eAbilityTemplate(this: any, event: any) {
/***************** THIS IS COPIED FROM THE DnD 5e CODE BASE `AbilityTemplate.prototype._onMovePlacement` `module/canvas/ability-template.mjs` ***************/
const now = Date.now(); // Apply a 20ms throttle
if ( now - this._moveTime <= 20 ) return;
const center = event.data.getLocalPosition(this.layer);
/**** MODIFIED THIS `getSnappedPosition` TO HAVE INTERVAL 1 INSTEAD OF 2 IF ENABLED ****/
const snapped = canvas.grid.getSnappedPosition(center.x, center.y, SETTINGS.get('SnapIntersect') ? 1 : 2);
this.document.updateSource({x: snapped.x, y: snapped.y});
this.refresh();
this._moveTime = now;
/***************** END OF COPY ***************/
}
}
8 changes: 4 additions & 4 deletions df-templates/src/SquareTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export default class SquareTemplate {
private static MeasuredTemplate_refreshRulerText(this: MeasuredTemplate, wrapped: () => void): void {
wrapped();
// Overwrite the text for the "rect" type
if (this.data.t === "rect") {
if (this.document.t === "rect") {
// Use simple Pythagoras to calculate the square's size from the diagonal "distance".
const size = Math.sqrt((this.data.distance * this.data.distance) / 2).toFixed(1);
const text = `${size}${canvas.scene.data.gridUnits}`;
(<any>this).hud.ruler.text = text;
const size = Math.sqrt((this.document.distance * this.document.distance) / 2).toFixed(1);
const text = `${size}${canvas.scene.grid.units}`;
(<any>this).ruler.text = text;
}
}
}
6 changes: 3 additions & 3 deletions df-templates/src/TemplateConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class TemplateConfig extends FormApplication<any, Data> {
return this._options;
}

static get defaultOptions(): FormApplication.Options {
static get defaultOptions(): FormApplicationOptions {
const options = mergeObject(super.defaultOptions, {
resizable: false,
submitOnChange: false,
Expand Down Expand Up @@ -93,13 +93,13 @@ export class TemplateConfig extends FormApplication<any, Data> {
rect: old5ePatch ? HighlightMode.TOUCH : HighlightMode.CENTER,
ray: old5ePatch ? HighlightMode.TOUCH : HighlightMode.CENTER
},
onChange: () => canvas.templates?.placeables.filter((t: MeasuredTemplate) => t.data.t === "circle")
onChange: () => canvas.templates?.placeables.filter((t: MeasuredTemplate) => t.document.t === "circle")
.forEach((t: MeasuredTemplate) => t.draw())
});

SETTINGS.registerMenu('template-config', {
restricted: true,
type: TemplateConfig,
type: <any>TemplateConfig,
label: "DF_TEMPLATES.TemplateConfig.Title"
});
}
Expand Down
Loading

0 comments on commit e9e9a38

Please sign in to comment.