Skip to content

Commit

Permalink
Merge branch 'release/0.7.3' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Jan 3, 2024
2 parents d31598e + ab4e735 commit 9adc1a9
Show file tree
Hide file tree
Showing 15 changed files with 1,129 additions and 417 deletions.
171 changes: 137 additions & 34 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,42 +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@v2
with:
submodules: 'true'

# 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: microsoft/variable-substitution@v1
with:
files: 'module.json'
env:
version: ${{github.event.release.tag_name}}
url: https://github.com/${{github.repository}}
manifest: https://github.com/${{github.repository}}/releases/latest/download/module.json
download: https://github.com/${{github.repository}}/releases/download/${{github.event.release.tag_name}}/module.zip

# 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/

# 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
prerelease: 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 }}
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.7.3
Updated lib-geometry to 0.2.12.
Refactor to use Patcher class.

# 0.7.2
Updated lib-geometry to 0.2.2.

Expand Down
11 changes: 5 additions & 6 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "elevationruler",
"minimumCoreVersion": "10",
"title": "Elevation Ruler",
"id": "elevationruler",
"description": "Modify Foundry VTT ruler to adjust for relative elevation of the destination.",
"version": "This is auto replaced",
"version": "#{VERSION}#",
"library": false,
"manifestPlusVersion": "1.0.0",
"compatibility": {
"minimum": "11",
"verified": "11.304"
"verified": "11.315"
},
"authors": [
{
Expand Down Expand Up @@ -37,9 +36,9 @@
"path": "languages/en.json"
}
],
"url": "This is auto replaced",
"manifest": "This is auto replaced",
"download": "This is auto replaced",
"url": "#{URL}#",
"manifest": "#{MANIFEST}#",
"download": "#{DOWNLOAD}#",
"license": "LICENSE",
"readme": "README.md"
}
35 changes: 35 additions & 0 deletions scripts/GridLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* globals
*/
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */

import { Ray3d } from "./geometry/3d/Ray3d.js";

// Patches for the GridLayer class
export const PATCHES = {};
PATCHES.BASIC = {};

/**
* Wrap GridLayer.prototype.measureDistances
* Called by Ruler.prototype._computeDistance
* If a segment ray has a z-dimension, re-do the segment by projecting the hypotenuse
* between the ray A and B endpoints in 3d onto the 2d canvas. Use the projected
* hypotenuse to do the measurement.
*/
function measureDistances(wrapped, segments, options = {}) {
if ( !segments.length || !(segments[0]?.ray instanceof Ray3d) ) return wrapped(segments, options);

// Avoid modifying the segment rays.
const ln = segments.length;
const origRays = Array(ln);
for ( let i = 0; i < ln; i += 1 ) {
const s = segments[i];
origRays[i] = s.ray;
s.ray = s.ray.projectOntoCanvas();
}

const out = wrapped(segments, options);
for ( let i = 0; i < ln; i += 1 ) segments[i].ray = origRays[i];
return out;
}

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

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

// Patches for the Setting class
export const PATCHES = {};
PATCHES.BASIC = {};

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

/**
* Wipe the settings cache on update
*/
function updateSetting(document, change, options, userId) { // eslint-disable-line no-unused-vars
const [module, ...arr] = document.key.split(".");
const key = arr.join("."); // If the key has periods, multiple will be returned by split.
if ( module === MODULE_ID && Settings.cache.has(key) ) Settings.cache.delete(key);
}

PATCHES.BASIC.HOOKS = { updateSetting };

export class ModuleSettingsAbstract {
/** @type {Map<string, *>} */
static cache = new Map();

/** @type {object} */
static KEYS = {};

// ---- NOTE: Settings static methods ---- //

/**
* Retrive a specific setting.
* Cache the setting. For caching to work, need to clean the cache whenever a setting below changes.
* @param {string} key
* @returns {*}
*/
static get(key) {
// TODO: Bring back a working cache.

const cached = this.cache.get(key);
if ( typeof cached !== "undefined" ) {
const origValue = game.settings.get(MODULE_ID, key);
if ( origValue !== cached ) {
console.debug(`Settings cache fail: ${origValue} !== ${cached} for key ${key}`);
return origValue;
}

return cached;

}
const value = game.settings.get(MODULE_ID, key);
this.cache.set(key, value);
return value;
}

/**
* Set a specific setting.
* @param {string} key
* @param {*} value
* @returns {Promise<boolean>}
*/
static async set(key, value) {
this.cache.delete(key);
return game.settings.set(MODULE_ID, key, value);
}

static async toggle(key) {
const curr = this.get(key);
return this.set(key, !curr);
}

/**
* Register a specific setting.
* @param {string} key Passed to registerMenu
* @param {object} options Passed to registerMenu
*/
static register(key, options) { game.settings.register(MODULE_ID, key, options); }

/**
* Register a submenu.
* @param {string} key Passed to registerMenu
* @param {object} options Passed to registerMenu
*/
static registerMenu(key, options) { game.settings.registerMenu(MODULE_ID, key, options); }

/**
* Localize a setting key.
* @param {string} key
*/
static localize(key) { return game.i18n.localize(`${MODULE_ID}.settings.${key}`); }

/**
* Register all settings
*/
static registerAll() {}
}
Loading

0 comments on commit 9adc1a9

Please sign in to comment.