Skip to content

Commit

Permalink
Added general support for trinkets
Browse files Browse the repository at this point in the history
Added trinket list and detail views
  • Loading branch information
O-Nemet committed Aug 19, 2024
1 parent b1dc026 commit d964587
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
/images/minions/*_render.png
/images/rewards/*_render.png
/images/spells/*_render.png
/images/trinkets/*_render.png
/images/quests/*_render.png
*.csv
107 changes: 107 additions & 0 deletions bgjson/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,110 @@
echo 'Spells select failed: (' . $mysqli->errno . ') ' . $mysqli->error . '<br>';
}

// generate trinkets files
if ($stmt = $mysqli->prepare("SELECT bgt.id,
bgt.name,
bgt.turn,
bgt.cost,
bgt.text,
bgt.id_blizzard,
bgt.id_playhs,
bgt.id_hpwn,
bgt.flag_active,
bgt.flag_duos
FROM bg_trinkets bgt
-- WHERE bgh.flag_active = ?
ORDER BY bgt.tier, bgt.cost ASC")) {
#$stmt->bind_param("i", $getActiveOnly);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id, $name, $tier, $cost, $text, $blizzardId, $playhsId, $hpwnId, $isActive, $isDuosOnly);

$row_count = $stmt->num_rows;

$csvHeader =
'Name' . CSV_SEPARATOR .
'Turn' . CSV_SEPARATOR .
'Cost' . CSV_SEPARATOR .
'Text' . CSV_SEPARATOR .
'Blizzard ID' . CSV_SEPARATOR .
'Picture link' . CSV_SEPARATOR .
'Active' . CSV_SEPARATOR .
'Duos only' . PHP_EOL;
$csvDataTrinkets = $csvHeader;
$csvDataTrinketsActive = $csvHeader;
$csvData = '';

// json metadata
$trinkets['meta']['date'] = date("Y-m-d");
$trinkets['meta']['version'] = VERSION;
$trinketsActive['meta']['date'] = date("Y-m-d");
$trinketsActive['meta']['version'] = VERSION;

$i = 0;
$j = 0;
while ($stmt->fetch()) {
$csvData =
$name . CSV_SEPARATOR .
$turn . CSV_SEPARATOR .
$cost . CSV_SEPARATOR .
(str_contains($text, ';') ? '"' . $text . '"' : $text) . CSV_SEPARATOR .
$blizzardId . CSV_SEPARATOR .
PICTURE_URL_RENDER_BG . $blizzardId . '.png' . CSV_SEPARATOR .
(bool)$isActive . CSV_SEPARATOR .
(bool)$isDuosOnly . PHP_EOL;

$csvDataTrinkets .= $csvData;

$trinkets['data'][$i]['name'] = $name;
$trinkets['data'][$i]['turn'] = $turn;
$trinkets['data'][$i]['cost'] = $cost;
$trinkets['data'][$i]['text'] = $text;
$trinkets['data'][$i]['id'] = $blizzardId;
$trinkets['data'][$i]['picture'] = PICTURE_URL_RENDER_BG . $blizzardId . '.png';
// $trinkets['data'][$i]['pictureSmall'] = PICTURE_LOCAL_HERO . $blizzardId . PICTURE_LOCAL_RENDER_SUFFIX_80;
$trinkets['data'][$i]['websites']['blizzard'] = ($playhsId ? URL_PHS . $playhsId : null);
$trinkets['data'][$i]['websites']['bgknowhow'] = URL_BKH . 'spell/?id=' . $id;
$trinkets['data'][$i]['websites']['wiki'] = URL_HSF . str_replace(' ', '_', $name);
$trinkets['data'][$i]['websites']['hearthpwn'] = ($hpwnId ? URL_HPN . $hpwnId : null);
$trinkets['data'][$i]['isActive'] = (bool)$isActive;
$trinkets['data'][$i]['isDuosOnly'] = (bool)$isDuosOnly;

if ($isActive) {
$csvDataTrinketsActive .= $csvData;
$trinketsActive['data'][$j] = $trinkets['data'][$i];

$j++;
}

$i++;
}

$stmt->free_result();
$stmt->close();

$csvFile = 'output/bg_trinkets_all.csv';
file_put_contents($csvFile, $csvDataTrinkets);
echo 'Written file ' . $csvFile . ' with ' . $i . ' entries.<br>' . PHP_EOL;

$csvFile = 'output/bg_trinkets_active.csv';
file_put_contents($csvFile, $csvDataTrinketsActive);
echo 'Written file ' . $csvFile . ' with ' . $j . ' entries.<br>' . PHP_EOL;

$jsonFile = 'output/bg_trinkets_all.json';
$jsonData = json_encode($trinkets);
file_put_contents($jsonFile, $jsonData);
echo 'Written file ' . $jsonFile . ' with ' . $i . ' entries.<br>' . PHP_EOL;

$jsonData = json_encode($trinketsActive);
$jsonFile = 'output/bg_trinkets_active.json';
file_put_contents($jsonFile, $jsonData);
echo 'Written file ' . $jsonFile . ' with ' . $j . ' entries.<br>' . PHP_EOL;

} else {
echo 'Trinkets select failed: (' . $mysqli->errno . ') ' . $mysqli->error . '<br>';
}


// json metadata
$allEntities['meta']['date'] = date("Y-m-d");
Expand All @@ -898,6 +1002,7 @@
$allEntities['data']['rewards'] = $rewards['data'];
$allEntities['data']['anomalies'] = $anomalies['data'];
$allEntities['data']['spells'] = $spells['data'];
$allEntities['data']['trinkets'] = $trinkets['data'];

$jsonFile = 'output/bg_entities_all.json';
$jsonData = json_encode($allEntities);
Expand All @@ -915,6 +1020,7 @@
unset($rewardsActive['meta']);
unset($anomaliesActive['meta']);
unset($spellsActive['meta']);
unset($trinketsActive['meta']);

$allEntitiesActive['data']['heroes'] = $heroesActive['data'];
$allEntitiesActive['data']['minions'] = $minionsActive['data'];
Expand All @@ -923,6 +1029,7 @@
@$allEntitiesActive['data']['rewards'] = $rewardsActive['data'];
@$allEntitiesActive['data']['anomalies'] = $anomaliesActive['data'];
@$allEntitiesActive['data']['spells'] = $spellsActive['data'];
@$allEntitiesActive['data']['trinkets'] = $trinketsActive['data'];

$jsonFile = 'output/bg_entities_active.json';
$jsonData = json_encode($allEntitiesActive);
Expand Down
25 changes: 16 additions & 9 deletions bgjson/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@
<tr>
<td><a href="/bgjson/output/bg_heroes_active.json"><i class="bi bi-file-earmark-arrow-down"></i> Active Heroes</a></td>
<td><a href="/bgjson/output/bg_minions_active.json"><i class="bi bi-file-earmark-arrow-down"></i> Active Minions</a></td>
<td><a href="/bgjson/output/bg_buddies_active.json"><i class="bi bi-file-earmark-arrow-down"></i> Active Buddies</a></td>
<td><a href="/bgjson/output/bg_spells_active.json"><i class="bi bi-file-earmark-arrow-down"></i> Active Spells</a></td>
<!-- <td><a href="/bgjson/output/bg_buddies_active.json"><i class="bi bi-file-earmark-arrow-down"></i> Active Buddies</a></td>-->
<!-- <td><a href="/bgjson/output/bg_quests_active.json"><i class="bi bi-file-earmark-arrow-down"></i> Active Quests</a></td>-->
<!-- <td><a href="/bgjson/output/bg_rewards_active.json"><i class="bi bi-file-earmark-arrow-down"></i> Active Rewards</a></td>-->
<!-- <td><a href="/bgjson/output/bg_anomalies_active.json"><i class="bi bi-file-earmark-arrow-down"></i> Active Anomalies</a></td>-->
<td><a href="/bgjson/output/bg_spells_active.json"><i class="bi bi-file-earmark-arrow-down"></i> Active Spells</a></td>
<td><a href="/bgjson/output/bg_trinkets_active.json"><i class="bi bi-file-earmark-arrow-down"></i> Active Trinkets</a></td>
</tr>
</tbody>
</table>
Expand All @@ -62,21 +63,22 @@
<table class="format-table">
<thead>
<tr>
<th colspan="7">JSON format (all)</th>
<th colspan="8">JSON format (all)</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7"><a href="/bgjson/output/bg_entities_all.json"><i class="bi bi-file-earmark-arrow-down-fill"></i> All Battlegrounds Entities</a></td>
<td colspan="8"><a href="/bgjson/output/bg_entities_all.json"><i class="bi bi-file-earmark-arrow-down-fill"></i> All Battlegrounds Entities</a></td>
</tr>
<tr>
<td><a href="/bgjson/output/bg_heroes_all.json"><i class="bi bi-file-earmark-arrow-down"></i> All Heroes</a></td>
<td><a href="/bgjson/output/bg_minions_all.json"><i class="bi bi-file-earmark-arrow-down"></i> All Minions</a></td>
<td><a href="/bgjson/output/bg_spells_all.json"><i class="bi bi-file-earmark-arrow-down"></i> All Spells</a></td>
<td><a href="/bgjson/output/bg_buddies_all.json"><i class="bi bi-file-earmark-arrow-down"></i> All Buddies</a></td>
<td><a href="/bgjson/output/bg_quests_all.json"><i class="bi bi-file-earmark-arrow-down"></i> All Quests</a></td>
<td><a href="/bgjson/output/bg_rewards_all.json"><i class="bi bi-file-earmark-arrow-down"></i> All Rewards</a></td>
<td><a href="/bgjson/output/bg_anomalies_all.json"><i class="bi bi-file-earmark-arrow-down"></i> All Anomalies</a></td>
<td><a href="/bgjson/output/bg_spells_all.json"><i class="bi bi-file-earmark-arrow-down"></i> All Spells</a></td>
<td><a href="/bgjson/output/bg_trinkets_all.json"><i class="bi bi-file-earmark-arrow-down"></i> All Trinkets</a></td>
</tr>
</tbody>
</table>
Expand All @@ -94,11 +96,12 @@
<tr>
<td><a href="/bgjson/output/bg_heroes_active.csv"><i class="bi bi-file-earmark-arrow-down"></i> Active Heroes</a></td>
<td><a href="/bgjson/output/bg_minions_active.csv"><i class="bi bi-file-earmark-arrow-down"></i> Active Minions</a></td>
<td><a href="/bgjson/output/bg_buddies_active.csv"><i class="bi bi-file-earmark-arrow-down"></i> Active Buddies</a></td>
<td><a href="/bgjson/output/bg_spells_active.csv"><i class="bi bi-file-earmark-arrow-down"></i> Active Spells</a></td>
<!-- <td><a href="/bgjson/output/bg_buddies_active.csv"><i class="bi bi-file-earmark-arrow-down"></i> Active Buddies</a></td>-->
<!-- <td><a href="/bgjson/output/bg_quests_active.csv"><i class="bi bi-file-earmark-arrow-down"></i> Active Quests</a></td>-->
<!-- <td><a href="/bgjson/output/bg_rewards_active.csv"><i class="bi bi-file-earmark-arrow-down"></i> Active Rewards</a></td>-->
<!-- <td><a href="/bgjson/output/bg_anomalies_active.csv"><i class="bi bi-file-earmark-arrow-down"></i> Active Anomalies</a></td>-->
<td><a href="/bgjson/output/bg_spells_active.csv"><i class="bi bi-file-earmark-arrow-down"></i> Active Spells</a></td>
<td><a href="/bgjson/output/bg_trinkets_active.csv"><i class="bi bi-file-earmark-arrow-down"></i> Active Trinkets</a></td>
</tr>
</tbody>
</table>
Expand All @@ -109,18 +112,19 @@
<table class="format-table">
<thead>
<tr>
<th colspan="7">CSV format (all)</th>
<th colspan="8">CSV format (all)</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="/bgjson/output/bg_heroes_all.csv"><i class="bi bi-file-earmark-arrow-down"></i> All Heroes</a></td>
<td><a href="/bgjson/output/bg_minions_all.csv"><i class="bi bi-file-earmark-arrow-down"></i> All Minions</a></td>
<td><a href="/bgjson/output/bg_spells_all.csv"><i class="bi bi-file-earmark-arrow-down"></i> All Spells</a></td>
<td><a href="/bgjson/output/bg_buddies_all.csv"><i class="bi bi-file-earmark-arrow-down"></i> All Buddies</a></td>
<td><a href="/bgjson/output/bg_quests_all.csv"><i class="bi bi-file-earmark-arrow-down"></i> All Quests</a></td>
<td><a href="/bgjson/output/bg_rewards_all.csv"><i class="bi bi-file-earmark-arrow-down"></i> All Rewards</a></td>
<td><a href="/bgjson/output/bg_anomalies_all.csv"><i class="bi bi-file-earmark-arrow-down"></i> All Anomalies</a></td>
<td><a href="/bgjson/output/bg_spells_all.csv"><i class="bi bi-file-earmark-arrow-down"></i> All Spells</a></td>
<td><a href="/bgjson/output/bg_trinkets_all.csv"><i class="bi bi-file-earmark-arrow-down"></i> All Trinkets</a></td>
</tr>
</tbody>
</table>
Expand All @@ -131,6 +135,9 @@
<p class="caption"><u>Latest Changes:</u></p>
<br>
<ul id="latest_changes">
<li>20.08.2024 - Added BG changes from the <a href="https://hearthstone.blizzard.com/en-us/news/24122902/30-2-patch-notes" target="_blank">30.2.0</a> patch notes</li>
<li>09.08.2024 - Added BG changes from the <a href="https://hearthstone.blizzard.com/en-us/news/24125212/30-0-3-patch-notes" target="_blank">30.0.3</a> patch notes</li>
<li>23.07.2024 - Added BG changes from the <a href="https://us.forums.blizzard.com/en/hearthstone/t/3001-hotfix-patch/131943" target="_blank">30.0.1</a> patch notes</li>
<li>27.06.2024 - Added BG changes from the <a href="https://hearthstone.blizzard.com/en-us/news/24108515/29-6-2-patch-notes" target="_blank">29.6.2</a> patch notes</li>
<li>21.06.2024 - Added BG armor changes from the <a href="https://us.forums.blizzard.com/en/hearthstone/t/2961-patch-notes/130456" target="_blank">29.6.1</a> patch notes</li>
<li>18.06.2024 - Added flag isDuosOnly to the buddy dataset.</li>
Expand Down
43 changes: 43 additions & 0 deletions bgstrategy/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,49 @@
<?php
}

if ($show == 'trinkets' || $show == 'all') {
echo '<h2 class="page_title">Trinkets</h2>';
echo '<p>Trinkets are special passive power-ups that you buy with Gold and use for the rest of the game. Trinkets are offered twice per game: on turns 6 and 9. Each offering, you’ll get 4 Trinkets to choose from. In total, there are 56 Lesser Trinkets (turn 6) and 60 Greater Trinkets (turn 9). Some Trinkets have a Lesser and a Greater version--letting you diversify or double-up on your effects.<br></p>';
}

if ($show == 'trinkets' && $mode == 'gfx') {
echo "<div class='strategy-images trinkets cf'>";
foreach ($trinkets as $trinket) {
echo "<a href='" . $trinket->websites->bgknowhow . "'><div class='image-container'><img width='256' height='333' src='" . PICTURE_LOCAL_trinket . $trinket->id . PICTURE_LOCAL_RENDER_SUFFIX_80 . "' class='" . (!$trinket->isActive ? 'inactive-img' : '') . "' alt='" . htmlspecialchars($trinket->name, ENT_QUOTES, 'utf-8') . ": " . htmlspecialchars($trinket->text, ENT_QUOTES, 'utf-8') . "'><span>" . $trinket->name . "</span>";
if ($trinket->isDuosOnly) {
echo "<div class='overlay-duo'><img src='" . PICTURE_LOCAL . "icons/duos.webp' title='Available only in Duos mode' alt='Duos only'></div>";
}
echo "</div></a>";
}
echo "</div><br><br>";
} else if ($show == 'trinkets' || $show == 'all') {
?>
<br>
<table class="strategy-table">
<thead>
<tr>
<th colspan="2">Trinkets</th>
</tr>
<tr>
<th>Name</th>
<th>Text</th>
</tr>
</thead>
<tbody>
<?php
foreach ($trinkets as $trinket) {
echo '<tr style="cursor: pointer;" onclick="window.location.href=\'' . $trinket->websites->bgknowhow . '\'">';
echo "<td>$trinket->name</td>";
echo "<td class='text' title='" . htmlspecialchars($trinket->text, ENT_QUOTES, 'utf-8') . "'>$trinket->text</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<br>
<?php
}

if ($show == 'quests' || $show == 'all') {
echo '<h2 class="page_title">Quests</h2>';
echo '<p>Quests are offered at the beginning of turn 4 (6 gold). The quest texts utilize placeholders like {0} (for example in the text "Spend {0} Gold."), which are replaced by an actual numeric value based on the armor value of the hero you are playing (heroes with more base armor will receive easier to complete quests) and the minion types in the lobby. The baseline value for each quest is documented on the details page. Finishing a quest will provide you with the attached <a href="/bgstrategy/?show=rewards">reward</a>.</p>';
Expand Down
45 changes: 45 additions & 0 deletions bgstrategy/trinket/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
include_once('../../header.php');
?>

<?php
// insert vote
include_once('../strategy_handling.php');
?>

<?php
// update votes
if ($selectedStrat && $selectedVote) {
setVote($selectedStrat, $selectedVote);
}

// get data
if ($selectedId) {
$stmt = getEntityData($selectedId, $unitType);

$stmt->bind_result($selectedId, $name, $turn, $cost, $text, $blizzardId, $isActive, $artist);

$stmt->fetch()
?>
<div class="card_wrapper">
<h1 class="cardname"><?= $name ?> <?= $isActive === 0 ? '[inactive]' : '' ?></h1>
<div class="card_picture_big2">
<img src="<?= PICTURE_LOCAL_TRINKET . $blizzardId . PICTURE_LOCAL_BIG_SUFFIX ?>" alt="The picture of <?= $name ?>">
</div>
<div class="card_info">
<?= $artist ? 'Artist:' : '' ?> <span class="price_font"><?= $artist ?? '' ?></span><br><br>
</div>
<div class="card_picture">
<img src="<?= PICTURE_LOCAL_TRINKET . $blizzardId . PICTURE_LOCAL_RENDER_SUFFIX_80 ?>" alt="<?= $text ?>">
</div>
</div>

<?php
include_once('../strategy_and_voting.php');
}
?>

</div> <!-- / content -->
<?php
include_once('../../footer.php');
?>
21 changes: 21 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
const FILE_MINIONS = 'https://bgknowhow.com/bgjson/output/bg_minions_all.json';
const FILE_ANOMALIES = 'https://bgknowhow.com/bgjson/output/bg_anomalies_all.json';
const FILE_SPELLS = 'https://bgknowhow.com/bgjson/output/bg_spells_all.json';
const FILE_TRINKETS = 'https://bgknowhow.com/bgjson/output/bg_trinkets_all.json';
const FILE_BUDDIES = 'https://bgknowhow.com/bgjson/output/bg_buddies_all.json';
const FILE_QUESTS = 'https://bgknowhow.com/bgjson/output/bg_quests_all.json';
const FILE_REWARDS = 'https://bgknowhow.com/bgjson/output/bg_rewards_all.json';
Expand All @@ -37,6 +38,7 @@
const PICTURE_LOCAL_BUDDY = IMG_PATH . 'buddies/';
const PICTURE_LOCAL_ANOMALY = IMG_PATH . 'anomalies/';
const PICTURE_LOCAL_SPELL = IMG_PATH . 'spells/';
const PICTURE_LOCAL_TRINKET = IMG_PATH . 'trinkets/';
const PICTURE_LOCAL_QUEST = IMG_PATH . 'quests/';
const PICTURE_LOCAL_REWARD = IMG_PATH . 'rewards/';
const PICTURE_LOCAL_MINION = IMG_PATH . 'minions/';
Expand Down Expand Up @@ -69,6 +71,7 @@
$tempMinions = json_decode(file_get_contents(FILE_MINIONS));
$tempAnomalies = json_decode(file_get_contents(FILE_ANOMALIES));
$tempSpells = json_decode(file_get_contents(FILE_SPELLS));
$tempTrinkets = json_decode(file_get_contents(FILE_TRINKETS));
$tempBuddies = json_decode(file_get_contents(FILE_BUDDIES));
$tempQuests = json_decode(file_get_contents(FILE_QUESTS));
$tempRewards = json_decode(file_get_contents(FILE_REWARDS));
Expand Down Expand Up @@ -195,6 +198,8 @@ function getWebsiteTitle(): string
$title .= 'Strategy Minions';
} else if (strpos($page, '/bgstrategy/show=spells') !== false) {
$title .= 'Strategy Spells';
} else if (strpos($page, '/bgstrategy/show=trinkets') !== false) {
$title .= 'Strategy Trinkets';
} else if (strpos($page, '/bgstrategy/show=anomalies') !== false) {
$title .= 'Strategy Anomalies';
} else if (strpos($page, '/bgstrategy/show=buddies') !== false) {
Expand Down Expand Up @@ -311,6 +316,22 @@ function getEntityData($selectedId, $unitType)
$stmt->execute();
$stmt->store_result();
}
} else if ($unitType == 'trinket') {
if ($stmt = $mysqli->prepare("SELECT bgt.id,
bgt.name,
bgt.turns,
bgt.cost,
bgt.text,
bgt.id_blizzard,
bgt.flag_active,
bgt.artist
FROM bg_trinkets bgt
WHERE bgt.id = ?
LIMIT 1")) {
$stmt->bind_param("i", $selectedId);
$stmt->execute();
$stmt->store_result();
}
} else if ($unitType == 'minion') {
if ($stmt = $mysqli->prepare("SELECT bgm.id,
bgm.name,
Expand Down
Loading

0 comments on commit d964587

Please sign in to comment.