ramiismail / dopresskit

presskit() - spend time making games, not press.
GNU General Public License v3.0
131 stars 50 forks source link

Sort images alphabetically #50

Open aresundnes opened 7 years ago

aresundnes commented 7 years ago

The readdir() method sorts objects in the filesystem order, but i think it would be nice to sort images alphabetically so you can have some control of the order.

I've fixed it locally but want to suggest you change the code to something like this:

    $images = array();
    if ($handle = opendir($game.'/images'))
    {
        while (false !== ($entry = readdir($handle))) array_push($images, $entry);      
        sort($images);
    }

    foreach($images as $entry) 
    {
        // business as usual in here
    }

Anyway, thanks for a great project!

paulcanning commented 7 years ago

On my local Windows machine, the images are already sorted alphabetically.

samizzo commented 7 years ago

@paulcanning on different file and operating systems the sort order will be different. The only way to guarantee an order is to explicitly sort it.