mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2024-11-30 12:36:03 +00:00
testing lvl editor
This commit is contained in:
parent
7b3869530f
commit
b26715aea2
148
test2.php
Normal file
148
test2.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
session_start();
|
||||
ob_start();
|
||||
|
||||
require_once './config.php';
|
||||
require_once './_pdo.php';
|
||||
|
||||
require_once './config.php';
|
||||
require_once './src/D2Functions.php';
|
||||
require_once './src/D2ByteReader.php';
|
||||
require_once './src/D2BitReader.php';
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(-1);
|
||||
ini_set('max_input_time', '-1');
|
||||
ini_set('max_execution_time', '0');
|
||||
|
||||
define('DB_FILE', $_SESSION['modname'] . ".db");
|
||||
try {
|
||||
PDO_Connect("sqlite:" . DB_FILE);
|
||||
} catch (Exception $e) {
|
||||
echo "Connection error: " . $e->getMessage();
|
||||
}
|
||||
|
||||
$query = "SELECT Id,LevelName FROM levels";
|
||||
$levels = PDO_FetchAssoc($query);
|
||||
|
||||
$query = "SELECT * FROM levels";
|
||||
$levelsAll = PDO_FetchAll($query);
|
||||
|
||||
$query = "SELECT monstats.Id, strings.String AS Name
|
||||
FROM monstats
|
||||
LEFT JOIN strings ON monstats.NameStr = strings.Key;";
|
||||
$monstats = PDO_FetchAssoc($query);
|
||||
|
||||
//ddump($monstats);
|
||||
|
||||
|
||||
$query = "SELECT LevelName,Vis0,Vis1,Vis2,Vis3,Vis4,Vis5,Vis6,Vis7 FROM levels";
|
||||
$res = PDO_FetchAll($query);
|
||||
|
||||
$output = [];
|
||||
|
||||
foreach ($res as $key => $item) {
|
||||
$newItem = [];
|
||||
$newItem['LevelName'] = $item['LevelName']; // Copy the LevelName to new item
|
||||
foreach ($levelsAll[$key] as $levelsKey => $levelsValue) {
|
||||
$newItem[$levelsKey] = isset($monstats[$levelsValue]) ? $monstats[$levelsValue] : $levelsValue;
|
||||
}
|
||||
|
||||
|
||||
$foundLevels = []; // Store found level names to avoid duplicates
|
||||
|
||||
foreach ($item as $subKey => $subItem) {
|
||||
// Check if the key starts with 'Vis', has a corresponding level, is non-empty, and is not a duplicate
|
||||
if (strpos($subKey, 'Vis') === 0 && isset($levels[$subItem]) && $levels[$subItem] !== '' && !in_array($levels[$subItem], $foundLevels)) {
|
||||
$newItem[$subKey] = $subItem;
|
||||
$foundLevels[] = $levels[$subItem]; // Add to found levels
|
||||
}
|
||||
}
|
||||
$output[] = array_filter($newItem); // Add the modified item to the output array
|
||||
}
|
||||
|
||||
|
||||
unset($output[0]);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Levels Table CRUD</title>
|
||||
<!-- Include Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<style>
|
||||
/* Colorize alternate rows */
|
||||
.table-striped tbody tr:nth-child(odd) {
|
||||
background-color: #f2f2f2; /* Alternate row color */
|
||||
}
|
||||
|
||||
/* Colorize alternate columns */
|
||||
.table-striped tbody tr td:nth-child(odd) {
|
||||
background-color: #e6e6e6; /* Alternate column color */
|
||||
}
|
||||
.sticky-top th {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background-color: #ffffff; /* Header background color */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
// Begin the form
|
||||
echo '<form id="levelsVizForm">';
|
||||
|
||||
// Start the HTML table with Bootstrap's table classes
|
||||
echo '<table class="table table-hover table-bordered">';
|
||||
|
||||
// Display table headers
|
||||
$headers = ['Id', 'LevelName', 'Name'];
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$headers[] = "Vis" . $i;
|
||||
}
|
||||
echo "<thead class='thead-light'>";
|
||||
foreach ($headers as $header) {
|
||||
echo "<th>" . $header . "</th>";
|
||||
}
|
||||
echo "</thead>";
|
||||
|
||||
// Display table data
|
||||
echo "<tbody>";
|
||||
foreach ($output as $level) {
|
||||
echo "<tr>";
|
||||
foreach ($headers as $header) {
|
||||
if ($header === 'Id' || $header === 'LevelName' || $header === 'Name') {
|
||||
echo "<td>" . (isset($level[$header]) ? $level[$header] : '') . "</td>";
|
||||
} else {
|
||||
// For the VisX fields, display dropdowns
|
||||
echo "<td>";
|
||||
echo "<select name='{$header}[]' class='form-control vizDropdown' data-id='" . $level['Id'] . "'>";
|
||||
foreach ($levels as $key => $lvl) {
|
||||
$selected = (isset($level[$header]) && $level[$header] == $key) ? "selected" : "";
|
||||
echo "<option value='{$key}' {$selected}>{$key} {$lvl}</option>"; // Note the change here
|
||||
}
|
||||
echo "</select>";
|
||||
echo "</td>";
|
||||
}
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</tbody>";
|
||||
echo '</table>';
|
||||
|
||||
// Close the form
|
||||
echo '</form>';
|
||||
?>
|
||||
|
||||
<!-- Include Bootstrap JS and jQuery -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user