commit 70cc1e540115f0f450867302eebea9d33b2b8d83 Author: Pavel Shevaev Date: Wed May 18 10:16:31 2022 +0300 first version diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..fa94607 --- /dev/null +++ b/composer.json @@ -0,0 +1,11 @@ +{ + "name": "bit/taskman_version", + "description": "taskman version utils", + "homepage": "https://git.bit5.ru/composer/taskman_version", + "require": { + "php": ">=7.4" + }, + "autoload": { + "classmap": ["version.inc.php"] + } +} diff --git a/version.inc.php b/version.inc.php new file mode 100644 index 0000000..0ba6e55 --- /dev/null +++ b/version.inc.php @@ -0,0 +1,88 @@ + 2; + if(!$has_patch_code) + return $full_str; + return substr($full_str, 0, strrpos($full_str, '.')); +} + +function game_version_code($str = null) +{ + $str = $str === null ? game_version() : $str; + $items = explode('.', $str); + if(sizeof($items) < 2) + throw new Exception("Bad version format: $str"); + + $maj = $items[0]; + $min = $items[1]; + $pat = isset($items[2]) ? $items[2] : 0; + + $num = $pat + $min*100 + $maj*1000000; + return $num; +} + +function game_patch_code() +{ + $full_str = game_version_full_str(); + $has_patch_code = substr_count($full_str, '.') > 2; + if(!$has_patch_code) + return 0; + + $code = substr($full_str, strrpos($full_str, '.')+1); + if($code > 9) + throw new Exception("Patch code must be <= 9"); + return $code; +} + +function get_inc_game_version() +{ + $string = game_version(); + + for($i = strlen($string) - 1; $i >= 0; $i--) + { + if(is_numeric($string[$i])) + { + $most_significant_number = $i; + if($string[$i] < 9) + { + $string[$i] = $string[$i] + 1; + break; + } + // The number was a 9, set it to zero and continue. + $string[$i] = 0; + } + } + + // If the most significant number was set to a zero it has overflowed so we + // need to prefix it with a '1'. + if($string[$most_significant_number] === '0') + $string = substr_replace($string, '1', $most_significant_number, 0); + + return $string; +} +