Skip to content

Commit f26e9a8

Browse files
committed
a
1 parent a8510fb commit f26e9a8

File tree

14 files changed

+108
-152
lines changed

14 files changed

+108
-152
lines changed

old/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Hooks.on("init", () => {
44
libWrapper.register(CONFIG.Levels.MODULE_ID, "Token.prototype.refresh", _levelsTokenRefresh, "MIXED");
55
libWrapper.register(CONFIG.Levels.MODULE_ID, "Tile.prototype.refresh", _levelsTileRefresh, "WRAPPER");
66
libWrapper.register(CONFIG.Levels.MODULE_ID, "Token.prototype._onMovementFrame", _levelsOnMovementFrame, "WRAPPER");
7-
if (!game.modules.get("perfect-vision")?.active || isNewerVersion("2.8.0", game.modules.get("perfect-vision").data.version)) {
7+
if (!game.modules.get("perfect-vision")?.active || foundry.utils.isNewerVersion("2.8.0", game.modules.get("perfect-vision").data.version)) {
88
libWrapper.register(CONFIG.Levels.MODULE_ID, "LightingLayer.prototype.refresh", _lightingRefresh, "OVERRIDE");
99
libWrapper.register(CONFIG.Levels.MODULE_ID, "SightLayer.prototype.testVisibility", _levelsTestVisibility, "OVERRIDE");
1010
libWrapper.register(CONFIG.Levels.MODULE_ID, "AmbientSound.prototype.isAudible", _levelsIsAudible, "OVERRIDE");
File renamed without changes.

packs/levels-samples/CURRENT

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
MANIFEST-002365
1+
MANIFEST-002379

packs/levels-samples/LOG

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
2024/05/29-13:25:15.441 60ec Recovering log #2364
2-
2024/05/29-13:25:15.444 60ec Delete type=0 #2364
3-
2024/05/29-13:25:15.445 60ec Delete type=3 #2363
1+
2024/05/30-14:24:29.324 3b48 Recovering log #2377
2+
2024/05/30-14:24:29.328 3b48 Delete type=0 #2377
3+
2024/05/30-14:24:29.328 3b48 Delete type=3 #2375
4+
2024/05/30-14:30:29.858 6724 Level-0 table #2382: started
5+
2024/05/30-14:30:29.858 6724 Level-0 table #2382: 0 bytes OK
6+
2024/05/30-14:30:29.859 6724 Delete type=0 #2380
7+
2024/05/30-14:30:29.860 6724 Manual compaction at level-0 from '!scenes!i1noRqT20RD5stIK' @ 72057594037927935 : 1 .. '!scenes.walls!zksLSgRdh6f8jiUO.z5ptMNOLPqAgK6MH' @ 0 : 0; will stop at (end)
8+
2024/05/30-14:30:29.860 6724 Manual compaction at level-1 from '!scenes!i1noRqT20RD5stIK' @ 72057594037927935 : 1 .. '!scenes.walls!zksLSgRdh6f8jiUO.z5ptMNOLPqAgK6MH' @ 0 : 0; will stop at (end)

packs/levels-samples/LOG.old

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
2024/05/29-00:08:16.392 3b80 Recovering log #2359
2-
2024/05/29-00:08:16.395 3b80 Delete type=0 #2359
3-
2024/05/29-00:08:16.395 3b80 Delete type=3 #2357
1+
2024/05/30-13:28:46.405 4c58 Recovering log #2374
2+
2024/05/30-13:28:46.408 4c58 Delete type=0 #2374
3+
2024/05/30-13:28:46.409 4c58 Delete type=3 #2373
4+
2024/05/30-13:28:53.661 4a68 Level-0 table #2378: started
5+
2024/05/30-13:28:53.661 4a68 Level-0 table #2378: 0 bytes OK
6+
2024/05/30-13:28:53.662 4a68 Delete type=0 #2376
7+
2024/05/30-13:28:53.662 4a68 Manual compaction at level-0 from '!scenes!i1noRqT20RD5stIK' @ 72057594037927935 : 1 .. '!scenes.walls!zksLSgRdh6f8jiUO.z5ptMNOLPqAgK6MH' @ 0 : 0; will stop at (end)
8+
2024/05/30-13:28:53.662 4a68 Manual compaction at level-1 from '!scenes!i1noRqT20RD5stIK' @ 72057594037927935 : 1 .. '!scenes.walls!zksLSgRdh6f8jiUO.z5ptMNOLPqAgK6MH' @ 0 : 0; will stop at (end)
Binary file not shown.
File renamed without changes.

packs/macros/CURRENT

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
MANIFEST-002363
1+
MANIFEST-002377

packs/macros/LOG

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
2024/05/29-13:25:15.432 4cb0 Recovering log #2362
2-
2024/05/29-13:25:15.435 4cb0 Delete type=0 #2362
3-
2024/05/29-13:25:15.435 4cb0 Delete type=3 #2361
1+
2024/05/30-14:24:29.318 4760 Recovering log #2375
2+
2024/05/30-14:24:29.322 4760 Delete type=0 #2375
3+
2024/05/30-14:24:29.322 4760 Delete type=3 #2373
4+
2024/05/30-14:30:29.853 6724 Level-0 table #2380: started
5+
2024/05/30-14:30:29.853 6724 Level-0 table #2380: 0 bytes OK
6+
2024/05/30-14:30:29.854 6724 Delete type=0 #2378
7+
2024/05/30-14:30:29.855 6724 Manual compaction at level-0 from '!macros!2LfY4Ky5rRDkK7h8' @ 72057594037927935 : 1 .. '!macros!yx7Eb76rfzjh0LEO' @ 0 : 0; will stop at (end)
8+
2024/05/30-14:30:29.855 6724 Manual compaction at level-1 from '!macros!2LfY4Ky5rRDkK7h8' @ 72057594037927935 : 1 .. '!macros!yx7Eb76rfzjh0LEO' @ 0 : 0; will stop at (end)

packs/macros/LOG.old

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
2024/05/29-00:08:16.385 6150 Recovering log #2359
2-
2024/05/29-00:08:16.388 6150 Delete type=0 #2359
3-
2024/05/29-00:08:16.388 6150 Delete type=3 #2357
1+
2024/05/30-13:28:46.397 f2c Recovering log #2372
2+
2024/05/30-13:28:46.400 f2c Delete type=0 #2372
3+
2024/05/30-13:28:46.400 f2c Delete type=3 #2371
4+
2024/05/30-13:28:53.658 4a68 Level-0 table #2376: started
5+
2024/05/30-13:28:53.658 4a68 Level-0 table #2376: 0 bytes OK
6+
2024/05/30-13:28:53.659 4a68 Delete type=0 #2374
7+
2024/05/30-13:28:53.659 4a68 Manual compaction at level-0 from '!macros!2LfY4Ky5rRDkK7h8' @ 72057594037927935 : 1 .. '!macros!yx7Eb76rfzjh0LEO' @ 0 : 0; will stop at (end)
8+
2024/05/30-13:28:53.659 4a68 Manual compaction at level-1 from '!macros!2LfY4Ky5rRDkK7h8' @ 72057594037927935 : 1 .. '!macros!yx7Eb76rfzjh0LEO' @ 0 : 0; will stop at (end)
Binary file not shown.

scripts/handlers/sightHandler.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class SightHandler {
77
const sourceZ = visionSource.elevation * unitsToPixel;
88
const dx = test.point.x - visionSource.x;
99
const dy = test.point.y - visionSource.y;
10-
const dz = (test.point.z ?? sourceZ) - sourceZ;
10+
const dz = (test.elevation ?? sourceZ) - sourceZ;
1111
return dx * dx + dy * dy + dz * dz <= radius * radius;
1212
}
1313

@@ -170,14 +170,42 @@ export class SightHandler {
170170
]
171171
: [[0, 0]];
172172
const e = object instanceof Token && !Number.isFinite(elevation) ? object.document.losHeight : elevation;
173-
return {
173+
const config = {
174174
object,
175175
tests: offsets.map((o) => ({
176176
point: { x: point.x + o[0], y: point.y + o[1] },
177177
e,
178178
los: new Map(),
179179
})),
180180
};
181+
return SightHandler.elevatePoints(config, e);
182+
}
183+
184+
static elevatePoints(config, e) {
185+
const object = config.object;
186+
const unitsToPixel = canvas.dimensions.size / canvas.dimensions.distance;
187+
if (object instanceof Token) {
188+
if (config.tests._levels !== object) {
189+
config.tests.length = 0;
190+
for (const p of SightHandler.getTestPoints(object)) {
191+
config.tests.push({ point: { x: p.x, y: p.y, z: p.z * unitsToPixel }, los: new Map() });
192+
}
193+
config.tests._levels = object;
194+
}
195+
} else {
196+
let z;
197+
if (object instanceof PlaceableObject) {
198+
z = object.document.elevation;
199+
} else if (object instanceof DoorControl) {
200+
z = e;
201+
}
202+
z ??= canvas.primary.background.elevation;
203+
z *= unitsToPixel;
204+
for (const test of config.tests) {
205+
test.point.z = z;
206+
}
207+
}
208+
return config;
181209
}
182210

183211
static _testCollision(wrapped, ...args) {

scripts/handlers/tileHandler.js

-13
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@ export class TileHandler{
4343
return true;
4444

4545
}
46-
47-
static _identifyOccludedTiles(tokens) {
48-
const occluded = new Set();
49-
const controlled = tokens.filter(t => t.controlled);
50-
for ( const token of (controlled.length ? controlled : tokens) ) {
51-
const tiles = canvas.tiles.quadtree.getObjects(token.bounds);
52-
for ( const tile of tiles ) {
53-
if ( occluded.has(tile) ) continue; // Don't bother re-testing a tile
54-
if ( tile.testOcclusion(token, {corners: tile.isRoof}) ) occluded.add(tile);
55-
}
56-
}
57-
return occluded;
58-
}
5946
}
6047

6148
function getFlags(document){

scripts/wrappers.js

+43-122
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,51 @@ export function registerWrappers() {
2121

2222
Hooks.on("refreshWall", (placeable) => {
2323
computeUI(placeable);
24-
})
24+
});
2525

2626
Hooks.on("refreshAmbientLight", (placeable) => {
2727
computeUI(placeable);
28-
})
29-
30-
libWrapper.register(LevelsConfig.MODULE_ID, "CONFIG.Tile.objectClass.prototype.isVisible", function (wrapped, ...args) {
31-
const visible = LevelsConfig.handlers.TileHandler.isTileVisible(this);
32-
let result = wrapped(...args);
33-
if (CONFIG.Levels.currentToken || canvas.tokens.controlled.length) {
34-
if ((CONFIG.Levels.currentToken ?? canvas.tokens.controlled[0]).losHeight < this.document.elevation) {
35-
if (!visible) {
36-
if (this.mesh) {
37-
/*this.mesh.occluded = true;
28+
});
29+
30+
libWrapper.register(
31+
LevelsConfig.MODULE_ID,
32+
"CONFIG.Tile.objectClass.prototype.isVisible",
33+
function (wrapped, ...args) {
34+
const visible = LevelsConfig.handlers.TileHandler.isTileVisible(this);
35+
let result = wrapped(...args);
36+
if (CONFIG.Levels.currentToken || canvas.tokens.controlled.length) {
37+
if ((CONFIG.Levels.currentToken ?? canvas.tokens.controlled[0]).losHeight < this.document.elevation) {
38+
if (!visible) {
39+
if (this.mesh) {
40+
/*this.mesh.occluded = true;
3841
this.mesh.shader.enabled = false;
3942
this.mesh.alpha = 0;*/
43+
}
44+
result = result && visible;
4045
}
46+
} else {
4147
result = result && visible;
4248
}
4349
} else {
4450
result = result && visible;
4551
}
46-
} else {
47-
result = result && visible;
48-
}
49-
const uiVisible = computeUI(this);
50-
return result && uiVisible;
51-
}, "WRAPPER");
52-
53-
libWrapper.register(LevelsConfig.MODULE_ID, "CONFIG.Drawing.objectClass.prototype.isVisible", function (wrapped, ...args){
54-
const result = wrapped(...args);
55-
const visible = LevelsConfig.handlers.DrawingHandler.isDrawingVisible(this);
56-
const uiVisible = computeUI(this);
57-
return result && visible && uiVisible;
58-
}, "WRAPPER");
59-
52+
const uiVisible = computeUI(this);
53+
return result && uiVisible;
54+
},
55+
"WRAPPER",
56+
);
6057

58+
libWrapper.register(
59+
LevelsConfig.MODULE_ID,
60+
"CONFIG.Drawing.objectClass.prototype.isVisible",
61+
function (wrapped, ...args) {
62+
const result = wrapped(...args);
63+
const visible = LevelsConfig.handlers.DrawingHandler.isDrawingVisible(this);
64+
const uiVisible = computeUI(this);
65+
return result && visible && uiVisible;
66+
},
67+
"WRAPPER",
68+
);
6169

6270
Hooks.on("activateTilesLayer ", () => {
6371
if (CONFIG.Levels.UI?.rangeEnabled) {
@@ -72,59 +80,21 @@ export function registerWrappers() {
7280
function (wrapped, ...args) {
7381
if (game.user.isGM) return wrapped(...args);
7482
else {
75-
return CONFIG.Levels.currentToken ? [CONFIG.Levels.currentToken] : wrapped(...args);
76-
}
77-
},
78-
"MIXED",
79-
);
80-
81-
libWrapper.register(
82-
LevelsConfig.MODULE_ID,
83-
"CONFIG.Tile.objectClass.prototype.isRoof",
84-
function isRoof(wrapped, ...args) {
85-
if (this.document.flags?.levels?.noCollision || this.document.flags["tile-scroll"]?.enableRotate || this.document.flags["tile-scroll"]?.enableScroll) return wrapped(...args);
86-
return wrapped(...args) || (this.document.overhead && Number.isFinite(this.document.elevation));
87-
},
88-
"WRAPPER",
89-
{ perf_mode: "FAST" },
90-
);
91-
92-
libWrapper.register(
93-
LevelsConfig.MODULE_ID,
94-
"CONFIG.Wall.objectClass.prototype.identifyInteriorState",
95-
function disableInteriorState(wrapped, ...args) {
96-
this.roof = null;
97-
for (const tile of canvas.tiles.roofs) {
98-
const allWallBlockSight = tile.document?.flags?.levels?.allWallBlockSight ?? true;
99-
if (tile.document.hidden || !allWallBlockSight) continue;
100-
const isBottomFinite = Number.isFinite(tile.document.elevation);
101-
if (isBottomFinite && Number.isFinite(tile.document?.flags?.levels?.rangeTop)) continue;
102-
if (isBottomFinite) {
103-
const bottom = tile.document.elevation;
104-
const wallBottom = this.document.flags["wall-height"]?.bottom ?? -Infinity;
105-
if (wallBottom >= bottom) continue;
106-
}
107-
const [x1, y1, x2, y2] = this.document.c;
108-
const isInterior = tile.mesh?.containsCanvasPoint({ x: x1, y: y1 }) && tile.mesh?.containsCanvasPoint({ x: x2, y: y2 });
109-
if (isInterior) {
110-
this.roof = tile;
111-
break;
83+
const M = CONST.TOKEN_OCCLUSION_MODES;
84+
const mode = this.occlusionMode;
85+
if (mode & M.VISIBLE || (mode & M.HIGHLIGHTED && this.highlightObjects)) {
86+
return this.placeables.filter((t) => t.visible);
11287
}
88+
const tokens = new Set();
89+
if (mode & M.HOVERED && this.hover) tokens.add(this.hover);
90+
if (mode & M.CONTROLLED && CONFIG.Levels.currentToken) tokens.add(CONFIG.Levels.currentToken);
91+
if (mode & M.OWNED) this.ownedTokens.filter((t) => !t.document.hidden).forEach((t) => tokens.add(t));
92+
return Array.from(tokens);
11393
}
11494
},
115-
"OVERRIDE",
116-
{ perf_mode: "FAST" },
95+
"MIXED",
11796
);
11897

119-
/*libWrapper.register(
120-
LevelsConfig.MODULE_ID,
121-
"TilesLayer.prototype.displayRoofs", function displayRoofs(wrapped, ...args){
122-
const res = wrapped(...args);
123-
return res || (CONFIG.Levels.UI?.rangeEnabled && !canvas.tokens.controlled.length);
124-
},
125-
"WRAPPER"
126-
);*/
127-
12898
const visibilityTestObjectStack = [];
12999
libWrapper.register(
130100
LevelsConfig.MODULE_ID,
@@ -141,53 +111,6 @@ export function registerWrappers() {
141111
"WRAPPER",
142112
);
143113

144-
function elevatePoints(config, visionSource) {
145-
const object = config.object;
146-
const unitsToPixel = canvas.dimensions.size / canvas.dimensions.distance;
147-
if (object instanceof Token) {
148-
if (config.tests._levels !== object) {
149-
config.tests.length = 0;
150-
for (const p of LevelsConfig.handlers.SightHandler.getTestPoints(object)) {
151-
config.tests.push({ point: { x: p.x, y: p.y, z: p.z * unitsToPixel }, los: new Map() });
152-
}
153-
config.tests._levels = object;
154-
}
155-
} else {
156-
let z;
157-
if (object instanceof PlaceableObject) {
158-
z = object.document.elevation;
159-
} else if (object instanceof DoorControl) {
160-
z = visionSource?.elevation;
161-
}
162-
z ??= canvas.primary.background.elevation;
163-
z *= unitsToPixel;
164-
for (const test of config.tests) {
165-
test.point.z = z;
166-
}
167-
}
168-
return config;
169-
}
170-
171-
libWrapper.register(
172-
LevelsConfig.MODULE_ID,
173-
"DetectionMode.prototype.testVisibility",
174-
function (wrapped, visionSource, mode, config) {
175-
return wrapped(visionSource, mode, elevatePoints(config, visionSource));
176-
},
177-
"WRAPPER",
178-
{ perf_mode: "FAST" },
179-
);
180-
181-
libWrapper.register(
182-
LevelsConfig.MODULE_ID,
183-
"foundry.canvas.sources.PointLightSource.prototype.testVisibility",
184-
function (wrapped, config) {
185-
return wrapped(elevatePoints(config, CONFIG.Levels.currentToken?.vision));
186-
},
187-
"WRAPPER",
188-
{ perf_mode: "FAST" },
189-
);
190-
191114
libWrapper.register(LevelsConfig.MODULE_ID, "CanvasVisibility.prototype._createVisibilityTestConfig", LevelsConfig.handlers.SightHandler._createVisibilityTestConfig, "OVERRIDE", { perf_mode: "FAST" });
192115

193116
libWrapper.register(LevelsConfig.MODULE_ID, "DetectionMode.prototype._testRange", LevelsConfig.handlers.SightHandler._testRange, "OVERRIDE", { perf_mode: "FAST" });
@@ -210,7 +133,5 @@ export function registerWrappers() {
210133

211134
libWrapper.register(LevelsConfig.MODULE_ID, "CONFIG.MeasuredTemplate.objectClass.prototype.isVisible", LevelsConfig.handlers.TemplateHandler.isVisible, "WRAPPER");
212135

213-
libWrapper.register(LevelsConfig.MODULE_ID, "CanvasOcclusionMask.prototype._identifyOccludedTiles", LevelsConfig.handlers.TileHandler._identifyOccludedTiles, "OVERRIDE");
214-
215136
libWrapper.register(LevelsConfig.MODULE_ID, "CONFIG.Token.objectClass.prototype.isVisible", LevelsConfig.handlers.UIHandler.tokenUIWrapperIsVisible, "WRAPPER");
216137
}

0 commit comments

Comments
 (0)