Skip to content

Commit

Permalink
Merge branch 'release/0.1.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Jan 3, 2024
2 parents 239035b + af7913d commit b6e9d30
Show file tree
Hide file tree
Showing 29 changed files with 1,801 additions and 591 deletions.
174 changes: 137 additions & 37 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,145 @@
name: Release Creation
# GitHub Actions workflow for creating a new FoundryVTT module release.
#
# Useful References:
# - https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
# - https://docs.github.com/en/actions/learn-github-actions/contexts
# - https://docs.github.com/en/actions/learn-github-actions/environment-variables
#
# Troubleshooting Checklist:
# - Is the module's manifest file valid JSON?
# You can test your manifest file using https://jsonlint.com/.
#
# - Does the module's manifest have all the required keys?
# See https://foundryvtt.com/article/module-development/#manifest for more
# information.
#
# - Are all the proper files and directories being included in the release's
# module archive ("module.zip")?
# Check that the correct files are being passed to the `zip` command run
# in the "Create Module Archive" step below.
#
# - Is the release tag the proper format?
# See the comments for the "Extract Version From Tag" step below.
#
# - Is a GitHub release being published?
# This workflow will only run when a release is published, not when a
# release is updated. Furthermore, note that while a GitHub release will
# (by default) create a repository tag, a repository tag will not create
# or publish a GitHub release.
#
# - Has the module's entry on FoundryVTT's module administration site
# (https://foundryvtt.com/admin) been updated?
#
name: Create Module Files For GitHub Release

on:

env:
# The URL used for the module's "Project URL" link on FoundryVTT's website.
project_url: "https://github.com/${{github.repository}}"

# A URL that will always point to the latest manifest.
# FoundryVTT uses this URL to check whether the current module version that
# is installed is the latest version. This URL should NOT change,
# otherwise FoundryVTT won't be able to perform this check.
latest_manifest_url: "https://github.com/${{github.repository}}/releases/latest/download/module.json"

# The URL to the module archive associated with the module release being
# processed by this workflow.
release_module_url: "https://github.com/${{github.repository}}/releases/download/${{github.event.release.tag_name}}/module.zip"


on:
# Only run this workflow when a release is published.
# To modify this workflow when other events occur, see:
# - https://docs.github.com/en/actions/using-workflows/triggering-a-workflow
# - https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
# - https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
#
# Note that some steps may depend on context variables that are only
# available for release events, so if you add other events, you may need to
# alter other parts of this workflow.
release:
types: [published]


jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v3
with:
submodules: 'true'

# get part of the tag after the `v`
- id: get_version
run: |
echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
echo "FOUNDRY_MANIFEST=https://github.com/${{github.repository}}/releases/latest/download/module.json" >> $GITHUB_ENV
echo "FOUNDRY_DOWNLOAD=https://github.com/${{github.repository}}/releases/download/${{github.event.release.tag_name}}/module.zip" >> $GITHUB_ENV
# Substitute the Manifest and Download URLs in the module.json
- name: Substitute Manifest and Download Links For Versioned Ones
id: sub_manifest_link_version
uses: restackio/[email protected]
with:
file: 'module.json'
fields: "{\"version\": \"${{env.VERSION}}\", \"manifest\": \"${{env.FOUNDRY_MANIFEST}}\", \"download\": \"${{env.FOUNDRY_DOWNLOAD}}\"}"

# Create a zip file with all files required by the module to add to the release
- run: zip -r ./module.zip module.json LICENSE styles/ scripts/ templates/ languages/ packs/

# Create a release for this specific version
- name: Update Release with Files
id: create_version_release
uses: ncipollo/release-action@v1
with:
allowUpdates: true # Set this to false if you want to prevent updating existing releases
name: ${{ github.event.release.name }}
draft: false
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: './module.json, ./module.zip'
tag: ${{ github.event.release.tag_name }}
body: ${{ github.event.release.body }}
- name: Checkout Repository
uses: actions/checkout@v3
with:
submodules: 'true'

