mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
remoteMap don't error on broken image links
This commit is contained in:
1 parent
486890480d
commit
2ab163ab68
2 files changed
+24
-4
No files matched your search
+22
-2
@@ -23,11 +23,31 @@ export function drawImageWithRotation(ctx, image, x, y, w, h, degrees, sprWidth,
|
||||
ctx.scale(1, -1);
|
||||
}
|
||||
|
||||
if(sprWidth != undefined && sprHeight != undefined && offLeft != undefined && offTop != undefined){
|
||||
if(isImageOk(image) && sprWidth != undefined && sprHeight != undefined && offLeft != undefined && offTop != undefined){
|
||||
// console.log(sprWidth+" "+sprHeight+" "+offLeft+" "+offTop+" "+w+" "+h)
|
||||
ctx.drawImage(image, offLeft, offTop, sprWidth, sprHeight, x, y, w, h);
|
||||
} else {
|
||||
} else if(isImageOk(image)){
|
||||
ctx.drawImage(image, x, y, w, h);
|
||||
} else {
|
||||
// console.log("Image is not OK! "+image.src);
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
export function isImageOk(img) {
|
||||
// During the onload event, IE correctly identifies any images that
|
||||
// weren't downloaded as not complete. Others should too. Gecko-based
|
||||
// browsers act like NS4 in that they report this incorrectly.
|
||||
if (!img.complete) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// However, they do have two very useful properties: naturalWidth and
|
||||
// naturalHeight. These give the true size of the image. If it failed
|
||||
// to load, either of these should be zero.
|
||||
if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// No other way of checking: assume it's ok.
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user