--Entrances / Trophies / Animations for PES 2020
--Edited by FuNZoTiK on 01/06/2020

local fileroot = ".\\content\\Entrance"
local entry
local tid

local function set_random(ctx)
	tid = ctx.tournament_id
	home = ctx.home_team
	away = ctx.away_team
end

function make_key(ctx, filename)
    if tid == 2 or tid == 1026 or tid == 2050 or tid == 3074 or tid == 4098 or tid == 5122 or tid == 6146 or tid == 7170 or tid == 8194 then
	     entry = 16
	     Entrance = "UEFA Champions League\\Group_Knockout"
	elseif tid == 3 or tid == 1027  or tid == 2051 or tid == 3075 or tid == 4099 or tid == 5123 or tid == 6147 or tid == 7171 or tid == 8195 or tid == 4 then
	     entry = 16
	   if ctx.match_info == 53 then
	      Entrance = "UEFA Champions League\\Final"
	   else
	      Entrance = "UEFA Champions League\\Group_Knockout"
	   end
    elseif tid == 5 or tid == 1029 or tid == 2053 or tid == 3077 or tid == 4101 or tid == 5125 or tid == 6149 or tid == 7173 or tid == 8197 or tid == 9221 or tid == 10245 or tid == 11269 or tid == 12293 or tid == 6 then
	   	 entry = 16
	   if ctx.match_info == 53 then
	      Entrance = "UEFA Europa League\\Final"
	   else
	      Entrance = "UEFA Europa League\\Group_Knockout"
	   end
	elseif tid == 7 then
	     entry = 16
		 Entrance = "UEFA Super Cup"
    elseif tid == 17 then
         entry = 16
		 Entrance = "Premier League"
	elseif tid == 20 then
         entry = 16
		 Entrance = "Ligue 1"
	elseif tid == 81 then
         entry = 16
		 Entrance = "Ligue 2"
	elseif tid == 26 then
         entry = 16
		 Entrance = "Coupe De La Ligue"
	elseif tid == 118 then
         entry = 16
		 Entrance = "Super Lig"
	elseif tid == 23 then
         entry = 16
	     Entrance = "FA Cup"
	elseif tid == 18 then
         entry = 16
	     Entrance = "Serie A"
	elseif tid == 82 or tid == 85 then
         entry = 16
	     Entrance = "Serie B"
	elseif tid == 21 then
         entry = 16
		 Entrance = "Eredivisie"
	elseif tid == 115 or tid == 155 or tid == 156 or tid == 157 or tid == 158 or tid == 159 then
         entry = 16
		 Entrance = "Jupiler Pro League"
	elseif tid == 50 then
         entry = 16
	     Entrance = "Bundesliga"
	elseif tid == 53 then
         entry = 16
	     Entrance = "DFB Pokal"
	elseif tid == 95 then
         entry = 16
	     Entrance = "DFL Supercup"
	elseif tid == 59 then
         entry = 16
		 Entrance = "Copa Argentina"	 
	elseif tid == 30 then
         entry = 16
		 Entrance = "Superliga Argentina"
	elseif tid == 8 or tid == 1032 or tid == 2056 or tid == 3080 or tid == 4104 or tid == 9 or tid == 1033 or tid == 2057 or tid == 3081 or tid == 4105 or tid == 5129  or tid == 6153 or tid == 7177 or tid == 8201 or tid == 10 then
         entry = 10
		 Entrance = "Copa Libertadores"
	elseif tid == 34 or tid == 1058 or tid == 2082 or tid == 3106 or tid == 4130 or tid == 5154 or tid == 6178 or tid == 7202 or tid == 8226 or tid == 35 then
         entry = 35
	     Entrance = "FIFA World Cup"
	elseif tid == 41 or tid == 1065 or tid == 2089 or tid == 3113 or tid == 4137 or tid == 5161 or tid == 6185 or tid == 42 then
         entry = 42
	     Entrance = "UEFA Euro"
	elseif tid == 43 then
         entry = 16
		 Entrance = "Copa America"
	elseif tid == 44 or tid == 1068 or tid == 2092 or tid == 3116 or tid == 4140 or tid == 45 then
         entry = 45
		 Entrance = "AFC Asian Cup"
	elseif tid == 46 then
         entry = 46
		 Entrance = "Africa Cup of Nations"
	elseif tid == 1 then
         entry = 16
		 Entrance = "FIFA Club World Cup"
	--elseif tid == 105 or tid == 106 or tid == 107 then
         --entry = 16
		 --Entrance = "International Champions Cup"
	elseif tid == 79 then
         entry = 16
		 Entrance = "EFL\\Championship"
	elseif tid == 83 then
         entry = 16
		 Entrance = "EFL\\Play-Off"
	elseif tid == 86 then
         entry = 16
		 Entrance = "Community Shield"
	elseif tid == 19 then
         entry = 16
		 Entrance = "LaLiga"
	elseif tid == 80 or tid == 84 then
         entry = 16
		 Entrance = "LaLiga Smartbank"
	elseif tid == 25 then
         entry = 16
		 Entrance = "Copa del Rey"
	elseif tid == 87 then
         entry = 16
		 Entrance = "Supercopa de Espana"
	elseif tid == 88 then
         entry = 16
		 Entrance = "Trophee des Champions"
	--elseif tid == 22 then
         --entry = 16
		 --Entrance = "Liga NOS"
	elseif tid == 24 then
         entry = 16
		 Entrance = "Coppa Italia"
	elseif tid == 89 then
         entry = 16
		 Entrance = "Supercoppa Italiana"
	--elseif tid == 27 then
         --entry = 16
		 --Entrance = "KNVB Beker"
	--elseif tid == 90 then
         --entry = 16
		 --Entrance = "Johan Cruyff Shield"
	elseif tid == 28 then
         entry = 16
		 Entrance = "Taca de Portugal"
	--elseif tid == 91 then
         --entry = 16
		 --Entrance = "Supertaca Cândido de Oliveira"
	elseif tid == 116 then
         entry = 16
		 Entrance = "Russian Premier League"
	--elseif tid == 123 then
         --entry = 16
		 --Entrance = "Russian Cup"
	--elseif tid == 123 then
         --entry = 16
		 --Entrance = "Russian Super Cup"
	--elseif tid == 117 then
         --entry = 16
		 --Entrance = "Raiffeisen Super League"
	--elseif tid == 124 then
         --entry = 16
		 --Entrance = "Swiss Cup"
	--elseif tid == 112 then
         --entry = 16
		 --Entrance = "Crocky Cup"
	--elseif tid == 128 then
         --entry = 16
		 --Entrance = "Belgian Super Cup"
	--elseif tid == 125 then
         --entry = 16
		 --Entrance = "Turkish Cup"
	--elseif tid == 130 then
         --entry = 16
		 --Entrance = "Turkish Super Cup"
	--elseif tid == 141 or tid == 142 or tid == 147 or tid == 148 or tid == 149 or tid == 150 or tid == 151 then
         --entry = 16
		 --Entrance = "Danish Superliga"
	elseif tid == 133 or tid == 134 or tid == 135 or tid == 136 then
         entry = 16
		 Entrance = "SPFL"
	elseif tid == 137 then
         entry = 16
		 Entrance = "Scottish Cup"
	--elseif tid == 119 or tid == 23800 or tid == 23801 or tid == 160 or tid == 161 then
         --entry = 16
		 --Entrance = "Liga Aguila"
	--elseif tid == 126 then
         --entry = 16
		 --Entrance = "Copa Colombia"
	--elseif tid == 131 then
         --entry = 16
		 --Entrance = "Superliga Colombiana"
	elseif tid == 67 or tid == 13400 or tid == 13401 then
         entry = 16
		 Entrance = "Campeonato AFP Planvital"
	elseif tid == 68 then
         entry = 16
		 Entrance = "Copa Chile"
	elseif tid == 92 then
         entry = 16
		 Entrance = "Supercopa Argentina"
	elseif tid == 29 then
         entry = 16
		 Entrance = "Brasileiro Serie A"
	--elseif tid == 31 then
         --entry = 16
		 --Entrance = "Copa do Brasil"
    elseif tid == 65535 or tid == 47 or tid == 48 or tid == 99 or tid == 9400 or tid == 9401 or tid == 9402 or tid == 9403 or tid == 9404 or tid == 9405 or tid == 9406 or tid == 9407 then
		 --Exhibition
	     if (home == 101 or home == 4071 or home == 107 or home == 378 or home == 377 or home == 102 or home == 382 or home == 177 or home == 388 or home == 4194 or home == 204 or home == 103 or home == 173 or home == 100 or home == 106 or home == 207 or home == 179 or home == 398 or home == 105 or home == 208) and (away == 101 or away == 4071 or away == 107 or away == 378 or away == 377 or away == 102 or away == 382 or away == 177 or away == 388 or away == 4194 or away == 204 or away == 103 or away == 173 or away == 100 or away == 106 or away == 207 or away == 179 or away == 398 or away == 105 or away == 208) then
		 	 entry = 16
	         Entrance = "Premier League"
		 elseif (home == 1588 or home == 201 or home == 176 or home == 4180 or home == 1760 or home == 379 or home == 203 or home == 383 or home == 178 or home == 2610 or home == 1589 or home == 104 or home == 4363 or home == 205 or home == 387 or home == 389 or home == 4192 or home == 1327 or home == 391 or home == 394 or home == 395 or home == 1909 or home == 399 or home == 400) and (away == 107 or away == 201 or away == 176 or away == 202 or away == 4180 or away == 1760 or away == 383 or away == 1589 or away == 386 or away == 104 or away == 205 or away == 387 or away == 388 or away == 389 or away == 4192 or away == 1327 or away == 391 or away == 4193 or away == 4194 or away == 394 or away == 395 or away == 1909 or away == 399 or away == 400) then
	         entry = 16
	         Entrance = "EFL\\Championship"
		 elseif (home == 4200 or home == 403 or home == 115 or home == 4123 or home == 1328 or home == 1329 or home == 213 or home == 112 or home == 215 or home == 216 or home == 217 or home == 1910 or home == 181 or home == 113 or home == 114 or home == 218 or home == 418 or home == 1330 or home == 4213 or home == 221) and (away == 4200 or away == 403 or away == 115 or away == 4123 or away == 1328 or away == 1329 or away == 213 or away == 112 or away == 215 or away == 216 or away == 217 or away == 1910 or away == 181 or away == 113 or away == 114 or away == 218 or away == 418 or away == 1330 or away == 4213 or away == 221) then
		 	 entry = 16
	         Entrance = "Ligue 1"
	     elseif (home == 209 or home == 180 or home == 405 or home == 4973 or home == 406 or home == 407 or home == 4370 or home == 211 or home == 413 or home == 212 or home == 414 or home == 415 or home == 416 or home == 4210 or home == 4211 or home == 182 or home == 4372 or home == 219 or home == 420 or home == 1528) and (away == 209 or away == 180 or away == 405 or away == 4973 or away == 406 or away == 407 or away == 4370 or away == 211 or away == 413 or away == 212 or away == 414 or away == 415 or away == 416 or away == 4210 or away == 4211 or away == 182 or away == 4372 or away == 219 or away == 420 or away == 1528) then
		 	 entry = 16
	         Entrance = "Ligue 2"
	     elseif (home == 234 or home == 186 or home == 187 or home == 320 or home == 124 or home == 323 or home == 336 or home == 119 or home == 120 or home == 122 or home == 121 or home == 327 or home == 123 or home == 125 or home == 240 or home == 1919 or home == 4923 or home == 4237 or home == 333 or home == 190) and (away == 234 or away == 186 or away == 187 or away == 320 or away == 124 or away == 323 or away == 336 or away == 119 or away == 120 or away == 122 or away == 121 or away == 327 or away == 123 or away == 125 or away == 240 or away == 1919 or away == 4923 or away == 4237 or away == 333 or away == 190) then
		 	 entry = 16
			 Entrance = "Serie A"
	     elseif (home == 317 or home == 4232 or home == 188 or home == 1920 or home == 4928 or home == 4220 or home == 1363 or home == 235 or home == 4234 or home == 2517 or home == 325 or home == 4240 or home == 328 or home == 4241 or home == 4915 or home == 4244 or home == 1600 or home == 4077 or home == 4229 or home == 4230) and (away == 317 or away == 4232 or away == 188 or away == 1920 or away == 4928 or away == 4220 or away == 1363 or away == 235 or away == 4234 or away == 2517 or away == 325 or away == 4240 or away == 328 or away == 4241 or away == 4915 or away == 4244 or away == 1600 or away == 4077 or away == 4229 or away == 4230) then
		 	 entry = 16
			 Entrance = "Serie B"
		 elseif (home == 4145 or home == 258 or home == 108 or home == 4146 or home == 362 or home == 1765 or home == 4272 or home == 366 or home == 259 or home == 109 or home == 172 or home == 261 or home == 263 or home == 265 or home == 194 or home == 110 or home == 266 or home == 196 or home == 195 or home == 267) and (away == 4145 or away == 258 or away == 108 or away == 4146 or away == 362 or away == 1765 or away == 4272 or away == 366 or away == 259 or away == 109 or away == 172 or away == 261 or away == 263 or away == 265 or away == 194 or away == 110 or away == 266 or away == 196 or away == 195 or away == 267) then
		 	 entry = 16
			 Entrance = "LaLiga"		 
		 elseif (home == 1930 or home == 2451 or home == 1245 or home == 2453 or home == 1246 or home == 2459 or home == 2454 or home == 1247 or home == 1931 or home == 1248 or home == 1249 or home == 5143 or home == 1933 or home == 1250 or home == 1252 or home == 137 or home == 1254 or home == 1255 or home == 1936 or home == 136) and (away == 1930 or away == 2451 or away == 1245 or away == 2453 or away == 1246 or away == 2459 or away == 2454 or away == 1247 or away == 1931 or away == 1248 or away == 1249 or away == 5143 or away == 1933 or away == 1250 or away == 1252 or away == 137 or away == 1254 or away == 1255 or away == 1936 or away == 136) then
		 	 entry = 16
			 Entrance = "Brasileiro Serie A"
		 elseif (home == 2192 or home == 2553 or home == 1256 or home == 2707 or home == 2708 or home == 2547 or home == 2543 or home == 2208 or home == 2545 or home == 2541 or home == 2548 or home == 2360 or home == 2546 or home == 2191 or home == 2551 or home == 2209) and (home == 2192 or home == 2553 or home == 1256 or home == 2707 or home == 2708 or home == 2547 or home == 2543 or home == 2208 or home == 2545 or home == 2541 or home == 2548 or home == 2360 or home == 2546 or home == 2191 or home == 2551 or home == 2209) then
		 	 entry = 16
			 Entrance = "Campeonato AFP Planvital"
		 elseif (home == 5202 or home == 5360 or home == 1989 or home == 273 or home == 5355 or home == 197 or home == 130 or home == 5356 or home == 1230 or home == 5203 or home == 1995 or home == 2625 or home == 1996 or home == 5204 or home == 5354 or home == 1809 or home == 1945 or home == 5206) and (away == 5202 or away == 5360 or away == 1989 or away == 273 or away == 5355 or away == 197 or away == 130 or away == 5356 or away == 1230 or away == 5203 or away == 1995 or away == 2625 or away == 1996 or away == 5204 or away == 5354 or away == 1809 or away == 1945 or away == 5206) then
		 	 entry = 16
			 Entrance = "Super Lig"
		 elseif (home == 5196 or home == 5197 or home == 1217 or home == 1753 or home == 2618 or home == 4143 or home == 271 or home == 5301 or home == 2229 or home == 1941 or home == 5296 or home == 135 or home == 5306 or home == 5200 or home == 5201 or home == 1218) and (away == 5196 or away == 5197 or away == 1217 or away == 1753 or away == 2618 or away == 4143 or away == 271 or away == 5301 or away == 2229 or away == 1941 or away == 5296 or away == 135 or away == 5306 or away == 5200 or away == 5201 or away == 1218) then
		 	 entry = 16
			 Entrance = "Russian Premier League"
		 elseif (home == 2717 or home == 1236 or home == 1921 or home == 2719 or home == 1927 or home == 139 or home == 4995 or home == 1923 or home == 2722 or home == 1238 or home == 1239 or home == 1924 or home == 1922 or home == 1240 or home == 1929 or home == 1241 or home == 2729 or home == 1237 or home == 138 or home == 1242 or home == 1243 or home == 5046 or home == 2538 or home == 1244) and (away == 2717 or away == 1236 or away == 1921 or away == 2719 or away == 1927 or away == 139 or away == 4995 or away == 1923 or away == 2722 or away == 1238 or away == 1239 or away == 1924 or away == 1922 or away == 1240 or away == 1929 or away == 1241 or away == 2729 or away == 1237 or away == 138 or away == 1242 or away == 1243 or away == 5046 or away == 2538 or away == 1244) then
		 	 entry = 16
			 Entrance = "Superliga Argentina"
		 elseif (home == 174 or home == 5191 or home == 2009 or home == 269 or home == 1195 or home == 1196 or home == 5190 or home == 2013 or home == 5192 or home == 1200 or home == 5193 or home == 5194 or home == 2010 or home == 1197 or home == 5195 or home == 2019) and (away == 174 or away == 5191 or away == 2009 or away == 269 or away == 1195 or away == 1196 or away == 5190 or away == 2013 or away == 5192 or away == 1200 or away == 5193 or away == 5194 or away == 2010 or away == 1197 or away == 5195 or away == 2019) then
		 	 entry = 16
			 Entrance = "Jupiler Pro League"
	     else
	         entry = nil
	     end
	else
	   entry = nil
    end

    if tid then
       return string.format("%s:%s", Entrance, filename)
    end
end

function trophy_rewrite(ctx, tournament_id)
   if entry ~= nil then
      local tid = entry
      if tid then
	     Entrance = string.gsub(Entrance, "\\Final", "")
	     Entrance = string.gsub(Entrance, "\\Group_Knockout", "")
	     log("---- " .. Entrance)
    	 return tid
      end
   else
	  log("---- Default")
   end
end

local function get_filepath(ctx, filename, key)
    if key then
        return string.format("%s\\%s\\%s", fileroot, Entrance, filename)
    end
end

function init(ctx)
    if fileroot:sub(1,1)=='.' then
        fileroot = ctx.sider_dir .. fileroot
    end
	math.randomseed(os.time())
    ctx.register("set_teams", set_random)
    ctx.register("trophy_rewrite", trophy_rewrite)
    ctx.register("livecpk_make_key", make_key)
    ctx.register("livecpk_get_filepath", get_filepath)
end

return { init = init }
