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
Unknown Object (File)
Sat, May 4, 12:31
Unknown Object (File)
Thu, Apr 25, 22:21
Unknown Object (File)
Wed, Apr 24, 22:43
Unknown Object (File)
Mon, Apr 22, 06:20
Unknown Object (File)
Mon, Apr 22, 05:58
Unknown Object (File)
Wed, Apr 17, 18:18
Unknown Object (File)
Wed, Apr 17, 06:44
Unknown Object (File)
Tue, Apr 16, 10:24

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