Skip to content

Commit

Permalink
[main] Skip unnecessary array length checks in icon action handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpaperno committed Aug 31, 2023
1 parent e830d05 commit caacff0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,16 @@ async function handleIconAction(actionId: string, data: TpActionDataArrayType)
// Parse and set the size property(ies).
const size = Size.new(parseInt(data[parseState.pos++].value) || PluginSettings.defaultIconSize.width);
// Size height parameter; Added in v1.2-alpha3
if (data.length > parseState.pos && data[parseState.pos].id.endsWith("size_h"))
if (data[parseState.pos]?.id.endsWith("size_h"))
size.height = parseInt(data[parseState.pos++].value) || PluginSettings.defaultIconSize.height
else
icon.sizeIsActual = false; // set flag indicating tiling style is for < v1.2-alpha3. TODO: Remove
Size.set(icon.size, size);

// Handle tiling parameters, if any; Added in v1.2.0
let tile: PointType = { x: 1, y: 1}
if (data.length > parseState.pos + 1 && data[parseState.pos].id.endsWith("tile_x"))
tile = { x: parseInt(data[parseState.pos++].value) || 1, y: parseInt(data[parseState.pos].value) || 1 };
if (data[parseState.pos]?.id.endsWith("tile_x"))
tile = { x: parseInt(data[parseState.pos++].value) || 1, y: parseInt(data[parseState.pos]?.value) || 1 };
// Create the TP state(s) now if we haven't yet (icon.tile will be 0,0); this way a user can create the new state at any time, separate from the render action.
// Also check if the tiling settings have changed; we may need to clean up any existing TP states first or create new ones.
if (!Point.equals(icon.tile, tile)) {
Expand Down

0 comments on commit caacff0

Please sign in to comment.