Skip to content

Commit

Permalink
Minor fixes (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Jan 15, 2024
1 parent 8d71668 commit 12e0455
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/electron.renderer/data/Project.hx
Original file line number Diff line number Diff line change
Expand Up @@ -920,13 +920,8 @@ class Project {
}


public function getOrLoadImage(relPath:String,x = -1, y = -1, w = -1, h = -1) : Null<data.DataTypes.CachedImage> {
public function getOrLoadImage(relPath:String, x=-1, y=-1, w=-1, h=-1) : Null<data.DataTypes.CachedImage> {
try {
var thumbnailPath = "";
if(x != -1 && y != -1 && w != -1 && h != -1) {
thumbnailPath = relPath + "_" + Std.string(x) + "_" + Std.string(y) + "_" + Std.string(w) + "_" + Std.string(h);
}

if( !imageCache.exists(relPath) ) {
// Load it from the disk
App.LOG.add("cache", 'Caching image $relPath...');
Expand All @@ -951,8 +946,14 @@ class Project {
pixels: pixels,
tex: texture,
});
if(thumbnailPath != "") {
var subPixels = pixels.sub(x, y, w, h);

// Store thumbnail to cache
var thumbnailPath = "";
if( x!=-1 && y!=-1 && w!=-1 && h!=-1 )
thumbnailPath = relPath + "_" + Std.string(x) + "_" + Std.string(y) + "_" + Std.string(w) + "_" + Std.string(h);

if( thumbnailPath!="" ) {
var subPixels = pixels.sub(x, y, w, h);
var b64 = haxe.crypto.Base64.encode( subPixels.toPNG() );
imageCache.set( thumbnailPath, {
fileName: dn.FilePath.extractFileWithExt(relPath),
Expand All @@ -965,7 +966,7 @@ class Project {
relPath = thumbnailPath;
}
}

return imageCache.get(relPath);
}
catch( e:Dynamic ) {
Expand Down

0 comments on commit 12e0455

Please sign in to comment.