Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Jul 10, 2021
2 parents cccb383 + 1d34a36 commit 8566abc
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 92 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.2.0
Add levels measurement function
- When over a levels tile, default to the bottom elevation of that tile.
- When over a levels hole, default to the bottom elevation of that hole.
- When starting at a token, stay at the floor level for that token unless over a hole or other token.
- Optional label for the current floor level.
Switch to using `canvas.terrain.terrainsFromPixels` (requires Enhanced Terrain Layer 1.0.30+).

## 0.1.3
Catch case where game.users.isGM is undefined.

Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

# Elevation Ruler

This module allows the default Foundry measurement ruler to track change in elevation. Elevation can be changed while using the ruler in three ways:
This module allows the default Foundry measurement ruler to track change in elevation. Elevation can be changed while using the ruler in four ways:
1. Manually. Hit the specified hot key (default: '[' to increment and ']' to decrement).
2. Token. When hovering over a token with the ruler, the origin or destination elevation (as applicable) will update.
3. Enhanced Terrain Layer. If a terrain layer is present with a finite max elevation, that max elevation will be used for the elevation.
4. Levels. If the Levels module is present, the ruler will look for Levels-enabled tiles or holes and default to the bottom elevation of that tile or hole.

The distance calculation updates based on the distance measured, assuming a straight line in three dimensions between origin and destination, taking into account elevation change.

Expand All @@ -25,6 +26,8 @@ Add this [Manifest URL](https://github.com/caewok/fvtt-elevation-ruler/releases/

## Modules that add functionality
- [Enhanced Terrain Layer](https://github.com/ironmonk88/enhanced-terrain-layer)
- [Levels](https://github.com/theripper93/Levels)
- [Wall Height](https://github.com/erithtotl/FVTT-Wall-Height)

## Known conflicts
- [Terrain Ruler](https://github.com/manuelVo/foundryvtt-terrain-ruler)
Expand All @@ -38,7 +41,7 @@ In general, modules that overwrite or extend the Ruler Class may cause the eleva

It has been tested on dnd5e 1.3.3 to 1.3.6. Because it adds to the functionality of the underlying Foundry measurement ruler, it may work on other systems as well, unless the system overrides key Foundry measurement functions in the Ruler Class.

# Details
# How to Use

To use, start measuring with the Foundry measurement ruler as normal. While doing so, hit '[' to increase the elevation at the destination by one step. A step is equal to the grid size (typically 5 feet). Hit ']' to decrease the elevation at the destination by one step.

Expand Down Expand Up @@ -87,7 +90,19 @@ This video shows both terrain and token measurement in action.

![Video Terrain Measurement](https://github.com/caewok/fvtt-elevation-ruler/raw/feature/media/media/terrain-measure.mov)

## Levels measurement

For a multi-level scene using the Levels module, the ruler will pick up on holes and Levels-enabled tiles.

In general, when the ruler endpoint is within a Levels-enabled tile, the bottom-most elevation of the bottom tile will be displayed.

If you start the ruler on a token, the ruler will stay at the bottom-most elevation of the current floor for that token, unless it encounters a hole, a token, or an area that is not within a Levels-enabled tile.

Hitting spacebar can move the token between levels if you start the ruler measurement at your token. Note that this may allow players to move between levels at points other than at stairs, holes, or elevators, just as directly adjusting a token's elevation would.

## Elevation changes when moving the token with spacebar

As with the normal Foundry ruler, if you begin a measurement at your token, you can hit spacebar to move the token. Elevation is modified at the end of each waypoint segment move. This may allow you, for example, to jump over a wall if that wall has a maximum height under your current elevation as can be set up using the Wall Height module (or Levels + Wall Height).



Expand Down
18 changes: 12 additions & 6 deletions scripts/ruler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MODULE_ID, log } from "./module.js";
import { calculateEndElevation, toGridDistance } from "./segments.js";
import { ElevationAtPoint, toGridDistance } from "./segments.js";


/**
Expand Down Expand Up @@ -248,25 +248,31 @@ export function decrementElevation() {
}

// When moving the token along the segments, update the token elevation to the destination + increment
// update the token after the move.
export async function elevationRulerAnimateToken(wrapped, token, ray, dx, dy, segment_num) {
// probably update first so the token is at elevation throughout the segment move.

log(`Updating token elevation for segment ${segment_num}`, token);

const elevation_increments = duplicate(this.getFlag(MODULE_ID, "elevation_increments"));
const destination_elevation_increment = this.getFlag(MODULE_ID, "destination_elevation_increment");
elevation_increments.push(destination_elevation_increment);

const incremental_elevation = toGridDistance(elevation_increments[segment_num]);
const end_elevation = calculateEndElevation(ray.B, incremental_elevation);

const current_elevation = getProperty(token, "data.elevation");
const destination_point_elevation = ElevationAtPoint(ray.B, undefined, current_elevation);
const end_elevation = destination_point_elevation + incremental_elevation;

log(`Current token elevation is ${current_elevation}. Will be changed to ${end_elevation}.`);

// move the token first.
let res = wrapped(token, ray, dx, dy, segment_num);

if(current_elevation !== end_elevation) {
await token.document.update({ 'elevation': end_elevation });
}


return wrapped(token, ray, dx, dy, segment_num);

return res;
}


Loading

0 comments on commit 8566abc

Please sign in to comment.