From f0d78d5de6713c061574945794c143736026e419 Mon Sep 17 00:00:00 2001 From: kremsy Date: Thu, 26 Dec 2013 11:28:58 +0100 Subject: [PATCH] moved country map into formatter class --- application/core/Formatter.php | 207 +++++++++++++++++++++++ application/core/Players/PlayerList.php | 215 +----------------------- 2 files changed, 210 insertions(+), 212 deletions(-) diff --git a/application/core/Formatter.php b/application/core/Formatter.php index 6d44c0d1..4631c34c 100644 --- a/application/core/Formatter.php +++ b/application/core/Formatter.php @@ -93,4 +93,211 @@ abstract class Formatter { static function stripColors($string) { return preg_replace('/(? 'AFG', + 'Albania' => 'ALB', + 'Algeria' => 'ALG', + 'Andorra' => 'AND', + 'Angola' => 'ANG', + 'Argentina' => 'ARG', + 'Armenia' => 'ARM', + 'Aruba' => 'ARU', + 'Australia' => 'AUS', + 'Austria' => 'AUT', + 'Azerbaijan' => 'AZE', + 'Bahamas' => 'BAH', + 'Bahrain' => 'BRN', + 'Bangladesh' => 'BAN', + 'Barbados' => 'BAR', + 'Belarus' => 'BLR', + 'Belgium' => 'BEL', + 'Belize' => 'BIZ', + 'Benin' => 'BEN', + 'Bermuda' => 'BER', + 'Bhutan' => 'BHU', + 'Bolivia' => 'BOL', + 'Bosnia&Herzegovina' => 'BIH', + 'Botswana' => 'BOT', + 'Brazil' => 'BRA', + 'Brunei' => 'BRU', + 'Bulgaria' => 'BUL', + 'Burkina Faso' => 'BUR', + 'Burundi' => 'BDI', + 'Cambodia' => 'CAM', + 'Cameroon' => 'CAR', // actually CMR + 'Canada' => 'CAN', + 'Cape Verde' => 'CPV', + 'Central African Republic' => 'CAF', + 'Chad' => 'CHA', + 'Chile' => 'CHI', + 'China' => 'CHN', + 'Chinese Taipei' => 'TPE', + 'Colombia' => 'COL', + 'Congo' => 'CGO', + 'Costa Rica' => 'CRC', + 'Croatia' => 'CRO', + 'Cuba' => 'CUB', + 'Cyprus' => 'CYP', + 'Czech Republic' => 'CZE', + 'Czech republic' => 'CZE', + 'DR Congo' => 'COD', + 'Denmark' => 'DEN', + 'Djibouti' => 'DJI', + 'Dominica' => 'DMA', + 'Dominican Republic' => 'DOM', + 'Ecuador' => 'ECU', + 'Egypt' => 'EGY', + 'El Salvador' => 'ESA', + 'Eritrea' => 'ERI', + 'Estonia' => 'EST', + 'Ethiopia' => 'ETH', + 'Fiji' => 'FIJ', + 'Finland' => 'FIN', + 'France' => 'FRA', + 'Gabon' => 'GAB', + 'Gambia' => 'GAM', + 'Georgia' => 'GEO', + 'Germany' => 'GER', + 'Ghana' => 'GHA', + 'Greece' => 'GRE', + 'Grenada' => 'GRN', + 'Guam' => 'GUM', + 'Guatemala' => 'GUA', + 'Guinea' => 'GUI', + 'Guinea-Bissau' => 'GBS', + 'Guyana' => 'GUY', + 'Haiti' => 'HAI', + 'Honduras' => 'HON', + 'Hong Kong' => 'HKG', + 'Hungary' => 'HUN', + 'Iceland' => 'ISL', + 'India' => 'IND', + 'Indonesia' => 'INA', + 'Iran' => 'IRI', + 'Iraq' => 'IRQ', + 'Ireland' => 'IRL', + 'Israel' => 'ISR', + 'Italy' => 'ITA', + 'Ivory Coast' => 'CIV', + 'Jamaica' => 'JAM', + 'Japan' => 'JPN', + 'Jordan' => 'JOR', + 'Kazakhstan' => 'KAZ', + 'Kenya' => 'KEN', + 'Kiribati' => 'KIR', + 'Korea' => 'KOR', + 'Kuwait' => 'KUW', + 'Kyrgyzstan' => 'KGZ', + 'Laos' => 'LAO', + 'Latvia' => 'LAT', + 'Lebanon' => 'LIB', + 'Lesotho' => 'LES', + 'Liberia' => 'LBR', + 'Libya' => 'LBA', + 'Liechtenstein' => 'LIE', + 'Lithuania' => 'LTU', + 'Luxembourg' => 'LUX', + 'Macedonia' => 'MKD', + 'Malawi' => 'MAW', + 'Malaysia' => 'MAS', + 'Mali' => 'MLI', + 'Malta' => 'MLT', + 'Mauritania' => 'MTN', + 'Mauritius' => 'MRI', + 'Mexico' => 'MEX', + 'Moldova' => 'MDA', + 'Monaco' => 'MON', + 'Mongolia' => 'MGL', + 'Montenegro' => 'MNE', + 'Morocco' => 'MAR', + 'Mozambique' => 'MOZ', + 'Myanmar' => 'MYA', + 'Namibia' => 'NAM', + 'Nauru' => 'NRU', + 'Nepal' => 'NEP', + 'Netherlands' => 'NED', + 'New Zealand' => 'NZL', + 'Nicaragua' => 'NCA', + 'Niger' => 'NIG', + 'Nigeria' => 'NGR', + 'Norway' => 'NOR', + 'Oman' => 'OMA', + 'Other Countries' => 'OTH', + 'Pakistan' => 'PAK', + 'Palau' => 'PLW', + 'Palestine' => 'PLE', + 'Panama' => 'PAN', + 'Paraguay' => 'PAR', + 'Peru' => 'PER', + 'Philippines' => 'PHI', + 'Poland' => 'POL', + 'Portugal' => 'POR', + 'Puerto Rico' => 'PUR', + 'Qatar' => 'QAT', + 'Romania' => 'ROM', // actually ROU + 'Russia' => 'RUS', + 'Rwanda' => 'RWA', + 'Samoa' => 'SAM', + 'San Marino' => 'SMR', + 'Saudi Arabia' => 'KSA', + 'Senegal' => 'SEN', + 'Serbia' => 'SCG', // actually SRB + 'Sierra Leone' => 'SLE', + 'Singapore' => 'SIN', + 'Slovakia' => 'SVK', + 'Slovenia' => 'SLO', + 'Somalia' => 'SOM', + 'South Africa' => 'RSA', + 'Spain' => 'ESP', + 'Sri Lanka' => 'SRI', + 'Sudan' => 'SUD', + 'Suriname' => 'SUR', + 'Swaziland' => 'SWZ', + 'Sweden' => 'SWE', + 'Switzerland' => 'SUI', + 'Syria' => 'SYR', + 'Taiwan' => 'TWN', + 'Tajikistan' => 'TJK', + 'Tanzania' => 'TAN', + 'Thailand' => 'THA', + 'Togo' => 'TOG', + 'Tonga' => 'TGA', + 'Trinidad and Tobago' => 'TRI', + 'Tunisia' => 'TUN', + 'Turkey' => 'TUR', + 'Turkmenistan' => 'TKM', + 'Tuvalu' => 'TUV', + 'Uganda' => 'UGA', + 'Ukraine' => 'UKR', + 'United Arab Emirates' => 'UAE', + 'United Kingdom' => 'GBR', + 'United States of America' => 'USA', + 'Uruguay' => 'URU', + 'Uzbekistan' => 'UZB', + 'Vanuatu' => 'VAN', + 'Venezuela' => 'VEN', + 'Vietnam' => 'VIE', + 'Yemen' => 'YEM', + 'Zambia' => 'ZAM', + 'Zimbabwe' => 'ZIM', + ); + + if (array_key_exists($country, $nations)) { + $nation = $nations[$country]; + } else { + $nation = 'OTH'; + if ($country != '') + trigger_error('Could not map country: ' . $country, E_USER_WARNING); + } + return $nation; + } } diff --git a/application/core/Players/PlayerList.php b/application/core/Players/PlayerList.php index 210144f9..23a8d834 100644 --- a/application/core/Players/PlayerList.php +++ b/application/core/Players/PlayerList.php @@ -169,11 +169,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { $neutralQuad->setSize(3.8,3.8); } + //Nation Quad $countryQuad = new Quad(); $playerFrame->add($countryQuad); - - $countryQuad->setImage("file://Skins/Avatars/Flags/{$this->mapCountry($listPlayer->getCountry())}.dds"); + $countryCode = Formatter::mapCountry($listPlayer->getCountry()); + $countryQuad->setImage("file://Skins/Avatars/Flags/{$countryCode}.dds"); $countryQuad->setX($x + 88); $countryQuad->setSize(4,4); $countryQuad->setZ(-0.1); @@ -596,214 +597,4 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { } } } - - - - //TODO move that into somewhere - /** - * Map country names to 3-letter Nation abbreviations - * Created by Xymph - * Based on http://en.wikipedia.org/wiki/List_of_IOC_country_codes - * See also http://en.wikipedia.org/wiki/Comparison_of_IOC,_FIFA,_and_ISO_3166_country_codes - */ - private function mapCountry($country) { - - $nations = array( - 'Afghanistan' => 'AFG', - 'Albania' => 'ALB', - 'Algeria' => 'ALG', - 'Andorra' => 'AND', - 'Angola' => 'ANG', - 'Argentina' => 'ARG', - 'Armenia' => 'ARM', - 'Aruba' => 'ARU', - 'Australia' => 'AUS', - 'Austria' => 'AUT', - 'Azerbaijan' => 'AZE', - 'Bahamas' => 'BAH', - 'Bahrain' => 'BRN', - 'Bangladesh' => 'BAN', - 'Barbados' => 'BAR', - 'Belarus' => 'BLR', - 'Belgium' => 'BEL', - 'Belize' => 'BIZ', - 'Benin' => 'BEN', - 'Bermuda' => 'BER', - 'Bhutan' => 'BHU', - 'Bolivia' => 'BOL', - 'Bosnia&Herzegovina' => 'BIH', - 'Botswana' => 'BOT', - 'Brazil' => 'BRA', - 'Brunei' => 'BRU', - 'Bulgaria' => 'BUL', - 'Burkina Faso' => 'BUR', - 'Burundi' => 'BDI', - 'Cambodia' => 'CAM', - 'Cameroon' => 'CAR', // actually CMR - 'Canada' => 'CAN', - 'Cape Verde' => 'CPV', - 'Central African Republic' => 'CAF', - 'Chad' => 'CHA', - 'Chile' => 'CHI', - 'China' => 'CHN', - 'Chinese Taipei' => 'TPE', - 'Colombia' => 'COL', - 'Congo' => 'CGO', - 'Costa Rica' => 'CRC', - 'Croatia' => 'CRO', - 'Cuba' => 'CUB', - 'Cyprus' => 'CYP', - 'Czech Republic' => 'CZE', - 'Czech republic' => 'CZE', - 'DR Congo' => 'COD', - 'Denmark' => 'DEN', - 'Djibouti' => 'DJI', - 'Dominica' => 'DMA', - 'Dominican Republic' => 'DOM', - 'Ecuador' => 'ECU', - 'Egypt' => 'EGY', - 'El Salvador' => 'ESA', - 'Eritrea' => 'ERI', - 'Estonia' => 'EST', - 'Ethiopia' => 'ETH', - 'Fiji' => 'FIJ', - 'Finland' => 'FIN', - 'France' => 'FRA', - 'Gabon' => 'GAB', - 'Gambia' => 'GAM', - 'Georgia' => 'GEO', - 'Germany' => 'GER', - 'Ghana' => 'GHA', - 'Greece' => 'GRE', - 'Grenada' => 'GRN', - 'Guam' => 'GUM', - 'Guatemala' => 'GUA', - 'Guinea' => 'GUI', - 'Guinea-Bissau' => 'GBS', - 'Guyana' => 'GUY', - 'Haiti' => 'HAI', - 'Honduras' => 'HON', - 'Hong Kong' => 'HKG', - 'Hungary' => 'HUN', - 'Iceland' => 'ISL', - 'India' => 'IND', - 'Indonesia' => 'INA', - 'Iran' => 'IRI', - 'Iraq' => 'IRQ', - 'Ireland' => 'IRL', - 'Israel' => 'ISR', - 'Italy' => 'ITA', - 'Ivory Coast' => 'CIV', - 'Jamaica' => 'JAM', - 'Japan' => 'JPN', - 'Jordan' => 'JOR', - 'Kazakhstan' => 'KAZ', - 'Kenya' => 'KEN', - 'Kiribati' => 'KIR', - 'Korea' => 'KOR', - 'Kuwait' => 'KUW', - 'Kyrgyzstan' => 'KGZ', - 'Laos' => 'LAO', - 'Latvia' => 'LAT', - 'Lebanon' => 'LIB', - 'Lesotho' => 'LES', - 'Liberia' => 'LBR', - 'Libya' => 'LBA', - 'Liechtenstein' => 'LIE', - 'Lithuania' => 'LTU', - 'Luxembourg' => 'LUX', - 'Macedonia' => 'MKD', - 'Malawi' => 'MAW', - 'Malaysia' => 'MAS', - 'Mali' => 'MLI', - 'Malta' => 'MLT', - 'Mauritania' => 'MTN', - 'Mauritius' => 'MRI', - 'Mexico' => 'MEX', - 'Moldova' => 'MDA', - 'Monaco' => 'MON', - 'Mongolia' => 'MGL', - 'Montenegro' => 'MNE', - 'Morocco' => 'MAR', - 'Mozambique' => 'MOZ', - 'Myanmar' => 'MYA', - 'Namibia' => 'NAM', - 'Nauru' => 'NRU', - 'Nepal' => 'NEP', - 'Netherlands' => 'NED', - 'New Zealand' => 'NZL', - 'Nicaragua' => 'NCA', - 'Niger' => 'NIG', - 'Nigeria' => 'NGR', - 'Norway' => 'NOR', - 'Oman' => 'OMA', - 'Other Countries' => 'OTH', - 'Pakistan' => 'PAK', - 'Palau' => 'PLW', - 'Palestine' => 'PLE', - 'Panama' => 'PAN', - 'Paraguay' => 'PAR', - 'Peru' => 'PER', - 'Philippines' => 'PHI', - 'Poland' => 'POL', - 'Portugal' => 'POR', - 'Puerto Rico' => 'PUR', - 'Qatar' => 'QAT', - 'Romania' => 'ROM', // actually ROU - 'Russia' => 'RUS', - 'Rwanda' => 'RWA', - 'Samoa' => 'SAM', - 'San Marino' => 'SMR', - 'Saudi Arabia' => 'KSA', - 'Senegal' => 'SEN', - 'Serbia' => 'SCG', // actually SRB - 'Sierra Leone' => 'SLE', - 'Singapore' => 'SIN', - 'Slovakia' => 'SVK', - 'Slovenia' => 'SLO', - 'Somalia' => 'SOM', - 'South Africa' => 'RSA', - 'Spain' => 'ESP', - 'Sri Lanka' => 'SRI', - 'Sudan' => 'SUD', - 'Suriname' => 'SUR', - 'Swaziland' => 'SWZ', - 'Sweden' => 'SWE', - 'Switzerland' => 'SUI', - 'Syria' => 'SYR', - 'Taiwan' => 'TWN', - 'Tajikistan' => 'TJK', - 'Tanzania' => 'TAN', - 'Thailand' => 'THA', - 'Togo' => 'TOG', - 'Tonga' => 'TGA', - 'Trinidad and Tobago' => 'TRI', - 'Tunisia' => 'TUN', - 'Turkey' => 'TUR', - 'Turkmenistan' => 'TKM', - 'Tuvalu' => 'TUV', - 'Uganda' => 'UGA', - 'Ukraine' => 'UKR', - 'United Arab Emirates' => 'UAE', - 'United Kingdom' => 'GBR', - 'United States of America' => 'USA', - 'Uruguay' => 'URU', - 'Uzbekistan' => 'UZB', - 'Vanuatu' => 'VAN', - 'Venezuela' => 'VEN', - 'Vietnam' => 'VIE', - 'Yemen' => 'YEM', - 'Zambia' => 'ZAM', - 'Zimbabwe' => 'ZIM', - ); - - if (array_key_exists($country, $nations)) { - $nation = $nations[$country]; - } else { - $nation = 'OTH'; - if ($country != '') - trigger_error('Could not map country: ' . $country, E_USER_WARNING); - } - return $nation; - } } \ No newline at end of file