Skip to content

Commit

Permalink
Check if sprites exist when generating, trying animated and regular s…
Browse files Browse the repository at this point in the history
…prites.
  • Loading branch information
nerdydrew committed Nov 22, 2016
1 parent 51c2a85 commit c68ca70
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
14 changes: 11 additions & 3 deletions setup/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

// These directories should contain sprites named by PokéDex ID
// without leading zeros (e.g. "25.gif").
define('PATH_TO_SPRITES', '/sprites/animated/');
define('PATH_TO_SHINY_SPRITES', '/sprites/animated/shiny/');
define('SPRITE_EXTENTION', '.gif');
// These directories should contain sprites named by PokéDex ID
// without leading zeros (e.g. "25.gif").
define('PATH_TO_ANIMATED_SPRITES', '/sprites/animated/');
define('PATH_TO_SHINY_ANIMATED_SPRITES', '/sprites/animated/shiny/');
define('ANIMATED_SPRITE_EXTENTION', '.gif');

define('PATH_TO_REGULAR_SPRITES', '/sprites/');
define('PATH_TO_SHINY_REGULAR_SPRITES', '/sprites/shiny/');
define('REGULAR_SPRITE_EXTENTION', '.png');

define('DEFAULT_SPRITE', '/sprites/0.png');
29 changes: 27 additions & 2 deletions utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Parameters {
public static $n_low = 1;
public static $n_high = 6;
public static $region_list = array('kanto','johto','hoenn','sinnoh','sinnoh_pt','unova','unova_b2w2','kalos');
public static $region_list = array('kanto','johto','hoenn','sinnoh','sinnoh_pt','unova','unova_b2w2','kalos', 'alola');
public static $type_list = array('bug','dark','dragon','electric','fairy','fighting','fire','flying','ghost','grass','ground','ice','normal','poison','psychic','rock','steel','water');

public static $nature_list = array('Adamant','Bashful','Bold','Brave','Calm','Careful','Docile','Gentle','Hardy','Hasty','Impish','Jolly','Lax','Lonely','Mild','Modest','Naïve','Naughty','Quiet','Quirky','Rash','Relaxed','Sassy','Serious','Timid');
Expand Down Expand Up @@ -225,7 +225,7 @@ public function generate() {
$row['shiny'] = (mt_rand(0,65535) < 16);

if ($this->get_sprites()) {
$row['sprite'] = ($row['shiny'] ? PATH_TO_SHINY_SPRITES : PATH_TO_SPRITES) . $sprite_name . SPRITE_EXTENTION;
$row['sprite'] = get_sprite_path($row, $sprite_name);
}

if ($this->get_natures()) {
Expand All @@ -242,6 +242,31 @@ public function generate() {

//////// FUNCTIONS ////////

function get_sprite_path($row, $sprite_name) {
if ($row['shiny']) {
$animated_path = PATH_TO_SHINY_ANIMATED_SPRITES . $sprite_name . ANIMATED_SPRITE_EXTENTION;
} else {
$animated_path = PATH_TO_ANIMATED_SPRITES . $sprite_name . ANIMATED_SPRITE_EXTENTION;
}

if (file_exists(dirname(__FILE__) . $animated_path)) {
return $animated_path;
} else {
if ($row['shiny']) {
$regular_path = PATH_TO_SHINY_REGULAR_SPRITES . $sprite_name . REGULAR_SPRITE_EXTENTION;
} else {
$regular_path = PATH_TO_REGULAR_SPRITES . $sprite_name . REGULAR_SPRITE_EXTENTION;
}

if (file_exists(dirname(__FILE__) . $regular_path)) {
return $regular_path;
} else {
return DEFAULT_SPRITE;
}
}

}

function validate_parameters($in_params) {
$params = new Parameters();
$params->set_n($in_params['n']);
Expand Down

0 comments on commit c68ca70

Please sign in to comment.