Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dev7355608 committed Aug 7, 2023
1 parent 7997475 commit b8b2cfd
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 175 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,30 @@

# Limits (Foundry VTT Module)

Light, sight, and sound restrictions.
This module allows you to define the maximum range of light, sight, and sound within the scene, drawings, templates, and tiles.

## Installation
![config](images/config.png)

Manual installation:
```
https://github.com/dev7355608/limits/releases/latest/download/module.json
```js
token.document.setFlag("limits", {
light: {
enabled: true,
range: 0,
},
sight: {
basicSight: {
enabled: true,
range: 0,
},
seeAll: {
enabled: true,
range: 30,
},
// ...
},
sound: {
enabled: false,
range: null, // Infinity
},
});
```
Binary file added images/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"id": "limits",
"title": "Limits",
"description": "Light, sight, and sound restrictions",
"description": "Light, sight, and sound limits.",
"authors": [
{
"name": "dev7355608",
"email": "[email protected]"
}
],
"version": "0.1.0",
"version": "1.0.0",
"compatibility": {
"minimum": "11",
"verified": "11"
Expand All @@ -17,7 +17,7 @@
"scripts/index.js"
],
"styles": [
"styles/form.css"
"styles/config.css"
],
"languages": [
{
Expand All @@ -36,8 +36,8 @@
},
"url": "https://github.com/dev7355608/limits",
"manifest": "https://github.com/dev7355608/limits/releases/latest/download/module.json",
"download": "https://github.com/dev7355608/limits/releases/download/v0.1.0/module.zip",
"changelog": "https://github.com/dev7355608/limits/releases/tag/v0.1.0",
"download": "https://github.com/dev7355608/limits/releases/download/v1.0.0/module.zip",
"changelog": "https://github.com/dev7355608/limits/releases/tag/v1.0.0",
"bugs": "https://github.com/dev7355608/limits/issues",
"readme": "https://raw.githubusercontent.com/dev7355608/limits/main/README.md",
"license": "https://raw.githubusercontent.com/dev7355608/limits/main/LICENSE"
Expand Down
2 changes: 1 addition & 1 deletion scripts/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class LimitsConfig extends DocumentSheet {
<div class="form-group">
<label>${game.i18n.localize("LIMITS.LimitsLabel")}</label>
<div class="form-fields">
<button type="button" name="flags.${MODULE_ID}" class="${MODULE_ID}--button">
<button type="button" name="flags.${MODULE_ID}" class="${MODULE_ID}--button" ${sheet.object.id ? "" : "disabled"}>
<i class="fas fa-eye"></i>
${game.i18n.localize("LIMITS.ConfigureLimits")}
</button>
Expand Down
1 change: 1 addition & 0 deletions scripts/data/models.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class FigureData extends foundry.abstract.DataModel {
schema.y = new foundry.data.fields.NumberField({ required: true, nullable: false, initial: 0 });
schema.rotation = new foundry.data.fields.AngleField({ required: true });
schema.shape = new foundry.data.fields.EmbeddedDataField(foundry.data.ShapeData, { required: true });
schema.bezierFactor = new foundry.data.fields.AlphaField({ required: false, initial: 0, max: 0.5 });
schema.texture = new foundry.data.TextureData({ required: true });
schema.mask = new BitmaskField({ required: true, initial: -1 });

Expand Down
31 changes: 14 additions & 17 deletions scripts/extensions/drawing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@ import { Extension } from "../extension.mjs";
export class DrawingExtension extends Extension {
/** @override */
registerHooks() {
Hooks.on("canvasReady", () => {
for (const object of canvas.drawings.placeables) {
if (object.isPreview) {
continue;
}

this.updateVolume(object.document);
}
});

Hooks.on("createDrawing", (document) => {
if (!document.rendered) {
Hooks.on("drawDrawing", (object) => {
if (object.isPreview) {
return;
}

this.updateVolume(document);
this.updateVolume(object.document);
});

Hooks.on("updateDrawing", (document) => {
Expand All @@ -29,11 +19,19 @@ export class DrawingExtension extends Extension {
this.updateVolume(document);
});

Hooks.on("deleteDrawing", (document) => {
this.updateVolume(document, true);
Hooks.on("destroyDrawing", (object) => {
if (object.isPreview) {
return;
}

this.updateVolume(object.document, true);
});

Hooks.on("renderDrawingConfig", (sheet) => {
if (sheet.options.configureDefault) {
return;
}

this.injectConfig(sheet, [`.tab[data-tab="position"]`], "beforeend");
});
}
Expand All @@ -52,8 +50,7 @@ export class DrawingExtension extends Extension {
rotation: document.rotation,
shape: document.shape,
bezierFactor: document.bezierFactor,
}],
bottom: document.elevation * document.parent.dimensions.distancePixels
}]
}
}]
});
Expand Down
34 changes: 12 additions & 22 deletions scripts/extensions/template.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@ import { Extension } from "../extension.mjs";
export class TemplateExtension extends Extension {
/** @override */
registerHooks() {
Hooks.on("canvasReady", () => {
for (const object of canvas.templates.placeables) {
if (object.isPreview) {
continue;
}

this.updateVolume(object.document);
}
});

Hooks.on("createMeasuredTemplate", (document) => {
if (!document.rendered) {
Hooks.on("drawMeasuredTemplate", (object) => {
if (object.isPreview) {
return;
}

this.updateVolume(document);
this.updateVolume(object.document);
});

Hooks.on("updateMeasuredTemplate", (document) => {
Expand All @@ -30,10 +20,6 @@ export class TemplateExtension extends Extension {
this.updateVolume(document);
});

Hooks.on("deleteMeasuredTemplate", (document) => {
this.updateVolume(document, true);
});

Hooks.on("refreshMeasuredTemplate", (object, flags) => {
if (object.isPreview || !flags.refreshShape) {
return;
Expand All @@ -42,6 +28,14 @@ export class TemplateExtension extends Extension {
this.updateVolume(object.document);
});

Hooks.on("destroyMeasuredTemplate", (object) => {
if (object.isPreview) {
return;
}

this.updateVolume(object.document, true);
});

Hooks.on("renderMeasuredTemplateConfig", (sheet) => {
this.injectConfig(sheet, [`button[type="submit"]`], "beforebegin");
});
Expand Down Expand Up @@ -107,11 +101,7 @@ export class TemplateExtension extends Extension {
mode: 4,
boundaries: base ? [{
type: "cylinder",
data: {
base: [base],
bottom: null,
top: null
}
data: { base: [base] }
}] : []
});
}
Expand Down
27 changes: 10 additions & 17 deletions scripts/extensions/tile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@ import { Extension } from "../extension.mjs";
export class TileExtension extends Extension {
/** @override */
registerHooks() {
Hooks.on("canvasReady", () => {
for (const object of canvas.tiles.placeables) {
if (object.isPreview) {
continue;
}

this.#updateVolume(object.document);
}
});

Hooks.on("createTile", (document) => {
if (!document.rendered) {
Hooks.on("drawTile", (object) => {
if (object.isPreview) {
return;
}

this.#updateVolume(document);
this.updateVolume(object.document);
});

Hooks.on("updateTile", (document) => {
Expand All @@ -29,8 +19,12 @@ export class TileExtension extends Extension {
this.#updateVolume(document);
});

Hooks.on("deleteTile", (document) => {
this.#updateVolume(document, true);
Hooks.on("destroyTile", (object) => {
if (object.isPreview) {
return;
}

this.updateVolume(object.document, true);
});

Hooks.on("renderTileConfig", (sheet) => {
Expand Down Expand Up @@ -75,8 +69,7 @@ export class TileExtension extends Extension {
offsetX: document.texture.offsetX,
offsetY: document.texture.offsetY
}
}],
bottom: document.elevation * document.parent.dimensions.distancePixels
}]
}
}]
});
Expand Down
26 changes: 26 additions & 0 deletions scripts/patches/light.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MODULE_ID } from "../const.mjs";
import { VolumeCollection } from "../volume.mjs";
import { Constraint } from "./../constraint.mjs";

Hooks.once("libWrapper.Ready", () => {
Expand All @@ -11,4 +12,29 @@ Hooks.once("libWrapper.Ready", () => {
libWrapper.WRAPPER,
{ perf_mode: libWrapper.PERF_FAST }
);

libWrapper.register(
MODULE_ID,
"GlobalLightSource.prototype._createPolygon",
function (wrapped, ...args) {
return new GlobalLightSourcePolygon(wrapped(...args).points);
},
libWrapper.WRAPPER,
{ perf_mode: libWrapper.PERF_FAST }
);
});

class GlobalLightSourcePolygon extends PIXI.Polygon {
contains(x, y) {
if (!super.contains(x, y)) {
return false;
}

return VolumeCollection.instance.castRay(
"light",
0,
x, y, 1000000,
x, y, -1000000
).targetHit;
}
}
2 changes: 1 addition & 1 deletion scripts/patches/sight.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Hooks.once("libWrapper.Ready", () => {
function (wrapped, ...args) {
return Constraint.apply(
wrapped(...args),
`sight.${this.visionMode.detectionMode?.id ?? DetectionMode.BASIC_MODE_ID}`,
`sight.${this.detectionMode?.id ?? DetectionMode.BASIC_MODE_ID}`,
{ scalingFactor: 100 }
);
},
Expand Down
Loading

0 comments on commit b8b2cfd

Please sign in to comment.