Skip to content

Commit

Permalink
Fixed crash in createTileRectPicker (#928, #927)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Sep 20, 2023
1 parent 511c532 commit 27eddb8
Showing 1 changed file with 40 additions and 36 deletions.
76 changes: 40 additions & 36 deletions src/electron.renderer/misc/JsTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1133,47 +1133,51 @@ class JsTools {
var jTileCanvas = new J('<canvas class="tile"></canvas>');

if( tilesetId!=null ) {
if( active )
jTileCanvas.addClass("active");

var td = Editor.ME.project.defs.getTilesetDef(tilesetId);

if( cur==null ) {
// No tile selected
if( td==null )
jTileCanvas.addClass("empty");
}
else {
// Tile rect
jTileCanvas.attr("width", cur.w);
jTileCanvas.attr("height", cur.h);
var scale = 35 / M.fmax(cur.w, cur.h);
jTileCanvas.css("width", cur.w * scale );
jTileCanvas.css("height", cur.h * scale );
td.drawTileRectToCanvas(jTileCanvas, cur);
}
ui.Tip.attach(jTileCanvas, "Use LEFT click to pick a tile or RIGHT click to remove it.");
if( active )
jTileCanvas.addClass("active");

// Open picker
if( active )
jTileCanvas.mousedown( (ev:js.jquery.Event)->{
switch ev.button {
case 0:
var m = new ui.Modal();
m.addClass("singleTilePicker");

var tp = new ui.Tileset(m.jContent, td, RectOnly);
tp.useSavedSelections = false;
tp.setSelectedRect(cur);
tp.onSelectAnything = ()->{
onPick( tp.getSelectedRect() );
m.close();
}
tp.focusOnSelection(true);
if( cur==null ) {
// No tile selected
jTileCanvas.addClass("empty");
}
else {
// Tile rect
jTileCanvas.attr("width", cur.w);
jTileCanvas.attr("height", cur.h);
var scale = 35 / M.fmax(cur.w, cur.h);
jTileCanvas.css("width", cur.w * scale );
jTileCanvas.css("height", cur.h * scale );
td.drawTileRectToCanvas(jTileCanvas, cur);
}
ui.Tip.attach(jTileCanvas, "Use LEFT click to pick a tile or RIGHT click to remove it.");

// Open picker
if( active )
jTileCanvas.mousedown( (ev:js.jquery.Event)->{
switch ev.button {
case 0:
var m = new ui.Modal();
m.addClass("singleTilePicker");

var tp = new ui.Tileset(m.jContent, td, RectOnly);
tp.useSavedSelections = false;
tp.setSelectedRect(cur);
tp.onSelectAnything = ()->{
onPick( tp.getSelectedRect() );
m.close();
}
tp.focusOnSelection(true);

case _:
onPick(null);
}
});
}

case _:
onPick(null);
}
});
}
else {
// Invalid tileset
Expand Down

0 comments on commit 27eddb8

Please # to comment.