Skip to content

Commit

Permalink
Patch with bugfix for dancing lights and user source now overrides co…
Browse files Browse the repository at this point in the history
…nfig value
  • Loading branch information
lupestro committed Sep 17, 2022
1 parent 4ae7158 commit f17be56
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Middle Kingdom - v10 branch

### 2.1.2 - September 14, 2022
- [BUGFIX] Fixed image used for dancing lights
- [BUGFIX] Reset precedence order to user-supplied light sources first, then the source in config settings, then module-provided defaults based on game rules.

### 2.1.1 - September 6, 2022
- [BUGFIX] (Lupestro) Fixed issue where unlinked tokens were adjusting inventory on source token.
- [BUGFIX] (Lupestro) Fixed designation of which stock light sources are consumable in GURPS
Expand Down
62 changes: 49 additions & 13 deletions library.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,27 @@ export default class SourceLibrary {
SourceLibrary.commonLibrary = await fetch('/modules/torch/sources.json')
.then( response => { return response.json(); });
}
let configuredLight = {
system: systemId,
name: selfItem,
states: 2,
light: [ {bright: selfBright, dim:selfDim, angle:360} ]
};
// The user library reloads every time you open the HUD to permit cut and try.
let mergedLibrary = userLibrary ? await fetch(userLibrary)
.then( response => { return response.json(); })
.then( userData => { return mergeLibraries (userData, SourceLibrary.commonLibrary); })
.then( userData => { return mergeLibraries (userData, SourceLibrary.commonLibrary, configuredLight); })
.catch(reason => {
console.warn("Failed loading user library: ", reason);
}) : mergeLibraries ({}, SourceLibrary.commonLibrary);
}) : mergeLibraries (
{}, SourceLibrary.commonLibrary, configuredLight);
// All local changes here take place against the merged data, which is a copy,
// not against the common or user libraries.
if (mergedLibrary[systemId]) {
mergedLibrary[systemId].topology = getTopology(
mergedLibrary[systemId].topology,
mergedLibrary[systemId].quantity);
let library = new SourceLibrary(mergedLibrary[systemId]);
let targetLightSource = library.getLightSource(selfItem);
if (targetLightSource) {
targetLightSource.states = 2;
targetLightSource.light = [{
bright: selfBright,
dim: selfDim,
angle: 360
}];
}
return library;
} else {
mergedLibrary["default"].topology = getTopology(
Expand Down Expand Up @@ -102,7 +100,7 @@ export default class SourceLibrary {
/*
* Create a merged copy of two libraries.
*/
let mergeLibraries = function (userLibrary, commonLibrary) {
let mergeLibraries = function (userLibrary, commonLibrary, configuredLight) {
let mergedLibrary = {}

// Merge systems - system properties come from common library unless the system only exists in user library
Expand Down Expand Up @@ -141,9 +139,47 @@ let mergeLibraries = function (userLibrary, commonLibrary) {
};
}
}
// Source properties for configured source override common library but not user library
let configuredName = "";
if (configuredLight.name) {
let inUserLibrary = false;
let template = null;
if (system === configuredLight.system) {
for (let source in mergedLibrary[system].sources) {
if (source.toLowerCase() === configuredLight.name.toLowerCase()) {
inUserLibrary = true;
break;
}
}
if (!inUserLibrary) {
for (let source in commonLibrary[system].sources) {
if (source.toLowerCase() === configuredLight.name.toLowerCase()) {
configuredName = source;
template = commonLibrary[system].sources[source];
break;
}
}
if (!configuredName) {
configuredName = configuredLight.name; //But might be blank
}
// We finally have the best name to use and perhaps a template
// We can build one
mergedLibrary[system].sources[configuredName] = {
"name": configuredName,
"type": template ? template["type"] :"equipment",
"consumable": template ? template["consumable"] : true,
"states": configuredLight.states,
"light": Object.assign({}, configuredLight.light )
};
}
}
}
// Finally, we will deal with the common library for whatever is left
if (system in commonLibrary) {
for (let source in commonLibrary[system].sources) {
if (!userLibrary || !(system in userLibrary) || !(source in userLibrary[system].sources)) {
if ((!userLibrary || !(system in userLibrary) ||
!(source in userLibrary[system].sources)) &&
(!configuredName || source !== configuredName)) {
let commonSource = commonLibrary[system].sources[source];
mergedLibrary[system].sources[source] = {
"name": commonSource["name"],
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "torch",
"title": "Torch",
"description": "Torch HUD Controls",
"version": "2.1.1",
"version": "2.1.2",
"authors": [{ "name": "Deuce"},{ "name": "Lupestro"}],
"languages": [
{
Expand Down Expand Up @@ -52,7 +52,7 @@
"minimumCoreVersion": "10",
"compatibility": {
"minimum": "10",
"verified": "10.284",
"verified": "10.285",
"maximum": "10"
}
}
2 changes: 1 addition & 1 deletion request.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class TorchRequest {
angle: 360
},
texture: {
src: "systems/dnd5e/icons/spells/light-air-fire-1.jpg",
src: "icons/magic/light/explosion-star-glow-orange.webp",
scaleX: 0.25,
scaleY: 0.25,
rotation: 0
Expand Down
Binary file modified torch.zip
Binary file not shown.

0 comments on commit f17be56

Please sign in to comment.