level editor functional

This commit is contained in:
Hash Borgir 2023-09-10 20:02:58 -06:00
parent 59c8e1ecfe
commit 974de24f6f
8 changed files with 144 additions and 163 deletions

View File

@ -76,11 +76,10 @@ unset($output[0]);
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Level Viz/Warp Editor</title> <title>Level Viz/Warp Editor</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <link rel="stylesheet" href="/res/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="/res/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> <script src="/res/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> <script src="/res/bootstrap.min.js"></script>
<style> <style>
.viz { .viz {
background-color: #fafafa; background-color: #fafafa;
@ -136,7 +135,6 @@ unset($output[0]);
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<script> <script>
$("select[name^='Vis'], select[name^='Warp']").change(function () { $("select[name^='Vis'], select[name^='Warp']").change(function () {
var levelId = $(this).data('id'); var levelId = $(this).data('id');

View File

@ -47,7 +47,10 @@ header("Content-Type: text/html");
<html> <html>
<head> <head>
<title>Drop Chances Table</title> <title>Drop Chances Table</title>
<script src="https://code.jquery.com/jquery-3.7.0.min.js" integrity="sha256-2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g=" crossorigin="anonymous"></script> <link rel="stylesheet" href="/res/bootstrap.min.css">
<script src="/res/jquery-3.5.1.min.js"></script>
<script src="/res/popper.min.js"></script>
<script src="/res/bootstrap.min.js"></script>
<script> <script>
$(document).ready(function () { $(document).ready(function () {
$('input.no-drop, input.prob').on('input', function () { $('input.no-drop, input.prob').on('input', function () {

5
res/popper.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -42,6 +42,70 @@
*/ */
function writeToTsvFile($tsvFileName, $db = DB_FILE) {
$tsvFilePath = $_SESSION['path'] . '/' . $tsvFileName . '.txt';
// Open the file for writing
$fileHandle = fopen($tsvFilePath, 'w');
if (!$fileHandle) {
return "Error opening file for writing.";
}
// Query to select all rows from the treasureclassex table
$query = "SELECT * FROM $tsvFileName";
// Execute the query
$result = $db->query($query);
if (!$result) {
fclose($fileHandle);
return "Error executing query.";
}
// Write the column headers to the file
$columnNames = [];
for ($i = 0; $i < $result->numColumns(); $i++) {
$columnNames[] = $result->columnName($i);
}
fwrite($fileHandle, implode("\t", $columnNames) . "\n");
// Write the rows to the file
while ($row = $result->fetchArray(SQLITE3_NUM)) {
fwrite($fileHandle, implode("\t", $row) . "\n");
}
// Close the file
fclose($fileHandle);
return "Successfully updated and written to TSV file!";
}
function exportSQLiteTableToTSV($tablename) {
$bin = "../bin/sqlite3.exe";
$dbfile = DB_FILE;
// Generate the output file name based on the tablename
$outputFile = $_SESSION['path'] . $tablename . ".txt";
// Build the command to export the SQLite table to a TSV file
$command = sprintf(
'%s %s ".mode tabs" ".headers on" "SELECT * FROM %s;" > "%s"',
escapeshellarg($bin),
escapeshellarg($dbfile),
escapeshellarg($tablename),
escapeshellarg($outputFile)
);
// Execute the command
$commandOutput = shell_exec($command);
if ($commandOutput) {
return "Error: $commandOutput";
} else {
return "Table exported successfully!";
}
}
/** /**
* @param $var * @param $var
* @return void * @return void

View File

@ -1,11 +1,8 @@
<div class="Doc-container"> <div class="Doc-container">
<div class="container"> <div class="container">
<h2>Generate Documentation</h2>
<div class="row"> <div class="row">
<div style="text-align: center; padding: 10px; margin-top: 20px;" class="col Doc-UniqueItems"> <div style="text-align: center; padding: 10px; margin-top: 20px;" class="col Doc-UniqueItems">
<div class="container"> <div class="container">
<div class="form-group row"> <div class="form-group row">
@ -31,8 +28,11 @@
<div class="col Doc-Misc"><?php require_once "Misc.php"; ?></div> <div class="col Doc-Misc"><?php require_once "Misc.php"; ?></div>
<div class="col Doc-Armor"><?php require_once "Armor.php"; ?></div> <div class="col Doc-Armor"><?php require_once "Armor.php"; ?></div>
<div class="col Doc-Weapons"><?php require_once "Weapons.php"; ?></div> <div class="col Doc-Weapons"><?php require_once "Weapons.php"; ?></div>
</div>
<h2>Various Editors</h2>
<div class="row">
<div class="col Doc-TCEX"><?php require_once "TC.php"; ?></div> <div class="col Doc-TCEX"><?php require_once "TC.php"; ?></div>
<div class="col Doc-Levels"><?php require_once "Levels.php"; ?></div>
</div> </div>
</div> </div>

59
src/tabs/Levels.php Normal file
View File

@ -0,0 +1,59 @@
<?php
/*
Copyright (C) 2021 Hash Borgir
This file is part of D2Modder
Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY!
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
?>
<div style="text-align: center; margin-top: 20px;">
<div class="container">
<div class="form-group row">
<div class="" style="text-align: center; margin: 0 auto;">
<a style="margin-top: 60px; text-align: center;" target="_blank" href="/LevelsEditor.php" class="">
<div style="height: 100px;">
<img style="height: 100px;" class="img-fluid" src="/img/loading_.gif">
</div>
</a>
</div>
</div>
<!-- <a class="btn btn-warning" target="_blank" href="/genDocs.php?cmd=genDocCube">Generate</a> -->
<p>Levels.txt Vis/Warp Editor</p>
</div>
</div>

View File

@ -45,7 +45,7 @@ foreach ($res as $key => $item) {
$newItem = []; $newItem = [];
$newItem['LevelName'] = $item['LevelName']; // Copy the LevelName to new item $newItem['LevelName'] = $item['LevelName']; // Copy the LevelName to new item
foreach ($levelsAll[$key] as $levelsKey => $levelsValue) { foreach ($levelsAll[$key] as $levelsKey => $levelsValue) {
//$newItem[$levelsKey] = isset($monstats[$levelsValue]) ? $monstats[$levelsValue] : $levelsValue; $newItem[$levelsKey] = isset($monstats[$levelsValue]) ? $monstats[$levelsValue] : $levelsValue;
} }
@ -97,7 +97,7 @@ ddump($output);
echo "<table id='myTable' class='table table-bordered table-striped'>"; echo "<table id='myTable' class='table table-bordered table-striped'>";
// Display table headers with Bootstrap styling // Display table headers with Bootstrap styling
$headers = ['Id', 'Name', 'LevelName', "", "", "", ""]; $headers = ['Id', 'Name', 'LevelName'];
for ($i = 0; $i < 8; $i++) { for ($i = 0; $i < 8; $i++) {
$headers[] = "Vis" . $i; $headers[] = "Vis" . $i;
} }

148
test2.php
View File

@ -1,148 +0,0 @@
<?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>