# Extract version embedded in the tag.
# This step expects the tag to be one of the following formats:
# - "v<major>.<minor>.<patch>" (e.g., "v1.2.3")
# - "<major>.<minor>.<patch>" (e.g., "1.2.3")
#
# The version will be used by later steps to fill in the value for the
# "version" key required for a valid module manifest.
- name: Extract Version From Tag
id: get_version
uses: battila7/get-version-action@v2


# Modify "module.json" with values specific to the release.
# Since the values for the "version" and "url" keys aren't known ahead of
# time, the manifest file in the repository is updated with these values.
#
# While this does modify the manifest file in-place, the changes are not
# commited to the repository, and only exist in the action's filesystem.
- name: Modify Module Manifest With Release-Specific Values
id: sub_manifest_link_version
uses: cschleiden/replace-tokens@v1
with:
files: 'module.json'
env:
VERSION: ${{steps.get_version.outputs.version-without-v}}
URL: ${{ env.project_url }}
MANIFEST: ${{ env.latest_manifest_url }}
DOWNLOAD: ${{ env.release_module_url }}


# Create a "module.zip" archive containing all the module's required files.
# If you have other directories or files that will need to be added to
# your packaged module, add them here.
- name: Create Module Archive
run: |
# Note that `zip` will only emit warnings when a file or directory
# doesn't exist, it will not fail.
zip \
`# Options` \
--recurse-paths \
`# The name of the output file` \
./module.zip \
`# The files that will be included.` \
module.json \
README.md \
LICENSE \
templates/ \
scripts/ \
styles/ \
packs/ \
languages/ \
assets/
# Don't forget to add a backslash at the end of the line for any
# additional files or directories!
# Update the GitHub release with the manifest and module archive files.
- name: Update Release With Files
id: create_version_release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
name: ${{ github.event.release.name }}
draft: ${{ github.event.release.unpublished }}
prerelease: ${{ github.event.release.prerelease }}
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: './module.json, ./module.zip'
tag: ${{ github.event.release.tag_name }}
body: ${{ github.event.release.body }}
14 changes: 14 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 0.1.0

### New Features
Users can add a terrain to a tile. Optionally set a transparency threshold for the tile, to have transparent pixels be considered to not have the terrain.
Users can add a terrain to a measured template.
Users can set an elevation to the tile or template, which can affect when the terrain is active.

### Bug fixes
Popout the terrain effect configuration when a new terrain is created. See issue #15.
Update terrain color when the configuration setting is updated. Closes issue #10.
Fix hexagon fill. Closes issue #14. Note that the hexagon fills are slightly blocky, reflecting the lower resolution of the terrain fill (for speed).
Refactor settings and patching classes.
Update lib geometry to 0.2.12.

## 0.0.6
Move the terrain import/replace/export buttons to the Terrain List.
Add add/remove terrain buttons to the Terrain List.
Expand Down
3 changes: 3 additions & 0 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"terrainmapper.list-config.replace": "Replace all terrains",
"terrainmapper.list-config.export": "Export all terrains",

"terrainmapper.tile-config.transparency-threshold.name": "Inner Transparency Threshold",
"terrainmapper.tile-config.transparency-threshold.hint": "Inner tile pixels with transparency less than this percent will be considered 'holes' when testing terrain.",

