Page MenuHomePhorge

Composing a custom project picture: Remove misaligned empty icon
ClosedPublic

Authored by aklapper on Dec 19 2023, 01:34.
Tags
None
Referenced Files
F3290767: D25499.1742871995.diff
Mon, Mar 24, 03:06
F3290313: D25499.1742862806.diff
Mon, Mar 24, 00:33
F3283947: D25499.1742763984.diff
Sat, Mar 22, 21:06
F3280298: D25499.1742648777.diff
Fri, Mar 21, 13:06
F3252559: D25499.1742393244.diff
Tue, Mar 18, 14:07
F3245751: D25499.1742192294.diff
Sun, Mar 16, 06:18
F3236498: D25499.1742174350.diff
Sun, Mar 16, 01:19
F3215647: D25499.1741657484.diff
Mon, Mar 10, 01:44

Details

Summary

Do not assume that all items under /resources/builtin/projects/ are image files (some can be subdirectories). Only add PNG files to the map.

Could be nicer to use is_file() or is_dir() but we are dealing only with string representations of files and folders.

Closes T15696

Test Plan

Go to /project/picture/1/ and click the Choose Icon and Color... button; check last icon shown under "Choose Icon".

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Thanks

Just for some micro-optimization, note that preg_replace() has a 5th parameter called $count

https://www.php.net/manual/en/function.preg-replace.php

Example usage

 $map = array();
 $list = Filesystem::listDirectory($root, $include_hidden = false);
 foreach ($list as $file) {
   $count = 0;
   $short = preg_replace('/\.png$/', '', $file, -1, $count);
   if ($count === 1) {
     $map[$short] = array(
       'path' => $root.$file,
       'quip' => idx($quips, $short, $short),
     );
  }
}
This revision is now accepted and ready to land.Dec 19 2023, 06:49

I'm too stupid to see the exact optimization, performance-wise (but probably not important). :)

Nah my friend, sorry me, my example was incomplete. I've updated that.

https://we.phorge.it/D25499#14398

In short, untested, but it executes only one regex in the loop

Improve performance (as proposed by Valerio)

If it still works, feel free to land

Already accepted previously

And happy xmas :D