Page MenuHomePhorge

Composing a custom project picture: Remove misaligned empty icon
ClosedPublic

Authored by aklapper on Dec 19 2023, 01:34.

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