-
-
Notifications
You must be signed in to change notification settings - Fork 25
DataDragonAPI: Usage example
Daniel Dolejška edited this page Aug 26, 2019
·
8 revisions
Version v3.0.0-rc.1
Let's show Orianna's loading screen image without skin and with Dark Star skin.
Source:
echo DataDragonAPI::getChampionLoading('Orianna');
echo DataDragonAPI::getChampionLoading('Orianna', 7);
Output:
<img alt="Orianna" class="dd-icon dd-loading" src="http://ddragon.leagueoflegends.com/cdn/img/champion/loading/Orianna_0.jpg">
<img alt="Orianna" class="dd-icon dd-loading" src="http://ddragon.leagueoflegends.com/cdn/img/champion/loading/Orianna_7.jpg">
Render:
Now, let's take a look at some spells:
Source:
use RiotAPI\DataDragonAPI\DataDragonAPI;
DataDragonAPI::initByCdn();
echo DataDragonAPI::getSpellIcon('SummonerFlash');
echo DataDragonAPI::getSpellIcon('OriannaDetonateCommand');
echo DataDragonAPI::getSpellIcon('EzrealR');
Output:
<img alt="SummonerFlash" class="dd-icon dd-spell" src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/SummonerFlash.png">
<img alt="OrianaDetonateCommand" class="dd-icon dd-spell" src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/OrianaDetonateCommand.png">
<img alt="EzrealR" class="dd-icon dd-spell" src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/EzrealR.png">
Render:
...a bit of nostalgia?
Source:
use RiotAPI\DataDragonAPI\DataDragonAPI;
DataDragonAPI::initByVersion('0.151.2');
echo DataDragonAPI::getItemIcon(3132);
echo DataDragonAPI::getItemIcon(3126);
echo DataDragonAPI::getItemIcon(3138);
Output:
<img alt="3132" class="dd-icon dd-item" src="http://ddragon.leagueoflegends.com/cdn/0.151.2/img/item/3132.png">
<img alt="3126" class="dd-icon dd-item" src="http://ddragon.leagueoflegends.com/cdn/0.151.2/img/item/3126.png">
<img alt="3138" class="dd-icon dd-item" src="http://ddragon.leagueoflegends.com/cdn/0.151.2/img/item/3138.png">
Render:
By specifying DataDragonAPI::SET_CUSTOM_IMG_ATTRS
, we can add attributes to all generated <img>
tags.
By specifying $attributes
as well (specified when calling the function), we can override values set in DataDragonAPI::SET_CUSTOM_IMG_ATTRS
. Only class
attribute is concatenated and not overridden.
Source:
use RiotAPI\DataDragonAPI\DataDragonAPI;
DataDragonAPI::initByCdn([
DataDragonAPI::SET_CUSTOM_IMG_ATTRS => [
'class' => 'class1 class2',
'data-toggle' => 'tooltip',
'title' => 'Default title',
]
]);
// no extra attributes
echo DataDragonAPI::getSpellIcon('SummonerFlash');
// one more class
echo DataDragonAPI::getSpellIcon('SummonerFlash', [
'class' => 'class3',
]);
// overriding preset attributes
echo DataDragonAPI::getSpellIcon('SummonerFlash', [
'alt' => 'Spell Flash',
'title' => 'Flash',
]);
Output:
<img alt="SummonerFlash" class="dd-icon dd-icon-spell" src="https://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/SummonerFlash.png">
<img alt="SummonerFlash" class="dd-icon dd-icon-spell class3" src="https://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/SummonerFlash.png">
<img alt="Spell Flash" title="Flash" class="dd-icon dd-icon-spell" src="https://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/SummonerFlash.png">
Render:
DataDragonAPI
can use result objects from RiotAPI
to easily render some assets.
Source:
use RiotAPI\LeagueAPI\LeagueAPI;
use RiotAPI\DataDragonAPI\DataDragonAPI;
$api = new LeagueAPI([...]);
DataDragonAPI::initByApi($api); // you can init by anything else
$orianna = $api->getStaticChampion(61, true);
echo DataDragonAPI::getChampionSplashO($orianna);
echo "<br>";
foreach($orianna->spells as $spell)
echo DataDragonAPI::getChampionSpellIconO($spell);
Output:
<img alt="Orianna" class="dd-icon dd-icon-champ " src="https://ddragon.leagueoflegends.com/cdn/8.24.1/img/champion/Orianna.png">
<br>
<img src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/OrianaIzunaCommand.png" class="dd-icon dd-spell" alt="OrianaIzunaCommand">
<img src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/OrianaDissonanceCommand.png" class="dd-icon dd-spell" alt="OrianaDissonanceCommand">
<img src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/OrianaRedactCommand.png" class="dd-icon dd-spell" alt="OrianaRedactCommand">
<img src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/OrianaDetonateCommand.png" class="dd-icon dd-spell" alt="OrianaDetonateCommand">
Render:
More usage examples for DataDragonAPI can be found here.