Skip to content

Commit

Permalink
Add null check to tile loadtexture
Browse files Browse the repository at this point in the history
Add null check to width checks because templates can have width==null
  • Loading branch information
KayelGee committed Oct 11, 2022
1 parent 330ed5a commit 0f65278
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "token-attacher",
"title": "Token Attacher",
"description": "Attach anything(even tokens) to tokens, so that they move when the token moves and rotate/move when the token rotates. Create prefabs and many more features, see the github readme for more details.",
"version": "4.5.4",
"version": "4.5.5",
"compatibility" :{
"minimum": 10,
"verified": "10.285",
Expand Down Expand Up @@ -56,6 +56,6 @@
"socket": true,
"url": "https://github.com/KayelGee/token-attacher",
"manifest": "https://raw.githubusercontent.com/KayelGee/token-attacher/master/module.json",
"download": "https://github.com/KayelGee/token-attacher/releases/download/v4.5.4/v4.5.4.zip",
"readme": "https://github.com/KayelGee/token-attacher/blob/v4.5.4/README.md"
"download": "https://github.com/KayelGee/token-attacher/releases/download/v4.5.5/v4.5.5.zip",
"readme": "https://github.com/KayelGee/token-attacher/blob/v4.5.5/README.md"
}
16 changes: 8 additions & 8 deletions scripts/token-attacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,11 @@ import {libWrapper} from './shim.js';
if(objData.hasOwnProperty("direction")) update.direction = rotation;
if(objData.hasOwnProperty("rotation")) update.rotation = rotation;

if(objData.hasOwnProperty('width')){
if(objData.hasOwnProperty('width') && objData.width != null){
update.width = offset.size.width * size_multi.w;
update.height = offset.size.height * size_multi.h;
}
if(objData.shape?.hasOwnProperty('width')){
if(objData.shape?.hasOwnProperty('width') && objData.shape.width != null){
if(!update.shape) update.shape = {};
update.shape.width = offset.size.width * size_multi.w;
update.shape.height = offset.size.height * size_multi.h;
Expand Down Expand Up @@ -1496,11 +1496,11 @@ import {libWrapper} from './shim.js';
offset.offRot %= 360;

offset.size = {};
if(objData.hasOwnProperty('width')){
if(objData.hasOwnProperty('width') && objData.width != null){
offset.size.width = objData.width;
offset.size.height = objData.height;
}
if(objData.shape?.hasOwnProperty('width')){
if(objData.shape?.hasOwnProperty('width') && objData.shape.width != null){
offset.size.width = objData.shape.width;
offset.size.height = objData.shape.height;
}
Expand Down Expand Up @@ -1695,14 +1695,14 @@ import {libWrapper} from './shim.js';
});
}

if(objData.hasOwnProperty('width')){
if(objData.hasOwnProperty('width') && objData.width != null){
mergeObject(objData, {
width : offset.size.width,
height: offset.size.height
});
}

if(objData.shape?.hasOwnProperty('width')){
if(objData.shape?.hasOwnProperty('width') && objData.shape.width != null){
mergeObject(objData, {
shape:{
width : offset.size.width,
Expand Down Expand Up @@ -1950,7 +1950,7 @@ import {libWrapper} from './shim.js';
element.texture = {src: element.img};
delete element.img;
}
promises.push(loadTexture(element.texture?.src, {fallback: 'icons/svg/hazard.svg'}));
if(element.texture?.src && element.texture?.src !== "" && element.texture?.src !== null) promises.push(loadTexture(element.texture?.src, {fallback: 'icons/svg/hazard.svg'}));
}
await Promise.all(promises);
}
Expand Down Expand Up @@ -2565,7 +2565,7 @@ import {libWrapper} from './shim.js';
const [x,y] = [objData.x, objData.y];
let center = {x:x, y:y};
//Tokens, Tiles
if ( "width" in objData && "height" in objData ) {
if (objData.width && objData.height && objData.width != null) {
let [width, height] = [objData.width, objData.height];
if(TokenAttacher.isGridSpace(type)) [width, height] = [width * grid.w, height * grid.h]
center={x:x + (Math.abs(width) / 2), y:y + (Math.abs(height) / 2)};
Expand Down

0 comments on commit 0f65278

Please sign in to comment.