Skip to content

Commit

Permalink
v1.15.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
drewg13 committed Dec 21, 2021
1 parent dfd7f9c commit 0844776
Show file tree
Hide file tree
Showing 200 changed files with 128 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,4 @@ v1.9.4 Fix Trauma tooltip z-indexing

1.14.16 Layout fixes

1.15.0 Added feature to create animated Tile when Planet or Star System dropped on canvas, added animated icons to Planets and Star Systems (idea and some icons contributed by brunocalado)
77 changes: 77 additions & 0 deletions module/sav-helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { warn } from "./sav-clock-util.js";

export class SaVHelpers {

/**
Expand Down Expand Up @@ -266,4 +268,79 @@ export class SaVHelpers {
let message = `<div class="resource-chat-notification">${ actor }<table><tr><td>${ resource }</td></tr></table></div>`;
ChatMessage.create({content: message});
}

/* -------------------------------------------- */

/**
* Creates a Tile on a canvas
*
* @param {Object} canvas
* canvas Object where the Tile should be created
* @param {Object} data
* data describing Tile to be created
*/
static async createTile( canvas, data ) {
if ( data.type === "Item" ) {
let sourceData;
if( data.pack ){
let packData;
if( game.majorVersion > 7 ) {
packData = await game.packs.get( data.pack ).getDocuments();
} else {
packData = await game.packs.get( data.pack ).getContent();
}
sourceData = packData.find( p => p.id === data.id ).data;
} else {
sourceData = game.items.get( data.id ).data;
}
if( ( sourceData.type === "planet" ) || ( sourceData.type === "star_system" ) ) {
let tileImg = sourceData.img.replace( /webp/g, "webm" );

try {
const t = await loadTexture( tileImg );
let tileData = {
img: tileImg,
width: t.width,
height: t.height,
x: data.x,
y: data.y
};

if( game.majorVersion === 7 ) {
await canvas.scene.createEmbeddedEntity( "Tile", [ tileData ] );
} else {
await canvas.scene.createEmbeddedDocuments( "Tile", [ tileData ] );
}

} catch( error ) {
ui.notifications.warn( "Error creating Tile, there needs to exist a WEBM file with the same filename and location as the Item img WEBP" )
}
}
}
}

/* -------------------------------------------- */

/**
* Gets files from a specified directory matching the target
*
* @param {string} target
* target variable to pass to FilePicker.browse()
* @param {string[]} extensions
* data describing Tile to be created
* @param {Boolean} wildcard
*
* @param {string} source
* source variable to pass to FilePicker.browse()
*/
static async getFiles(target, extensions, wildcard = false, source = "user")
{
extensions = extensions instanceof Array ? extensions : [extensions];
let options = { extensions: extensions, wildcard: wildcard };
let filePicker = await FilePicker.browse(source, target, options);
if(filePicker.files)
return [...filePicker.files];
return [];
}

}
10 changes: 7 additions & 3 deletions module/sav-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ export class SaVItem extends Item {
await actor.deleteEmbeddedDocuments( "Item", removeItems );
}
}

if ( this.type === "star_system" ) {
this.data.update({img: "systems/scum-and-villainy/styles/assets/icons/orbital.png"});
let stars = await SaVHelpers.getFiles("systems/scum-and-villainy/styles/assets/stars/star*", ".webp", true);
let random = Math.floor( Math.random() * stars.length ) + 1;
this.data.update( { img: stars[random] } );
}
if ( this.type === "planet" ) {
this.data.update({img: "systems/scum-and-villainy/styles/assets/icons/moon-orbit.png"});
let planets = await SaVHelpers.getFiles("systems/scum-and-villainy/styles/assets/planets/planet*", ".webp", true);
let random = Math.floor( Math.random() * planets.length ) + 1;
this.data.update( { img: planets[random] } );
}
}

Expand Down
7 changes: 6 additions & 1 deletion module/sav-roll.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ async function showChatRollMessage(r, zeromode, attribute_name = "", position =

let speaker = ChatMessage.getSpeaker();
let rolls = (r.terms)[0].results;
let attribute_label = SaVHelpers.getAttributeLabel(attribute_name);
let attribute_label;
if( attribute_name === "Fortune!"){
attribute_label = attribute_name;
} else {
attribute_label = SaVHelpers.getAttributeLabel(attribute_name);
}

// Retrieve Roll status.
let roll_status;
Expand Down
30 changes: 19 additions & 11 deletions module/sav.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,19 @@ Hooks.on("preUpdateActor", (actor, data, options, userId) => {
});

Hooks.on("preUpdateItem", (item, data, options, userId) => {
if ( Object.keys( data.data )[0] === "is_damaged" ) {
let actorName = item.actor.name;
let itemName = item.name;
let resource;
if( data.data.is_damaged === 1 ) {
resource = itemName + " " + game.i18n.localize( "BITD.ItemDamaged" );
} else {
resource = itemName + " " + game.i18n.localize( "BITD.ItemRepaired" );
}
if ( game.settings.get("scum-and-villainy", "logResourceToChat") ) {
SaVHelpers.chatNotifyString( actorName, resource );
if( data.data !== undefined ){
if( Object.keys( data.data )[0] === "is_damaged" ) {
let actorName = item.actor.name;
let itemName = item.name;
let resource;
if( data.data.is_damaged === 1 ) {
resource = itemName + " " + game.i18n.localize( "BITD.ItemDamaged" );
} else {
resource = itemName + " " + game.i18n.localize( "BITD.ItemRepaired" );
}
if( game.settings.get( "scum-and-villainy", "logResourceToChat" ) ) {
SaVHelpers.chatNotifyString( actorName, resource );
}
}
}
});
Expand Down Expand Up @@ -441,3 +443,9 @@ Hooks.on("renderTokenHUD", async (hud, html, token) => {
rootElement.classList.remove('hide-ui');
}
});

Hooks.on("dropCanvasData", async (canvas, data) => {
if( data.type === "Item" ){
await SaVHelpers.createTile( canvas, data );
}
});
Loading

0 comments on commit 0844776

Please sign in to comment.