"terrainmapper.settings.terrain.anchorOptions.absolute": "Absolute",
"terrainmapper.settings.terrain.anchorOptions.relativeToTerrain": "Relative to Ground Elevation",
"terrainmapper.settings.terrain.anchorOptions.relativeToLayer": "Relative to Layer Elevation",
Expand Down
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"socket": "true",
"manifestPlusVersion": "1.2.0",
"compatibility": {
"minimum": 11,
"verified": 11.311
"minimum": "11",
"verified": "11.315"
},
"authors": [
{
Expand Down Expand Up @@ -52,7 +52,7 @@
"styles/terrainlayer.css"
],

"url": "https://github.com/caewok/fvtt-terrain-mapper",
"url": "#{URL}#",
"manifest": "#{MANIFEST}#",
"download": "#{DOWNLOAD}#",
"license": "LICENSE",
Expand Down
32 changes: 32 additions & 0 deletions scripts/ActiveEffect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* globals
canvas,
Terrain
*/
"use strict";
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */

// Methods related to ActiveEffect

import { MODULE_ID } from "./const.js";
import { Terrain } from "./Terrain.js";

export const PATCHES = {};
PATCHES.BASIC = {};

/**
* Hook active effect creation. If the terrain color is updated, update the TerrainLayerShader.
*
* @event updateDocument
* @category Document
* @param {Document} document The existing Document which was updated
* @param {object} change Differential data that was used to update the document
* @param {DocumentModificationContext} options Additional options which modified the update request
* @param {string} userId The ID of the User who triggered the update workflow
*/
function updateActiveEffect(ae, changed, _options, _userId) {
if ( !changed.flags?.[MODULE_ID]?.color ) return;
const terrain = new Terrain(ae);
canvas.terrain._terrainColorsMesh.shader.updateTerrainColor(terrain);
}

PATCHES.BASIC.HOOKS = { updateActiveEffect };
93 changes: 93 additions & 0 deletions scripts/MeasuredTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* globals
*/
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
"use strict";

import { MODULE_ID, FLAGS } from "./const.js";
import { Terrain } from "./Terrain.js";
import { TerrainMeasuredTemplate } from "./TerrainLevel.js";

export const PATCHES = {};
PATCHES.BASIC = {};


// Attach a terrain to a tile and interface with it.
// For now, only a single terrain can be attached to a tile.

// ----- NOTE: Hooks ----- //

/**
* Hook tile update and erase the terrain if the attachedTerrain flag was updated.
* A hook event that fires for every Document type after conclusion of an update workflow.
* Substitute the Document name in the hook event to target a specific Document type, for example "updateActor".
* This hook fires for all connected clients after the update has been processed.
*
* @event updateDocument
* @category Document
* @param {Document} document The existing Document which was updated
* @param {object} change Differential data that was used to update the document
* @param {DocumentModificationContext} options Additional options which modified the update request
* @param {string} userId The ID of the User who triggered the update workflow
*/
function updateMeasuredTemplate(templateD, changed, _options, _userId) {
const modFlag = changed.flags?.[MODULE_ID];
if ( !modFlag || !Object.hasOwn(modFlag, [FLAGS.ATTACHED_TERRAIN]) ) return;
templateD.object._terrain = undefined;
}

PATCHES.BASIC.HOOKS = { updateMeasuredTemplate };

// ----- NOTE: Methods ----- //

/**
* Attach a terrain to this tile.
* At the moment, only one terrain can be associated with a tile at a time. Existing terrain
* will be removed.
* @param {Terrain} terrain
*/
async function attachTerrain(terrain) {
this._terrain = undefined;
await this.document.setFlag(MODULE_ID, FLAGS.ATTACHED_TERRAIN, terrain.id);
}

/**
* Remove a terrain from this tile.
* At the moment, only one terrain can be associated with a tile at a time.
*/
async function removeTerrain() {
this._terrain = undefined;
await this.document.setFlag(MODULE_ID, FLAGS.ATTACHED_TERRAIN, "");
}

/**
* Determine if a terrain is active at a given point and elevation for this tile.
* @param {number} elevation
* @param {x, y} location
* @returns {boolean} If no terrain attached, returns false.
* Ignores the outer transparent edges of the tile.
* If option is set, ignores inner transparent portions.
*/
function terrainActiveAt(elevation, location) {
const terrain = this.attachedTerrain;
return !terrain || terrain.activeAt(elevation, location);
}

PATCHES.BASIC.METHODS = { attachTerrain, removeTerrain, terrainActiveAt };

// ----- NOTE: Getters ----- //
function attachedTerrain() {
if ( !this._terrain ) {
const effectId = this.document.getFlag(MODULE_ID, FLAGS.ATTACHED_TERRAIN);
if ( !effectId ) return undefined;
const terrain = Terrain.fromEffectId(effectId);
this._terrain = new TerrainMeasuredTemplate(terrain, this);
}
return this._terrain;
}

function hasAttachedTerrain() {
return Boolean(this.document.getFlag(MODULE_ID, FLAGS.ATTACHED_TERRAIN));
}


PATCHES.BASIC.GETTERS = { attachedTerrain, hasAttachedTerrain };
Loading

0 comments on commit b6e9d30

Please sign in to comment.